Esempio n. 1
0
        public void RunTests()
        {
            Matrix3 a, b;
            DXMtx dxa, dxb;

            a = new Matrix3(3, 1, 2, 1, 1, 2, 2, 3, 1);
            b = new Matrix3(4, 2, 1, 3, 1, 2, 2, 1, 2);
            dxa = new DXMtx();
            dxb = new DXMtx();

            dxa.M11 = 3; dxa.M12 = 1; dxa.M13 = 2;
            dxa.M21 = 1; dxa.M22 = 1; dxa.M23 = 2;
            dxa.M31 = 2; dxa.M32 = 3; dxa.M33 = 1;
            dxb.M11 = 4; dxb.M12 = 2; dxb.M13 = 1;
            dxb.M21 = 3; dxb.M22 = 1; dxb.M23 = 2;
            dxb.M31 = 2; dxb.M32 = 1; dxb.M33 = 2;

            Roll = 45;
            Yaw = 10;
            Pitch = 30;

            TestAdd(a, b, dxa, dxb);
            TestSub(a, b, dxa, dxb);
            TestMul(a, b, dxa, dxb);
            TestTranspose(a, dxa);
            TestInvert(a, dxa);
            TestRotations();

            PrintResults(a, b);
        }
Esempio n. 2
0
        public void RunTests()
        {
            Matrix2 a, b;
            DXMtx dxa, dxb;

            a = new Matrix2(1, 2, 2, 1);
            b = new Matrix2(3, 1, 4, 2);
            dxa = new DXMtx();
            dxb = new DXMtx();
            dxa.M11 = 1;
            dxa.M12 = 2;
            dxa.M21 = 2;
            dxa.M22 = 1;
            dxa.M33 = 1;
            dxa.M44 = 1;
            dxb.M11 = 3;
            dxb.M12 = 1;
            dxb.M21 = 4;
            dxb.M22 = 2;
            RotationAngle = (float)(30 * Math.PI / 180);

            TestAdd(a, b, dxa, dxb);
            TestSub(a, b, dxa, dxb);
            TestMul(a, b, dxa, dxb);
            TestTranspose(a, dxa);
            TestInvert(a, dxa);
            TestRotation();

            PrintResults(a, b);
        }
Esempio n. 3
0
 public static Matrix ConvertFrom(Microsoft.DirectX.Matrix value)
 {
     return(new Matrix()
     {
         M11 = value.M11, M12 = value.M12, M13 = value.M13, M14 = value.M14,
         M21 = value.M21, M22 = value.M22, M23 = value.M23, M24 = value.M24,
         M31 = value.M31, M32 = value.M32, M33 = value.M33, M34 = value.M34,
         M41 = value.M41, M42 = value.M42, M43 = value.M43, M44 = value.M44
     });
 }
Esempio n. 4
0
        /// <summary>
        /// Converts a <see cref="Microsoft.DirectX.Matrix"/> to <see cref="Fusee.Math.Core.Matrix4F"/>.
        /// </summary>
        /// <param name="value">The matrix value to convert.</param>
        /// <returns>A <see cref="Fusee.Math.Core.Matrix4F"/> value.</returns>
        public static Fusee.Math.Core.Matrix4F FromDirectX(Microsoft.DirectX.Matrix value)
        {
            Fusee.Math.Core.Matrix4F m = new Fusee.Math.Core.Matrix4F();
            // Since directx use column-major matrices we transpose the matrix.
            m[0, 0] = value.M11;     m[0, 1] = value.M21;     m[0, 2] = value.M31;     m[0, 2] = value.M41;
            m[1, 0] = value.M12;     m[1, 1] = value.M22;     m[1, 2] = value.M32;     m[1, 2] = value.M42;
            m[2, 0] = value.M13;     m[2, 1] = value.M23;     m[2, 2] = value.M33;     m[2, 2] = value.M43;
            m[3, 0] = value.M14;     m[3, 1] = value.M24;     m[3, 2] = value.M34;     m[3, 2] = value.M44;

            return(m);
        }
