com.jme3.scene.Geometry.addControl()方法的使用及代码示例

x33g5p2x  于2022-01-20 转载在 其他  
字(12.1k)|赞(0)|评价(0)|浏览(127)

本文整理了Java中com.jme3.scene.Geometry.addControl()方法的一些代码示例,展示了Geometry.addControl()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Geometry.addControl()方法的具体详情如下:
包路径:com.jme3.scene.Geometry
类名称:Geometry
方法名:addControl

Geometry.addControl介绍

暂无

代码示例

代码示例来源:origin: jMonkeyEngine/jmonkeyengine

private Geometry getRandomBall(Vector3f location) {
  Vector3f localLocation = new Vector3f();
  localLocation.set(location);
  localLocation.addLocal(new Vector3f(random.nextFloat() - 0.5f, random.nextFloat() - 0.5f, random.nextFloat() - 0.5f).normalize().mult(3));
  Geometry poiGeom = new Geometry("ball", ballMesh);
  poiGeom.setLocalTranslation(localLocation);
  poiGeom.setMaterial(ballMaterial);
  RigidBodyControl control = new RigidBodyControl(ballCollisionShape, 1);
  //!!! Important
  control.setApplyPhysicsLocal(true);
  poiGeom.addControl(control);
  float x = (random.nextFloat() - 0.5f) * 100;
  float y = (random.nextFloat() - 0.5f) * 100;
  float z = (random.nextFloat() - 0.5f) * 100;
  control.setLinearVelocity(new Vector3f(x, y, z));
  return poiGeom;
}

代码示例来源:origin: jMonkeyEngine/jmonkeyengine

public void onAction(String name, boolean keyPressed, float tpf) {
      if (name.equals("shoot") && !keyPressed) {
        Geometry bulletg = new Geometry("bullet", bullet);
        bulletg.setMaterial(mat2);
        bulletg.setShadowMode(ShadowMode.CastAndReceive);
        bulletg.setLocalTranslation(cam.getLocation());
        
        SphereCollisionShape bulletCollisionShape = new SphereCollisionShape(0.4f);
        RigidBodyControl bulletNode = new BombControl(assetManager, bulletCollisionShape, 1);
//                RigidBodyControl bulletNode = new RigidBodyControl(bulletCollisionShape, 1);
        bulletNode.setLinearVelocity(cam.getDirection().mult(25));
        bulletg.addControl(bulletNode);
        rootNode.attachChild(bulletg);
        getPhysicsSpace().add(bulletNode);
      }
      if (name.equals("gc") && !keyPressed) {
        System.gc();
      }
    }
  };

代码示例来源:origin: jMonkeyEngine/jmonkeyengine

/** Make a solid floor and add it to the scene. */
public void initFloor() {
 Geometry floor_geo = new Geometry("Floor", floor);
 floor_geo.setMaterial(floor_mat);
 floor_geo.setLocalTranslation(0, -0.1f, 0);
 this.rootNode.attachChild(floor_geo);
 /* Make the floor physical with mass 0.0f! */
 floor_phy = new RigidBodyControl(0.0f);
 floor_geo.addControl(floor_phy);
 bulletAppState.getPhysicsSpace().add(floor_phy);
}

代码示例来源:origin: jMonkeyEngine/jmonkeyengine

public void addBrick(Vector3f ori) {
  Geometry reBoxg = new Geometry("brick", brick);
  reBoxg.setMaterial(mat);
  reBoxg.setLocalTranslation(ori);
  reBoxg.rotate(0f, (float)Math.toRadians(angle) , 0f );
  reBoxg.addControl(new RigidBodyControl(1.5f));
  reBoxg.setShadowMode(ShadowMode.CastAndReceive);
  reBoxg.getControl(RigidBodyControl.class).setFriction(1.6f);
  this.batchNode.attachChild(reBoxg);
  this.getPhysicsSpace().add(reBoxg);
  nbBrick++;
}

代码示例来源:origin: jMonkeyEngine/jmonkeyengine

