Example #1
0
        protected override void ConfigureCollidable(TriangleEntry entry, float dt)
        {
            TriangleShape shape = entry.Collidable.Shape;

            mesh.Shape.TriangleMesh.Data.GetTriangle(entry.Index, out shape.vA, out shape.vB, out shape.vC);
            Matrix3x3 o;

            Matrix3x3.CreateFromQuaternion(ref mesh.worldTransform.Orientation, out o);
            Matrix3x3.Transform(ref shape.vA, ref o, out shape.vA);
            Matrix3x3.Transform(ref shape.vB, ref o, out shape.vB);
            Matrix3x3.Transform(ref shape.vC, ref o, out shape.vC);
            Vector3 center;

            Vector3.Add(ref shape.vA, ref shape.vB, out center);
            Vector3.Add(ref center, ref shape.vC, out center);
            Vector3.Multiply(ref center, 1 / 3f, out center);
            Vector3.Subtract(ref shape.vA, ref center, out shape.vA);
            Vector3.Subtract(ref shape.vB, ref center, out shape.vB);
            Vector3.Subtract(ref shape.vC, ref center, out shape.vC);

            Vector3.Add(ref center, ref mesh.worldTransform.Position, out center);
            //The bounding box doesn't update by itself.
            entry.Collidable.worldTransform.Position    = center;
            entry.Collidable.worldTransform.Orientation = Quaternion.Identity;
            entry.Collidable.UpdateBoundingBoxInternal(dt);
        }
Example #2
0
        protected void TryToAdd(int index)
        {
            TriangleEntry entry = new TriangleEntry {
                Index = index
            };

            if (!subPairs.ContainsKey(entry))
            {
                CollidablePair collidablePair =
                    new CollidablePair(CollidableA, entry.Collidable = GetOpposingCollidable(index));
                MobileMeshPairHandler newPair =
                    (MobileMeshPairHandler)NarrowPhaseHelper.GetPairHandler(ref collidablePair);
                if (newPair != null)
                {
                    newPair.CollisionRule = CollisionRule;
                    newPair.UpdateMaterialProperties(MaterialA,
                                                     MaterialB); //Override the materials, if necessary.  Meshes don't currently support custom materials but..
                    newPair.Parent = this;
                    subPairs.Add(entry, newPair);
                }
            }

            containedPairs.Add(entry);
        }
Example #3
0
 /// <summary>
 /// Configure a triangle from CollidableB to represent the object at the given index.
 /// </summary>
 /// <param name="entry">Entry to configure.</param>
 /// <param name="dt">Time step duration.</param>
 protected abstract void ConfigureCollidable(TriangleEntry entry, float dt);
 protected override void ConfigureCollidable(TriangleEntry entry, float dt)
 {
 }