Esempio n. 5
0
        /// <summary>
        /// Converts a <see cref="Fusee.Math.Core.Matrix4F"/> to <see cref="Microsoft.DirectX.Matrix"/>.
        /// </summary>
        /// <param name="value">The matrix value to convert.</param>
        /// <returns>A <see cref="Microsoft.DirectX.Matrix"/> value.</returns>
        public static Microsoft.DirectX.Matrix ToDirectX(Fusee.Math.Core.Matrix4F value)
        {
            Microsoft.DirectX.Matrix m = new Microsoft.DirectX.Matrix();
            // Since directx use column-major matrices we transpose our matrix.
            m.M11 = value[0, 0]; m.M12 = value[1, 0]; m.M13 = value[2, 0];     m.M14 = value[3, 0];
            m.M21 = value[0, 1];     m.M22 = value[1, 1]; m.M23 = value[2, 1]; m.M24 = value[3, 1];
            m.M31 = value[0, 2];     m.M32 = value[1, 2];     m.M33 = value[2, 2]; m.M34 = value[3, 2];
            m.M41 = value[0, 3];     m.M42 = value[1, 3];     m.M43 = value[2, 3];     m.M44 = value[3, 3];

            return(m);
        }
Esempio n. 6
0
        /// <summary>
        /// This method builds a rotation matrix from the global coordinate system
        /// to the local coordinate system formed by the local axes
        /// </summary>
        /// <param name="m">The rotation matrix to build</param>
        public void RotationMatrix(out Microsoft.DirectX.Matrix m)
        {
            m = Microsoft.DirectX.Matrix.Identity;

            //Obtain local axes
            Microsoft.DirectX.Vector3[] axes = LocalAxes;

            // Build rotation matrix
            m.M11 = axes[0].X; m.M12 = axes[0].Y; m.M13 = axes[0].Z;
            m.M21 = axes[1].X; m.M22 = axes[1].Y; m.M23 = axes[1].Z;
            m.M31 = axes[2].X; m.M32 = axes[2].Y; m.M33 = axes[2].Z;
        }
Esempio n. 7
0
        public void FillTextWithFont(Microsoft.DirectX.Direct3D.Font p_font, int x, int y, string text, Color color, int center)
        {
            var device    = D3DDevice.Instance.Device;
            var screen_dx = device.PresentationParameters.BackBufferWidth;
            var screen_dy = device.PresentationParameters.BackBufferHeight;

            // elimino cualquier textura que me cague el modulate del vertex color
            device.SetTexture(0, null);
            // Desactivo el zbuffer
            bool ant_zenable = device.RenderState.ZBufferEnable;

            device.RenderState.ZBufferEnable = false;
            // pongo la matriz identidad
            Microsoft.DirectX.Matrix matAnt = sprite.Transform * Microsoft.DirectX.Matrix.Identity;
            sprite.Transform = Microsoft.DirectX.Matrix.Identity;
            sprite.Begin(SpriteFlags.AlphaBlend);
            switch (center)
            {
            case 1:
            {
                Rectangle rc = new Rectangle(0, y, screen_dx, y + 100);
                p_font.DrawText(sprite, text, rc, DrawTextFormat.Center, color);
            }
            break;

            case 2:
            {
                Rectangle rc = new Rectangle(x - screen_dx, y, x, y + 100);
                p_font.DrawText(sprite, text, rc, DrawTextFormat.NoClip | DrawTextFormat.Top | DrawTextFormat.Right, color);
            }
            break;

            default:
            {
                Rectangle rc = new Rectangle(x, y, x + 600, y + 100);
                p_font.DrawText(sprite, text, rc, DrawTextFormat.NoClip | DrawTextFormat.Top | DrawTextFormat.Left, color);
            }
            break;
            }
            sprite.End();

            // Restauro el zbuffer
            device.RenderState.ZBufferEnable = ant_zenable;
            // Restauro la transformacion del sprite
            sprite.Transform = matAnt;
        }
Esempio n. 8
0
 public Matrix(DxMatrix m)
 {
     this.M11 = m.M11;
     this.M12 = m.M12;
     this.M13 = m.M13;
     this.M14 = m.M14;
     this.M21 = m.M21;
     this.M22 = m.M22;
     this.M23 = m.M23;
     this.M24 = m.M24;
     this.M31 = m.M31;
     this.M32 = m.M32;
     this.M33 = m.M33;
     this.M34 = m.M34;
     this.M41 = m.M41;
     this.M42 = m.M42;
     this.M43 = m.M43;
     this.M44 = m.M44;
 }
