com.bulletphysics.dynamics.RigidBody Java Examples
The following examples show how to use
com.bulletphysics.dynamics.RigidBody.
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: Physical3DWorldAgent.java From gama with GNU General Public License v3.0 | 5 votes |
@action ( name = "compute_forces", args = { @arg ( name = "step", type = IType.FLOAT, optional = true, doc = @doc ("allows to define the time step considered for the physical world agent. " + "If not defined, the physical world agent will use the step global variable. ")) }) @doc ( value = "This action allows the world to compute the forces exerted on each agent", examples = { @example ( value = "do compute_forces step: 1.0;", isExecutable = false) }) public Object primComputeForces(final IScope scope) throws GamaRuntimeException { final Double timeStep = scope.hasArg("step") ? (Double) scope.getArg("step", IType.FLOAT) : 1.0; // DEBUG.LOG("Time step : "+ timeStep); world.update(timeStep.floatValue()); registeredMap.keySet().removeIf(entry -> entry == null || entry.dead()); for (final IAgent ia : registeredMap.keySet()) { if ((Double) ia.getAttribute("mass") == 0.0) { continue; } final RigidBody node = registeredMap.get(ia); final Vector3f _position = world.getNodePosition(node); final GamaPoint position = new GamaPoint(new Double(_position.x), new Double(_position.y), new Double(_position.z)); ia.setLocation(position); final Coordinate[] coordinates = ia.getInnerGeometry().getCoordinates(); for (int i = 0; i < coordinates.length; i++) { coordinates[i].z = _position.z; } } return null; }
Example #2
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 #3
Source File: VehicleWheel.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * returns the object this wheel is in contact with or null if no contact * @return the PhysicsCollisionObject (PhysicsRigidBody, PhysicsGhostObject) */ public PhysicsCollisionObject getGroundObject() { if (wheelInfo.raycastInfo.groundObject == null) { return null; } else if (wheelInfo.raycastInfo.groundObject instanceof RigidBody) { System.out.println("RigidBody"); return (PhysicsRigidBody) ((RigidBody) wheelInfo.raycastInfo.groundObject).getUserPointer(); } else { return null; } }
Example #4
Source File: VehicleWheel.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 5 votes |
/** * returns the object this wheel is in contact with or null if no contact * @return the PhysicsCollisionObject (PhysicsRigidBody, PhysicsGhostObject) */ public PhysicsCollisionObject getGroundObject() { if (wheelInfo.raycastInfo.groundObject == null) { return null; } else if (wheelInfo.raycastInfo.groundObject instanceof RigidBody) { System.out.println("RigidBody"); return (PhysicsRigidBody) ((RigidBody) wheelInfo.raycastInfo.groundObject).getUserPointer(); } else { return null; } }
Example #5
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); } }
Example #6
Source File: Physical3DWorldAgent.java From gama with GNU General Public License v3.0 | 4 votes |
public void registerAgent(final IAgent ia) { final RigidBody body = this.CollisionBoundToCollisionShape(ia); registeredMap.put(ia, body); }
Example #7
Source File: PhysicsRigidBody.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 4 votes |
/** * used internally */ public RigidBody getObjectId() { return rBody; }
Example #8
Source File: PhysicsRigidBody.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 4 votes |
/** * used internally */ public RigidBody getObjectId() { return rBody; }