Example #1
0
        public void updateCameraVectors()
        {
            Vec3f front = new Vec3f();

            front.x = (float)(Math.Cos(Yaw * ONEDEGRAD) * Math.Cos(Pitch * ONEDEGRAD));
            front.x = GeneralVariables.FCMP(0.0f, front.x) ? 0.0f : front.x;

            front.y = (float)(Math.Sin(Pitch * ONEDEGRAD));
            front.y = GeneralVariables.FCMP(0.0f, front.y) ? 0.0f : front.y;

            front.z = (float)(Math.Sin(Yaw * ONEDEGRAD) * Math.Cos(Pitch * ONEDEGRAD));
            front.z = GeneralVariables.FCMP(0.0f, front.z) ? 0.0f : front.z;
            Front   = front.unit();

            Right = Front.cross(WorldUp).normal();
            Up    = Right.cross(Front).normal();
        }
        public static void setDirection(Vec3f dir)
        {
            if (playerVob == null)
            {
                return;
            }

            dir = dir.normalise();

            Process process = Process.ThisProcess();
            zCVob   vob     = playerVob;


            Vec3f zAxis = dir;
            Vec3f up    = new Vec3f(0.0f, 0.0f, 0.0f);

            if (Math.Abs(zAxis.Y) > 0.5)
            {
                if (zAxis.Y > 0)
                {
                    up.Z = -1.0f;
                }
                else
                {
                    up.Z = 1.0f;
                }
            }
            else if (Math.Abs(zAxis.X) < 0.0001 && Math.Abs(zAxis.Y) < 0.0001)
            {
                if (zAxis.Y > -0.0001)
                {
                    up.Y = 1.0f;
                }
                else
                {
                    up.Y = -1.0f;
                }
            }
            else
            {
                up.Y = 1.0f;
            }



            Vec3f xAxis = up.cross(zAxis).normalise();
            Vec3f yAxis = zAxis.cross(xAxis).normalise();

            Matrix4 trafo = vob.TrafoObjToWorld;

            trafo.set(12, 0);
            trafo.set(13, 0);
            trafo.set(14, 0);
            trafo.set(15, 1);

            trafo.set(0, xAxis.X);
            trafo.set(4, xAxis.Y);
            trafo.set(8, xAxis.Z);

            trafo.set(1, yAxis.X);
            trafo.set(5, yAxis.Y);
            trafo.set(9, yAxis.Z);

            trafo.set(2, zAxis.X);
            trafo.set(6, zAxis.Y);
            trafo.set(10, zAxis.Z);


            zVec3 p = vob.GetPosition();

            vob.SetPositionWorld(p);

            p.Dispose();
        }