本文整理汇总了Java中com.bulletphysics.collision.dispatch.CollisionFlags类的典型用法代码示例。如果您正苦于以下问题:Java CollisionFlags类的具体用法?Java CollisionFlags怎么用?Java CollisionFlags使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
CollisionFlags类属于com.bulletphysics.collision.dispatch包,在下文中一共展示了CollisionFlags类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: initPhysics
import com.bulletphysics.collision.dispatch.CollisionFlags; //导入依赖的package包/类
@Override
public void initPhysics() {
Transform startTranform = new Transform();
startTranform.setIdentity();
startTranform.origin.set(5, -35, -4);
collisionShape = new CapsuleShape(0.5f, 1);
ghostObject = new PairCachingGhostObject();
ghostObject.setWorldTransform(startTranform);
// set getOverlappingPairCache & setInternalGhostPairCallback
ghostObject.setCollisionShape(collisionShape);
ghostObject.setCollisionFlags(CollisionFlags.CHARACTER_OBJECT);
characterController = new KinematicCharacterController(ghostObject, collisionShape, 0.5f);
characterController.setGravity(10);
characterController.setMaxJumpHeight(1.5f);
}
示例2: setMass
import com.bulletphysics.collision.dispatch.CollisionFlags; //导入依赖的package包/类
/**
* Sets the mass of this PhysicsRigidBody, objects with mass=0 are static.
* @param mass
*/
public void setMass(float mass) {
this.mass = mass;
if(collisionShape instanceof MeshCollisionShape && mass != 0){
throw new IllegalStateException("Dynamic rigidbody can not have mesh collision shape!");
}
if (collisionShape != null) {
collisionShape.calculateLocalInertia(mass, localInertia);
}
if (rBody != null) {
rBody.setMassProps(mass, localInertia);
if (mass == 0.0f) {
rBody.setCollisionFlags(rBody.getCollisionFlags() | CollisionFlags.STATIC_OBJECT);
} else {
rBody.setCollisionFlags(rBody.getCollisionFlags() & ~CollisionFlags.STATIC_OBJECT);
}
}
}
示例3: keyboardCallback
import com.bulletphysics.collision.dispatch.CollisionFlags; //导入依赖的package包/类
@Override
public void keyboardCallback(char key, int x, int y, int modifiers) {
if (key == 'g') {
animatedMesh = !animatedMesh;
if (animatedMesh) {
staticBody.setCollisionFlags(staticBody.getCollisionFlags() | CollisionFlags.KINEMATIC_OBJECT);
staticBody.setActivationState(CollisionObject.DISABLE_DEACTIVATION);
}
else {
staticBody.setCollisionFlags(staticBody.getCollisionFlags() & ~CollisionFlags.KINEMATIC_OBJECT);
staticBody.forceActivationState(CollisionObject.ACTIVE_TAG);
}
}
super.keyboardCallback(key, x, y, modifiers);
}
示例4: contactAdded
import com.bulletphysics.collision.dispatch.CollisionFlags; //导入依赖的package包/类
public boolean contactAdded(ManifoldPoint cp, CollisionObject colObj0, int partId0, int index0, CollisionObject colObj1, int partId1, int index1) {
float friction0 = colObj0.getFriction();
float friction1 = colObj1.getFriction();
float restitution0 = colObj0.getRestitution();
float restitution1 = colObj1.getRestitution();
if ((colObj0.getCollisionFlags() & CollisionFlags.CUSTOM_MATERIAL_CALLBACK) != 0) {
friction0 = 1f; //partId0,index0
restitution0 = 0f;
}
if ((colObj1.getCollisionFlags() & CollisionFlags.CUSTOM_MATERIAL_CALLBACK) != 0) {
if ((index1 & 1) != 0) {
friction1 = 1f; //partId1,index1
}
else {
friction1 = 0f;
}
restitution1 = 0f;
}
cp.combinedFriction = calculateCombinedFriction(friction0, friction1);
cp.combinedRestitution = calculateCombinedRestitution(restitution0, restitution1);
// this return value is currently ignored, but to be on the safe side: return false if you don't calculate friction
return true;
}
示例5: BulletPhysics
import com.bulletphysics.collision.dispatch.CollisionFlags; //导入依赖的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));
}
示例6: scanArea
import com.bulletphysics.collision.dispatch.CollisionFlags; //导入依赖的package包/类
public Iterable<EntityRef> scanArea(AABB area, Iterable<CollisionGroup> collisionFilter) {
// TODO: Add the aabbTest method from newer versions of bullet to TeraBullet, use that instead
BoxShape shape = new BoxShape(area.getExtents());
GhostObject scanObject = createCollider(area.getCenter(), shape, CollisionFilterGroups.SENSOR_TRIGGER, combineGroups(collisionFilter), CollisionFlags.NO_CONTACT_RESPONSE);
// This in particular is overkill
_broadphase.calculateOverlappingPairs(_dispatcher);
List<EntityRef> result = Lists.newArrayList();
for (int i = 0; i < scanObject.getNumOverlappingObjects(); ++i) {
CollisionObject other = scanObject.getOverlappingObject(i);
Object userObj = other.getUserPointer();
if (userObj instanceof EntityRef) {
result.add((EntityRef)userObj);
}
}
removeCollider(scanObject);
return result;
}
示例7: postRebuild
import com.bulletphysics.collision.dispatch.CollisionFlags; //导入依赖的package包/类
protected void postRebuild() {
rBody.setUserPointer(this);
if (mass == 0.0f) {
rBody.setCollisionFlags(rBody.getCollisionFlags() | CollisionFlags.STATIC_OBJECT);
} else {
rBody.setCollisionFlags(rBody.getCollisionFlags() & ~CollisionFlags.STATIC_OBJECT);
}
}
示例8: setKinematic
import com.bulletphysics.collision.dispatch.CollisionFlags; //导入依赖的package包/类
/**
* Sets the node to kinematic mode. in this mode the node is not affected by physics
* but affects other physics objects. Iits kinetic force is calculated by the amount
* of movement it is exposed to and its weight.
* @param kinematic
*/
public void setKinematic(boolean kinematic) {
this.kinematic = kinematic;
if (kinematic) {
rBody.setCollisionFlags(rBody.getCollisionFlags() | CollisionFlags.KINEMATIC_OBJECT);
rBody.setActivationState(com.bulletphysics.collision.dispatch.CollisionObject.DISABLE_DEACTIVATION);
} else {
rBody.setCollisionFlags(rBody.getCollisionFlags() & ~CollisionFlags.KINEMATIC_OBJECT);
rBody.setActivationState(com.bulletphysics.collision.dispatch.CollisionObject.ACTIVE_TAG);
}
}
示例9: setMassProps
import com.bulletphysics.collision.dispatch.CollisionFlags; //导入依赖的package包/类
public void setMassProps (float mass, Vector3 inertia) {
if (mass == 0f) {
collisionFlags |= CollisionFlags.STATIC_OBJECT;
inverseMass = 0f;
} else {
collisionFlags &= (~CollisionFlags.STATIC_OBJECT);
inverseMass = 1f / mass;
}
invInertiaLocal.set(inertia.x != 0f ? 1f / inertia.x : 0f, inertia.y != 0f ? 1f / inertia.y : 0f,
inertia.z != 0f ? 1f / inertia.z : 0f);
}
示例10: setMassProps
import com.bulletphysics.collision.dispatch.CollisionFlags; //导入依赖的package包/类
public void setMassProps(float mass, Vector3f inertia) {
if (mass == 0f) {
collisionFlags |= CollisionFlags.STATIC_OBJECT;
inverseMass = 0f;
}
else {
collisionFlags &= (~CollisionFlags.STATIC_OBJECT);
inverseMass = 1f / mass;
}
invInertiaLocal.set(inertia.x != 0f ? 1f / inertia.x : 0f,
inertia.y != 0f ? 1f / inertia.y : 0f,
inertia.z != 0f ? 1f / inertia.z : 0f);
}
示例11: setKinematic
import com.bulletphysics.collision.dispatch.CollisionFlags; //导入依赖的package包/类
@Override
public void setKinematic(boolean kinematic) {
this.kinematic = kinematic;
if (kinematic) {
rBody.setCollisionFlags(rBody.getCollisionFlags() | CollisionFlags.KINEMATIC_OBJECT);
rBody.setActivationState(CollisionObject.DISABLE_DEACTIVATION);
} else {
rBody.setCollisionFlags(rBody.getCollisionFlags() & ~CollisionFlags.KINEMATIC_OBJECT);
// use forceActivationState instead of setActivationState
// otherwise once the state is set to DISABLE_DEACTIVATION, it can
// never set back to ACTIVE_TAG
rBody.forceActivationState(CollisionObject.ACTIVE_TAG);
}
rBody.activate();
}
示例12: CapsulePhysicsBody
import com.bulletphysics.collision.dispatch.CollisionFlags; //导入依赖的package包/类
/**
* Creates a capsule physics body
*
* @param radius in meters
* @param height
*/
public CapsulePhysicsBody(Vector3f center, float radius, float mass, float height, int collisionTypes)
{
super(mass, new Quat4f(0, 0, 0, 1), center, new CapsuleShape(radius, height), collisionTypes);
body.setSleepingThresholds(0, 0);
body.setAngularFactor(0);
body.setDamping(0.85f, 1);
body.setFriction(1f);
body.setGravity(PhysicsTools.openGLToBullet(new Vector3f(0f,-100f,0f)));
body.setCollisionFlags(body.getCollisionFlags() | CollisionFlags.CUSTOM_MATERIAL_CALLBACK);
}
示例13: initPhysics
import com.bulletphysics.collision.dispatch.CollisionFlags; //导入依赖的package包/类
public void initPhysics() throws Exception {
CollisionShape groundShape = new BoxShape(new Vector3f(50, 3, 50));
collisionShapes.add(groundShape);
collisionConfiguration = new DefaultCollisionConfiguration();
dispatcher = new CollisionDispatcher(collisionConfiguration);
Vector3f worldMin = new Vector3f(-1000f,-1000f,-1000f);
Vector3f worldMax = new Vector3f(1000f,1000f,1000f);
AxisSweep3 sweepBP = new AxisSweep3(worldMin, worldMax);
overlappingPairCache = sweepBP;
constraintSolver = new SequentialImpulseConstraintSolver();
dynamicsWorld = new DiscreteDynamicsWorld(dispatcher,overlappingPairCache,constraintSolver,collisionConfiguration);
Transform startTransform = new Transform();
startTransform.setIdentity();
startTransform.origin.set(0.0f, 4.0f, 0.0f);
ghostObject = new PairCachingGhostObject();
ghostObject.setWorldTransform(startTransform);
sweepBP.getOverlappingPairCache().setInternalGhostPairCallback(new GhostPairCallback());
float characterHeight = 1.75f * characterScale;
float characterWidth = 1.75f * characterScale;
ConvexShape capsule = new CapsuleShape(characterWidth, characterHeight);
ghostObject.setCollisionShape(capsule);
ghostObject.setCollisionFlags(CollisionFlags.CHARACTER_OBJECT);
float stepHeight = 0.35f * characterScale;
character = new KinematicCharacterController(ghostObject, capsule, stepHeight);
new BspToBulletConverter().convertBsp(getClass().getResourceAsStream("/com/bulletphysics/demos/bsp/exported.bsp.txt"));
dynamicsWorld.addCollisionObject(ghostObject, CollisionFilterGroups.CHARACTER_FILTER, (short)(CollisionFilterGroups.STATIC_FILTER | CollisionFilterGroups.DEFAULT_FILTER));
dynamicsWorld.addAction(character);
clientResetScene();
setCameraDistance(56f);
}
示例14: createRigidBody
import com.bulletphysics.collision.dispatch.CollisionFlags; //导入依赖的package包/类
public static RigidBody createRigidBody(RigidBodyConstructionInfo rbci) {
RigidBody rb = new RigidBody(rbci);
if (rbci.mass <= EMath.FLOAT_EPSILON) {
rb.setCollisionFlags(CollisionFlags.STATIC_OBJECT);
}
bodies.add(rb);
world.addRigidBody(rb);
return rb;
}
示例15: KinematicCharacterControllerComponent
import com.bulletphysics.collision.dispatch.CollisionFlags; //导入依赖的package包/类
public KinematicCharacterControllerComponent(boolean gravity, float radius, float height, float stepHeight, Vector3f position, int jumpKey, int forwardKey, int backKey, int leftKey, int rightKey) {
shape = new CapsuleShape(radius,height);
ghostObject = new PairCachingGhostObject();
ghostObject.setWorldTransform(PhysicsSystem.createTransform(position, null));
ghostObject.setCollisionShape(shape);
ghostObject.setCollisionFlags(CollisionFlags.CHARACTER_OBJECT);
// http://hub.jmonkeyengine.org/javadoc/com/jme3/bullet/control/BetterCharacterControl.html
character = new KinematicCharacterController(ghostObject,shape ,stepHeight);
if (gravity) {
character.setJumpSpeed(5.0f);
character.setFallSpeed(500.0f);
} else {
character.setJumpSpeed(0.0f);
character.setFallSpeed(0.0f);
character.setGravity(0);
}
this.gravity = gravity;
PhysicsSystem.getWorld().addCollisionObject(ghostObject,CollisionFilterGroups.CHARACTER_FILTER,(short)(CollisionFilterGroups.STATIC_FILTER | CollisionFilterGroups.DEFAULT_FILTER));
PhysicsSystem.getWorld().addAction(character);
this.jumpKey = jumpKey;
this.forwardKey = forwardKey;
this.backKey = backKey;
this.leftKey = leftKey;
this.rightKey = rightKey;
this.height = height;
initFeet();
lastWalkPosition.set(position);
wasOnGround = character.onGround();
}