예제 #1
0
        public static Matrix ToSlimDX(this Microsoft.Xna.Framework.Matrix v)
        {
            Matrix m;

            m.M11 = v.M11;
            m.M12 = v.M12;
            m.M13 = v.M13;
            m.M14 = v.M14;

            m.M21 = v.M21;
            m.M22 = v.M22;
            m.M23 = v.M23;
            m.M24 = v.M24;

            m.M31 = v.M31;
            m.M32 = v.M32;
            m.M33 = v.M33;
            m.M34 = v.M34;

            m.M41 = v.M41;
            m.M42 = v.M42;
            m.M43 = v.M43;
            m.M44 = v.M44;

            return(m);
        }
예제 #2
0
        public BasicEntity(Model model, MaterialEffect material, Vector3 position, double angleZ, double angleX, double angleY, Vector3 scale, MeshMaterialLibrary library = null, Entity physicsObject = null)
        {
            Id             = IdGenerator.GetNewId();
            WorldTransform = new TransformMatrix(Matrix.Identity, Id);

            Position = position;
            AngleZ   = angleZ;
            AngleX   = angleX;
            AngleY   = angleY;
            Scale    = scale;

            RotationMatrix = Matrix.CreateRotationX((float)AngleX) * Matrix.CreateRotationY((float)AngleY) *
                             Matrix.CreateRotationZ((float)AngleZ);

            Material = material;
            Model    = model;

            if (library != null)
            {
                RegisterInLibrary(library);
            }

            if (physicsObject != null)
            {
                RegisterPhysics(physicsObject);
            }
        }
예제 #3
0
        public void Matrix_Conversion_ToMath()
        {
            var xnaMatrix = new XnaMatrix(
                11, 12, 13, 14,
                21, 22, 23, 24,
                31, 32, 33, 34,
                41, 42, 43, 44);

            Matrix matrix = xnaMatrix.ToMath();

            Assert.AreEqual(xnaMatrix.M11, matrix.R1C1);
            Assert.AreEqual(xnaMatrix.M12, matrix.R1C2);
            Assert.AreEqual(xnaMatrix.M13, matrix.R1C3);
            Assert.AreEqual(xnaMatrix.M14, matrix.R1C4);

            Assert.AreEqual(xnaMatrix.M21, matrix.R2C1);
            Assert.AreEqual(xnaMatrix.M22, matrix.R2C2);
            Assert.AreEqual(xnaMatrix.M23, matrix.R2C3);
            Assert.AreEqual(xnaMatrix.M24, matrix.R2C4);

            Assert.AreEqual(xnaMatrix.M31, matrix.R3C1);
            Assert.AreEqual(xnaMatrix.M32, matrix.R3C2);
            Assert.AreEqual(xnaMatrix.M33, matrix.R3C3);
            Assert.AreEqual(xnaMatrix.M34, matrix.R3C4);

            Assert.AreEqual(xnaMatrix.M41, matrix.R4C1);
            Assert.AreEqual(xnaMatrix.M42, matrix.R4C2);
            Assert.AreEqual(xnaMatrix.M43, matrix.R4C3);
            Assert.AreEqual(xnaMatrix.M44, matrix.R4C4);
        }
예제 #4
0
 public virtual void Draw(
     Microsoft.Xna.Framework.GameTime gameTime,
     Microsoft.Xna.Framework.Graphics.SpriteBatch batch,
     float alpha,
     Microsoft.Xna.Framework.Matrix transform)
 {
 }
예제 #5
0
        /// <summary>
        /// Gets an array of vertices and indices from the provided model.
        /// </summary>
        /// <param name="collisionModel">Model to use for the collision shape.</param>
        /// <param name="vertices">Compiled set of vertices from the model.</param>
        /// <param name="indices">Compiled set of indices from the model.</param>
        public static void GetVerticesAndIndicesFromModel(Model collisionModel, out Microsoft.Xna.Framework.Vector3[] vertices, out int[] indices)
        {
            var verticesList = new List <Microsoft.Xna.Framework.Vector3>();
            var indicesList  = new List <int>();
            var transforms   = new Matrix[collisionModel.Bones.Count];

            collisionModel.CopyAbsoluteBoneTransformsTo(transforms);

            Matrix transform;

            foreach (ModelMesh mesh in collisionModel.Meshes)
            {
                if (mesh.ParentBone != null)
                {
                    transform = transforms[mesh.ParentBone.Index];
                }
                else
                {
                    transform = Matrix.Identity;
                }
                AddMesh(mesh, transform, verticesList, indicesList);
            }

            vertices = verticesList.ToArray();
            indices  = indicesList.ToArray();
        }
