本文整理汇总了Java中com.jme3.bullet.collision.PhysicsCollisionObject类的典型用法代码示例。如果您正苦于以下问题:Java PhysicsCollisionObject类的具体用法?Java PhysicsCollisionObject怎么用?Java PhysicsCollisionObject使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
PhysicsCollisionObject类属于com.jme3.bullet.collision包,在下文中一共展示了PhysicsCollisionObject类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: physicsTick
import com.jme3.bullet.collision.PhysicsCollisionObject; //导入依赖的package包/类
public void physicsTick(PhysicsSpace space, float f) {
//get all overlapping objects and apply impulse to them
for (Iterator<PhysicsCollisionObject> it = ghostObject.getOverlappingObjects().iterator(); it.hasNext();) {
PhysicsCollisionObject physicsCollisionObject = it.next();
if (physicsCollisionObject instanceof PhysicsRigidBody) {
PhysicsRigidBody rBody = (PhysicsRigidBody) physicsCollisionObject;
rBody.getPhysicsLocation(vector2);
vector2.subtractLocal(vector);
float force = explosionRadius - vector2.length();
force *= forceFactor;
force = force > 0 ? force : 0;
vector2.normalizeLocal();
vector2.multLocal(force);
((PhysicsRigidBody) physicsCollisionObject).applyImpulse(vector2, Vector3f.ZERO);
}
}
space.removeTickListener(this);
space.remove(ghostObject);
}
示例2: buildPlayer
import com.jme3.bullet.collision.PhysicsCollisionObject; //导入依赖的package包/类
private void buildPlayer() {
spaceCraft = assetManager.loadModel("Models/HoverTank/Tank2.mesh.xml");
CollisionShape colShape = CollisionShapeFactory.createDynamicMeshShape(spaceCraft);
spaceCraft.setShadowMode(ShadowMode.CastAndReceive);
spaceCraft.setLocalTranslation(new Vector3f(-140, 14, -23));
spaceCraft.setLocalRotation(new Quaternion(new float[]{0, 0.01f, 0}));
hoverControl = new PhysicsHoverControl(colShape, 500);
hoverControl.setCollisionGroup(PhysicsCollisionObject.COLLISION_GROUP_02);
spaceCraft.addControl(hoverControl);
rootNode.attachChild(spaceCraft);
getPhysicsSpace().add(hoverControl);
ChaseCamera chaseCam = new ChaseCamera(cam, inputManager);
spaceCraft.addControl(chaseCam);
flyCam.setEnabled(false);
}
示例3: add
import com.jme3.bullet.collision.PhysicsCollisionObject; //导入依赖的package包/类
/**
* adds an object to the physics space
* @param obj the PhysicsControl or Spatial with PhysicsControl to add
*/
public void add(Object obj) {
if (obj instanceof PhysicsControl) {
((PhysicsControl) obj).setPhysicsSpace(this);
} else if (obj instanceof Spatial) {
Spatial node = (Spatial) obj;
PhysicsControl control = node.getControl(PhysicsControl.class);
control.setPhysicsSpace(this);
} else if (obj instanceof PhysicsCollisionObject) {
addCollisionObject((PhysicsCollisionObject) obj);
} else if (obj instanceof PhysicsJoint) {
addJoint((PhysicsJoint) obj);
} else {
throw (new UnsupportedOperationException("Cannot add this kind of object to the physics space."));
}
}
示例4: remove
import com.jme3.bullet.collision.PhysicsCollisionObject; //导入依赖的package包/类
/**
* removes an object from the physics space
* @param obj the PhysicsControl or Spatial with PhysicsControl to remove
*/
public void remove(Object obj) {
if (obj instanceof PhysicsControl) {
((PhysicsControl) obj).setPhysicsSpace(null);
} else if (obj instanceof Spatial) {
Spatial node = (Spatial) obj;
PhysicsControl control = node.getControl(PhysicsControl.class);
control.setPhysicsSpace(null);
} else if (obj instanceof PhysicsCollisionObject) {
removeCollisionObject((PhysicsCollisionObject) obj);
} else if (obj instanceof PhysicsJoint) {
removeJoint((PhysicsJoint) obj);
} else {
throw (new UnsupportedOperationException("Cannot remove this kind of object from the physics space."));
}
}
示例5: controlUpdate
import com.jme3.bullet.collision.PhysicsCollisionObject; //导入依赖的package包/类
@Override
protected void controlUpdate(float tpf) {
List<PhysicsCollisionObject> collisionObjects
= ghost.getOverlappingObjects();
for (PhysicsCollisionObject collisionObject : collisionObjects) {
if (collisionObject.getUserObject() instanceof Spatial) {
Spatial spatial = (Spatial) collisionObject.getUserObject();
Integer entityId = spatial.getUserData(UserData.ENTITY_ID);
if (collidedWith.contains(entityId)) {
continue;
}
collidedWith.add(entityId);
collisionEffect(spatial);
}
}
}
示例6: isExplode
import com.jme3.bullet.collision.PhysicsCollisionObject; //导入依赖的package包/类
public boolean isExplode() {
List<PhysicsCollisionObject> collision = ghost.getOverlappingObjects();
for (int i = 0; i < collision.size(); i++) {
if(collision.get(i) instanceof SaGhost){
SaGhost sa = (SaGhost) collision.get(i);
if(sa.getSa().isIsShield()){
sa.getSa().setIsShield(false);
shieldBroke.playInstance();
continue;
}
sa.getSa().die();
} else if(collision.get(i) instanceof WormGhost) {
WormGhost worm = (WormGhost) collision.get(i);
worm.getWorm().die();
}
}
return isExplode;
}
示例7: remove
import com.jme3.bullet.collision.PhysicsCollisionObject; //导入依赖的package包/类
/**
* removes an object from the physics space
* @param obj the PhysicsControl or Spatial with PhysicsControl to remove
*/
public void remove(Object obj) {
if (obj instanceof PhysicsControl) {
((PhysicsControl) obj).setPhysicsSpace(null);
} else if (obj instanceof Spatial) {
Spatial node = (Spatial) obj;
PhysicsControl control = node.getControl(PhysicsControl.class);
control.setPhysicsSpace(null);
} else if (obj instanceof PhysicsCollisionObject) {
removeCollisionObject((PhysicsCollisionObject) obj);
} else if (obj instanceof PhysicsJoint) {
removeJoint((PhysicsJoint) obj);
} else if (obj == null) {
return;
} else {
throw (new UnsupportedOperationException("Cannot remove this kind of object from the physics space."+obj));
}
}
示例8: attachPhysicsSelection
import com.jme3.bullet.collision.PhysicsCollisionObject; //导入依赖的package包/类
protected void attachPhysicsSelection(Spatial geom) {
PhysicsCollisionObject control = geom.getControl(RigidBodyControl.class);
if (control == null) {
control = geom.getControl(VehicleControl.class);
}
if (control == null) {
control = geom.getControl(GhostControl.class);
}
if (control == null) {
control = geom.getControl(CharacterControl.class);
}
if (control == null) {
return;
}
Spatial selectionGeometry = DebugShapeFactory.getDebugShape(control.getCollisionShape());
if (selectionGeometry != null) {
selectionGeometry.setMaterial(blueMat);
selectionGeometry.setLocalTransform(geom.getWorldTransform());
toolsNode.attachChild(selectionGeometry);
selectionShape = selectionGeometry;
}
}
示例9: makePhysics
import com.jme3.bullet.collision.PhysicsCollisionObject; //导入依赖的package包/类
@Override
protected void makePhysics(PhysicsSpace physicsSpace) {
// intialise the real physics control
CollisionShape cs = new CapsuleCollisionShape(1.5f,5f,1);
physics = new ForceCharacterControl(cs,4);
//physics.setGravity(-200f);
physics.setGravity(200f);
physics.setFallSpeed(200f);
physics.setJumpSpeed(50f);
geometry.addControl(physics);
// create the ghost control
ghost = new GhostControl(cs);
geometry.addControl(ghost);
// put the ghost physics in a different group actor don't collide with themselves
geometry.getControl(GhostControl.class).setCollisionGroup(PhysicsCollisionObject.COLLISION_GROUP_07);
geometry.getControl(GhostControl.class).removeCollideWithGroup(PhysicsCollisionObject.COLLISION_GROUP_01);
geometry.getControl(GhostControl.class).addCollideWithGroup(PhysicsCollisionObject.COLLISION_GROUP_07);
physicsSpace.add(ghost);
physicsSpace.add(physics);
physicsSpace.addTickListener(physicsTickListener);
}
示例10: handleResult
import com.jme3.bullet.collision.PhysicsCollisionObject; //导入依赖的package包/类
/**
* Handle the result from the dialog.
*
* @param vars the table with variables.
*/
@FXThread
private void handleResult(@NotNull final VarTable vars) {
final TreeNode<?> treeNode = getNode();
final PhysicsCollisionObject element = (PhysicsCollisionObject) treeNode.getElement();
final CollisionShape shape = createShape(vars);
final CollisionShape currentShape = element.getCollisionShape();
final NodeTree<?> nodeTree = getNodeTree();
final ChangeConsumer changeConsumer = notNull(nodeTree.getChangeConsumer());
changeConsumer.execute(new ChangeCollisionShapeOperation(shape, currentShape, element));
}
示例11: simpleInitApp
import com.jme3.bullet.collision.PhysicsCollisionObject; //导入依赖的package包/类
@Override
public void simpleInitApp() {
bulletAppState = new BulletAppState();
stateManager.attach(bulletAppState);
bulletAppState.getPhysicsSpace().enableDebug(assetManager);
// Add a physics sphere to the world
Node physicsSphere = PhysicsTestHelper.createPhysicsTestNode(assetManager, new SphereCollisionShape(1), 1);
physicsSphere.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(3, 6, 0));
rootNode.attachChild(physicsSphere);
getPhysicsSpace().add(physicsSphere);
// Add a physics sphere to the world
Node physicsSphere2 = PhysicsTestHelper.createPhysicsTestNode(assetManager, new SphereCollisionShape(1), 1);
physicsSphere2.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(4, 8, 0));
physicsSphere2.getControl(RigidBodyControl.class).addCollideWithGroup(PhysicsCollisionObject.COLLISION_GROUP_02);
rootNode.attachChild(physicsSphere2);
getPhysicsSpace().add(physicsSphere2);
// an obstacle mesh, does not move (mass=0)
Node node2 = PhysicsTestHelper.createPhysicsTestNode(assetManager, new MeshCollisionShape(new Sphere(16, 16, 1.2f)), 0);
node2.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(2.5f, -4, 0f));
node2.getControl(RigidBodyControl.class).setCollisionGroup(PhysicsCollisionObject.COLLISION_GROUP_02);
node2.getControl(RigidBodyControl.class).setCollideWithGroups(PhysicsCollisionObject.COLLISION_GROUP_02);
rootNode.attachChild(node2);
getPhysicsSpace().add(node2);
// the floor, does not move (mass=0)
Node node3 = PhysicsTestHelper.createPhysicsTestNode(assetManager, new MeshCollisionShape(new Box(Vector3f.ZERO, 100f, 0.2f, 100f)), 0);
node3.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(0f, -6, 0f));
rootNode.attachChild(node3);
getPhysicsSpace().add(node3);
}
示例12: makeMissile
import com.jme3.bullet.collision.PhysicsCollisionObject; //导入依赖的package包/类
public void makeMissile() {
Vector3f pos = spaceCraft.getWorldTranslation().clone();
Quaternion rot = spaceCraft.getWorldRotation();
Vector3f dir = rot.getRotationColumn(2);
Spatial missile = assetManager.loadModel("Models/SpaceCraft/Rocket.mesh.xml");
missile.scale(0.5f);
missile.rotate(0, FastMath.PI, 0);
missile.updateGeometricState();
BoundingBox box = (BoundingBox) missile.getWorldBound();
final Vector3f extent = box.getExtent(null);
BoxCollisionShape boxShape = new BoxCollisionShape(extent);
missile.setName("Missile");
missile.rotate(rot);
missile.setLocalTranslation(pos.addLocal(0, extent.y * 4.5f, 0));
missile.setLocalRotation(hoverControl.getPhysicsRotation());
missile.setShadowMode(ShadowMode.Cast);
RigidBodyControl control = new BombControl(assetManager, boxShape, 20);
control.setLinearVelocity(dir.mult(100));
control.setCollisionGroup(PhysicsCollisionObject.COLLISION_GROUP_03);
missile.addControl(control);
rootNode.attachChild(missile);
getPhysicsSpace().add(missile);
}
示例13: collide
import com.jme3.bullet.collision.PhysicsCollisionObject; //导入依赖的package包/类
public void collide(Bone bone, PhysicsCollisionObject object, PhysicsCollisionEvent event) {
if (object.getUserObject() != null && object.getUserObject() instanceof Geometry) {
Geometry geom = (Geometry) object.getUserObject();
if ("Floor".equals(geom.getName())) {
return;
}
}
ragdoll.setRagdollMode();
}
示例14: getOverlappingObjects
import com.jme3.bullet.collision.PhysicsCollisionObject; //导入依赖的package包/类
/**
* Another Object is overlapping with this GhostNode,
* if and if only there CollisionShapes overlaps.
* They could be both regular PhysicsRigidBodys or PhysicsGhostObjects.
* @return All CollisionObjects overlapping with this GhostNode.
*/
public List<PhysicsCollisionObject> getOverlappingObjects() {
overlappingObjects.clear();
for (com.bulletphysics.collision.dispatch.CollisionObject collObj : gObject.getOverlappingPairs()) {
overlappingObjects.add((PhysicsCollisionObject) collObj.getUserPointer());
}
return overlappingObjects;
}
示例15: getGroundObject
import com.jme3.bullet.collision.PhysicsCollisionObject; //导入依赖的package包/类
/**
* 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;
}
}