当前位置: 首页>>代码示例>>Java>>正文


Java CollisionShapeFactory类代码示例

本文整理汇总了Java中com.jme3.bullet.util.CollisionShapeFactory的典型用法代码示例。如果您正苦于以下问题:Java CollisionShapeFactory类的具体用法?Java CollisionShapeFactory怎么用?Java CollisionShapeFactory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


CollisionShapeFactory类属于com.jme3.bullet.util包,在下文中一共展示了CollisionShapeFactory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: buildPlayer

import com.jme3.bullet.util.CollisionShapeFactory; //导入依赖的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);
}
 
开发者ID:mleoking,项目名称:PhET,代码行数:22,代码来源:TestHoveringTank.java

示例2: setCollisionBox

import com.jme3.bullet.util.CollisionShapeFactory; //导入依赖的package包/类
/**
 * 设置一个BOX用于作为相机碰撞检测的物体。
 * @param box 
 */
public final void setCollisionBox(Box box) {
    // 移除旧的
    if (collisionChecker != null) {
        if (physicsSpace != null) {
            physicsSpace.remove(collisionChecker);
        }
        collisionChecker.removeFromParent();
    }
    
    // 重建新的碰撞检测
    collisionChecker = new Geometry("camCollisionChecker", box);
    collisionChecker.setMaterial(MaterialUtils.createWireFrame());
    collisionChecker.setCullHint(Spatial.CullHint.Always);
    
    // GhostControl
    // 给物理体设置一个不同的碰撞组,这会优化碰撞检测性能.
    GhostControl gc = new GhostControl(CollisionShapeFactory.createBoxShape(collisionChecker));
    collisionChecker.addControl(gc);
}
 
开发者ID:huliqing,项目名称:LuoYing,代码行数:24,代码来源:CollisionChaseCamera.java

示例3: PhysicalBrick

import com.jme3.bullet.util.CollisionShapeFactory; //导入依赖的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);
}
 
开发者ID:devinbost,项目名称:jMathGame3d,代码行数:22,代码来源:SharedConstructors.java

示例4: installGameComponent

import com.jme3.bullet.util.CollisionShapeFactory; //导入依赖的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);
}
 
开发者ID:samynk,项目名称:DArtE,代码行数:24,代码来源:PhysicsConcaveComponent.java

示例5: installGameComponent

import com.jme3.bullet.util.CollisionShapeFactory; //导入依赖的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);
    }
}
 
开发者ID:samynk,项目名称:DArtE,代码行数:19,代码来源:PhysicsTerrainComponent.java

示例6: resetWallPhysics

import com.jme3.bullet.util.CollisionShapeFactory; //导入依赖的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);
    }
}
 
开发者ID:TripleSnail,项目名称:Arkhados,代码行数:25,代码来源:BasicSquareArena.java

示例7: createPlayer

import com.jme3.bullet.util.CollisionShapeFactory; //导入依赖的package包/类
/**
 * Create a new player.
 * @param parentNode Parent of player. Should be root node.
 * @param playerIdx Order of created player starting at 0.
 * @return Spatial of new player.
 */
private Spatial createPlayer(Node parentNode, int playerIdx) {
  // Currently a simple box is used for the player.
  Box box = new Box(1, 1, 1);
  Geometry player = new Geometry("PLAYER" + playerIdx, box);

  Material mat = new Material(application.getAssetManager(),
      "Common/MatDefs/Misc/Unshaded.j3md");
  mat.setColor("Color", ColorRGBA.Blue);
  player.setMaterial(mat);

  // Move player in front of first course point.
  Spatial[] coursePoints = coursePath.getCoursePoints();
  if (coursePoints.length > 0) {
    Spatial startPoint = coursePoints[0];
    Vector3f forward = startPoint.getWorldRotation().mult(Vector3f.UNIT_Z);
    player.move(forward.mult(PLAYER_START_DISTANCE));
  }

  // Attribute that this is a player.
  player.setUserData(IS_PLAYER_ATTR, true);
  // Add physics to player
  CollisionShape shape = CollisionShapeFactory.createBoxShape(player);
  GhostControl playerPhysics = new GhostControl(shape);
  player.addControl(playerPhysics);
  bullet.getPhysicsSpace().add(playerPhysics);

  // Attach to root node and course path.
  parentNode.attachChild(player);
  coursePath.addPlayer(player);
  return player;
}
 
