Exemplo n.º 1
0
        /// <summary>
        /// Create the collision plane.
        /// </summary>
        /// <param name="normal">Plane normal vector.</param>
        public CollisionEndlessPlane(Vector3?normal = null)
        {
            // default normal
            if (normal == null)
            {
                normal = Vector3.Up;
            }

            // create the plane shape
            _shape = new BulletSharp.StaticPlaneShape(ToBullet.Vector((Vector3)normal), 1);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Create the collision height map.
        /// </summary>
        /// <param name="heightData">Height map data (should be defined as byte[size.X * size.Y * 4]).</param>
        /// <param name="size">Tilemap size (Y is actually Z axis).</param>
        /// <param name="scale">Scale tiles width and depth.</param>
        /// <param name="minHeight">Min height value.</param>
        /// <param name="maxHeight">Max height value.</param>
        /// <param name="heightScale">Optional height scale.</param>
        /// <param name="upIndex">Up index.</param>
        /// <param name="useDiamondSubdivision">Divide the tiles into diamond shapes for more accurare results.</param>
        private void Build(float[] heightData, Point size, Vector2 scale, float minHeight = 0f, float maxHeight = 100f, float heightScale = 1f, int upIndex = 1, bool useDiamondSubdivision = false)
        {
            // get int ptr for data bytes
            _rawDataHandle = System.Runtime.InteropServices.GCHandle.Alloc(heightData, System.Runtime.InteropServices.GCHandleType.Pinned);
            var address = _rawDataHandle.AddrOfPinnedObject();

            // create heightmap
            var heightmap = new BulletSharp.HeightfieldTerrainShape(size.X, size.Y, address,
                                                                    heightScale, minHeight, maxHeight, upIndex,
                                                                    BulletSharp.PhyScalarType.Single, false);

            // set transform and diamond subdivision
            heightmap.SetUseDiamondSubdivision(useDiamondSubdivision);
            heightmap.LocalScaling = ToBullet.Vector(new Vector3(scale.X, 1, scale.Y));

            // set shape
            _shape = heightmap;
        }
Exemplo n.º 3
0
 /// <summary>
 /// Create the collision triangle.
 /// </summary>
 /// <param name="p1">Triangle point 1.</param>
 /// <param name="p2">Triangle point 2.</param>
 /// <param name="p3">Triangle point 2.</param>
 public CollisionTriangle(Vector3 p1, Vector3 p2, Vector3 p3)
 {
     _shape = new BulletSharp.TriangleShape(ToBullet.Vector(p1), ToBullet.Vector(p2), ToBullet.Vector(p3));
 }