Пример #1
0
        //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;
        }
Пример #2
0
        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;
        }