예제 #6
0
        public void UpdateToObject(Vector3 position, Matrix rotationMatrix, float scaleX, float scaleY, Camera camera)
        {
            this.Position = position;

            this.RotationMatrix = rotationMatrix;

            // Use 2 so that there's a 1-pixel space between the inner and outer
            float extraDistance = (float)(2) / camera.PixelsPerUnitAt(position.Z);

            mDarkPolygon.SetPoint(0, -scaleX - extraDistance,
                                  scaleY + extraDistance);
            mDarkPolygon.SetPoint(1, scaleX + extraDistance,
                                  scaleY + extraDistance);
            mDarkPolygon.SetPoint(2, scaleX + extraDistance,
                                  -scaleY - extraDistance);
            mDarkPolygon.SetPoint(3, -scaleX - extraDistance,
                                  -scaleY - extraDistance);
            mDarkPolygon.SetPoint(4, -scaleX - extraDistance,
                                  scaleY + extraDistance);

            mLightPolygon.SetPoint(0, -scaleX, scaleY);
            mLightPolygon.SetPoint(1, scaleX, scaleY);
            mLightPolygon.SetPoint(2, scaleX, -scaleY);
            mLightPolygon.SetPoint(3, -scaleX, -scaleY);
            mLightPolygon.SetPoint(4, -scaleX, scaleY);
        }
예제 #7
0
        public static Matrix ToBalder(this Microsoft.Xna.Framework.Matrix matrix)
        {
            var m = new Matrix
            {
                M11 = matrix.M11,
                M12 = matrix.M12,
                M13 = matrix.M13,
                M14 = matrix.M14,

                M21 = matrix.M21,
                M22 = matrix.M22,
                M23 = matrix.M23,
                M24 = matrix.M24,

                M31 = matrix.M31,
                M32 = matrix.M32,
                M33 = matrix.M33,
                M34 = matrix.M34,

                M41 = matrix.M41,
                M42 = matrix.M42,
                M43 = matrix.M43,
                M44 = matrix.M44
            };

            return(m);
        }
예제 #8
0
 public AffineTransform(XNAMAT matrix)
 {
     if (!matrix.Decompose(out this.Scale, out this.Rotation, out this.Translation))
     {
         throw new ArgumentException("matrix is invalid or skewed.", nameof(matrix));
     }
 }
예제 #9
0
        public void Draw(Matrix _viewProjection, Model isosphere, Texture2D tex)
        {
            //_spriteBatch.Begin(SpriteSortMode.Deferred, null, null, null, null, texFilterEffect, null);
            //_spriteBatch.Draw(tex, new Rectangle(0,0,256, 1536), Color.White);
            //_spriteBatch.End();
            ModelMeshPart meshpart = isosphere.Meshes[0].MeshParts[0];

            texFilterEffect.Parameters["WorldViewProj"].SetValue(Matrix.CreateScale(10) * _viewProjection);
            Texture.SetValue(tex);

            _graphics.SetRenderTarget(null);
            _graphics.RasterizerState = RasterizerState.CullCounterClockwise;
            _graphics.BlendState      = BlendState.Opaque;

            _graphics.SetVertexBuffer(meshpart.VertexBuffer);
            _graphics.Indices = (meshpart.IndexBuffer);
            int primitiveCount = meshpart.PrimitiveCount;
            int vertexOffset   = meshpart.VertexOffset;
            int startIndex     = meshpart.StartIndex;

            Shaders.EmissiveEffect.CurrentTechnique.Passes[0].Apply();

            texFilterEffect.CurrentTechnique.Passes[0].Apply();

            _graphics.DrawIndexedPrimitives(PrimitiveType.TriangleList, vertexOffset,
                                            startIndex, primitiveCount);
        }
