Beispiel #1
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);
            }
        }
Beispiel #2
0
        public void ApplyTransformation()
        {
            if (_dynamicPhysicsObject == null)
            {
                RotationMatrix = Matrix.CreateRotationX((float)AngleX) * Matrix.CreateRotationY((float)AngleY) *
                                 Matrix.CreateRotationZ((float)AngleZ);
                Matrix scaleMatrix = Matrix.CreateScale(Scale);
                _worldOldMatrix = scaleMatrix * RotationMatrix * Matrix.CreateTranslation(Position);

                WorldTransform.Scale = Scale;
                WorldTransform.World = _worldOldMatrix;

                if (StaticPhysicsObject != null)
                {
                    AffineTransform change = new AffineTransform(
                        new BEPUutilities.Vector3(Scale.X, Scale.Y, Scale.Z),
                        Quaternion.CreateFromRotationMatrix(MathConverter.Convert(RotationMatrix)),
                        MathConverter.Convert(Position));

                    if (!MathConverter.Equals(change.Matrix, StaticPhysicsObject.WorldTransform.Matrix))
                    {
                        //StaticPhysicsMatrix = MathConverter.Copy(Change.Matrix);

                        StaticPhysicsObject.WorldTransform = change;
                    }
                }
            }
            else
            {
                //Has something changed?
                WorldTransform.Scale = Scale;
                _worldOldMatrix      = Extensions.CopyFromBepuMatrix(_worldOldMatrix, _dynamicPhysicsObject.WorldTransform);
                Matrix scaleMatrix = Matrix.CreateScale(Scale);
                //WorldOldMatrix = Matrix.CreateScale(Scale)*WorldOldMatrix;
                WorldTransform.World = scaleMatrix * _worldOldMatrix;
            }
        }
 public static Matrix CreateRotationY(float rotY)
 {
     return(new Matrix(Matrix4x4.CreateRotationY(rotY)));
 }