public void addBrick(Vector3f ori) {
  Geometry reBoxg = new Geometry("brick", brick);
  reBoxg.setMaterial(mat);
  reBoxg.setLocalTranslation(ori);
  reBoxg.rotate(0f, (float)Math.toRadians(angle) , 0f );
  reBoxg.addControl(new RigidBodyControl(1.5f));
  reBoxg.setShadowMode(ShadowMode.CastAndReceive);
  reBoxg.getControl(RigidBodyControl.class).setFriction(1.6f);
  this.rootNode.attachChild(reBoxg);
  this.getPhysicsSpace().add(reBoxg);
}

代码示例来源:origin: jMonkeyEngine/jmonkeyengine

/**
 * creates a box geometry with a RigidBodyControl
 *
 * @param assetManager for loading assets
 * @return a new Geometry
 */
public static Geometry createPhysicsTestBox(AssetManager assetManager) {
  Material material = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
  material.setTexture("ColorMap", assetManager.loadTexture("Interface/Logo/Monkey.jpg"));
  Box box = new Box(0.25f, 0.25f, 0.25f);
  Geometry boxGeometry = new Geometry("Box", box);
  boxGeometry.setMaterial(material);
  //RigidBodyControl automatically uses box collision shapes when attached to single geometry with box mesh
  boxGeometry.addControl(new RigidBodyControl(2));
  return boxGeometry;
}

代码示例来源:origin: jMonkeyEngine/jmonkeyengine

/** This method creates one individual physical brick. */
public void makeBrick(Vector3f loc) {
 /** Create a brick geometry and attach to scene graph. */
 Geometry brick_geo = new Geometry("brick", box);
 brick_geo.setMaterial(wall_mat);
 rootNode.attachChild(brick_geo);
 /** Position the brick geometry  */
 brick_geo.setLocalTranslation(loc);
 /** Make brick physical with a mass > 0.0f. */
 brick_phy = new RigidBodyControl(2f);
 /** Add physical brick to physics space. */
 brick_geo.addControl(brick_phy);
 bulletAppState.getPhysicsSpace().add(brick_phy);
}

代码示例来源:origin: jMonkeyEngine/jmonkeyengine

private void addBrick(Vector3f ori) {
  Geometry reBoxg = new Geometry("brick", brick);
  reBoxg.setMaterial(matBullet);
  reBoxg.setLocalTranslation(ori);
  reBoxg.addControl(new RigidBodyControl(1.5f));
  reBoxg.setShadowMode(ShadowMode.CastAndReceive);
  this.rootNode.attachChild(reBoxg);
  this.getPhysicsSpace().add(reBoxg);
}

代码示例来源:origin: jMonkeyEngine/jmonkeyengine

/**
 * creates a sphere geometry with a RigidBodyControl
 *
 * @param assetManager for loading assets
 * @return a new Geometry
 */
public static Geometry createPhysicsTestSphere(AssetManager assetManager) {
  Material material = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
  material.setTexture("ColorMap", assetManager.loadTexture("Interface/Logo/Monkey.jpg"));
  Sphere sphere = new Sphere(8, 8, 0.25f);
  Geometry boxGeometry = new Geometry("Sphere", sphere);
  boxGeometry.setMaterial(material);
  //RigidBodyControl automatically uses sphere collision shapes when attached to single geometry with sphere mesh
  boxGeometry.addControl(new RigidBodyControl(2));
  return boxGeometry;
}

代码示例来源:origin: jMonkeyEngine/jmonkeyengine

public void onAction(String name, boolean keyPressed, float tpf) {
      if (name.equals("shoot") && !keyPressed) {
        Geometry bulletg = new Geometry("bullet", bullet);
        bulletg.setMaterial(mat2);
        bulletg.setShadowMode(ShadowMode.CastAndReceive);
        bulletg.setLocalTranslation(cam.getLocation());
        RigidBodyControl bulletNode = new BombControl(assetManager, bulletCollisionShape, 1);
//                RigidBodyControl bulletNode = new RigidBodyControl(bulletCollisionShape, 1);
        bulletNode.setLinearVelocity(cam.getDirection().mult(25));
        bulletg.addControl(bulletNode);
        rootNode.attachChild(bulletg);
        getPhysicsSpace().add(bulletNode);
      }
    }
  };