예제 #10
0
 public static Matrix CreateBillboard(
     Vector3 objectPosition,
     Vector3 cameraPosition,
     Vector3 cameraUp,
     Vector3?cameraForward)
 {
     return(new Matrix(Matrix4x4.CreateBillboard(objectPosition, cameraPosition, cameraUp, cameraForward)));
 }
예제 #11
0
파일: Vector.cs 프로젝트: Anttifer/Jypeli
 /// <summary>
 /// Kertoo vektorin matriisilla.
 /// </summary>
 /// <param name="matrix"></param>
 /// <returns></returns>
 public Vector Transform(Matrix matrix)
 {
     return(new Vector
            (
                (X * matrix.M11) + (Y * matrix.M21) + matrix.M41,
                (X * matrix.M12) + (Y * matrix.M22) + matrix.M42
            ));
 }
예제 #12
0
 public static Matrix CreateConstrainedBillboard(
     Vector3 objectPosition,
     Vector3 cameraPosition,
     Vector3 rotateAxis,
     Vector3?cameraForward,
     Vector3?objectForward)
 {
     return(new Matrix(Matrix4x4.CreateConstrainedBillboard(objectPosition, cameraPosition, rotateAxis, cameraForward, objectForward)));
 }
예제 #13
0
 public override void UpdateView()
 {
     if (effect != null)
     {
         FreeLook freelook = Demo.Freelook;
         effect.View  = Matrix.CreateLookAt(MathHelper.Convert(freelook.Eye), MathHelper.Convert(freelook.Target), MathHelper.Convert(freelook.Up));
         effect.View *= Matrix.CreateScale(-1, 1, 1);
     }
 }
예제 #14
0
 public static SharpDX.Matrix ToMatrix(this Microsoft.Xna.Framework.Matrix value)
 {
     return(new SharpDX.Matrix(
                value.M11, value.M12, value.M13, value.M14,
                value.M21, value.M22, value.M23, value.M24,
                value.M31, value.M32, value.M33, value.M34,
                value.M41, value.M42, value.M43, value.M44
                ));
 }
예제 #15
0
 public static Matrix ConvertFrom(Microsoft.Xna.Framework.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
     });
 }
예제 #16
0
        public void SetLocalMatrix(string name, XNAMAT localMatrix)
        {
            var n = LogicalNodes.FirstOrDefault(item => item.Name == name);

            if (n == null)
            {
                return;
            }
            n.LocalMatrix = localMatrix;
        }
예제 #17
0
        /// <summary>
        /// Draws the individual <see cref="Komodo.Core.ECS.Components.Drawable2DComponent"/>.
        /// </summary>
        /// <param name="component"><see cref="Komodo.Core.ECS.Components.Drawable2DComponent"/> to render.</param>
        /// <param name="spriteBatch"><see cref="Microsoft.Xna.Framework.Graphics.SpriteBatch"/> to render with.</param>
        private void DrawComponent(Drawable2DComponent component, SpriteBatch spriteBatch)
        {
            var position = component.WorldPosition;
            var rotation = component.Rotation;
            var scale    = component.Scale;

            if (ActiveCamera != null)
            {
                if (component.IsBillboard)
                {
                    position = Vector3.Transform(
                        position,
                        ActiveCamera.ViewMatrix * Matrix.CreateScale(1f, -1f, 1f)
                        );
                }
                else
                {
                    position = Vector3.Transform(
                        position,
                        Matrix.CreateScale(1f, -1f, 1f)
                        );
                }
            }

            switch (component)
            {
            case SpriteComponent spriteComponent:
                spriteBatch.Draw(
                    spriteComponent.Texture.MonoGameTexture,
                    position.XY.MonoGameVector,
                    null,
                    Color.White,
                    -rotation.Z,
                    spriteComponent.Center.MonoGameVector,
                    scale.XY.MonoGameVector,
                    SpriteEffects.None,
                    position.Z
                    );
                break;

            case TextComponent textComponent:
                spriteBatch.DrawString(
                    textComponent.Font,
                    textComponent.Text,
                    position.XY.MonoGameVector,
                    textComponent.Color,
                    -rotation.Z,
                    textComponent.IsCentered ? textComponent.Center.MonoGameVector : Vector2.Zero.MonoGameVector,
                    scale.XY.MonoGameVector,
                    SpriteEffects.None,
                    position.Z
                    );
                break;
            }
        }