开发者ID:meoblast001,项目名称:seally-racing,代码行数:38,代码来源:PlayerManager.java

示例8: CoursePath

import com.jme3.bullet.util.CollisionShapeFactory; //导入依赖的package包/类
/**
 * Course path constructor. Locate the course path and organise the points
 * into an ordered list. Rotate these points to create a smooth path.
 * @param scene Root node of scene.
 */
public CoursePath(Node scene, BulletAppState bullet) {
  // Locate each course point and create an array of those points ordered by
  // the order data in the user data of the spatials.
  Spatial coursePath = scene.getChild(COURSE_PATH_NODE_NAME);
  final TreeMap<Integer, Spatial> points = new TreeMap<Integer, Spatial>();
  coursePath.breadthFirstTraversal(new SceneGraphVisitor() {
    public void visit(Spatial spatial) {
      Integer order = spatial.getUserData(COURSE_ORDER_ATTR);
      if (order != null) {
        points.put(order, spatial);
      }
    }
  });
  coursePoints = points.values().toArray(new Spatial[0]);

  // To create a smooth rotation along the course, each course point is
  // rotated to look in the direction of the vector connecting the preceding
  // point with the succeeding point.
  for (int i = 0; i < coursePoints.length; ++i) {
    Spatial current = coursePoints[i];
    Spatial previous = i > 0
        ? coursePoints[i - 1] : coursePoints[coursePoints.length - 1];
    Spatial next = coursePoints[(i + 1) % coursePoints.length];
    Vector3f lookDirection
        = previous.getLocalTranslation().subtract(next.getLocalTranslation());
    current.getLocalRotation().lookAt(lookDirection,
                                      new Vector3f(0.0f, 1.0f, 0.0f));
    CollisionShape shape = CollisionShapeFactory.createBoxShape(current);
    GhostControl physics = new GhostControl(shape);
    current.addControl(physics);
    bullet.getPhysicsSpace().add(physics);
  }

  // Install listener for collisions between player and node.
  bullet.getPhysicsSpace()
      .addCollisionListener(new CoursePointCollisionListener(this));
}
 
开发者ID:meoblast001,项目名称:seally-racing,代码行数:43,代码来源:CoursePath.java

示例9: doCreateHullShapeFromSelected

import com.jme3.bullet.util.CollisionShapeFactory; //导入依赖的package包/类
public void doCreateHullShapeFromSelected(VehicleControl control, Spatial spat) {
//        Logger.getLogger(VehicleEditorController.class.getName()).log(Level.INFO, "Merging Geometries");
//        Mesh mesh = new Mesh();
//        GeometryBatchFactory.mergeGeometries(list, mesh);
//        control.setCollisionShape(new HullCollisionShape(list.get(0).getMesh()));
        control.setCollisionShape(CollisionShapeFactory.createDynamicMeshShape(spat));
        refreshSelected();
    }
 
开发者ID:jMonkeyEngine,项目名称:sdk,代码行数:9,代码来源:VehicleEditorController.java

示例10: ConstructLevel

import com.jme3.bullet.util.CollisionShapeFactory; //导入依赖的package包/类
private void ConstructLevel(){
    assetManager.registerLocator("town.zip", ZipLocator.class);
    gameLevel = assetManager.loadModel("main.scene"); // be sure to give new names to new scenes
    gameLevel.setLocalTranslation(0, -5.2f, 0); // move the level down by 5.2 units
    gameLevel.setLocalScale(2f);
    // Wrap the scene in a rigidbody collision object.
    CollisionShape sceneShape = CollisionShapeFactory.createMeshShape((Node) gameLevel);
    landscape = new RigidBodyControl(sceneShape, 0);
    gameLevel.addControl(landscape);
    bulletAppState.getPhysicsSpace().addAll(gameLevel);
    // Now attach it.
    shootables.attachChild(gameLevel); // should we add the shootables to the bulletAppState?
}
 
开发者ID:devinbost,项目名称:jMathGame3d,代码行数:14,代码来源:HelloJME3.java

示例11: installGameComponent

