I know how to use rotate(),move() etc. But I’m have no idea how to move spatial foward.
For example: I’m have a spatial named SpaceShip.
And I’m rotate it for example 2 radiants.
But how to calculate move() arguments for purpose move spaceship foward?
(“classic” move() move only along absolute x/y/z).
balon said:
("classic" move() move only along absolute x/y/z).
And you live in a universe with how many dimensions exactly that this is not sufficient?
[java]getRotation().getRotationColumn(2);[/java]
Using that you’ll get the “forward” vector.
1 Like
This is not a problem with number of dimensions.
For example:
1.Create spacial
2.Rotate spacial 2 radians
3.How to calculate what parameters of move(x,y,z) should be used for moving 1 unit foward of ship?
If ship is directed along axis X this will be move(1,0,0).
If this is axis Y - move(0,1,0)
But If ship is directed for example 1.5 radians betwen X and Y?
EDIT: Thanks ricard.
Hey, Thank you for that! Very useful for me ie.
that’s this code:
pre type="java"
package org.jme3;
import com.jme3.app.SimpleApplication;
import com.jme3.material.Material;
import com.jme3.math.ColorRGBA;
import com.jme3.math.FastMath;
import com.jme3.math.Quaternion;
import com.jme3.math.Spline;
import com.jme3.math.Vector3f;
import com.jme3.scene.Geometry;
import com.jme3.scene.Node;
import com.jme3.scene.shape.Box;
import com.jme3.scene.shape.Curve;
/**
Sample 2 - How to use nodes as handles to manipulate objects in the scene
graph. You can rotate, translate, and scale objects by manipulating their
parent nodes. The Root Node is special: Only what is attached to the Root
Node appears in the scene.
/
public class HelloNode4 extends SimpleApplication {
public static void main(String[] args) {
HelloNode4 app = new HelloNode4();
app.setShowSettings(false);
app.start();
}
/
(non-Javadoc)
@see com.jme3.app.SimpleApplication#simpleUpdate(float)
/
@Override
public void simpleUpdate(float tpf) {
yaw = (yaw + FastMath.DEG_TO_RAD 4 tpf) % (FastMath.PI 2);
roll = (roll + FastMath.DEG_TO_RAD 7 tpf) % (FastMath.PI 2);
pitch = (pitch + FastMath.DEG_TO_RAD 11 tpf) % (FastMath.PI 2);
rot.fromAngles(yaw, roll, pitch);
geoBox.setLocalRotation(rot);
Vector3f store = new Vector3f(box.getXExtent(), box.getYExtent(),
box.getZExtent());
geoBox.getLocalTransform().transformVector(store, store);
spline.addControlPoint(store);
if (geoCurve != null) {
subNode.detachChild(geoCurve);
}
geoCurve = new Geometry(“trails”, new Curve(spline, 1));
geoCurve.setMaterial(curveMat);
subNode.attachChild(geoCurve);
geoBox.move(geoBox.getLocalRotation().getRotationColumn(2)
.mult(1 tpf));
}
Geometry geoCurve = null;
Material curveMat;
Box box;
Geometry geoBox;
Quaternion rot = new Quaternion();
float yaw = 0f;
float roll = 0f;
float pitch = 0f;
Spline spline = new Spline();
Node subNode;
@Override
public void simpleInitApp() {
subNode = new Node();
subNode.setLocalTranslation(new Vector3f(1, 3, 1));
rot = new Quaternion();
rot.fromAngles(1f, -2f, 4f);
subNode.setLocalRotation(rot);
box = new Box(0.5f, 0.9f, 1.3f);
geoBox = new Geometry(“Box”, box);
geoBox.setLocalTranslation(1f, 2f, 3f);
geoBox.scale(1.3f, 1.2f, 1.1f);
Material mat2 = new Material(assetManager,
“Common/MatDefs/Misc/WireColor.j3md”);
mat2.setColor(“Color”, ColorRGBA.Red);
geoBox.setMaterial(mat2);
curveMat = new Material(assetManager,
“Common/MatDefs/Misc/WireColor.j3md”);
curveMat.setColor(“Color”, ColorRGBA.Green);
rootNode.setLocalTranslation(-1, -2, -4);
rootNode.rotate(-1f, 2f, -4f);
flyCam.setMoveSpeed(20f);
subNode.attachChild(geoBox);
rootNode.attachChild(subNode);
subNode.scale(0.4f);
// subNode.scale(1.3f, 0.7f, 0.4f);// XXX: bug when uncommented
}
}
/pre