コード例 #1
0
ファイル: Quaternion.cs プロジェクト: ByteChkR/bepuphysics1
        /// <summary>
        /// Constructs a quaternion from a rotation matrix.
        /// </summary>
        /// <param name="r">Rotation matrix to create the quaternion from.</param>
        /// <param name="q">Quaternion based on the rotation matrix.</param>
        public static void CreateFromRotationMatrix(ref Matrix r, out Quaternion q)
        {
            Matrix3x3 downsizedMatrix;

            Matrix3x3.CreateFromMatrix(ref r, out downsizedMatrix);
            CreateFromRotationMatrix(ref downsizedMatrix, out q);
        }
コード例 #2
0
        protected override void OnCollisionObjectScaleChanged()
        {
            for (int i = 0; i < Entity.CollisionInformation.Shape.Shapes.Count; i++)
            {
                CompoundShapeEntry childShape = Entity.CollisionInformation.Shape.Shapes[i];

                if (childShape.Shape is TransformableShape)
                {
                    ((TransformableShape)childShape.Shape).Transform = Matrix3x3.CreateFromMatrix(Matrix.CreateScale(CollisionObjectScale) * CollisionObjectWorldTransform);
                }
            }
        }
コード例 #3
0
 protected override void OnCollisionObjectScaleChanged()
 {
     Entity.CollisionInformation.Shape.Transform = Matrix3x3.CreateFromMatrix(Matrix.CreateScale(CollisionObjectScale) * CollisionObjectWorldTransform);
 }
コード例 #4
0
        /// <summary>
        /// Creates a new instance
        /// </summary>
        /// <param name="collisionObject">The ParentObject this instance will be associated with</param>
        /// <param name="model">The Model used to compute the ConvexHull shape used for collision & physics</param>
        /// <remarks>If a previously created instance uses the same Model as the one provided here, it will reuse the computed ConvexHull instance to save CPU</remarks>
        public ConvexHullCollisionMove(ICollisionObject collisionObject, Model model) : base(collisionObject)
        {
            ModelReferencesToDelete.Clear();

            foreach (var modelConvexHull in ModelConvexHulls)
            {
                if (!modelConvexHull.Key.IsAlive)
                {
                    ModelReferencesToDelete.Add(modelConvexHull.Key);
                }
                else if (modelConvexHull.Key.Target == model)
                {
                    ConvexHull convexHull = modelConvexHull.Value;

                    TransformableShape shape = new TransformableShape(convexHull.CollisionInformation.Shape, Matrix3x3.CreateFromMatrix(ParentObject.World));

                    SpaceObject = new Entity <ConvexCollidable <TransformableShape> >(
                        new ConvexCollidable <TransformableShape>(shape),
                        ParentObject.Mass,
                        convexHull.LocalInertiaTensor,
                        convexHull.Volume);
                    Entity.Position = ParentObject.World.Translation;
                }
            }

            foreach (var modelReference in ModelReferencesToDelete)
            {
                ModelConvexHulls.Remove(modelReference);
            }

            if (SpaceObject == null)
            {
                Vector3[] vertices;
                int[]     indices;

                TriangleMesh.GetVerticesAndIndicesFromModel(model, out vertices, out indices);

                var modelReference = new WeakReference(model);
                var convexHull     = new ConvexHull(vertices, ParentObject.Mass);

                ModelConvexHulls.Add(modelReference, convexHull);

                TransformableShape shape = new TransformableShape(convexHull.CollisionInformation.Shape, Matrix3x3.CreateFromMatrix(ParentObject.World));

                SpaceObject = new Entity <ConvexCollidable <TransformableShape> >(
                    new ConvexCollidable <TransformableShape>(shape),
                    ParentObject.Mass,
                    convexHull.LocalInertiaTensor,
                    convexHull.Volume);
                Entity.Position = ParentObject.World.Translation;
            }

            ParentObject.World.GetScaleComponent(out CollisionObjectScale);
        }