[java]public Vector3f localToWorld(final Vector3f in, Vector3f store) {
return worldTransform.transformVector(in, store);
}
[/java]
vs
[java]public Transform getWorldTransform() {
checkDoTransformUpdate();
return worldTransform;
}[/java]
Also :
[java]public Vector3f worldToLocal(final Vector3f in, final Vector3f store) {
return worldTransform.transformInverseVector(in, store);
}[/java]
Actually there may be other places where checkDoTransformUpdate() need to be called, possible ie. in clone() ? or better yet, should there be places where getWorldTransform() should be called instead of directly accessing the worldTransform field ? (not really meaning to dictate policies here, the word “should” is inappropriate , feel free to replace it in your mind, reader xD)
See this example for testing (must comment one of the 2 lines below “XXX:”):
pre type="java"
package org.jme3.tests;
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.Vector3f;
import com.jme3.scene.Geometry;
import com.jme3.scene.Node;
import com.jme3.scene.shape.Box;
public class Main3 extends SimpleApplication {
public static void main(String[] args) {
Main3 app = new Main3();
app.start();
}
Node cosmos;
Node farAway;
Vector3f translationVector, translationUnityVector;
float myTimer = 0.0f;
@Override
public void simpleInitApp() {
flyCam.setMoveSpeed(4000f);
Box b = new Box(Vector3f.ZERO, 100, 100, 100);
Geometry geom = new Geometry(“Box”, b);
// geom.updateModelBound();
Material mat = new Material(assetManager,
“Common/MatDefs/Misc/SolidColor.j3md”);
mat.setColor(“m_Color”, ColorRGBA.Blue);
geom.setMaterial(mat);
cosmos = new Node(“cosmos”);
farAway = new Node(“farAway”);
farAway.attachChild(geom);
cosmos.attachChild(farAway);
rootNode.attachChild(cosmos);
rootNode.setLocalRotation(new Quaternion().fromAngles(
FastMath.DEG_TO_RAD * 34, FastMath.DEG_TO_RAD * 78,
FastMath.DEG_TO_RAD * 187));
rootNode.setLocalScale(2.3f, 7f, 5.2f);
rootNode.setLocalTranslation(12f, -8f, -5.2f);
translationVector = new Vector3f(1200.0f, 1000.0f, 1600.0f);
farAway.setLocalTranslation(translationVector);
farAway.setLocalScale(2.3f, 0.7f, 0.2f);
farAway.setLocalRotation(new Quaternion().fromAngles(
FastMath.DEG_TO_RAD * 24, FastMath.DEG_TO_RAD * 98,
FastMath.DEG_TO_RAD * 217));
// translationUnityVector = new Vector3f(translationVector.normalize());
// System.out.println(geom.getWorldTranslation());
cam.setFrustumFar(115000.0f);
// cam.setDirection(translationUnityVector);
// cam.lookAt(rootNode.worldToLocal(translationVector, null),
// rootNode.worldToLocal(cam.getUp(), null));// Vector3f.UNIT_Y
// cam.lookAt(farAway.localToWorld(Vector3f.ZERO, null),
// Vector3f.UNIT_Y);
// XXX:
cam.lookAt(farAway.localToWorld(Vector3f.ZERO, null), Vector3f.UNIT_Y);// bugged
cam.lookAt(
farAway.getWorldTransform()
.transformVector(Vector3f.ZERO, null), Vector3f.UNIT_Y);
// cam.lookAt(translationVector, Vector3f.UNIT_Y);
// cam.update();
// flyCam.
// cam.updateViewProjection();
// cam.update();
System.out.println("TansUnity Vector = " + translationUnityVector);
System.out.println("Camera Direction = " + cam.getDirection());
}
@Override
public void simpleUpdate(float tpf) {
// myTimer += tpf;
// if (myTimer > 5) {
// System.out.println(“After five seconds: …”);
// System.out.println("TansUnity Vector = " + translationUnityVector);
// System.out.println("Camera Direction = " + cam.getDirection());
// myTimer = -1000000.0f;
// }
}
}/pre
PS: this thread lead to this
http://hub.jmonkeyengine.org/groups/general-2/forum/topic/cam-setdirection-anomaly/
Thanks, it should be fixed now …
1 Like