Hi ,
This is a noob question.,I have a first person camera and a cube in it.I want the cube to be rotated to the same direction where my camera is rotated so that the camera and cube will be a straight line.How can I do this? Thanks in adavance.
sorry , I am using jme2.Forgot to mention that.I have already gone through it.Is the concept differ in jme3?.However, let me explain little bit.
I created a camera node and attached cube to it.
[java]
cn.attachChile(b) where cn is the camera node and b is he box.
[/java]
Also, I have a created a new first personal handler as well to control the camera movement.Why I created a new first person handler is when I move camera forward, the cube also should move.If I have not created the fps handler, my cube does not move.
Now, when I move camera forward, the cube also moves forward.This is not happening automatically.I have coded to move the box.My whole idea here is to enable a simple collision detection.But when I rotate the camera, the cube is still where it was.It is not getting rotated along with the camera, even though I have attached to it. In the update method, I am moving the cube. like following:
[java]
b.setLocalTranslation(cam.getLocation().x,cam.getLocation().y,cam.getLocation().z-3);
b.updateWorldBound();
oldCamLoc1.set(cam.getLocation());
[/java]
what mistake I am doing here.
Both your camera and cube have to be rotated along the same axis. If your camera is controlled by a pivot, attach your cube to that pivot, and rotate the pivot.
About the links above, despite they talk about jme3 stuffs, you should at least read them, because scenegraph and 3d maths of all engines follow the same pattern.
reading the manual and tutorials might help, and also these:
https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:scenegraph_for_dummies
https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:math_for_dummies
@glaucomardano thanks for the reply.
Both your camera and cube have to be rotated along the same axis. If your camera is controlled by a pivot, attach your cube to that pivot, and rotate the pivot.
I have gone through the pivot node concept in hello node tutorial in jme3.In my case, the hierarchy is like this.
1.created camera node
2. created cube node.
3. attached cube node to camera node.
4. attached camera node to root node.
5. attached quake level node to root node.
So here my pivot node is camera node,right.Correct me if I am wrong
yes.
I am just going through this link for further understanding.
http://hub.jmonkeyengine.org/groups/general-2/forum/topic/dragging-mouse-for-camera-orbit-with-exampel/
In this example, a box, three spheres have been added to the rootNode(which is default).
2. created a camera node
3. created a pivot node
4. this pivot node attached to camera node.
so when the mouse dragged, all the objects are getting translated.But here I want only one object should be rotated, but all other objects need to be still visible in the scene.How can I do that?
You should attach all those spatials to the pivot node, and rotate the node pivotNode.rotate();
yes I am able to attach the cube to my camera node.At least when I move my camera left or right , my cube also getting moved accordingly.But what I have understood is that if I do want to rotate or move along with my camera,add that object to the root node and add the camera node to pivot node.This is what I have experienced. Please correct my understanding.
That example that you saw, doesn’t rotate all objects, it just rotates the pivot node, and consequently the cam node. If you wanna rotate the other objects, just attach them to the pivot node. Please, read the scenegraph for dummies and the math for dummies tutorials.
sure thanks for the help.