예제 #18
0
 public BasicEntity(Model model, MaterialEffect material, Vector3 position, Matrix rotationMatrix, Vector3 scale)
 {
     Id             = IdGenerator.GetNewId();
     Name           = GetType().Name + " " + Id;
     WorldTransform = new TransformMatrix(Matrix.Identity, Id);
     Model          = model;
     Material       = material;
     Position       = position;
     RotationMatrix = rotationMatrix;
     Scale          = scale;
     RotationMatrix = rotationMatrix;
 }
예제 #19
0
        public Microsoft.Xna.Framework.Matrix ToMatrixProjection()
        {
            Microsoft.Xna.Framework.Matrix matrix = Microsoft.Xna.Framework.Matrix.Identity;
            matrix.Right    = _basis.GetColumn(0).ToVector3();
            matrix.Up       = _basis.GetColumn(1).ToVector3();
            matrix.Backward = _basis.GetColumn(2).ToVector3();

            matrix.Translation = _origin.ToVector3();
            matrix.M34         = -1;
            matrix.M44         = 0;
            return(matrix);
        }
예제 #20
0
        public virtual void OnResetDevice()
        {
            Info.OnResetDevice();

            effect.Projection = Matrix.CreatePerspectiveFieldOfView(FieldOfView, AspectRatio, NearPlane, FarPlane);
            UpdateView();

            //Device.SetRenderState(RenderState.Ambient, Ambient);

            //Device.SetLight(0, light);
            //Device.EnableLight(0, true);
        }
예제 #21
0
        XNAVector3 Unproject(XNAVector3 v, XNAMatrix projection, XNAMatrix view, XNAMatrix world, XNAVector3 camPos)
        {
            XNAVector3 p0 = GraphicsDevice.Viewport.Unproject(new XNAVector3(v.X, v.Y, 0), projection, view, world);
            XNAVector3 p1 = GraphicsDevice.Viewport.Unproject(new XNAVector3(v.X, v.Y, 1), projection, view, world);

            if (Math.Abs(p1.Z - p0.Z) <= 1e-4)
            {
                return(v);
            }
            XNAVector3 dir = XNAVector3.Normalize(p1 - p0);
            XNAVector3 p   = camPos + dir * (v.Z - camPos.Z) / dir.Z;

            return(p);
        }
예제 #22
0
        public Microsoft.Xna.Framework.Matrix ToMatrix()
        {
            Microsoft.Xna.Framework.Matrix m = Microsoft.Xna.Framework.Matrix.Identity;
            IndexedVector3 right;
            IndexedVector3 up;
            IndexedVector3 backward;

            _basis.GetOpenGLMatrix(out right, out up, out backward);
            m.Right       = right;
            m.Up          = up;
            m.Backward    = backward;
            m.Translation = _origin.ToVector3();
            return(m);
        }
예제 #23
0
        public static void Convert(ref Matrix matrix, out Matrix3x3 bepuMatrix)
        {
            bepuMatrix.M11 = matrix.M11;
            bepuMatrix.M12 = matrix.M12;
            bepuMatrix.M13 = matrix.M13;

            bepuMatrix.M21 = matrix.M21;
            bepuMatrix.M22 = matrix.M22;
            bepuMatrix.M23 = matrix.M23;

            bepuMatrix.M31 = matrix.M31;
            bepuMatrix.M32 = matrix.M32;
            bepuMatrix.M33 = matrix.M33;
        }
예제 #24
0
        public void Update(XNAMAT worldMatrix)
        {
            _WorldMatrix = worldMatrix;

            // http://m-hikari.com/ija/ija-password-2009/ija-password5-8-2009/hajrizajIJA5-8-2009.pdf

            float determinant3x3 =
                +(worldMatrix.M13 * worldMatrix.M21 * worldMatrix.M32)
                + (worldMatrix.M11 * worldMatrix.M22 * worldMatrix.M33)
                + (worldMatrix.M12 * worldMatrix.M23 * worldMatrix.M31)
                - (worldMatrix.M12 * worldMatrix.M21 * worldMatrix.M33)
                - (worldMatrix.M13 * worldMatrix.M22 * worldMatrix.M31)
                - (worldMatrix.M11 * worldMatrix.M23 * worldMatrix.M32);

            _Visible   = Math.Abs(determinant3x3) > float.Epsilon;
            _FlipFaces = determinant3x3 < 0;
        }