Esempio n. 9
0
        public void renderForShadow(Microsoft.DirectX.Matrix mat)
        {
            effect    = g.shadow.shader;
            technique = "RenderShadow";

            effect.SetValue("matWorld", TGCMatrix.Identity);
            effect.SetValue("mViewLightProj", mat);

            effect.SetValue("type", 0);

            D3DDevice.Instance.Device.VertexDeclaration = TGCShaders.Instance.VdecPositionTextured;
            effect.Technique = technique;
            D3DDevice.Instance.Device.SetStreamSource(0, vbTerrain, 0);

            //Render con shader
            effect.Begin(0);
            effect.BeginPass(0);
            D3DDevice.Instance.Device.DrawPrimitives(PrimitiveType.TriangleList, 0, totalVertices / 3);
            effect.EndPass();
            effect.End();
        }
Esempio n. 10
0
 private void TestAdd(Matrix3 a, Matrix3 b, DXMtx dxa, DXMtx dxb)
 {
     AdditionResults = new Matrix3[2];
     AdditionResults[0] = a + b;
     AdditionResults[1] = DXMtxToMtx3(DXMtx.Add(dxa, dxb));
 }
Esempio n. 11
0
        private void TestTransform(Vector2 v1, Vector2 v2, DXVec2 dx1, DXVec2 dx2)
        {
            TransformResults = new Vector2[4];
            float rads = (float)(30 * Math.PI / 180);
            Matrix2 rotation = Matrix2.Rotation(rads);
            DXTransformMatrix = Microsoft.DirectX.Matrix.AffineTransformation2D(1, new DXVec2(0, 0), rads, new DXVec2(0, 0));

            DXTransformResults = new Microsoft.DirectX.Vector4[2];
            DXTransformResults[0] = DXVec2.Transform(dx1, DXTransformMatrix);
            DXTransformResults[1] = DXVec2.Transform(dx2, DXTransformMatrix);

            TransformResults[0] = v1 * rotation;
            TransformResults[1] = v2 * rotation;
            TransformResults[2] = new Vector2(DXTransformResults[0].X, DXTransformResults[0].Y);
            TransformResults[3] = new Vector2(DXTransformResults[1].X, DXTransformResults[1].Y);
        }
Esempio n. 12
0
 private Matrix2 DXMtxToMtx2(DXMtx m)
 {
     return new Matrix2(m.M11, m.M12, m.M21, m.M22);
 }
Esempio n. 13
0
 private Matrix3 DXMtxToMtx3(DXMtx m)
 {
     return new Matrix3(m.M11, m.M12, m.M13, m.M21, m.M22, m.M23, m.M31, m.M32, m.M33);
 }
Esempio n. 14
0
 private void TestSub(Matrix3 a, Matrix3 b, DXMtx dxa, DXMtx dxb)
 {
     SubtractionResults = new Matrix3[2];
     SubtractionResults[0] = a - b;
     SubtractionResults[1] = DXMtxToMtx3(DXMtx.Subtract(dxa, dxb));
 }
Esempio n. 15
0
 private void TestTranspose(Matrix3 a, DXMtx dxa)
 {
     TransposeResults = new Matrix3[2];
     TransposeResults[0] = Matrix3.Transpose(a);
     TransposeResults[1] = DXMtxToMtx3(DXMtx.TransposeMatrix(dxa));
 }
Esempio n. 16
0
 private void TestInvert(Matrix3 a, DXMtx dxa)
 {
     InverseResults = new Matrix3[2];
     InverseResults[0] = Matrix3.Invert(a);
     InverseResults[1] = DXMtxToMtx3(DXMtx.Invert(dxa));
 }
Esempio n. 17
0
 private void TestMul(Matrix3 a, Matrix3 b, DXMtx dxa, DXMtx dxb)
 {
     MultiplyResults = new Matrix3[2];
     MultiplyResults[0] = a * b;
     MultiplyResults[1] = DXMtxToMtx3(DXMtx.Multiply(dxa, dxb));
 }
