コード例 #1
0
        public static Matrix PointAtMatrix(Vec3D pos, Vec3D target, Vec3D up)
        {
            // ny frammåt
            Vec3D newForward = target - pos;

            newForward.Normalize();

            // ny uppåt
            Vec3D a     = newForward * Vec3D.Dot(up, newForward);
            Vec3D newUp = up - a;

            newUp.Normalize();

            Vec3D  newRight = Vec3D.Cross(newUp, newForward);
            Matrix mat      = new Matrix();

            mat.m[0, 0] = newRight.x;       mat.m[0, 1] = newRight.y;       mat.m[0, 2] = newRight.z;       mat.m[0, 3] = 0.0f;
            mat.m[1, 0] = newUp.x;          mat.m[1, 1] = newUp.y;          mat.m[1, 2] = newUp.z;          mat.m[1, 3] = 0.0f;
            mat.m[2, 0] = newForward.x; mat.m[2, 1] = newForward.y; mat.m[2, 2] = newForward.z; mat.m[2, 3] = 0.0f;
            mat.m[3, 0] = pos.x;            mat.m[2, 1] = pos.y;            mat.m[2, 2] = pos.z;            mat.m[2, 3] = 1.0f;
            return(mat);
        }
コード例 #2
0
        public override void Create()
        {
            Engine.SetPalette(Palettes.Pico8);
            Engine.SetBackground(0);
            Engine.Borderless();

            Console.Title = "3D Demo";

            mesh.LoadFromObj("monkey.obj");

            consoleWidth  = Engine.WindowSize.X;
            consoleHeight = Engine.WindowSize.Y;

            // projektions matris
            float near        = 0.1f;
            float far         = 1000.0f;
            float fov         = 90.0f;
            float aspectRatio = (float)consoleHeight / (float)consoleWidth;

            projectionMatrix = Matrix.ProjectionMatrix(fov, aspectRatio, near, far);

            // normaliserar ljusriktningen
            lightDirection.Normalize();
        }