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

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

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

Spatial.setLocalRotation介绍

[英]setLocalRotation sets the local rotation of this node by using a Matrix3f.
[中]setLocalRotation使用Matrix3f设置此节点的局部旋转。

代码示例

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

Quaternion rotation = new Quaternion();
rotation.fromAngleNormalAxis(angle, Vector3f.UNIT_Y);
floor.setLocalRotation(rotation);
sky.setLocalRotation(rotation);

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

Quaternion q = new Quaternion();
  q.lookAt(direction, upVector);
  spatial.setLocalRotation(q);
  break;
case LookAt:
    q2.lookAt(direction, upVector);
    q2.multLocal(rotation);
    spatial.setLocalRotation(q2);
    spatial.setLocalRotation(rotation);

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

public void update(float tpf) {
  if (enabled && spatial != null) {
    Quaternion localRotationQuat = spatial.getLocalRotation();
    Vector3f localLocation = spatial.getLocalTranslation();
    if (!applyLocal && spatial.getParent() != null) {
      getPhysicsLocation(localLocation);
      localLocation.subtractLocal(spatial.getParent().getWorldTranslation());
      localLocation.divideLocal(spatial.getParent().getWorldScale());
      tmp_inverseWorldRotation.set(spatial.getParent().getWorldRotation()).inverseLocal().multLocal(localLocation);
      spatial.setLocalTranslation(localLocation);
      if (useViewDirection) {
        localRotationQuat.lookAt(viewDirection, Vector3f.UNIT_Y);
        spatial.setLocalRotation(localRotationQuat);
      }
    } else {
      spatial.setLocalTranslation(getPhysicsLocation());
      localRotationQuat.lookAt(viewDirection, Vector3f.UNIT_Y);
      spatial.setLocalRotation(localRotationQuat);
    }
  }
}

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

public void update(float tpf) {
  if (enabled && spatial != null) {
    Quaternion localRotationQuat = spatial.getLocalRotation();
    Vector3f localLocation = spatial.getLocalTranslation();
    if (!applyLocal && spatial.getParent() != null) {
      getPhysicsLocation(localLocation);
      localLocation.subtractLocal(spatial.getParent().getWorldTranslation());
      localLocation.divideLocal(spatial.getParent().getWorldScale());
      tmp_inverseWorldRotation.set(spatial.getParent().getWorldRotation()).inverseLocal().multLocal(localLocation);
      spatial.setLocalTranslation(localLocation);
      if (useViewDirection) {
        localRotationQuat.lookAt(viewDirection, Vector3f.UNIT_Y);
        spatial.setLocalRotation(localRotationQuat);
      }
    } else {
      spatial.setLocalTranslation(getPhysicsLocation());
      localRotationQuat.lookAt(viewDirection, Vector3f.UNIT_Y);
      spatial.setLocalRotation(localRotationQuat);
    }
  }
}

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

/**
 * applies the current transform to the given jme Node if the location has been updated on the physics side
 * @param spatial
 */
public boolean applyTransform(Spatial spatial) {
  if (!physicsLocationDirty) {
    return false;
  }
  if (!applyPhysicsLocal && spatial.getParent() != null) {
    localLocation.set(worldLocation).subtractLocal(spatial.getParent().getWorldTranslation());
    localLocation.divideLocal(spatial.getParent().getWorldScale());
    tmp_inverseWorldRotation.set(spatial.getParent().getWorldRotation()).inverseLocal().multLocal(localLocation);
    localRotationQuat.set(worldRotationQuat);
    tmp_inverseWorldRotation.set(spatial.getParent().getWorldRotation()).inverseLocal().mult(localRotationQuat, localRotationQuat);
    spatial.setLocalTranslation(localLocation);
    spatial.setLocalRotation(localRotationQuat);
  } else {
    spatial.setLocalTranslation(worldLocation);
    spatial.setLocalRotation(worldRotationQuat);
  }
  physicsLocationDirty = false;
  return true;
}

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

public void applyWheelTransform() {
  if (wheelSpatial == null) {
    return;
  }
  Quaternion localRotationQuat = wheelSpatial.getLocalRotation();
  Vector3f localLocation = wheelSpatial.getLocalTranslation();
  if (!applyLocal && wheelSpatial.getParent() != null) {
    localLocation.set(wheelWorldLocation).subtractLocal(wheelSpatial.getParent().getWorldTranslation());
    localLocation.divideLocal(wheelSpatial.getParent().getWorldScale());
    tmp_inverseWorldRotation.set(wheelSpatial.getParent().getWorldRotation()).inverseLocal().multLocal(localLocation);
    localRotationQuat.set(wheelWorldRotation);
    tmp_inverseWorldRotation.set(wheelSpatial.getParent().getWorldRotation()).inverseLocal().mult(localRotationQuat, localRotationQuat);
    wheelSpatial.setLocalTranslation(localLocation);
    wheelSpatial.setLocalRotation(localRotationQuat);
  } else {
    wheelSpatial.setLocalTranslation(wheelWorldLocation);
    wheelSpatial.setLocalRotation(wheelWorldRotation);
  }
}

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