Esempio n. 18
0
        private void TestTransform(Vector3 v1, Vector3 v2, DXVec3 dx1, DXVec3 dx2)
        {
            TransformResults = new Vector3[4];
            float rads = (float)(30 * Math.PI / 180);
            Vector3 axis = (new Vector3(1, 2, 3)).Normalize();

            Matrix3 rotation = Matrix3.RotateAxisAngle(new Vector3(1, 2, 3), rads);
            Microsoft.DirectX.Matrix dxaxisangle = Microsoft.DirectX.Matrix.RotationAxis(new DXVec3(1, 2, 3), rads);

            DXTransformMatrix = Microsoft.DirectX.Matrix.RotationAxis(new DXVec3(1, 2, 3), rads);

            DXTransformResults = new Microsoft.DirectX.Vector4[2];
            DXTransformResults[0] = DXVec3.Transform(dx1, DXTransformMatrix);
            DXTransformResults[1] = DXVec3.Transform(dx2, DXTransformMatrix);

            TransformResults[0] = v1 * rotation;
            TransformResults[1] = v2 * rotation;
            TransformResults[2] = new Vector3(DXTransformResults[0].X, DXTransformResults[0].Y, DXTransformResults[0].Z);
            TransformResults[3] = new Vector3(DXTransformResults[1].X, DXTransformResults[1].Y, DXTransformResults[1].Z);
        }
        /// <summary>
        /// Converts a <see cref="Fusee.Math.Core.Matrix4F"/> to <see cref="Microsoft.DirectX.Matrix"/>.
        /// </summary>
        /// <param name="value">The matrix value to convert.</param>
        /// <returns>A <see cref="Microsoft.DirectX.Matrix"/> value.</returns>
        public static Microsoft.DirectX.Matrix ToDirectX(Fusee.Math.Core.Matrix4F value)
        {
            Microsoft.DirectX.Matrix m = new Microsoft.DirectX.Matrix();
            // Since directx use column-major matrices we transpose our matrix.
            m.M11 = value[0,0]; m.M12 = value[1,0];	m.M13 = value[2,0];	m.M14 = value[3,0];
            m.M21 = value[0,1];	m.M22 = value[1,1]; m.M23 = value[2,1];	m.M24 = value[3,1];
            m.M31 = value[0,2];	m.M32 = value[1,2];	m.M33 = value[2,2]; m.M34 = value[3,2];
            m.M41 = value[0,3];	m.M42 = value[1,3];	m.M43 = value[2,3];	m.M44 = value[3,3];

            return m;
        }
Esempio n. 20
0
 internal Matrix(Microsoft.DirectX.Matrix matrix)
 {
     _matrix = matrix;
 }
Esempio n. 21
0
 private Microsoft.DirectX.Matrix GetAsMatrix(string matrix)
 {
     string[] values = matrix.Split(",".ToCharArray());
     Microsoft.DirectX.Matrix m = new Microsoft.DirectX.Matrix();
     if (values.Length >= 16)
     {
         int i = 0;
         m.M11 = float.Parse(values[i++]);
         m.M12 = float.Parse(values[i++]);
         m.M13 = float.Parse(values[i++]);
         m.M14 = float.Parse(values[i++]);
         m.M21 = float.Parse(values[i++]);
         m.M22 = float.Parse(values[i++]);
         m.M23 = float.Parse(values[i++]);
         m.M24 = float.Parse(values[i++]);
         m.M31 = float.Parse(values[i++]);
         m.M32 = float.Parse(values[i++]);
         m.M33 = float.Parse(values[i++]);
         m.M34 = float.Parse(values[i++]);
         m.M41 = float.Parse(values[i++]);
         m.M42 = float.Parse(values[i++]);
         m.M43 = float.Parse(values[i++]);
         m.M44 = float.Parse(values[i++]);
     }
     return m;
 }
Esempio n. 22
0
        public void ShadowTest()
        {
            Vector4 light = Utilities.GenerateVector4();
            light.W = 0f;
            Plane plane = Utilities.GeneratePlane();
            plane.Normalize();

            Microsoft.DirectX.Matrix temp = new Microsoft.DirectX.Matrix();
            temp.Shadow(Utilities.ConvertToMdx(light), Utilities.ConvertToMdx(plane));
            Matrix expected = Utilities.ConvertFrom(temp);

            Matrix actual;
            actual = Matrix.Shadow(light, plane);
            Utilities.AreEqual(expected, actual);
        }