import com.jme3.bullet.util.CollisionShapeFactory; //导入依赖的package包/类
@Override
public void installGameComponent(Spatial parent) {
    CollisionShape cs;
    if (parent instanceof Node) {
        Node p = (Node) parent;
        Spatial physics = p.getChild("physics");
        if (physics != null) {
            Vector3f scaleToApply = parent.getWorldScale().clone();
            physics.setLocalScale(scaleToApply);
            physics.updateGeometricState();
            CompoundCollisionShape ccs = new CompoundCollisionShape();

            ccs.addChildShape(CollisionShapeFactory.createDynamicMeshShape(physics), Vector3f.ZERO);
            cs = ccs;
            /*parent.setLocalScale(Vector3f.UNIT_XYZ);
            for (Spatial s : p.getChildren()) {
                if (physics != s) {
                    s.setLocalScale(scaleToApply.x, scaleToApply.y, scaleToApply.z);
                }
            }*/
        } else {
            cs = CollisionShapeFactory.createDynamicMeshShape(parent);
        }
    } else {
        cs = CollisionShapeFactory.createDynamicMeshShape(parent);
    }
    parent.updateGeometricState();
    rigidBodyControl = new RigidBodyControl(cs, mass);
    rigidBodyControl.setRestitution(restitution);
    rigidBodyControl.setFriction(getFriction());
    rigidBodyControl.setDamping(0.5f, 0.25f);
    parent.addControl(rigidBodyControl);
}
 
开发者ID:samynk,项目名称:DArtE,代码行数:34,代码来源:PhysicsConvexComponent.java

示例12: build

import com.jme3.bullet.util.CollisionShapeFactory; //导入依赖的package包/类
@Override
public Node build(BuildParameters params) {
    Node node = (Node) assets.loadModel("Models/Spear.j3o");
    node.getChild(0).scale(3f);
    node.setLocalTranslation(params.location);

    node.setUserData(UserData.SPEED, 140f);
    node.setUserData(UserData.MASS, 30f);
    node.setUserData(UserData.DAMAGE, 200f);
    node.setUserData(UserData.IMPULSE_FACTOR, 0f);
    
    CollisionShape collisionShape = 
            CollisionShapeFactory.createBoxShape(node);
    RigidBodyControl physicsBody = new RigidBodyControl(collisionShape,
            (float) node.getUserData(UserData.MASS));

    physicsBody.setCollisionGroup(CollisionGroups.PROJECTILES);
    physicsBody.removeCollideWithGroup(CollisionGroups.PROJECTILES);

    physicsBody.addCollideWithGroup(CollisionGroups.WALLS);

    GhostControl characterCollision = new GhostControl(collisionShape);
    characterCollision.setCollideWithGroups(CollisionGroups.CHARACTERS);
    characterCollision.setCollisionGroup(CollisionGroups.PROJECTILES);
    node.addControl(characterCollision);
    
    node.addControl(physicsBody);

    node.addControl(new CProjectile());
    CSpellBuff buffControl = new CSpellBuff();
    node.addControl(buffControl);
    buffControl.addBuff(new SpeedBleedBuff.MyBuilder(4.2f));

    node.addControl(new CSpear());

    return node;
}
 
开发者ID:TripleSnail,项目名称:Arkhados,代码行数:38,代码来源:VoidSpear.java

示例13: resetWallPhysics

import com.jme3.bullet.util.CollisionShapeFactory; //导入依赖的package包/类
private void resetWallPhysics(PhysicsSpace space) {
    List<Spatial> children = ((Node) getTerrainNode().getChild("Walls"))
            .getChildren();
    for (Spatial wallNode : children) {
        Spatial wall = ((Node) wallNode).getChild("Grave");                                    
        
        Vector3f originalScale = wall.getLocalScale().clone();
        
        wall.setLocalScale(wallNode.getWorldScale().clone());
        
        space.removeAll(wallNode);
        
        CollisionShape meshShape = CollisionShapeFactory
                .createMeshShape(wall);
        
        wall.setLocalScale(originalScale);

        RigidBodyControl wallPhysics = new RigidBodyControl(meshShape, 0);
        wallPhysics.setCollideWithGroups(CollisionGroups.NONE);

        wallPhysics.setFriction(0f);
        wall.addControl(wallPhysics);
        wall.getControl(RigidBodyControl.class)
                .setCollisionGroup(CollisionGroups.WALLS);

        space.addAll(wall);
    }
}
 
