com.bulletphysics.collision.shapes.SphereShape Java Examples

The following examples show how to use com.bulletphysics.collision.shapes.SphereShape. 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: Jbullet.java    From BowlerStudio with GNU General Public License v3.0 4 votes vote down vote up
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);
		}
	}
 
Example #2
Source File: SphereCollisionShape.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
protected void createShape() {
    cShape = new SphereShape(radius);
    cShape.setLocalScaling(Converter.convert(getScale()));
    cShape.setMargin(margin);
}
 
Example #3
Source File: SphereCollisionShape.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
protected void createShape() {
    cShape = new SphereShape(radius);
    cShape.setLocalScaling(Converter.convert(getScale()));
    cShape.setMargin(margin);
}