예제 #25
0
        internal void UpdateVertices()
        {
            // Vic says: I tried to optimize this on
            // March 6, 2011 for the windows phone - I
            // couldn't get it to run any faster on the
            // the emulator.  Seems like it's pretty darn
            // optimized.
            mVertices[0].Position.X = (mScaleX * mVertices[0].Scale.X);
            mVertices[1].Position.X = (mScaleX * mVertices[1].Scale.X);
            mVertices[2].Position.X = (mScaleX * mVertices[2].Scale.X);
            mVertices[3].Position.X = (mScaleX * mVertices[3].Scale.X);

            mVertices[0].Position.Y = (mScaleY * mVertices[0].Scale.Y);
            mVertices[1].Position.Y = (mScaleY * mVertices[1].Scale.Y);
            mVertices[2].Position.Y = (mScaleY * mVertices[2].Scale.Y);
            mVertices[3].Position.Y = (mScaleY * mVertices[3].Scale.Y);

            mVertices[0].Position.Z = 0;
            mVertices[1].Position.Z = 0;
            mVertices[2].Position.Z = 0;
            mVertices[3].Position.Z = 0;

            if (IsBillboarded)
            {
                Matrix modifiedMatrix = mRotationMatrix * Camera.Main.RotationMatrix;

                MathFunctions.TransformVector(ref mVertices[0].Position, ref modifiedMatrix);
                MathFunctions.TransformVector(ref mVertices[1].Position, ref modifiedMatrix);
                MathFunctions.TransformVector(ref mVertices[2].Position, ref modifiedMatrix);
                MathFunctions.TransformVector(ref mVertices[3].Position, ref modifiedMatrix);
            }
            else
            {
                MathFunctions.TransformVector(ref mVertices[0].Position, ref mRotationMatrix);
                MathFunctions.TransformVector(ref mVertices[1].Position, ref mRotationMatrix);
                MathFunctions.TransformVector(ref mVertices[2].Position, ref mRotationMatrix);
                MathFunctions.TransformVector(ref mVertices[3].Position, ref mRotationMatrix);
            }

            mVertices[0].Position += Position;
            mVertices[1].Position += Position;
            mVertices[2].Position += Position;
            mVertices[3].Position += Position;
        }
예제 #26
0
        internal void UpdateVertices(Camera camera)
        {
            // Vic says: I tried to optimize this on
            // March 6, 2011 for the windows phone - I
            // couldn't get it to run any faster on the
            // the emulator.  Seems like it's pretty darn
            // optimized.
            mVertices[0].Position.X = (mScaleX * mVertices[0].Scale.X);
            mVertices[1].Position.X = (mScaleX * mVertices[1].Scale.X);
            mVertices[2].Position.X = (mScaleX * mVertices[2].Scale.X);
            mVertices[3].Position.X = (mScaleX * mVertices[3].Scale.X);

            mVertices[0].Position.Y = (mScaleY * mVertices[0].Scale.Y);
            mVertices[1].Position.Y = (mScaleY * mVertices[1].Scale.Y);
            mVertices[2].Position.Y = (mScaleY * mVertices[2].Scale.Y);
            mVertices[3].Position.Y = (mScaleY * mVertices[3].Scale.Y);

            mVertices[0].Position.Z = 0;
            mVertices[1].Position.Z = 0;
            mVertices[2].Position.Z = 0;
            mVertices[3].Position.Z = 0;

            if (this.ListsBelongingTo.Contains(camera.mSpritesToBillBoard))
            {
                Matrix modifiedMatrix = mRotationMatrix * SpriteManager.Camera.RotationMatrix;

                MathFunctions.TransformVector(ref mVertices[0].Position, ref modifiedMatrix);
                MathFunctions.TransformVector(ref mVertices[1].Position, ref modifiedMatrix);
                MathFunctions.TransformVector(ref mVertices[2].Position, ref modifiedMatrix);
                MathFunctions.TransformVector(ref mVertices[3].Position, ref modifiedMatrix);
            }
            else
            {
                MathFunctions.TransformVector(ref mVertices[0].Position, ref mRotationMatrix);
                MathFunctions.TransformVector(ref mVertices[1].Position, ref mRotationMatrix);
                MathFunctions.TransformVector(ref mVertices[2].Position, ref mRotationMatrix);
                MathFunctions.TransformVector(ref mVertices[3].Position, ref mRotationMatrix);
            }

            mVertices[0].Position += Position;
            mVertices[1].Position += Position;
            mVertices[2].Position += Position;
            mVertices[3].Position += Position;
        }
