本文整理汇总了Java中com.jme3.math.Vector3f.addLocal方法的典型用法代码示例。如果您正苦于以下问题:Java Vector3f.addLocal方法的具体用法?Java Vector3f.addLocal怎么用?Java Vector3f.addLocal使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.jme3.math.Vector3f
的用法示例。
在下文中一共展示了Vector3f.addLocal方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: moveDirectionCamera
import com.jme3.math.Vector3f; //导入方法依赖的package包/类
/**
* Move a camera to direction.
*
* @param value the value to move.
*/
@JMEThread
private void moveDirectionCamera(final float value, final boolean isAction, final boolean isPressed, final int key) {
if (!canCameraMove()) return;
if (isAction && isPressed) startCameraMoving(key);
else if (isAction) finishCameraMoving(key, false);
if (!isCameraMoving() || isAction) return;
final EditorCamera editorCamera = getEditorCamera();
if (editorCamera == null) return;
final Camera camera = EDITOR.getCamera();
final Node nodeForCamera = getNodeForCamera();
final LocalObjects local = LocalObjects.get();
final Vector3f direction = camera.getDirection(local.nextVector());
direction.multLocal(value * cameraSpeed);
direction.addLocal(nodeForCamera.getLocalTranslation());
nodeForCamera.setLocalTranslation(direction);
}
示例2: moveSideCamera
import com.jme3.math.Vector3f; //导入方法依赖的package包/类
/**
* Move a camera to side.
*
* @param value the value to move.
*/
@JMEThread
private void moveSideCamera(final float value, final boolean isAction, final boolean isPressed, final int key) {
if (!canCameraMove()) return;
if (isAction && isPressed) startCameraMoving(key);
else if (isAction) finishCameraMoving(key, false);
if (!isCameraMoving() || isAction) return;
final EditorCamera editorCamera = getEditorCamera();
if (editorCamera == null) return;
final Camera camera = EDITOR.getCamera();
final Node nodeForCamera = getNodeForCamera();
final LocalObjects local = LocalObjects.get();
final Vector3f left = camera.getLeft(local.nextVector());
left.multLocal(value * cameraSpeed);
left.addLocal(nodeForCamera.getLocalTranslation());
nodeForCamera.setLocalTranslation(left);
}
示例3: updateModel
import com.jme3.math.Vector3f; //导入方法依赖的package包/类
/**
* Update position and rotation of a model.
*/
@JMEThread
public void updateModel() {
final AudioNode audioNode = getAudioNode();
final Node model = getModel();
if (model == null || audioNode == null) return;
final Node parent = audioNode.getParent();
if (parent != null) {
setLocalTranslation(parent.getWorldTranslation());
setLocalRotation(parent.getWorldRotation());
setLocalScale(parent.getWorldScale());
}
final Node editedNode = getEditedNode();
final LocalObjects local = LocalObjects.get();
final Vector3f positionOnCamera = local.nextVector();
positionOnCamera.set(editedNode.getWorldTranslation()).subtractLocal(camera.getLocation());
positionOnCamera.normalizeLocal();
positionOnCamera.multLocal(camera.getFrustumNear() + 0.4f);
positionOnCamera.addLocal(camera.getLocation());
model.setLocalTranslation(positionOnCamera);
model.setLocalRotation(editedNode.getLocalRotation());
}
示例4: update
import com.jme3.math.Vector3f; //导入方法依赖的package包/类
@Override
public void update() {
//update the character state based on the needed components
//first collect some necessary information
PhysicsCharacter character = get(PhysicsCharacter.class);
Vector2f move = get(PhysicsCharacterMovement.class).getDirection();
set(new PhysicsCharacterMovementForce(new Vector3f(
move.x*character.getMass()*character.getAcceleration(), 0,
move.y*character.getMass()*character.getAcceleration())));
float capsuleHeight = character.getHeight()-2*character.getRadius()-character.getStepHeight();
float bodyHeight = capsuleHeight+2*character.getRadius();
float jumpSpeed = FastMath.sqrt(2*9.81f*character.getJumpHeight());
boolean jumping = get(PhysicsCharacterState.class).isJumping();
boolean ducking = get(PhysicsCharacterState.class).isDucking();
set(new PhysicsCharacterState(false, false)); //TODO remove
int jumpCount = get(PhysicsCharacterJumpCount.class).getCount();
boolean onGround = false;
Vector3f velocity = get(LinearVelocity.class).getVelocity();
PhysicsPosition pos = get(PhysicsPosition.class);
//the most important part is the ray system which keeps the capsule floating
//in the air over the ground
List<PhysicsRayTestResult> rayTestResultList = bulletSystem.getPhysicsSpace()
.rayTest(pos.getLocation(), pos.getLocation().add(0,-50,0));
if(rayTestResultList.size() > 0){
float len = 60;
for (PhysicsRayTestResult physicsRayTestResult : rayTestResultList) {
if(physicsRayTestResult.getHitFraction()*50 < len){
len = physicsRayTestResult.getHitFraction()*50;
}
}
//if the character is near the ground or below it push it to the min step height.
if(len <= character.getStepHeight() + bodyHeight/2){
float diff = character.getStepHeight() + bodyHeight/2-len;
set(new WarpPosition(pos.getLocation().add(0, diff, 0), pos.getRotation()));
if(velocity.y < 0) {
set(new WarpVelocity(velocity.clone().setY(0), Vector3f.ZERO));
}
onGround = true;
set(new PhysicsCharacterJumpCount(0));
jumpCount = 0;
}
}
Vector3f impulse = new Vector3f();
//apply jump
if(jumping && (onGround || jumpCount < character.getMaxJumpNumber())){
set(new PhysicsCharacterJumpCount(jumpCount+1));
impulse.addLocal(new Vector3f(0, character.getMass()*jumpSpeed, 0));
}
//slow the character down if no movement is applied
if(onGround){
Vector3f slowDownImpulse = new Vector3f();
if(FastMath.approximateEquals(move.x, 0)){
slowDownImpulse.setX(-velocity.x*character.getMass()*0.05f);
}
if(FastMath.approximateEquals(move.y, 0)){
slowDownImpulse.setZ(-velocity.z*character.getMass()*0.05f);
}
impulse.addLocal(slowDownImpulse);
}
//TODO use combined impulse
set(new Impulse(impulse, new Vector3f()));
}
示例5: processTransform
import com.jme3.math.Vector3f; //导入方法依赖的package包/类
@Override
public void processTransform() {
final EditorTransformSupport editorControl = getEditorControl();
final LocalObjects local = LocalObjects.get();
final Camera camera = editorControl.getCamera();
final InputManager inputManager = EDITOR.getInputManager();
final Transform transform = notNull(editorControl.getTransformCenter());
// cursor position and selected position vectors
final Vector2f cursorPos = inputManager.getCursorPosition();
final Vector3f transformOnScreen = camera.getScreenCoordinates(transform.getTranslation(), local.nextVector());
final Vector2f selectedCoords = local.nextVector(transformOnScreen.getX(), transformOnScreen.getY());
// set new deltaVector if it's not set (scale tool stores position of a cursor)
if (Float.isNaN(editorControl.getTransformDeltaX())) {
editorControl.setTransformDeltaX(cursorPos.getX());
editorControl.setTransformDeltaY(cursorPos.getY());
}
final Node parentNode = getParentNode();
final Node childNode = getChildNode();
// Picked vector
final Spatial toTransform = notNull(editorControl.getToTransform());
final TransformationMode transformationMode = editorControl.getTransformationMode();
transformationMode.prepareToScale(parentNode, childNode, transform, camera);
// scale according to distance
final Vector3f deltaVector = local.nextVector(editorControl.getTransformDeltaX(), editorControl.getTransformDeltaY(), 0F);
final Vector2f delta2d = local.nextVector(deltaVector.getX(), deltaVector.getY());
final Vector3f baseScale = local.nextVector(transform.getScale()); // default scale
final Vector3f pickedVector = local.nextVector(transformationMode.getScaleAxis(transform, editorControl.getPickedAxis(), camera));
pickedVector.setX(abs(pickedVector.getX()));
pickedVector.setY(abs(pickedVector.getY()));
pickedVector.setZ(abs(pickedVector.getZ()));
if (Config.DEV_TRANSFORMS_DEBUG) {
System.out.println("Base scale " + baseScale + ", pickedVector " + pickedVector);
}
// scale object
float disCursor = cursorPos.distance(selectedCoords);
float disDelta = delta2d.distance(selectedCoords);
float scaleValue = (float) (cursorPos.distance(delta2d) * 0.01f * Math.sqrt(baseScale.length()));
if (disCursor > disDelta) {
baseScale.addLocal(pickedVector.mult(scaleValue, local.nextVector()));
} else {
scaleValue = Math.min(scaleValue, 0.999f); // remove negateve values
baseScale.subtractLocal(pickedVector.mult(scaleValue, local.nextVector()));
}
parentNode.setLocalScale(baseScale);
if (Config.DEV_TRANSFORMS_DEBUG) {
System.out.println("New scale " + baseScale + ", result world " + childNode.getWorldScale());
}
parentNode.setLocalScale(baseScale);
toTransform.setLocalScale(childNode.getWorldScale());
editorControl.notifyTransformed(toTransform);
}