Esempio n. 23
0
        public void ShadowByRefTest()
        {
            Vector4 light = Utilities.GenerateVector4();
            Vector4 lightExpected = light;
            Plane plane = Utilities.GeneratePlane();
            plane.Normalize();
            Plane planeExpected = plane;
            Matrix result;

            Microsoft.DirectX.Matrix temp = new Microsoft.DirectX.Matrix();
            temp.Shadow(Utilities.ConvertToMdx(light), Utilities.ConvertToMdx(plane));
            Matrix resultExpected = Utilities.ConvertFrom(temp);

            Matrix.Shadow(ref light, ref plane, out result);
            Utilities.AreEqual(lightExpected, light);
            Utilities.AreEqual(planeExpected, plane);
            Utilities.AreEqual(resultExpected, result);
        }
Esempio n. 24
0
 public static Matrix Scaling(int x, int y, int z)
 {
     return(new Matrix(DxMatrix.Scaling(x, y, z)));
 }
Esempio n. 25
0
        public static void CameraControlFps(Camera camera)
        {
            GuiManager.Cursor.StaticPosition = true;
            Vector3 up = new Vector3(0, 1, 0);

            camera.Velocity = new Vector3();

            Keys forwardKey = Keys.W;
            Keys backKey    = Keys.S;
            Keys leftKey    = Keys.A;
            Keys rightKey   = Keys.D;

            FlatRedBall.Input.Keyboard keyboard = InputManager.Keyboard;

            float movementSpeed = 7;

            if (keyboard.KeyDown(forwardKey))
            {
                camera.Velocity +=
                    new Vector3(camera.RotationMatrix.M31, camera.RotationMatrix.M32, camera.RotationMatrix.M33) *
                    movementSpeed;
            }
            else if (keyboard.KeyDown(backKey))
            {
                camera.Velocity +=
                    new Vector3(camera.RotationMatrix.M31, camera.RotationMatrix.M32, camera.RotationMatrix.M33) *
                    -movementSpeed;
            }

            if (keyboard.KeyDown(leftKey))
            {
                camera.Velocity +=
                    new Vector3(camera.RotationMatrix.M11, camera.RotationMatrix.M12, camera.RotationMatrix.M13) *
                    -movementSpeed;
            }
            if (keyboard.KeyDown(rightKey))
            {
                camera.Velocity +=
                    new Vector3(camera.RotationMatrix.M11, camera.RotationMatrix.M12, camera.RotationMatrix.M13) *
                    movementSpeed;
            }

#if FRB_XNA
            // These vaules may be way too fast/slow because I modified it to use pixels rather
            // than the somewhat arbitrary world coordinates
            camera.RotationMatrix *=
                Matrix.CreateFromAxisAngle(
                    camera.RotationMatrix.Right,
                    -.2f * GuiManager.Cursor.ScreenYChange * TimeManager.SecondDifference);

            camera.RotationMatrix *=
                Matrix.CreateFromAxisAngle(
                    up,
                    -.2f * GuiManager.Cursor.ScreenXChange * TimeManager.SecondDifference);
#elif FRB_MDX
            camera.RotationMatrix *=
                Matrix.RotationAxis(
                    new Vector3(camera.RotationMatrix.M11, camera.RotationMatrix.M12, camera.RotationMatrix.M13),
                    -.2f * GuiManager.Cursor.YVelocity * TimeManager.SecondDifference);

            camera.RotationMatrix *=
                Matrix.RotationAxis(
                    up,
                    -.2f * GuiManager.Cursor.XVelocity * TimeManager.SecondDifference);
#endif
        }
Esempio n. 26
0
 private Matrix4 DXMtxToMtx4(DXMtx m)
 {
     return new Matrix4(m.M11, m.M12, m.M13, m.M14, m.M21, m.M22, m.M23, m.M24, m.M31, m.M32, m.M33, m.M34, m.M41, m.M42, m.M43, m.M44);
 }