예제 #27
0
 public static UnityEngine.Matrix4x4 Matrix(XMatrix input, out UMatrix output)
 {
     output.m00 = input.M11;
     output.m01 = input.M21;
     output.m02 = input.M31;
     output.m03 = input.M41;
     output.m10 = input.M12;
     output.m11 = input.M22;
     output.m12 = input.M32;
     output.m13 = input.M42;
     output.m20 = input.M13;
     output.m21 = input.M23;
     output.m22 = input.M33;
     output.m23 = input.M43;
     output.m30 = input.M14;
     output.m31 = input.M24;
     output.m32 = input.M34;
     output.m33 = input.M44;
     return(output);
 }
예제 #28
0
        protected override void Initialize()
        {
            basicEffect = new BasicEffect(GraphicsDevice);
            basicEffect.TextureEnabled     = true;
            basicEffect.VertexColorEnabled = true;
            basicEffect.View = XNAMatrix.CreateLookAt(
                orgCameraPosition,
                XNAVector3.Zero,
                XNAVector3.Up
                );
            basicEffect.Projection = XNAMatrix.CreatePerspectiveFieldOfView(
                XNAMathHelper.ToRadians(45.0f),
                (float)GraphicsDevice.Viewport.Width / GraphicsDevice.Viewport.Height,
                1.0f,
                10000.0f
                );
            basicEffect.Texture = null;

            dummyTexture = XNATexture.Load(GraphicsDevice, "./dummyTexture.png");
        }
예제 #29
0
        static public Vector2 WorldToScreen(Vector3 worldPos)
        {
            Microsoft.Xna.Framework.Matrix transData = getViewMatrix();

            float   num = transData.M41 * worldPos.x + transData.M42 * worldPos.y + transData.M43 * worldPos.z + transData.M44;
            Vector2 result;

            if ((double)num < 0.01)
            {
                result = new Vector2(-1f, -1f);
            }
            else
            {
                float num2 = 1f / num;
                float num3 = (transData.M11 * worldPos.x + transData.M12 * worldPos.y + transData.M13 * worldPos.z + transData.M14) * num2;
                float num4 = (transData.M21 * worldPos.x + transData.M22 * worldPos.y + transData.M23 * worldPos.z + transData.M24) * num2;
                result = new Vector2((num3 + 1f) * 0.5f * 1920, (num4 - 1f) * -0.5f * 1080);
            }
            return(result);
        }
예제 #30
0
        /// <summary>
        /// Transforms the polygon using the defined matrix.
        /// </summary>
        /// <param name="transform">The matrix to use as transformation.</param>
        public void Transform(ref Matrix transform)
        {
            // Transform main polygon
            for (int i = 0; i < Count; i++)
            {
                this[i] = Vector2.Transform(this[i], transform);
            }

            // Transform holes
            if (Holes != null && Holes.Count > 0)
            {
                for (int i = 0; i < Holes.Count; i++)
                {
                    Vector2[] temp = Holes[i].ToArray();
                    Vector2.Transform(temp, ref transform, temp);

                    Holes[i] = new Vertices(temp);
                }
            }
        }
