コード例 #1
0
        protected override TriangleCollidable GetOpposingCollidable(int index)
        {
            //Construct a TriangleCollidable from the static mesh.
            TriangleCollidable toReturn = PhysicsResources.GetTriangleCollidable();
            TriangleShape      shape    = toReturn.Shape;

            mesh.Shape.TriangleMesh.Data.GetTriangle(index, out shape.vA, out shape.vB, out shape.vC);
            Matrix3x3.Transform(ref shape.vA, ref mesh.worldTransform.LinearTransform, out shape.vA);
            Matrix3x3.Transform(ref shape.vB, ref mesh.worldTransform.LinearTransform, out shape.vB);
            Matrix3x3.Transform(ref shape.vC, ref mesh.worldTransform.LinearTransform, 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.Translation, out center);
            //The bounding box doesn't update by itself.
            toReturn.worldTransform.Position    = center;
            toReturn.worldTransform.Orientation = Quaternion.Identity;
            toReturn.UpdateBoundingBoxInternal(0);
            shape.sidedness       = mesh.Sidedness;
            shape.collisionMargin = mobileMesh.Shape.MeshCollisionMargin;
            return(toReturn);
        }
コード例 #2
0
 /// <summary>
 /// Returns a resource to the pool.
 /// </summary>
 /// <param name="triangle">Triangle collidable to return.</param>
 public static void GiveBack(TriangleCollidable triangle)
 {
     if (SubPoolTriangleCollidables == null)
     {
         SubPoolTriangleCollidables = new UnsafeResourcePool <TriangleCollidable>();
     }
     triangle.CleanUp();
     SubPoolTriangleCollidables.GiveBack(triangle);
 }
コード例 #3
0
        protected override TriangleCollidable GetOpposingCollidable(int index)
        {
            //Construct a TriangleCollidable from the static mesh.
            TriangleCollidable toReturn = PhysicsResources.GetTriangleCollidable();

            toReturn.Shape.sidedness       = mesh.Shape.Sidedness;
            toReturn.Shape.collisionMargin = mobileMesh.Shape.MeshCollisionMargin;
            toReturn.Entity = mesh.entity;
            return(toReturn);
        }
コード例 #4
0
        /// <summary>
        /// Retrieves a TriangleCollidable from the resource pool.
        /// </summary>
        /// <param name="a">First vertex in the triangle.</param>
        /// <param name="b">Second vertex in the triangle.</param>
        /// <param name="c">Third vertex in the triangle.</param>
        /// <returns>Initialized TriangleCollidable.</returns>
        public static TriangleCollidable GetTriangleCollidable(ref Vector3 a, ref Vector3 b, ref Vector3 c)
        {
            if (SubPoolTriangleCollidables == null)
            {
                SubPoolTriangleCollidables = new UnsafeResourcePool <TriangleCollidable>();
            }

            TriangleCollidable tri   = SubPoolTriangleCollidables.Take();
            TriangleShape      shape = tri.Shape;

            shape.vA = a;
            shape.vB = b;
            shape.vC = c;
            RigidTransform identity = RigidTransform.Identity;

            tri.UpdateBoundingBoxForTransform(ref identity);
            return(tri);
        }
コード例 #5
0
        protected override TriangleCollidable GetOpposingCollidable(int index)
        {
            //Construct a TriangleCollidable from the static mesh.
            TriangleCollidable toReturn  = PhysicsResources.GetTriangleCollidable();
            Vector3            terrainUp = new Vector3(mesh.worldTransform.LinearTransform.M21,
                                                       mesh.worldTransform.LinearTransform.M22, mesh.worldTransform.LinearTransform.M23);
            float         dot;
            Vector3       AB, AC, normal;
            TriangleShape shape = toReturn.Shape;

            mesh.Shape.GetTriangle(index, ref mesh.worldTransform, out shape.vA, out shape.vB, 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);

            //The bounding box doesn't update by itself.
            toReturn.worldTransform.Position    = center;
            toReturn.worldTransform.Orientation = Quaternion.Identity;
            toReturn.UpdateBoundingBoxInternal(0);

            Vector3.Subtract(ref shape.vB, ref shape.vA, out AB);
            Vector3.Subtract(ref shape.vC, ref shape.vA, out AC);
            Vector3.Cross(ref AB, ref AC, out normal);
            Vector3.Dot(ref terrainUp, ref normal, out dot);
            if (dot > 0)
            {
                shape.sidedness = TriangleSidedness.Clockwise;
            }
            else
            {
                shape.sidedness = TriangleSidedness.Counterclockwise;
            }

            shape.collisionMargin = mobileMesh.Shape.MeshCollisionMargin;
            return(toReturn);
        }
コード例 #6
0
 protected override void CleanUpCollidable(TriangleCollidable collidable)
 {
     collidable.Entity = null;
     base.CleanUpCollidable(collidable);
 }
コード例 #7
0
 /// <summary>
 /// Returns a resource to the pool.
 /// </summary>
 /// <param name="triangle">Triangle collidable to return.</param>
 public static void GiveBack(TriangleCollidable triangle)
 {
     if (SubPoolTriangleCollidables == null)
         SubPoolTriangleCollidables = new UnsafeResourcePool<TriangleCollidable>();
     triangle.CleanUp();
     SubPoolTriangleCollidables.GiveBack(triangle);
 }
コード例 #8
0
 protected override void CleanUpCollidable(TriangleCollidable collidable)
 {
     collidable.Entity = null;
     base.CleanUpCollidable(collidable);
 }
コード例 #9
0
 /// <summary>
 /// Cleans up the collidable.
 /// </summary>
 /// <param name="collidable">Collidable to clean up.</param>
 protected virtual void CleanUpCollidable(TriangleCollidable collidable)
 {
     PhysicsResources.GiveBack(collidable);
 }
コード例 #10
0
 /// <summary>
 /// Returns a resource to the pool.
 /// </summary>
 /// <param name="triangle">Triangle collidable to return.</param>
 public static void GiveBack(TriangleCollidable triangle)
 {
     triangle.CleanUp();
     SubPoolTriangleCollidables.GiveBack(triangle);
 }
コード例 #11
0
ファイル: Resources.cs プロジェクト: VICOGameStudio-Ujen/igf
 /// <summary>
 /// Returns a resource to the pool.
 /// </summary>
 /// <param name="triangle">Triangle collidable to return.</param>
 public static void GiveBack(TriangleCollidable triangle)
 {
     triangle.CleanUp();
     SubPoolTriangleCollidables.GiveBack(triangle);
 }
コード例 #12
0
 protected override void CleanUpCollidable(TriangleCollidable collidable)
 {
     base.CleanUpCollidable(collidable);
 }
コード例 #13
0
 protected override void CleanUpCollidable(TriangleCollidable collidable)
 {
     base.CleanUpCollidable(collidable);
 }