//private Matrix DoubleArrayToMatrix(double[] m) //{ // return new Matrix(new double[,] { // { m[00], m[04], m[08], m[12] }, // { m[01], m[05], m[09], m[13] }, // { m[02], m[06], m[10], m[14] }, // { m[03], m[07], m[11], m[15] } // }); //} //public Matrix GetGLModelMatrix() //{ // double[] m = new double[16]; // GL.GetDouble(GetPName.ModelviewMatrix, m); // return DoubleArrayToMatrix(m); //} //public Matrix GetGLProjectionMatrix() //{ // double[] m = new double[16]; // GL.GetDouble(GetPName.ProjectionMatrix, m); // return DoubleArrayToMatrix(m); //} #endregion public void Set(Vec3f tar, Quatf rot, float dist) { rot = rot.Normalize(); this.qrot = rot; this.dist = dist; Vec3f _forward = rot.Rotate(Vec3f.Y); Vec3f _up = rot.Rotate(Vec3f.Z); Position = tar - _forward * dist; Scale = 50.0f / dist; Forward = Vec3f.Normalize(_forward); Target = tar; Up = _up; }
/*public void OrbitTargetUpDownNatural( double theta_degrees ) * { * float fn = Forward.Val % NaturalUp.Val; * if( ( theta_degrees < 0.0 && fn >= 0.95f ) || ( theta_degrees > 0.0 && fn <= -0.95f ) ) return; * * double theta = theta_degrees * Math.PI / 180.0; * Vec3f posreltar = Position.Val - Target.Val; * Vec3f right = Forward.Val ^ NaturalUp.Val; * float dist = (Target.Val - Position.Val).Length; * * Properties.DeferPropertyChanged = true; * bIgnoreChanges = true; * Position.Set( Target.Val + Vec3f.Normalize( VecExtensions.RotateVectorAroundAxis( posreltar, right, (float) theta ) ) * dist ); * Up.Set( VecExtensions.RotateVectorAroundAxis( Up.Val, right, (float) theta ) ); * bIgnoreChanges = false; * Target.Set( Target.Val ); * Properties.DeferPropertyChanged = false; * }*/ public void OrbitTargetUpDown(double theta_degrees, bool clampflips) { double theta = theta_degrees * Math.PI / 180.0; Quatf newrot = qrot * Quatf.AxisAngleToQuatf(GetRight(), (float)theta); if (clampflips) { // prevent camera from flipping over! Vec3f newup = Vec3f.Normalize(newrot.Rotate(Vec3f.Y)); float dot = FMath.PI / 2.0f - Vec3f.AngleBetween(newup, NaturalUp.Val); if (dot < 0) { Vec3f newforward = Vec3f.Normalize(newrot.Rotate(-Vec3f.Z)); Vec3f newright = newforward ^ newup; float sign = -Math.Sign(newforward % NaturalUp.Val); newrot = newrot * Quatf.RotAxisAngleToQuatf(newright, dot * sign); } } Set(Target.Val, newrot, dist); }
public void Set(Vec3f tar, Quatf rot, float dist) { rot = rot.Normalize(); /*if( AlwaysUp ) * { * // prevent camera from rolling * Vec3f newright = Vec3f.Normalize( rot.Rotate( Vec3f.X ) ); * Vec3f newup = Vec3f.Normalize( rot.Rotate( Vec3f.Y ) ); * Vec3f newforward = Vec3f.Normalize( rot.Rotate( -Vec3f.Z ) ); * * if( Math.Abs( newforward % NaturalUp ) < 0.95f ) { * Vec3f goodright = Vec3f.Normalize( newforward ^ Vec3f.Z ); * float dot = Vec3f.AngleBetween( goodright, newright ); * System.Console.WriteLine( newup.ToStringFormatted() + " " + newright.ToStringFormatted() + " " + goodright.ToStringFormatted() ); * float sign = -Math.Sign( newright % NaturalUp ); * //rot = rot * Quatf.RotAxisAngleToQuatf( newforward, dot * sign ); * } * }*/ this.qrot = rot; this.dist = dist; Properties.DeferPropertyChanged = true; bIgnoreChanges = true; Vec3f fwd = rot.Rotate(-Vec3f.Z); Vec3f up = rot.Rotate(Vec3f.Y); Position.Set(tar - fwd * dist); Scale.Set(50.0f / dist); Target.Set(tar); Forward.Set(Vec3f.Normalize(fwd)); Up.Set(up); bIgnoreChanges = false; Properties.DeferPropertyChanged = false; }