Hi, I am having several problems with lookat when using nodes, I was trying to build a test case, and I was not able even to do it :
The problem is simple, I have a sphere, and a camera looking to it at 0,0,0.
If I remove the code on simpleupdate it shows the sphere, if not, it shows nothing, and the code on simpleupdate suppose not to do anything at all, at least at starting.
My felling is that its a serious bug out there , follow the test case:
package mygame;
import com.jme3.app.SimpleApplication;
import com.jme3.asset.TextureKey;
import com.jme3.input.KeyInput;
import com.jme3.input.MouseInput;
import com.jme3.input.controls.ActionListener;
import com.jme3.input.controls.AnalogListener;
import com.jme3.input.controls.KeyTrigger;
import com.jme3.input.controls.MouseAxisTrigger;
import com.jme3.input.controls.MouseButtonTrigger;
import com.jme3.light.DirectionalLight;
import com.jme3.material.Material;
import com.jme3.math.ColorRGBA;
import com.jme3.math.FastMath;
import com.jme3.math.Matrix3f;
import com.jme3.math.Quaternion;
import com.jme3.math.Vector3f;
import com.jme3.scene.CameraNode;
import com.jme3.scene.Geometry;
import com.jme3.scene.Node;
import com.jme3.scene.control.CameraControl;
import com.jme3.scene.shape.Box;
import com.jme3.scene.shape.Sphere;
import com.jme3.texture.Texture;
public class rotTestCase extends SimpleApplication implements ActionListener, AnalogListener {
Material matRock;
Geometry sphere , oPlayer;
Vector3f lookAt = new Vector3f(0,0,1);
Vector3f up = new Vector3f(0,1,0);
boolean pressed = false;
Node playerNode = new Node();
CameraNode chaseCam;
Node centralCamNode = new Node();
float valuex,valuey;
public static void main(String[] args) { new rotTestCase().start(); }
@Override public void simpleInitApp() {
setupInput();
createMaterial();
Sphere mesh = new Sphere(16, 16, 1);
sphere = new Geometry("sphere", mesh);
sphere.setMaterial(matRock);
rootNode.attachChild(sphere);
Box pmesh = new Box(0.1f, 0.1f, 0.1f);
Material m = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
oPlayer = new Geometry("player", pmesh);
playerNode.attachChild(oPlayer);
oPlayer.setLocalTranslation(0, 1.2f, 0);
m.setColor("Color", ColorRGBA.Blue); oPlayer.setMaterial(m);
rootNode.attachChild(playerNode);
chaseCam = new CameraNode("Camera Node", cam);
centralCamNode.attachChild(chaseCam);
chaseCam.setControlDir(CameraControl.ControlDirection.SpatialToCamera);
chaseCam.setLocalTranslation(0, 4f, 0);
chaseCam.lookAt(sphere.getLocalTranslation(), Vector3f.UNIT_Y);
rootNode.attachChild(centralCamNode);
valuex=0; valuey=0;
// for some reason I need to do this, maybe a bug ??
centralCamNode.setLocalRotation( playerNode.getLocalRotation() );
rootNode.addLight(new DirectionalLight());
flyCam.setEnabled(false);
}
private void setupInput() {
inputManager.addMapping("left", new KeyTrigger(KeyInput.KEY_LEFT)); inputManager.addMapping("left", new KeyTrigger(KeyInput.KEY_A ));
inputManager.addMapping("right", new KeyTrigger(KeyInput.KEY_RIGHT)); inputManager.addMapping("right", new KeyTrigger(KeyInput.KEY_D));
inputManager.addMapping("up", new KeyTrigger(KeyInput.KEY_UP)); inputManager.addMapping("up", new KeyTrigger(KeyInput.KEY_W));
inputManager.addMapping("down", new KeyTrigger(KeyInput.KEY_DOWN)); inputManager.addMapping("down", new KeyTrigger(KeyInput.KEY_S));
inputManager.addListener(this, "left","right","up","down","space");
}
private void createMaterial() {
matRock = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
TextureKey key2 = new TextureKey("Textures/Rock/Rock.PNG");
key2.setGenerateMips(true);
Texture tex2 = assetManager.loadTexture(key2);
matRock.setTexture("ColorMap", tex2);
}
@Override public void simpleUpdate(float tpf) {
Node temp = new Node();
temp.lookAt( sphere.getLocalTranslation() , Vector3f.UNIT_Y );
centralCamNode.setLocalRotation(temp.getLocalRotation());
}
public void onAction(String name, boolean isPressed, float tpf) {
//if (binding.equals("Button")) { pressed = value; System.out.println("button: " + value); }
}
public void onAnalog(String name, float value, float tpf) {
//System.out.println("name "+name+" ispressed="+isPressed);
valuey=1f*tpf;
valuex=-1f*tpf;
if (name.equals("left")) {
Quaternion add = new Quaternion().fromAngleAxis(+FastMath.QUARTER_PI * valuey * 4, Vector3f.UNIT_Y);
//add.multLocal(lookAt);
//add.multLocal(up);
playerNode.rotate(add);
} else if (name.equals("right")) {
Quaternion add = new Quaternion().fromAngleAxis(-FastMath.QUARTER_PI * valuey * 4, Vector3f.UNIT_Y);
//add.multLocal(lookAt);
//add.multLocal(up);
playerNode.rotate(add);
} else if (name.equals("up")) {
Quaternion add = new Quaternion().fromAngleAxis(-FastMath.QUARTER_PI * valuex * 4, Vector3f.UNIT_X);
//add.multLocal(lookAt);
//add.multLocal(up);
playerNode.rotate(add);
} else if (name.equals("down")) {
Quaternion add = new Quaternion().fromAngleAxis(+FastMath.QUARTER_PI * valuex * 4, Vector3f.UNIT_X);
//add.multLocal(lookAt);
//add.multLocal(up);
playerNode.rotate(add);
}
/*if (binding.equals("MouseLeft")) {
if (pressed) {
Quaternion add = new Quaternion().fromAngleAxis(-FastMath.QUARTER_PI * value * 10, Vector3f.UNIT_Y);
add.multLocal(lookAt);
add.multLocal(up);
}
} else if (binding.equals("MouseRight")) {
if (pressed) {
Quaternion add = new Quaternion().fromAngleAxis(FastMath.QUARTER_PI * value * 10, Vector3f.UNIT_Y);
add.multLocal(lookAt);
add.multLocal(up);
}
} else if (binding.equals("MouseUp")) {
if (pressed) {
Quaternion add = new Quaternion().fromAngleAxis(FastMath.QUARTER_PI * value * 10, Vector3f.UNIT_X);
add.multLocal(lookAt);
add.multLocal(up);
}
} else if (binding.equals("MouseDown")) {
if (pressed) {
Quaternion add = new Quaternion().fromAngleAxis(-FastMath.QUARTER_PI * value * 10, Vector3f.UNIT_X);
add.multLocal(lookAt);
add.multLocal(up);
}
}*/
}
public static Vector3f getForward(Node node) {
Vector3f forward = new Vector3f(0,0,1);
node.localToWorld(forward,forward);
return forward;
}
public static Vector3f getUpVector(Node node) {
Vector3f forward = new Vector3f(0,1,0);
node.localToWorld(forward,forward);
return forward;
}
}
Please note that centralCamNode and sphere have 0 rotation.
It seens I am having the same problem from the old post :
This is only one problem I have , but there is more all related.
Do anyone knows why it happens ? If its a bug and or a way to make it work ?