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

x33g5p2x  于2022-01-30 转载在 其他  
字(9.5k)|赞(0)|评价(0)|浏览(119)

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

Spatial.getWorldBound介绍

[英]getWorldBound retrieves the world bound at this node level.
[中]getWorldBound检索此节点级别的世界绑定。

代码示例

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

@Override
protected void computeLastDistance(Spatial owner) {
  if (owner.getWorldBound() != null) {
    BoundingVolume bv = owner.getWorldBound();
    lastDistance = bv.distanceSquaredTo(position);
  } else {
    lastDistance = owner.getWorldTranslation().distanceSquared(position);
  }
}

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

@Override
protected void computeLastDistance(Spatial owner) {
  if (owner.getWorldBound() != null) {
    BoundingVolume bv = owner.getWorldBound();
    lastDistance = bv.distanceSquaredTo(position);
  } else {
    lastDistance = owner.getWorldTranslation().distanceSquared(position);
  }
}

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

@Override
public void computeLastDistance(Spatial owner) {
  if (owner.getWorldBound() != null) {
    BoundingVolume bv = owner.getWorldBound();
    lastDistance = bv.distanceSquaredTo(position);
  } else {
    lastDistance = owner.getWorldTranslation().distanceSquared(position);
  }
}

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

private void fixRefreshFlags(){
  // force transforms to update below this node
  spatial.updateGeometricState();
  
  // force world bound to update
  Spatial rootNode = spatial;
  while (rootNode.getParent() != null){
    rootNode = rootNode.getParent();
  }
  rootNode.getWorldBound(); 
}

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

@Override
protected void updateWorldBound(){
  super.updateWorldBound();
  // for a node, the world bound is a combination of all its children
  // bounds
  BoundingVolume resultBound = null;
  for (Spatial child : children.getArray()) {
    // child bound is assumed to be updated
    assert (child.refreshFlags & RF_BOUND) == 0;
    if (resultBound != null) {
      // merge current world bound with child world bound
      resultBound.mergeLocal(child.getWorldBound());
    } else {
      // set world bound to first non-null child world bound
      if (child.getWorldBound() != null) {
        resultBound = child.getWorldBound().clone(this.worldBound);
      }
    }
  }
  if (resultBound == null) {
    resultBound = new BoundingBox(getWorldTranslation(), 0f, 0f, 0f);
  }
  this.worldBound = resultBound;
}

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

/**
 * Centers the spatial in the origin of the world bound.
 * @return The spatial on which this method is called, e.g <code>this</code>.
 */
public Spatial center() {
  Vector3f worldTrans = getWorldTranslation();
  Vector3f worldCenter = getWorldBound().getCenter();
  Vector3f absTrans = worldTrans.subtract(worldCenter);
  setLocalTranslation(absTrans);
  return this;
}

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

/**
 * Use the bounding box of the supplied spatial to create a
 * BoxCollisionShape.
 *
 * @param spatial the spatial on which to base the shape (not null)
 * @param parent unused
 * @return a new shape with the dimensions of the spatial's bounding box
 * (not null)
 */
private static BoxCollisionShape createSingleBoxShape(Spatial spatial, Spatial parent) {
  //TODO: using world bound here instead of "local world" bound...
  BoxCollisionShape shape = new BoxCollisionShape(
      ((BoundingBox) spatial.getWorldBound()).getExtent(new Vector3f()));
  return shape;
}

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

/**
 * Use the bounding box of the supplied spatial to create a
 * BoxCollisionShape.
 *
 * @param spatial the spatial on which to base the shape (not null)
 * @param parent unused
 * @return a new shape with the dimensions of the spatial's bounding box
 * (not null)
 */
private static BoxCollisionShape createSingleBoxShape(Spatial spatial, Spatial parent) {
  //TODO: using world bound here instead of "local world" bound...
  BoxCollisionShape shape = new BoxCollisionShape(
      ((BoundingBox) spatial.getWorldBound()).getExtent(new Vector3f()));
  return shape;
}

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