예제 #31
0
        /// <summary>
        /// Initializes a new instance of the <see cref="PhysxTriangleMesh"/> class.
        /// Cooks the Model on the fly
        /// </summary>
        /// <param name="PhysxPhysicWorld">The physx physic world.</param>
        /// <param name="model">The model.</param>
        /// <param name="worldTransformation">The world transformation.</param>
        /// <param name="scale">The scale.</param>
        /// <param name="density">The density.</param>
        /// <param name="material">The material.</param>
        public PhysxTriangleMesh(PhysxPhysicWorld PhysxPhysicWorld, IModelo model, Microsoft.Xna.Framework.Matrix worldTransformation, Microsoft.Xna.Framework.Vector3 scale, float density = 1, StillDesign.PhysX.Material material = null)
        {
            Microsoft.Xna.Framework.Vector3[] vertices = null;
            int[] indices = null;
            ExtractData(ref vertices, ref indices, model);


            TriangleMeshDescription meshDesc = new TriangleMeshDescription();

            meshDesc.AllocateVertices <Microsoft.Xna.Framework.Vector3>(vertices.Count());
            meshDesc.VerticesStream.SetData <Microsoft.Xna.Framework.Vector3>(vertices);
            meshDesc.AllocateTriangles <int>(indices.Count());
            meshDesc.TriangleStream.SetData <int>(indices);
            meshDesc.Flags         = 0;
            meshDesc.VertexCount   = vertices.Count();
            meshDesc.TriangleCount = indices.Count();

            MemoryStream ms = new MemoryStream();

            Cooking.InitializeCooking();
            if (Cooking.CookTriangleMesh(meshDesc, ms) == false)
            {
                PloobsEngine.Engine.Logger.ActiveLogger.LogMessage("Cant Cook Model", Engine.Logger.LogLevel.FatalError);
            }
            Cooking.CloseCooking();

            ms.Position = 0;
            TriangleMesh triangleMesh = PhysxPhysicWorld.Core.CreateTriangleMesh(ms);
            TriangleMeshShapeDescription bunnyShapeDesc = new TriangleMeshShapeDescription();

            if (material != null)
            {
                bunnyShapeDesc.Material = material;
            }
            bunnyShapeDesc.TriangleMesh = triangleMesh;
            ActorDesc = new ActorDescription();
            ActorDesc.Shapes.Add(bunnyShapeDesc);
            ActorDesc.BodyDescription = null;
            ActorDesc.GlobalPose      = worldTransformation.AsPhysX();
            this.Scale = scale;
        }
예제 #32
0
        public void loadbody(System.IO.BinaryReader br)
        {
            baseskelet = Skeleton.FromStream(br);
            HeadIndex = br.ReadInt32();
            WeaponIndex = br.ReadInt32();

            HeadMatrix = br.ReadMatrix();
            WeaponMatrix = br.ReadMatrix();

            RootIndex = br.ReadInt32();
            TopRootIndex = br.ReadInt32();
            BottomRootIndex = br.ReadInt32();
            botomindexes = new int[br.ReadInt32()];
            for (int i = 0; i < botomindexes.Length; i++)
                botomindexes[i] = br.ReadInt32();

            topindexes = new int[br.ReadInt32()];
            for (int i = 0; i < topindexes.Length; i++)
                topindexes[i] = br.ReadInt32();

            //TODO load matrices
        }
예제 #33
0
 public virtual void RenderDepth(XnaMatrix transform, RenderEventArgs e) { }
예제 #34
0
 private Matrix(Matrix4x4 matrix)
 {
     _matrix = matrix;
 }
예제 #35
0
		private void UpdateMatrices()
		{
			if (m_dirty)
			{
				m_viewMatrix = XnaMatrix.CreateLookAt(Position, LookAt, Up);
				m_projectionMatrix = IsPerspective
									 ? XnaMatrix.CreatePerspective(ViewportWidth, ViewportHeight, NearPlane, FarPlane)
									 : XnaMatrix.CreateOrthographic(ViewportWidth, ViewportHeight, NearPlane, FarPlane);
				m_toProjection = PostWorldMatrix * m_viewMatrix * m_projectionMatrix;
				m_invToProjection = m_toProjection.Invert();

				var forward = XnaVector.Normalize(LookAt - Position);
				var position = Position + NearPlane * 1.01f * forward;
				var xAxis = XnaVector.Cross(forward, Up);
				var yAxis = XnaVector.Normalize(XnaVector.Cross(xAxis, forward));
				var mat = XnaMatrix.CreateWorld(position, forward, yAxis);
				var vpWidth = Math.Abs(ViewportWidth);
				var vpHeight = Math.Abs(ViewportHeight);
				m_alignToNearPlane = PostWorldMatrix * XnaMatrix.CreateScale(vpWidth * 0.5f, vpHeight * 0.5f, 1) * mat * PostWorldMatrix.Invert();

				m_dirty = false;
			}
		}
예제 #36
0
 public virtual void RenderPostMain(XnaMatrix transform, RenderEventArgs e) { }