本文整理汇总了Java中com.bulletphysics.linearmath.DefaultMotionState类的典型用法代码示例。如果您正苦于以下问题:Java DefaultMotionState类的具体用法?Java DefaultMotionState怎么用?Java DefaultMotionState使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DefaultMotionState类属于com.bulletphysics.linearmath包,在下文中一共展示了DefaultMotionState类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: localCreateRigidBody
import com.bulletphysics.linearmath.DefaultMotionState; //导入依赖的package包/类
private RigidBody localCreateRigidBody(float mass,
Transform startTransform, CollisionShape shape) {
Vector3f localInertia = new Vector3f(0f, 0f, 0f);
shape.calculateLocalInertia(mass, localInertia);
DefaultMotionState myMotionState = new DefaultMotionState(
startTransform);
RigidBodyConstructionInfo rbInfo = new RigidBodyConstructionInfo(mass,
myMotionState, shape, localInertia);
RigidBody body = new RigidBody(rbInfo);
body.setRestitution(2f);
body.setDamping(.01f, .3f);
ownerWorld.addRigidBody(body);
return body;
}
示例2: makeDomino
import com.bulletphysics.linearmath.DefaultMotionState; //导入依赖的package包/类
public boolean makeDomino(float mass, Vector3f inertia, Vector3f loc,
float angle) {
if (cntCreated >= numDominoes)
return false;
int i = cntCreated++;
dominoOrigTransform[i] = new Transform(new Matrix4f(new Quat4f(0,
sin(angle) / (float) Math.sqrt(2), 0, 1), loc, 1.0f));
DefaultMotionState dominoMotion = new DefaultMotionState(
dominoOrigTransform[i]);
RigidBodyConstructionInfo dominoRigidBodyCI = new RigidBodyConstructionInfo(
mass, dominoMotion, dominoShape, inertia);
domino[i] = new RigidBody(dominoRigidBodyCI);
domino[i].setRestitution(0.5f);
world.addRigidBody(domino[i]);
return true;
}
示例3: localCreateRigidBody
import com.bulletphysics.linearmath.DefaultMotionState; //导入依赖的package包/类
private RigidBody localCreateRigidBody(float mass, Transform startTransform, CollisionShape shape) {
boolean isDynamic = (mass != 0f);
Vector3f localInertia = new Vector3f();
localInertia.set(0f, 0f, 0f);
if (isDynamic) {
shape.calculateLocalInertia(mass, localInertia);
}
DefaultMotionState myMotionState = new DefaultMotionState(startTransform);
RigidBodyConstructionInfo rbInfo = new RigidBodyConstructionInfo(mass, myMotionState, shape, localInertia);
rbInfo.additionalDamping = true;
RigidBody body = new RigidBody(rbInfo);
ownerWorld.addRigidBody(body);
return body;
}
示例4: localCreateRigidBody
import com.bulletphysics.linearmath.DefaultMotionState; //导入依赖的package包/类
private RigidBody localCreateRigidBody(float mass, Transform startTransform, CollisionShape shape) {
boolean isDynamic = (mass != 0f);
Vector3f localInertia = new Vector3f();
localInertia.set(0f, 0f, 0f);
if (isDynamic) {
shape.calculateLocalInertia(mass, localInertia);
}
DefaultMotionState myMotionState = new DefaultMotionState(startTransform);
RigidBodyConstructionInfo rbInfo = new RigidBodyConstructionInfo(mass, myMotionState, shape, localInertia);
RigidBody body = new RigidBody(rbInfo);
ownerWorld.addRigidBody(body);
return body;
}
示例5: addCollisionObject
import com.bulletphysics.linearmath.DefaultMotionState; //导入依赖的package包/类
public RigidBody addCollisionObject(CollisionShape shape, float mass, Vector3f position, Vector3f velocity){
Transform startTransform = new Transform();
startTransform.setIdentity();
startTransform.origin.set(position);
boolean isDynamic = (mass != 0f);
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
DefaultMotionState myMotionState = new DefaultMotionState(startTransform);
RigidBodyConstructionInfo rbInfo = new RigidBodyConstructionInfo(
mass, myMotionState, shape, localInertia);
RigidBody body = new RigidBody(rbInfo);
// System.out.println(velocity);
// body.applyCentralForce(velocity);
body.setLinearVelocity(velocity);
dynamicsWorld.addRigidBody(body);
return body;
}
示例6: mkStaticGroundPlane
import com.bulletphysics.linearmath.DefaultMotionState; //导入依赖的package包/类
protected void mkStaticGroundPlane(DynamicsWorld world) {
// floor
float mass = 0;
CollisionShape shape = new BoxShape(new Vector3f(L, 10, W));
Transform t = new Transform();
t.setIdentity();
t.origin.set(new Vector3f(p.x,p.y-10,p.z));
MotionState motionState = new DefaultMotionState(t);
RigidBodyConstructionInfo info = new RigidBodyConstructionInfo(mass, motionState, shape);
RigidBody body = new RigidBody(info);
body.setFriction(1f);
body.setRestitution(.5f);
world.addRigidBody(body);
}
示例7: initializePhysics
import com.bulletphysics.linearmath.DefaultMotionState; //导入依赖的package包/类
protected void initializePhysics(DynamicsWorld world){
t = new Transform();
t.setIdentity();
t.origin.set(new Vector3f(p.x,p.y,p.z));
Vector3f inertia = new Vector3f(0,0,0);
shape.calculateLocalInertia(p.mass,inertia);
shape.setLocalScaling(new Vector3f(p.size, p.size, p.size));
MotionState motionState = new DefaultMotionState(t);
RigidBodyConstructionInfo info = new RigidBodyConstructionInfo(p.mass,motionState,shape,inertia);
body = new RigidBody(info);
body.setFriction(friction);
body.setDamping(linDamping, angDamping);
body.setAngularFactor(angularFactor);
body.setRestitution(restitution);
Scene.world.addRigidBody(body);
}
示例8: p3dRuler
import com.bulletphysics.linearmath.DefaultMotionState; //导入依赖的package包/类
public void p3dRuler(){
float length = 10/2f;
float width = 10/2f;
List<Vector3f> vertices = new ArrayList<Vector3f>();
vertices.add(new Vector3f(-length,0,-width));
vertices.add(new Vector3f(-length,0,width));
vertices.add(new Vector3f(length,0,width));
vertices.add(new Vector3f(length,0,-width));
Transform startTransform = new Transform();
startTransform.setIdentity();
Vector3f translate = new Vector3f();
startTransform.origin.set(translate);
CollisionShape shape = new ConvexHullShape(vertices);
Vector3f localInertia = new Vector3f(0f, 0f, 0f);
DefaultMotionState myMotionState = new DefaultMotionState(startTransform);
RigidBodyConstructionInfo cInfo = new RigidBodyConstructionInfo(0f, myMotionState, shape, localInertia);
RigidBody body = new RigidBody(cInfo);
body.setGravity(new Vector3f(0,0,0));
pInterfaceWorld.addRigidBody(body);
//adding this to another dynamic world*interfaceworld*
}
示例9: BulletPhysics
import com.bulletphysics.linearmath.DefaultMotionState; //导入依赖的package包/类
public BulletPhysics(WorldProvider world) {
collisionGroupManager = CoreRegistry.get(CollisionGroupManager.class);
_broadphase = new DbvtBroadphase();
_broadphase.getOverlappingPairCache().setInternalGhostPairCallback(new GhostPairCallback());
_defaultCollisionConfiguration = new DefaultCollisionConfiguration();
_dispatcher = new CollisionDispatcher(_defaultCollisionConfiguration);
_sequentialImpulseConstraintSolver = new SequentialImpulseConstraintSolver();
_discreteDynamicsWorld = new DiscreteDynamicsWorld(_dispatcher, _broadphase, _sequentialImpulseConstraintSolver, _defaultCollisionConfiguration);
_discreteDynamicsWorld.setGravity(new Vector3f(0f, -15f, 0f));
blockEntityRegistry = CoreRegistry.get(BlockEntityRegistry.class);
CoreRegistry.get(EventSystem.class).registerEventReceiver(this, BlockChangedEvent.class, BlockComponent.class);
PhysicsWorldWrapper wrapper = new PhysicsWorldWrapper(world);
VoxelWorldShape worldShape = new VoxelWorldShape(wrapper);
Matrix3f rot = new Matrix3f();
rot.setIdentity();
DefaultMotionState blockMotionState = new DefaultMotionState(new Transform(new Matrix4f(rot, new Vector3f(0, 0, 0), 1.0f)));
RigidBodyConstructionInfo blockConsInf = new RigidBodyConstructionInfo(0, blockMotionState, worldShape, new Vector3f());
RigidBody rigidBody = new RigidBody(blockConsInf);
rigidBody.setCollisionFlags(CollisionFlags.STATIC_OBJECT | rigidBody.getCollisionFlags());
_discreteDynamicsWorld.addRigidBody(rigidBody, combineGroups(StandardCollisionGroup.WORLD), (short)(CollisionFilterGroups.ALL_FILTER ^ CollisionFilterGroups.STATIC_FILTER));
}
示例10: setCollisionShape
import com.bulletphysics.linearmath.DefaultMotionState; //导入依赖的package包/类
/**
* Creates a {@link com.bulletphysics.dynamics.RigidBody} with the specified shape and mass.
*
* @param colShape Collision shape for physics simulation
* @param mass Mass of the body
*/
protected void setCollisionShape(CollisionShape colShape, float mass) {
// compute inertia (only for non static bodies)
Vector3f localInertia = new Vector3f(0, 0, 0);
if (mass != 0) {
colShape.calculateLocalInertia(mass, localInertia);
}
// create rigid body for physics simulation
synchronized (mPhysicsTransform) {
DefaultMotionState motionState = new DefaultMotionState(mPhysicsTransform);
RigidBodyConstructionInfo rbInfo = new RigidBodyConstructionInfo(mass, motionState,
colShape, localInertia);
mPhysicsBody = new RigidBody(rbInfo);
mPhysicsBody.setFriction(1.0f);
}
}
示例11: initPhysics
import com.bulletphysics.linearmath.DefaultMotionState; //导入依赖的package包/类
/**
*
*/
@Override
public void initPhysics() {
DefaultMotionState groundMotionState = new DefaultMotionState(new Transform(new Matrix4f(new Quat4f(0, 0, 0, 1), new Vector3f(0, -1, 0), 1.0f)));
//TODO: Un uglify this code.
TriangleIndexVertexArray vertArray = new TriangleIndexVertexArray();
for (Mesh mesh : this.getMeshes()) {
// Construct collision shape based on the mesh vertices in the Mesh.
float[] positions = mesh.getPositions();
int[] indices = mesh.getIndices();
IndexedMesh indexedMesh = new IndexedMesh();
indexedMesh.numTriangles = indices.length / 3;
indexedMesh.triangleIndexBase = ByteBuffer.allocateDirect(indices.length*4).order(ByteOrder.nativeOrder());
indexedMesh.triangleIndexBase.asIntBuffer().put(indices);
indexedMesh.triangleIndexStride = 3 * 4;
indexedMesh.numVertices = positions.length / 3;
indexedMesh.vertexBase = ByteBuffer.allocateDirect(positions.length*4).order(ByteOrder.nativeOrder());
indexedMesh.vertexBase.asFloatBuffer().put(positions);
indexedMesh.vertexStride = 3 * 4;
vertArray.addIndexedMesh(indexedMesh);
}
BvhTriangleMeshShape collShape = new BvhTriangleMeshShape(vertArray, false);
System.out.println("SCALE: " + this.getScale());
//collisionShape = new ScaledBvhTriangleMeshShape(collShape, new Vector3f(this.getcale(), this.getScale(), this.getScale()));
collisionShape = collShape;
collisionShape.setLocalScaling(new Vector3f(this.getScale(), this.getScale(), this.getScale()));
RigidBodyConstructionInfo groundRigidBodyCI = new RigidBodyConstructionInfo(0, groundMotionState, collisionShape, new Vector3f(0,0,0));
rigidBody = new RigidBody(groundRigidBodyCI);
this.rigidBody.activate();
}
示例12: initPhysics
import com.bulletphysics.linearmath.DefaultMotionState; //导入依赖的package包/类
/**
* Method to initialize all physics related
* values.
*/
@Override
public void initPhysics() {
motionState = new DefaultMotionState(new Transform(new Matrix4f(new Quat4f(0, 0, 0, 1), new Vector3f(-2, -400, 0), 1.0f)));
// Construct collision shape based on the mesh vertices in the Mesh.
fallInertia = new Vector3f(0,0,0);
collisionShape = new BoxShape(new Vector3f(1, 1, 1));
collisionShape.calculateLocalInertia(mass,fallInertia);
// Construct the RigidBody.
RigidBodyConstructionInfo rigidBodyCI = new RigidBodyConstructionInfo(mass, motionState, collisionShape, fallInertia);
rigidBody = new RigidBody(rigidBodyCI);
}
示例13: makeBrick
import com.bulletphysics.linearmath.DefaultMotionState; //导入依赖的package包/类
/**
* This method creates one individual physical brick.
*/
public void makeBrick(int i, float mass, Vector3f inertia, Transform trans) {
brickOrigTransform[i] = trans;
DefaultMotionState brickMotion = new DefaultMotionState(
brickOrigTransform[i]);
RigidBodyConstructionInfo brickRigidBodyCI = new RigidBodyConstructionInfo(
mass, brickMotion, brickShape, inertia);
brick[i] = new RigidBody(brickRigidBodyCI);
world.addRigidBody(brick[i]);
}
示例14: makeBrick
import com.bulletphysics.linearmath.DefaultMotionState; //导入依赖的package包/类
/**
* This method creates one individual physical domino.
*/
public RigidBody makeBrick(int i, float mass, Vector3f inertia,
Vector3f loc, float angle) {
brickOrigTransform[i] = new Transform(new Matrix4f(new Quat4f(0f, 0f,
0f, 1f), new Vector3f(loc), 1f));
MotionState brickMotion = new DefaultMotionState(brickOrigTransform[i]);
RigidBodyConstructionInfo brickRigidBodyCI = new RigidBodyConstructionInfo(
mass, brickMotion, brickShape, inertia);
brick[i] = new RigidBody(brickRigidBodyCI);
world.addRigidBody(brick[i]);
return brick[i];
}
示例15: initWorld
import com.bulletphysics.linearmath.DefaultMotionState; //导入依赖的package包/类
protected void initWorld() {
BroadphaseInterface broadphase = new DbvtBroadphase();
DefaultCollisionConfiguration collisionConfiguration = new DefaultCollisionConfiguration();
CollisionDispatcher dispatcher = new CollisionDispatcher(
collisionConfiguration);
SequentialImpulseConstraintSolver solver = new SequentialImpulseConstraintSolver();
world = new DiscreteDynamicsWorld(dispatcher, broadphase, solver,
collisionConfiguration);
world.setGravity(new Vector3f(0, -1, 0));
groundShape = new StaticPlaneShape(new Vector3f(0, 1, 0), 1);
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));
groundRigidBody = new RigidBody(groundRigidBodyCI);
world.addRigidBody(groundRigidBody);
dollOne = new RagDollShape(world, new Vector3f(0.0f, 30.0f, 0.0f), 5.0f);
dollTwo = new RagDollShape(world, new Vector3f(10.0f, 30.0f, 0.0f),
5.0f);
dollOne.setLinearSpeed(new Vector3f(30f, 0f, 0f));
dollTwo.setLinearSpeed(new Vector3f(-30f, 0f, 0f));
dollOne.saveState();
dollTwo.saveState();
}