return cam.containsGui(getWorldBound());
} else {
  frustrumIntersects = cam.contains(getWorldBound());

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

protected void controlRender(RenderManager rm, ViewPort vp) {
  BoundingVolume bv = spatial.getWorldBound();
  Camera cam = vp.getCamera();
  float atanNH = FastMath.atan(cam.getFrustumNear() * cam.getFrustumTop());
  float ratio = (FastMath.PI / (8f * atanNH));
  float newDistance = bv.distanceTo(vp.getCamera().getLocation()) / ratio;
  int level;
  if (Math.abs(newDistance - lastDistance) <= distTolerance) {
    level = lastLevel; // we haven't moved relative to the model, send the old measurement back.
  } else if (lastDistance > newDistance && lastLevel == 0) {
    level = lastLevel; // we're already at the lowest setting and we just got closer to the model, no need to keep trying.
  } else if (lastDistance < newDistance && lastLevel == numLevels - 1) {
    level = lastLevel; // we're already at the highest setting and we just got further from the model, no need to keep trying.
  } else {
    lastDistance = newDistance;
    // estimate area of polygon via bounding volume
    float area = AreaUtils.calcScreenArea(bv, lastDistance, cam.getWidth());
    float trisToDraw = area * trisPerPixel;
    level = numLevels - 1;
    for (int i = numLevels; --i >= 0;) {
      if (trisToDraw - numTris[i] < 0) {
        break;
      }
      level = i;
    }
    lastLevel = level;
  }
  spatial.setLodLevel(level);
}

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

/**
 * A handy method that will attach all bounding boxes of this terrain
 * to the node you supply.
 * Useful to visualize the bounding boxes when debugging.
 *
 * @param parent that will get the bounding box shapes of the terrain attached to
 */
public void attachBoundChildren(Node parent) {
  for (int i = 0; i < this.getQuantity(); i++) {
    if (this.getChild(i) instanceof TerrainQuad) {
      ((TerrainQuad) getChild(i)).attachBoundChildren(parent);
    } else if (this.getChild(i) instanceof TerrainPatch) {
      BoundingVolume bv = getChild(i).getWorldBound();
      if (bv instanceof BoundingBox) {
        attachBoundingBox((BoundingBox)bv, parent);
      }
    }
  }
  BoundingVolume bv = getWorldBound();
  if (bv instanceof BoundingBox) {
    attachBoundingBox((BoundingBox)bv, parent);
  }
}

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

/**
 * Helper function used to recursively populate the outputGeometryList 
 * with geometry children of scene node
 * 
 * @param camera
 * @param scene
 * @param outputGeometryList 
 */
private static void addGeometriesInCamFrustumFromNode(Camera camera, Node scene, RenderQueue.ShadowMode mode, GeometryList outputGeometryList) {
  if (scene.getCullHint() == Spatial.CullHint.Always) return;
  camera.setPlaneState(0);
  if (camera.contains(scene.getWorldBound()) != Camera.FrustumIntersect.Outside) {
    for (Spatial child: scene.getChildren()) {
      if (child instanceof Node) addGeometriesInCamFrustumFromNode(camera, (Node)child, mode, outputGeometryList);
      else if (child instanceof Geometry && child.getCullHint() != Spatial.CullHint.Always) {
        camera.setPlaneState(0);
        if (checkShadowMode(child.getShadowMode(), mode) &&
            !((Geometry)child).isGrouped() &&
            camera.contains(child.getWorldBound()) != Camera.FrustumIntersect.Outside) {
         outputGeometryList.add((Geometry)child);
        }
      }
    }
  }
}

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

int planeState = camera.getPlaneState();
camera.setPlaneState(0);
inFrustum = camera.contains(scene.getWorldBound()) != Camera.FrustumIntersect.Outside && scene.checkCulling(vpCamera);
camera.setPlaneState(planeState);

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

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);
}

代码示例来源:origin: info.projectkyoto/mms-engine

@Override
public void computeLastDistance(Spatial owner) {
  if (owner.getWorldBound() != null) {
    BoundingVolume bv = owner.getWorldBound();
    lastDistance = bv.distanceSquaredTo(position);
  } else {
    lastDistance = owner.getWorldTranslation().distanceSquared(position);
  }
}

代码示例来源:origin: org.jmonkeyengine/jme3-core

@Override
public void computeLastDistance(Spatial owner) {
  if (owner.getWorldBound() != null) {
    BoundingVolume bv = owner.getWorldBound();
    lastDistance = bv.distanceSquaredTo(position);
  } else {
    lastDistance = owner.getWorldTranslation().distanceSquared(position);
  }
}

代码示例来源:origin: info.projectkyoto/mms-engine

private void fixRefreshFlags(){
  // force transforms to update below this node
  spatial.updateGeometricState();
  
  // force world bound to update
  Spatial rootNode = spatial;
  while (rootNode.getParent() != null){
    rootNode = rootNode.getParent();
  }
  rootNode.getWorldBound(); 
}

代码示例来源:origin: org.jmonkeyengine/jme3-core

private void fixRefreshFlags(){
  // force transforms to update below this node
  spatial.updateGeometricState();
  
  // force world bound to update
  Spatial rootNode = spatial;
  while (rootNode.getParent() != null){
    rootNode = rootNode.getParent();
  }
  rootNode.getWorldBound(); 
}

代码示例来源:origin: net.sf.phat/phat-core

public static Vector3f getCenterBoinding(Spatial spatial) {
  spatial.updateModelBound();
  BoundingVolume wb = spatial.getWorldBound();
  if (wb == null) {
    return spatial.getWorldTranslation();
  } else {
    return wb.getCenter();
  }
}

代码示例来源:origin: net.sf.phat/phat-core

public static Vector3f getMinBounding(Spatial spatial) {
  spatial.updateModelBound();
  BoundingVolume wb = spatial.getWorldBound();
  if (wb instanceof BoundingBox) {
    BoundingBox bb = (BoundingBox) wb;
    Vector3f min = new Vector3f();
    return bb.getMin(min);
  } else if (wb instanceof BoundingSphere) {
    BoundingSphere bs = (BoundingSphere) wb;
    float radius = bs.getRadius();
    return new Vector3f(-radius, -radius, -radius);
  }
  return spatial.getWorldTranslation();
}

相关文章

Spatial类方法