Problems with CameraNode

Ops, I put a wrong link, this is the right.



OK, what I want in my game is the illusion that the center object(targeted by the ChaseCamera) is rotating according the player drag the mouse. So, if I make a spatial background behind the targeted spatial



Did you try creating a normal ChaseCam and then just creating a CameraNode, set its mode to Cam->Spatial after you corrected your double-controller setup? It should work.

Yes, I tried, but is like if the cube (a simple test) was attached to the rootNode, it does not move and I can see it :cry:

Here are the methods where I create the CameraNode, ChaseCam and attach the cube to camNode:

[java] public void initCam() {

camNode = new CameraNode("Camera Node", cam);

camNode.setControlDir(ControlDirection.CameraToSpatial);

rootNode.attachChild(camNode);



flyCam.setEnabled(false);

chaseCam = new ChaseCamera(cam, objeto, inputManager);

chaseCam.setDefaultDistance(5f);

chaseCam.setInvertVerticalAxis(true);

chaseCam.setSmoothMotion(true);

chaseCam.setToggleRotationTrigger(new MouseButtonTrigger(mouseInput.BUTTON_LEFT),

new KeyTrigger(KeyInput.KEY_SPACE));

chaseCam.setMinVerticalRotation(-FastMath.PI / 2);

chaseCam.setMaxDistance(7f);

chaseCam.setMinDistance(2.5f);

chaseCam.setDefaultVerticalRotation(-0.076f);

chaseCam.setDragToRotate(true);

}



public void initFundo() {

TextureKey key = new TextureKey("Textures/Fundos/2.jpg");

key.setGenerateMips(true);

Texture tex = assetManager.loadTexture(key);

tex.setWrap(WrapMode.Repeat);



Box b = new Box(Vector3f.ZERO, 1, 1, 1);

cube = new Geometry("blue cube", b);

Material matCom = new Material(assetManager, "Common/MatDefs/Misc/SolidColor.j3md");

matCom.setColor("m_Color", ColorRGBA.Blue);

cube.setLocalTranslation(new Vector3f(5f, 5f, 5f));

cube.setMaterial(matCom);

camNode.attachChild(cube);





rootNode.attachChild(SkyFactory.createSky(

assetManager,

tex,

true));

}[/java]

Here is the video showing the blue cube attached with the up code.

Any comentary? :roll:

Ok you want a fixed background behind your camera isn’t it?

don’t use a geometry.



look at this post,

http://hub.jmonkeyengine.org/groups/general-2/forum/topic/background-gradient/?topic_page=2&num=15#post-118379

i posted a way to have a fixed gradient in the background.

You can adapt this to have a texture or anything easily

Hi



I’m new to jMonkeyEngine (and 3d graphics engines in general) so I may be wrong. But from my own messing with CameraNode (jME 3 alpha 4) it looks like what prevents it from being translated/rotated according to camera (direction is ControlDirection.CameraToSpatial) is a bug in the code of it’s CameraControl.





If you look at controlUpdate(float) method of CameraControl, you can see that although the code adjusts translation and rotation of the CameraNode spatial, it does it internally in the vectors (lines 142 & 146, addLocal()). That way the CameraNode’s refreshFlags aren’t touched and won’t reflect the fact that it’s world transform need to be recalculated. Simply, the node is not set dirty, so it’s world transform won’t be altered according to changed local transform.

Simple check is to add another control to CameraNode that extends AbstractControl and does nothing more than just



[java]@Override

protected void controlUpdate(float tpf) {

spatial.setLocalTransform(spatial.getLocalTransform());

}[/java]



setLocalTransform() method takes care of setting CameraNode’s refreshFlags right. This worked as expected for me.





Again, I’m new to jME, so I may be wrong. It would be gr8 if someone evaluated it.

Hi @redeemer

I just took a quick look at CameraControl and I believe this issue you mention has been fixed. You will need to check out the latest nightly build or the head version from SVN, alpha 4 doesn’t have this fix.



[java]

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()));

[/java]