spatial.setLocalRotation(localRotationQuat);
} else {
  spatial.setLocalTranslation(localLocation);
  spatial.setLocalRotation(localRotationQuat);

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

/**
 * Apply this wheel's physics location and orientation to its associated
 * spatial, if any.
 */
public void applyWheelTransform() {
  if (wheelSpatial == null) {
    return;
  }
  Quaternion localRotationQuat = wheelSpatial.getLocalRotation();
  Vector3f localLocation = wheelSpatial.getLocalTranslation();
  if (!applyLocal && wheelSpatial.getParent() != null) {
    localLocation.set(wheelWorldLocation).subtractLocal(wheelSpatial.getParent().getWorldTranslation());
    localLocation.divideLocal(wheelSpatial.getParent().getWorldScale());
    tmp_inverseWorldRotation.set(wheelSpatial.getParent().getWorldRotation()).inverseLocal().multLocal(localLocation);
    localRotationQuat.set(wheelWorldRotation);
    tmp_inverseWorldRotation.set(wheelSpatial.getParent().getWorldRotation()).inverseLocal().mult(localRotationQuat, localRotationQuat);
    wheelSpatial.setLocalTranslation(localLocation);
    wheelSpatial.setLocalRotation(localRotationQuat);
  } else {
    wheelSpatial.setLocalTranslation(wheelWorldLocation);
    wheelSpatial.setLocalRotation(wheelWorldRotation);
  }
}

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

/**
 * Apply a physics transform to the spatial.
 *
 * @param worldLocation location vector (in physics-space coordinates, not
 * null, unaffected)
 * @param worldRotation orientation (in physics-space coordinates, not null,
 * unaffected)
 */
protected void applyPhysicsTransform(Vector3f worldLocation, Quaternion worldRotation) {
  if (enabled && spatial != null) {
    Vector3f localLocation = spatial.getLocalTranslation();
    Quaternion localRotationQuat = spatial.getLocalRotation();
    if (!applyLocal && spatial.getParent() != null) {
      localLocation.set(worldLocation).subtractLocal(spatial.getParent().getWorldTranslation());
      localLocation.divideLocal(spatial.getParent().getWorldScale());
      tmp_inverseWorldRotation.set(spatial.getParent().getWorldRotation()).inverseLocal().multLocal(localLocation);
      localRotationQuat.set(worldRotation);
      tmp_inverseWorldRotation.set(spatial.getParent().getWorldRotation()).inverseLocal().mult(localRotationQuat, localRotationQuat);
      spatial.setLocalTranslation(localLocation);
      spatial.setLocalRotation(localRotationQuat);
    } else {
      spatial.setLocalTranslation(worldLocation);
      spatial.setLocalRotation(worldRotation);
    }
  }
}

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

/**
   * Apply the specified location and orientation to the specified spatial.
   *
   * @param worldLocation location vector (in physics-space coordinates, not
   * null, unaffected)
   * @param worldRotation orientation (in physics-space coordinates, not null,
   * unaffected)
   * @param spatial where to apply (may be null)
   */
  protected void applyPhysicsTransform(Vector3f worldLocation, Quaternion worldRotation, Spatial spatial) {
    if (spatial != null) {
      Vector3f localLocation = spatial.getLocalTranslation();
      Quaternion localRotationQuat = spatial.getLocalRotation();
      if (spatial.getParent() != null) {
        localLocation.set(worldLocation).subtractLocal(spatial.getParent().getWorldTranslation());
        localLocation.divideLocal(spatial.getParent().getWorldScale());
        tmp_inverseWorldRotation.set(spatial.getParent().getWorldRotation()).inverseLocal().multLocal(localLocation);
        localRotationQuat.set(worldRotation);
        tmp_inverseWorldRotation.set(spatial.getParent().getWorldRotation()).inverseLocal().mult(localRotationQuat, localRotationQuat);
        spatial.setLocalTranslation(localLocation);
        spatial.setLocalRotation(localRotationQuat);
      } else {
        spatial.setLocalTranslation(worldLocation);
        spatial.setLocalRotation(worldRotation);
      }
    }

  }
}

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

