public Point2PointConstraint(RigidBody rbA, ref IndexedVector3 pivotInA) : base(TypedConstraintType.POINT2POINT_CONSTRAINT_TYPE, rbA) { m_pivotInA = pivotInA; m_pivotInB = rbA.GetCenterOfMassTransform() * pivotInA; }
public void BuildCollisionData(Color[] map, int width, int height, Vector3 bottomLeft) { Vector2 dim = Vector2.One; Vector3 scale = new Vector3(dim, 1); BoxShape collisionBoxShape = new BoxShape(new IndexedVector3(0.5f)); for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { int currentIndex = x + y * width; if (map[currentIndex] == Color.White) { float yOffset = -dim.Y;//0f;// -(dim.Y / 2f); Vector3 position = new Vector3(x - bottomLeft.X, (bottomLeft.Y - y) + yOffset, bottomLeft.Z); m_waterLocations.Add(position); } if (map[currentIndex] == Color.White) { // check the 4 ordinals , if we're surrounded by other solid blocks // then we don't need a block here. bool upSet = false; bool downSet = false; bool leftSet = false; bool rightSet = false; if (x >= 1 && x < width - 1) { if (map[currentIndex - 1] == Color.White) { leftSet = true; } if (map[currentIndex + 1] == Color.White) { rightSet = true; } } if (y >= 1 && y < height - 1) { if (map[currentIndex - height] == Color.White) { upSet = true; } if (map[currentIndex + height] == Color.White) { downSet = true; } } // if we're not surrounded by blocks then add in. if (!(upSet && downSet && leftSet && rightSet)) { Object rigifdBody; float yOffset = -dim.Y;//0f;// -(dim.Y / 2f); Vector3 position = new Vector3(x - bottomLeft.X, (bottomLeft.Y - y) + yOffset, bottomLeft.Z); RigidBodyConstructionInfo constructionInfo = new BulletMonogame.BulletDynamics.RigidBodyConstructionInfo(0f, null, (BulletMonogame.BulletCollision.CollisionShape)collisionBoxShape); RigidBody rigidBody = new BulletMonogame.BulletDynamics.RigidBody(constructionInfo); Matrix bsm = Matrix.CreateTranslation(position); rigidBody.SetWorldTransform(bsm); // FIXME MAN - setup some collision flags on these bodies... BulletMonogame.BulletCollision.CollisionFilterGroups flags = (BulletMonogame.BulletCollision.CollisionFilterGroups)(1 << 8); BulletMonogame.BulletCollision.CollisionFilterGroups mask = (BulletMonogame.BulletCollision.CollisionFilterGroups)(1 << 9); //rigidBody.CollisionFlags |= (BulletSharp.CollisionFlags)CollisionObjectType.Ground; m_dynamicsWorld.AddRigidBody(rigidBody, flags, mask); } } // Build water ghost objects. foreach (Vector3 pos in m_waterLocations) { GhostObject ghostObject = new GhostObject(); ghostObject.SetCollisionShape((BulletMonogame.BulletCollision.CollisionShape)collisionBoxShape); CollisionFilterGroups flags = (CollisionFilterGroups)(1 << 10); CollisionFilterGroups mask = (CollisionFilterGroups)(1 << 9); ghostObject.SetCollisionFlags(CollisionFlags.CF_NO_CONTACT_RESPONSE | CollisionFlags.CF_STATIC_OBJECT); // We can choose to make it "solid" if we want... ghostObject.SetWorldTransform(BulletMonogame.LinearMath.IndexedMatrix.CreateTranslation(pos)); m_dynamicsWorld.AddCollisionObject(ghostObject, flags, mask); break; } } } }
public Point2PointConstraint(RigidBody rbA, RigidBody rbB, ref IndexedVector3 pivotInA, ref IndexedVector3 pivotInB) : base(TypedConstraintType.POINT2POINT_CONSTRAINT_TYPE, rbA, rbB) { m_pivotInA = pivotInA; m_pivotInB = pivotInB; }