本文整理汇总了Java中com.jme3.bullet.collision.shapes.CollisionShape类的典型用法代码示例。如果您正苦于以下问题:Java CollisionShape类的具体用法?Java CollisionShape怎么用?Java CollisionShape使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
CollisionShape类属于com.jme3.bullet.collision.shapes包,在下文中一共展示了CollisionShape类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: updateObject
import com.jme3.bullet.collision.shapes.CollisionShape; //导入依赖的package包/类
@Override
protected void updateObject(PhysicsRigidBody rigidBody, Entity e) {
RigidBody rigidBodyInfo = e.get(RigidBody.class);
CustomShape collisionShapeInfo = e.get(CustomShape.class);
rigidBody.setKinematic(rigidBodyInfo.isKinematic());
rigidBody.setMass(rigidBodyInfo.getMass());
//rigidBody.setFriction(rigidBodyInfo.getFriction());
rigidBody.setRestitution(rigidBodyInfo.getRestitution());
if(!rigidBody.getCollisionShape().equals(collisionShapeInfo.getDefinition())) {
physicsSpace.remove(rigidBody);
CollisionShape shape = provider.getShape(e.get(shapeType));
rigidBody.setCollisionShape(shape);
physicsSpace.add(rigidBody);
}
// rigidBody.setUserObject(e.getId()); already set?
}
示例2: controlUpdate
import com.jme3.bullet.collision.shapes.CollisionShape; //导入依赖的package包/类
@Override
protected void controlUpdate(final float tpf) {
final PhysicsCharacter body = getBody();
final CollisionShape shape = body.getCollisionShape();
if (currentShape != shape) {
final Node node = (Node) getSpatial();
node.detachChild(geom);
geom = getDebugShape(shape);
geom.setMaterial(debugAppState.getDebugPink());
node.attachChild(geom);
currentShape = shape;
}
final Vector3f physicsLocation = body.getPhysicsLocation(physicalLocation);
applyPhysicsTransform(physicsLocation, Quaternion.IDENTITY);
geom.setLocalScale(shape.getScale());
}
示例3: buildPlayer
import com.jme3.bullet.collision.shapes.CollisionShape; //导入依赖的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);
}
示例4: createSheet
import com.jme3.bullet.collision.shapes.CollisionShape; //导入依赖的package包/类
@Override
protected Sheet createSheet() {
Sheet sheet = super.createSheet();
Sheet.Set set = Sheet.createPropertiesSet();
set.setDisplayName("GhostControl");
set.setName(GhostControl.class.getName());
GhostControl obj = geom;//getLookup().lookup(Spatial.class);
if (obj == null) {
return sheet;
}
set.put(makeProperty(obj, Vector3f.class, "getPhysicsLocation", "setPhysicsLocation", "Physics Location"));
set.put(makeProperty(obj, Quaternion.class, "getPhysicsRotation", "setPhysicsRotation", "Physics Rotation"));
set.put(makeProperty(obj, CollisionShape.class, "getCollisionShape", "setCollisionShape", "Collision Shape"));
set.put(makeProperty(obj, int.class, "getCollisionGroup", "setCollisionGroup", "Collision Group"));
set.put(makeProperty(obj, int.class, "getCollideWithGroups", "setCollideWithGroups", "Collide With Groups"));
sheet.put(set);
return sheet;
}
示例5: addItem
import com.jme3.bullet.collision.shapes.CollisionShape; //导入依赖的package包/类
public MyRigidBodyControl addItem(Spatial item, float mass, CollisionShape cs) {
MyRigidBodyControl rbc;
if (cs != null) {
rbc = new MyRigidBodyControl(cs, mass);
} else {
rbc = new MyRigidBodyControl(mass);
}
item.addControl(rbc);
bulletAppState.getPhysicsSpace().add(rbc);
rbc.setDamping(0.2f, 0.2f);
rootNode.attachChild(item);
items.add(item);
objectBondTracker.addBondPointsForItem(item);
for (InventoryListener l : listeners) {
l.objectCreated(item);
}
return rbc;
}
示例6: create
import com.jme3.bullet.collision.shapes.CollisionShape; //导入依赖的package包/类
private void create(Spatial s, VHACDParameters p, CompoundCollisionShape out) {
if(s instanceof Geometry){
Geometry geo=(Geometry)s;
CompoundCollisionShape ccs=create(geo.getMesh(),p);
for(ChildCollisionShape cc:ccs.getChildren()){
CollisionShape ccc=cc.shape;
ccc.setScale(geo.getLocalScale());
out.addChildShape(ccc,new Vector3f());
}
}else if(s instanceof Node){
Node n=(Node)s;
Collection<Spatial> cs=n.getChildren();
for(Spatial c:cs){
create(c,p,out);
}
}
}
示例7: load
import com.jme3.bullet.collision.shapes.CollisionShape; //导入依赖的package包/类
private Geometry load(String path,ColorRGBA c,float mass,Vector3f location,Vector3f scale){
Spatial s=assetManager.loadModel(path);
Mesh m=cache.get(path);
Geometry geo;
if(m!=null){
System.out.println("Load "+path+" from cache.");
geo=new Geometry("",m);
}else{
geo= Commons.getGeom(s);
cache.put(path,geo.getMesh());
}
geo.setLocalScale(scale);
geo.setLocalTranslation(location);
Material mat=new Material(assetManager,"Common/MatDefs/Light/Lighting.j3md");
mat.setColor("Diffuse",c);
mat.setBoolean("UseMaterialColors",true);
geo.setMaterial(mat);
CollisionShape cs=vhacd_factory.create(geo);
RigidBodyControl rb=new RigidBodyControl(cs,mass);
geo.addControl(rb);
return geo;
}
示例8: makeFloor
import com.jme3.bullet.collision.shapes.CollisionShape; //导入依赖的package包/类
public static void makeFloor(SimpleApplication app) {
Box box=new Box(160,.2f,160);
Geometry floor=new Geometry("the Floor",box);
floor.setLocalTranslation(0,-4f,0);
Material mat1=new Material(app.getAssetManager(),"Common/MatDefs/Light/Lighting.j3md");
mat1.setColor("Diffuse",new ColorRGBA(.54f,.68f,.16f,1f));
mat1.setBoolean("UseMaterialColors",true);
floor.setMaterial(mat1);
CollisionShape floorcs=new MeshCollisionShape(floor.getMesh());
RigidBodyControl floor_phy=new RigidBodyControl(floorcs,0);
floor.addControl(floor_phy);
floor_phy.setPhysicsLocation(new Vector3f(0,-30,0));
app.getStateManager().getState(BulletAppState.class).getPhysicsSpace().add(floor_phy);
app.getRootNode().attachChild(floor);
}
示例9: setShip
import com.jme3.bullet.collision.shapes.CollisionShape; //导入依赖的package包/类
private void setShip() {
Box b = new Box(Vector3f.ZERO, 0.5f, 0.5f, 1);
Geometry geomShip = new Geometry("Box", b);
geomShip.setUserData("Type", "Player");
ship.attachChild(geomShip);
ship.setUserData("Type", "Player");
Material mat = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
ship.setMaterial(mat);
CollisionShape colShape = new BoxCollisionShape(new Vector3f(1.0f, 1.0f, 1.0f));
colShape.setMargin(0.05f);
shipControl = new ShipPhysicsControl(colShape, 1, bulletAppState);
shipControl.setDamping(0.75f, 0.999f);
shipControl.setFriction(0.2f);
shipControl.setAngularFactor(0.1f);
ship.addControl(shipControl);
bulletAppState.getPhysicsSpace().add(shipControl);
shipControl.setEnabled(true);
// shipControl.setGravity(new Vector3f(0, 0, 0));
}
示例10: SimpleCharacterControl
import com.jme3.bullet.collision.shapes.CollisionShape; //导入依赖的package包/类
public SimpleCharacterControl(Application app, float centerToBottomHeight, CollisionShape colShape, float mass) {
super(colShape, mass);
this.app = app;
jumpSpeedY = 40f;
moveSpeed = 0.5f;
moveSpeedMultiplier = 1;
moveSlopeSpeed = 0.3f;
slopeLimitAngle = FastMath.DEG_TO_RAD * 45f;
stopDamping = 0.8f;
stopTimer = 0;
jumpTimer = 0;
maxStopTimer = 30;
maxJumpTimer = 20;
frictionWalk = 0.1f;
frictionStop = 7f;
mainWalkInterpolation = 0.7f;
otherWalkInterpolation = 0.9f;
this.centerToBottomHeight = centerToBottomHeight;
this.app.getStateManager().getState(BulletAppState.class).getPhysicsSpace().addTickListener(this);
}
示例11: PhysicalBrick
import com.jme3.bullet.collision.shapes.CollisionShape; //导入依赖的package包/类
public PhysicalBrick(Vector3f loc, Box box, Material wall_mat){
_brick_geo = new Geometry("brick", box);
_brick_geo.scale(4f);
_brick_geo.setMaterial(wall_mat);
/** Position the brick geometry */
_brick_geo.setLocalTranslation(loc);
/** Make brick physical with a mass > 0.0f. */
CollisionShape brick_collision = CollisionShapeFactory.createBoxShape(_brick_geo);
_brick_phy = new RigidBodyControl(4f);
//brick_phy.getCollisionShape().setScale(new Vector3f(2,2,2));
_brick_phy.setCollisionShape(brick_collision);
_brick_phy.setFriction(2f);
_brick_phy.setDamping(.2f, .2f);
//brick_phy.getCollisionShape().setScale(new Vector3f(2,2,2)); // Won’t work as this is now a CompoundCollisionShape containing a MeshCollisionShape
/** Add physical brick to physics space. */
_brick_geo.addControl(_brick_phy);
// You must scale the geometry for the scale change to work.
_brick_geo.getControl(RigidBodyControl.class).setCcdMotionThreshold(0.01f); // Do this if needed.
//this.getBulletAppState().getPhysicsSpace().setMaxSubSteps(2);
}
示例12: installGameComponent
import com.jme3.bullet.collision.shapes.CollisionShape; //导入依赖的package包/类
@Override
public void installGameComponent(Spatial parent)
{
CollisionShape cs;
Spatial physicsChild = null;
if ( parent instanceof Node)
{
Node n = (Node)parent;
physicsChild = n.getChild("physics");
}
if (physicsChild != null) {
cs = CollisionShapeFactory.createMeshShape(physicsChild);
} else {
cs = CollisionShapeFactory.createMeshShape(parentComponent);
}
rigidBodyControl = new RigidBodyControl(cs, 0);
rigidBodyControl.setFriction(getFriction());
parent.addControl(rigidBodyControl);
rigidBodyControl.setEnabled(true);
}
示例13: installGameComponent
import com.jme3.bullet.collision.shapes.CollisionShape; //导入依赖的package包/类
@Override
public void installGameComponent(Spatial parent) {
if (parent instanceof Terrain || parent instanceof TerrainQuad) {
Vector3f backupTrans = parent.getLocalTranslation().clone();
Quaternion backupRotation = parent.getLocalRotation().clone();
parent.setLocalTranslation(Vector3f.ZERO);
parent.setLocalRotation(Quaternion.IDENTITY);
CollisionShape terrainShape = CollisionShapeFactory.createMeshShape(parent);
rbc = new RigidBodyControl(terrainShape, 0);
rbc.setFriction(friction);
rbc.setCollisionGroup(collisionGroup);
parent.addControl(rbc);
rbc.setPhysicsLocation(backupTrans);
rbc.setPhysicsRotation(backupRotation);
rbc.setEnabled(true);
}
}
示例14: resetWallPhysics
import com.jme3.bullet.collision.shapes.CollisionShape; //导入依赖的package包/类
private void resetWallPhysics(PhysicsSpace space) {
List<Spatial> children = ((Node) getTerrainNode()
.getChild("Walls")).getChildren();
for (Spatial wallNode : children) {
Spatial wall = ((Node) wallNode).getChild("Wall");
wall.scale(6f);
space.removeAll(wallNode);
CollisionShape meshShape
= CollisionShapeFactory.createMeshShape(wall);
wall.scale(1f / 6f);
RigidBodyControl wallPhysics = new RigidBodyControl(meshShape, 0);
wallPhysics.setCollideWithGroups(CollisionGroups.NONE);
wallPhysics.setFriction(0.5f);
wall.addControl(wallPhysics);
wall.getControl(RigidBodyControl.class)
.setCollisionGroup(CollisionGroups.WALLS);
space.addAll(wall);
}
}
示例15: makePhysics
import com.jme3.bullet.collision.shapes.CollisionShape; //导入依赖的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);
}