/// <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); }
/// <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; }
/// <summary> /// Create the collision convext hull. /// </summary> /// <param name="points">Points to create convex hull from.</param> public CollisionConvexHull(Vector3[] points) { // convert to bullet vectors and create the shape BulletSharp.Math.Vector3[] bvectors = ToBullet.Vectors(points); _shape = new BulletSharp.ConvexHullShape(bvectors); }
/// <summary> /// Add a child shape to this compound shape. /// </summary> /// <param name="shape">Collision shape to add.</param> /// <param name="transform">Transformations for child shape.</param> public void AddShape(ICollisionShape shape, Matrix?transform = null) { var comShape = _shape as BulletSharp.CompoundShape; comShape.AddChildShape(ToBullet.Matrix(transform ?? Matrix.Identity), shape.BulletCollisionShape); }
/// <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)); }