开发者ID:TripleSnail,项目名称:Arkhados,代码行数:29,代码来源:PillarArena.java

示例14: createLod

import com.jme3.bullet.util.CollisionShapeFactory; //导入依赖的package包/类
private void createLod()
{
	Vector3f[] vertexTab = new Vector3f[vertexList.size()];
	Vector3f[] normalTab = new Vector3f[normalList.size()];
	Vector4f[] colorTab = new Vector4f[colorList.size()];
	int[] faceTab = new int[faceList.size()*3];
	int j=0;
	for(int[] face : faceList)
	{
		for(int k=0; k<3; k++)
		{
			faceTab[j] = face[k];
			j++;
		}
	}
	
	Mesh mesh = new Mesh();
	mesh.setBuffer(Type.Position, 3, BufferUtils.createFloatBuffer(vertexList.toArray(vertexTab)));
	mesh.setBuffer(Type.Normal, 3, BufferUtils.createFloatBuffer(normalList.toArray(normalTab)));
	mesh.setBuffer(Type.Color, 4,  BufferUtils.createFloatBuffer(colorList.toArray(colorTab)));
	mesh.setBuffer(Type.Index, 3, BufferUtils.createIntBuffer(faceTab));
	mesh.updateBound();
	meshList.add(mesh);
	
	Geometry geometry = new Geometry("chunky", mesh);
	geometry.setLocalTranslation(Vector3f.ZERO);
	geometry.setMaterial(wmat);
	geometryList.add(geometry);
	
	CollisionShape collisionShape = CollisionShapeFactory.createMeshShape(geometry);
	RigidBodyControl rigidBody = new RigidBodyControl(collisionShape, 0.0f);
	geometry.addControl(rigidBody);
	rigidBodyControlList.add(rigidBody);
}
 
开发者ID:Daepso,项目名称:minerim,代码行数:35,代码来源:Chunk.java

示例15: simpleInitApp

import com.jme3.bullet.util.CollisionShapeFactory; //导入依赖的package包/类
public void simpleInitApp() {
  /** Set up Physics */
  bulletAppState = new BulletAppState();
  stateManager.attach(bulletAppState);

  // We re-use the flyby camera for rotation, while positioning is handled by physics
  viewPort.setBackgroundColor(new ColorRGBA(0.7f,0.8f,1f,1f));
  flyCam.setMoveSpeed(100);
  setUpKeys();
  setUpLight();

  // We load the scene from the zip file and adjust its size.
  assetManager.registerLocator("town.zip", ZipLocator.class.getName());
  sceneModel = assetManager.loadModel("main.scene");
  sceneModel.setLocalScale(2f);

  // We set up collision detection for the scene by creating a
  // compound collision shape and a static physics node with mass zero.
  CollisionShape sceneShape =
    CollisionShapeFactory.createMeshShape((Node) sceneModel);
  landscape = new RigidBodyControl(sceneShape, 0);
  sceneModel.addControl(landscape);
  
  // We set up collision detection for the player by creating
  // a capsule collision shape and a physics character node.
  // The physics character node offers extra settings for
  // size, stepheight, jumping, falling, and gravity.
  // We also put the player in its starting position.
  CapsuleCollisionShape capsuleShape = new CapsuleCollisionShape(1.5f, 6f, 1);
  player = new CharacterControl(capsuleShape, 0.05f);
  player.setJumpSpeed(20);
  player.setFallSpeed(30);
  player.setGravity(30);
  player.setPhysicsLocation(new Vector3f(0, 10, 0));

  // We attach the scene and the player to the rootnode and the physics space,
  // to make them appear in the game world.
  rootNode.attachChild(sceneModel);
  bulletAppState.getPhysicsSpace().add(landscape);
  bulletAppState.getPhysicsSpace().add(player);
}
 
开发者ID:mleoking,项目名称:PhET,代码行数:42,代码来源:HelloCollision.java


注:本文中的com.jme3.bullet.util.CollisionShapeFactory类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。