コード例 #1
0
        /// <summary>
        /// päivitä kameran paikka (6DOF kamera)
        /// </summary>
        public void Update6DOF()
        {
            GL.LoadIdentity();
            MathExt.LookAt(Position, Position + Front, Up);

            GL.GetFloat(GetPName.ModelviewMatrix, CameraMatrix);
        }
コード例 #2
0
 public void LookAt(Vector3 pos)
 {
     GL.LoadIdentity();
     MathExt.LookAt(Position, pos, Up);
 }
コード例 #3
0
        public void UpdatePath(float updateTime)
        {
            Time += updateTime;

            int v1 = (int)Time;
            int v2 = v1 + 1;

            if ((v1 >= path.Length || v2 >= path.Length) && Looping == false)
            {
                return;
            }

            v1 %= path.Length;
            v2 %= path.Length;

            // laske Position reitillä
            Vector3 p1 = path[v1];
            Vector3 p2 = path[v2];
            Vector3 p  = p2 - p1;
            float   d  = Time - (int)Time;

            p *= d;
            attachedObj.Position = p1 + p;

            Vector3 to;

            // laske kohta johon katsotaan
            if (LookAtNextPoint)
            {
                to = (path[(v2 + 1) % path.Length]) - p2;
                to = p2 + (to * d);
                attachedObj.Front = to;
            }
            else
            {
                to = Front;
            }

            // kamera asetetaan heti
            if (attachedObj is Camera)
            {
                GL.LoadIdentity();
                MathExt.LookAt(attachedObj.Position, to, attachedObj.Up);
                GL.GetFloat(GetPName.ModelviewMatrix, Util.ModelMatrix);
                Util.CopyArray(ref Util.ModelMatrix, ref attachedObj.Matrix);
            }
            else
            {
                if (LookAtNextPoint)
                {
                    // otetaan käännetyn objektin matriisi talteen
                    GL.PushMatrix();
                    GL.LoadIdentity();
                    MathExt.LookAt(attachedObj.Position, to, attachedObj.Up);
                    GL.GetFloat(GetPName.ModelviewMatrix, Util.ModelMatrix);

                    //Util.CopyArray(ref Util.ModelMatrix, ref attachedObj.Matrix);
                    //Util.CopyArray(ref Util.ModelMatrix, ref attachedObj.WMatrix);
                    // paikkatiedot nollaks
                    //Matrix[13] = Matrix[14] = Matrix[15] = 0;
                    //WMatrix[13] = WMatrix[14] = WMatrix[15] = 0;

                    GL.PopMatrix();

                    float heading, attitude, bank;
                    MathExt.MatrixToEuler(ref Util.ModelMatrix, out heading, out attitude, out bank);
                    attachedObj.Rotation.Y = heading * MathExt.RadToDeg;
                    attachedObj.Rotation.X = bank * MathExt.RadToDeg;
                    attachedObj.Rotation.Z = attitude * MathExt.RadToDeg;
                }
            }
        }