代码示例来源:origin: jMonkeyEngine/jmonkeyengine

public void onAction(String name, boolean keyPressed, float tpf) {
      if (name.equals("shoot") && !keyPressed) {
        Geometry bulletg = new Geometry("bullet", bullet);
        bulletg.setMaterial(mat2);
        bulletg.setShadowMode(ShadowMode.CastAndReceive);
        bulletg.setLocalTranslation(cam.getLocation());
        RigidBodyControl bulletNode = new BombControl(assetManager, bulletCollisionShape, 1);
//                RigidBodyControl bulletNode = new RigidBodyControl(bulletCollisionShape, 1);
        bulletNode.setLinearVelocity(cam.getDirection().mult(25));
        bulletg.addControl(bulletNode);
        rootNode.attachChild(bulletg);
        getPhysicsSpace().add(bulletNode);
      }
    }
  };

代码示例来源:origin: jMonkeyEngine/jmonkeyengine

public void addBrick(Vector3f ori) {
  Geometry reBoxg = new Geometry("brick", brick);
  reBoxg.setMaterial(mat);
  reBoxg.setLocalTranslation(ori);
  //for geometry with sphere mesh the physics system automatically uses a sphere collision shape
  reBoxg.addControl(new RigidBodyControl(1.5f));
  reBoxg.setShadowMode(ShadowMode.CastAndReceive);
  reBoxg.getControl(RigidBodyControl.class).setFriction(0.6f);
  this.rootNode.attachChild(reBoxg);
  this.getPhysicsSpace().add(reBoxg);
}

代码示例来源:origin: jMonkeyEngine/jmonkeyengine

public void initFloor() {
  Box floorBox = new Box(10f, 0.1f, 5f);
  floorBox.scaleTextureCoordinates(new Vector2f(3, 6));
  Geometry floor = new Geometry("floor", floorBox);
  floor.setMaterial(mat3);
  floor.setShadowMode(ShadowMode.Receive);
  floor.setLocalTranslation(0, 0, 0);
  floor.addControl(new RigidBodyControl(0));
  this.rootNode.attachChild(floor);
  this.getPhysicsSpace().add(floor);
}

代码示例来源:origin: jMonkeyEngine/jmonkeyengine

public void initFloor() {
  Box floorBox = new Box(10f, 0.1f, 5f);
  floorBox.scaleTextureCoordinates(new Vector2f(3, 6));
  Geometry floor = new Geometry("floor", floorBox);
  floor.setMaterial(mat3);
  floor.setShadowMode(ShadowMode.Receive);
  floor.setLocalTranslation(0, 0, 0);
  floor.addControl(new RigidBodyControl(0));
  this.rootNode.attachChild(floor);
  this.getPhysicsSpace().add(floor);
}

代码示例来源:origin: jMonkeyEngine/jmonkeyengine

public void onAction(String name, boolean keyPressed, float tpf) {
    Sphere bullet = new Sphere(32, 32, 0.4f, true, false);
    bullet.setTextureMode(TextureMode.Projected);
    Material mat2 = new Material(app.getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md");
    TextureKey key2 = new TextureKey("Textures/Terrain/Rock/Rock.PNG");
    key2.setGenerateMips(true);
    Texture tex2 = app.getAssetManager().loadTexture(key2);
    mat2.setTexture("ColorMap", tex2);
    if (name.equals("shoot") && !keyPressed) {
      Geometry bulletg = new Geometry("bullet", bullet);
      bulletg.setMaterial(mat2);
      bulletg.setShadowMode(ShadowMode.CastAndReceive);
      bulletg.setLocalTranslation(app.getCamera().getLocation());
      RigidBodyControl bulletControl = new RigidBodyControl(10);
      bulletg.addControl(bulletControl);
      bulletControl.setLinearVelocity(app.getCamera().getDirection().mult(25));
      bulletg.addControl(bulletControl);
      rootNode.attachChild(bulletg);
      space.add(bulletControl);
    }
  }
};

