com.bulletphysics.dynamics.RigidBodyConstructionInfo Java Examples
The following examples show how to use
com.bulletphysics.dynamics.RigidBodyConstructionInfo.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PhysicsWorldJBullet.java From gama with GNU General Public License v3.0 | 5 votes |
public RigidBody addCollisionObject(final CollisionShape shape, final float mass, final Vector3f position, final Vector3f velocity, float friction, float lin_damping, float ang_damping, float restitution) { final Transform startTransform = new Transform(); startTransform.setIdentity(); startTransform.origin.set(position); final boolean isDynamic = mass != 0f; final Vector3f localInertia = new Vector3f(0, 0, 0); if (isDynamic) { shape.calculateLocalInertia(mass, localInertia); } // using motionstate is recommended, it provides // interpolation capabilities, and only synchronizes // 'active' objects final DefaultMotionState myMotionState = new DefaultMotionState(startTransform); final RigidBodyConstructionInfo rbInfo = new RigidBodyConstructionInfo(mass, myMotionState, shape, localInertia); final RigidBody body = new RigidBody(rbInfo); // DEBUG.OUT(velocity); // body.applyCentralForce(velocity); body.setLinearVelocity(velocity); body.setFriction(friction); body.setDamping(lin_damping, ang_damping); body.setRestitution(restitution); dynamicsWorld.addRigidBody(body); return body; }
Example #2
Source File: Jbullet.java From BowlerStudio with GNU General Public License v3.0 | 4 votes |
public static void main(String[] args) { BroadphaseInterface broadphase = new DbvtBroadphase(); DefaultCollisionConfiguration collisionConfiguration = new DefaultCollisionConfiguration(); CollisionDispatcher dispatcher = new CollisionDispatcher(collisionConfiguration); SequentialImpulseConstraintSolver solver = new SequentialImpulseConstraintSolver(); DiscreteDynamicsWorld dynamicsWorld = new DiscreteDynamicsWorld(dispatcher, broadphase, solver, collisionConfiguration); // set the gravity of our world dynamicsWorld.setGravity(new Vector3f(0, -10, 0)); // setup our collision shapes CollisionShape groundShape = new StaticPlaneShape(new Vector3f(0, 1, 0), 1); CollisionShape fallShape = new SphereShape(1); // setup the motion state DefaultMotionState groundMotionState = new DefaultMotionState( new Transform(new Matrix4f(new Quat4f(0, 0, 0, 1), new Vector3f(0, -1, 0), 1.0f))); RigidBodyConstructionInfo groundRigidBodyCI = new RigidBodyConstructionInfo(0, groundMotionState, groundShape, new Vector3f(0, 0, 0)); RigidBody groundRigidBody = new RigidBody(groundRigidBodyCI); dynamicsWorld.addRigidBody(groundRigidBody); // add our ground to the // dynamic world.. // setup the motion state for the ball DefaultMotionState fallMotionState = new DefaultMotionState( new Transform(new Matrix4f(new Quat4f(0, 0, 0, 1), new Vector3f(0, 100, 0), 1.0f))); // This we're going to give mass so it responds to gravity int mass = 1; Vector3f fallInertia = new Vector3f(0, 0, 0); fallShape.calculateLocalInertia(mass, fallInertia); RigidBodyConstructionInfo fallRigidBodyCI = new RigidBodyConstructionInfo(mass, fallMotionState, fallShape, fallInertia); RigidBody fallRigidBody = new RigidBody(fallRigidBodyCI); // now we add it to our physics simulation dynamicsWorld.addRigidBody(fallRigidBody); for (int i = 0; i < 300; i++) { dynamicsWorld.stepSimulation(1 / 60.f, 10); Transform trans = new Transform(); fallRigidBody.getMotionState().getWorldTransform(trans); System.out.println("sphere height: " + trans.origin.y); } }