/**
   * Apply the specified location and orientation to the specified spatial.
   *
   * @param worldLocation location vector (in physics-space coordinates, not
   * null, unaffected)
   * @param worldRotation orientation (in physics-space coordinates, not null,
   * unaffected)
   * @param spatial where to apply (may be null)
   */
  protected void applyPhysicsTransform(Vector3f worldLocation, Quaternion worldRotation, Spatial spatial) {
    if (spatial != null) {
      Vector3f localLocation = spatial.getLocalTranslation();
      Quaternion localRotationQuat = spatial.getLocalRotation();
      if (spatial.getParent() != null) {
        localLocation.set(worldLocation).subtractLocal(spatial.getParent().getWorldTranslation());
        localLocation.divideLocal(spatial.getParent().getWorldScale());
        tmp_inverseWorldRotation.set(spatial.getParent().getWorldRotation()).inverseLocal().multLocal(localLocation);
        localRotationQuat.set(worldRotation);
        tmp_inverseWorldRotation.set(spatial.getParent().getWorldRotation()).inverseLocal().mult(localRotationQuat, localRotationQuat);
        spatial.setLocalTranslation(localLocation);
        spatial.setLocalRotation(localRotationQuat);
      } else {
        spatial.setLocalTranslation(worldLocation);
        spatial.setLocalRotation(worldRotation);
      }
    }

  }
}

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

/**
 * Apply a physics transform to the spatial.
 *
 * @param worldLocation location vector (in physics-space coordinates, not
 * null, unaffected)
 * @param worldRotation orientation (in physics-space coordinates, not null,
 * unaffected)
 */
protected void applyPhysicsTransform(Vector3f worldLocation, Quaternion worldRotation) {
  if (enabled && spatial != null) {
    Vector3f localLocation = spatial.getLocalTranslation();
    Quaternion localRotationQuat = spatial.getLocalRotation();
    if (!applyLocal && spatial.getParent() != null) {
      localLocation.set(worldLocation).subtractLocal(spatial.getParent().getWorldTranslation());
      localLocation.divideLocal(spatial.getParent().getWorldScale());
      tmp_inverseWorldRotation.set(spatial.getParent().getWorldRotation()).inverseLocal().multLocal(localLocation);
      localRotationQuat.set(worldRotation);
      tmp_inverseWorldRotation.set(spatial.getParent().getWorldRotation()).inverseLocal().mult(localRotationQuat, localRotationQuat);
      spatial.setLocalTranslation(localLocation);
      spatial.setLocalRotation(localRotationQuat);
    } else {
      spatial.setLocalTranslation(worldLocation);
      spatial.setLocalRotation(worldRotation);
    }
  }
}

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

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, 50, -23));
  spaceCraft.setLocalRotation(new Quaternion(new float[]{0, 0.01f, 0}));
  hoverControl = new PhysicsHoverControl(colShape, 500);
  spaceCraft.addControl(hoverControl);
  rootNode.attachChild(spaceCraft);
  getPhysicsSpace().add(hoverControl);
  hoverControl.setCollisionGroup(PhysicsCollisionObject.COLLISION_GROUP_02);
  ChaseCamera chaseCam = new ChaseCamera(cam, inputManager);
  spaceCraft.addControl(chaseCam);
  flyCam.setEnabled(false);
}

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

/**
 * Rotate the billboard so it points directly opposite the direction the
 * camera's facing
 *
 * @param camera
 *            Camera
 */
private void rotateScreenAligned(Camera camera) {
  // coopt diff for our in direction:
  look.set(camera.getDirection()).negateLocal();
  // coopt loc for our left direction:
  left.set(camera.getLeft()).negateLocal();
  orient.fromAxes(left, camera.getUp(), look);
  Node parent = spatial.getParent();
  Quaternion rot=new Quaternion().fromRotationMatrix(orient);
  if ( parent != null ) {
    rot =  parent.getWorldRotation().inverse().multLocal(rot);
    rot.normalizeLocal();
  }
  spatial.setLocalRotation(rot);
  fixRefreshFlags();
}

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

rot =  rot.set(parent.getWorldRotation()).inverseLocal().multLocal(getLocalRotation());
rot.normalizeLocal();
setLocalRotation(rot);

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

@Override
protected void controlUpdate(float tpf) {
  if (spatial != null && camera != null) {
    switch (controlDir) {
      case SpatialToCamera:
        camera.setLocation(spatial.getWorldTranslation());
        camera.setRotation(spatial.getWorldRotation());
        break;
      case CameraToSpatial:
        // set the localtransform, so that the worldtransform would be equal to the camera's transform.
        // Location:
        TempVars vars = TempVars.get();
        Vector3f vecDiff = vars.vect1.set(camera.getLocation()).subtractLocal(spatial.getWorldTranslation());
        spatial.setLocalTranslation(vecDiff.addLocal(spatial.getLocalTranslation()));
        // Rotation:
        Quaternion worldDiff = vars.quat1.set(camera.getRotation()).subtractLocal(spatial.getWorldRotation());
        spatial.setLocalRotation(worldDiff.addLocal(spatial.getLocalRotation()));
        vars.release();
        break;
    }
  }
}

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

spatial.setLocalRotation(orient);
fixRefreshFlags();

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

targetModel.setLocalRotation(modelRotation);

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

targetModel.setLocalRotation(modelRotation);

代码示例来源: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);
}

相关文章

Spatial类方法