代码示例来源:origin: jMonkeyEngine/jmonkeyengine

/** This method creates one individual physical cannon ball.
 * By defaul, the ball is accelerated and flies
 * from the camera position in the camera direction.*/
 public void makeCannonBall() {
 /** Create a cannon ball geometry and attach to scene graph. */
 Geometry ball_geo = new Geometry("cannon ball", sphere);
 ball_geo.setMaterial(stone_mat);
 rootNode.attachChild(ball_geo);
 /** Position the cannon ball  */
 ball_geo.setLocalTranslation(cam.getLocation());
 /** Make the ball physical with a mass > 0.0f */
 ball_phy = new RigidBodyControl(1f);
 /** Add physical ball to physics space. */
 ball_geo.addControl(ball_phy);
 bulletAppState.getPhysicsSpace().add(ball_phy);
 /** Accelerate the physical ball to shoot it. */
 ball_phy.setLinearVelocity(cam.getDirection().mult(25));
}

代码示例来源:origin: jMonkeyEngine/jmonkeyengine

private void setupPlanet() {
  Material material = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
  material.setTexture("ColorMap", assetManager.loadTexture("Interface/Logo/Monkey.jpg"));
  //immovable sphere with mesh collision shape
  Sphere sphere = new Sphere(64, 64, 20);
  planet = new Geometry("Sphere", sphere);
  planet.setMaterial(material);
  planet.setLocalTranslation(30, -15, 30);
  planet.addControl(new RigidBodyControl(new MeshCollisionShape(sphere), 0));
  rootNode.attachChild(planet);
  getPhysicsSpace().add(planet);
}

代码示例来源:origin: jMonkeyEngine/jmonkeyengine

public void initFloor() {
  Box floorBox = new Box(10f, 0.1f, 5f);
  floorBox.scaleTextureCoordinates(new Vector2f(3, 6));
  Geometry floor = new Geometry("floor", floorBox);
  floor.setMaterial(mat3);
  floor.setShadowMode(ShadowMode.Receive);
  floor.setLocalTranslation(0, -0.1f, 0);
  floor.addControl(new RigidBodyControl(new BoxCollisionShape(new Vector3f(10f, 0.1f, 5f)), 0));
  this.rootNode.attachChild(floor);
  this.getPhysicsSpace().add(floor);
}

代码示例来源:origin: jMonkeyEngine/jmonkeyengine

private void bulletControl() {
  shootingChannel.setAnim("Dodge", 0.1f);
  shootingChannel.setLoopMode(LoopMode.DontLoop);
  Geometry bulletg = new Geometry("bullet", bullet);
  bulletg.setMaterial(matBullet);
  bulletg.setShadowMode(ShadowMode.CastAndReceive);
  bulletg.setLocalTranslation(character.getPhysicsLocation().add(cam.getDirection().mult(5)));
  RigidBodyControl bulletControl = new BombControl(bulletCollisionShape, 1);
  bulletControl.setCcdMotionThreshold(0.1f);
  bulletControl.setLinearVelocity(cam.getDirection().mult(80));
  bulletg.addControl(bulletControl);
  rootNode.attachChild(bulletg);
  getPhysicsSpace().add(bulletControl);
}

代码示例来源:origin: jMonkeyEngine/jmonkeyengine

public void setupFloor() {
  Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
  TextureKey key = new TextureKey("Interface/Logo/Monkey.jpg", true);
  key.setGenerateMips(true);
  Texture tex = assetManager.loadTexture(key);
  tex.setMinFilter(Texture.MinFilter.Trilinear);
  mat.setTexture("ColorMap", tex);
  Box floor = new Box(100, 1f, 100);
  Geometry floorGeom = new Geometry("Floor", floor);
  floorGeom.setMaterial(mat);
  floorGeom.setLocalTranslation(new Vector3f(0f, -3, 0f));
  floorGeom.addControl(new RigidBodyControl(new MeshCollisionShape(floorGeom.getMesh()), 0));
  rootNode.attachChild(floorGeom);
  getPhysicsSpace().add(floorGeom);
}

相关文章