Hi!
I need some help understanding how to ie. create something in front of wherever the camera (cam.) is looking (not relevant of it's up vector) …
I have cam.getDirection()
and cam.getLocation()
I'm guessing we'd somehow mix those with some maths and some value H which is a float expressing how far ahead of the cam do we want to go. But since I'm no good at Maths and a newbie at jME(jme2 btw), I was hoping someone could help me get this idea
Thank you in advance people!
Cheers!
PS: or point me to the relevant documentation
Vector3f targetTranslation = cam.getLocation().add(cam.getDirection().mult(NunitsAwayFromCam));
set targetTranslation as the localtranslation of the object you want there.
Cool! That is so awesome! Thank you mucho
That is very intuitive.
I am reading that localTranslation is "Spatial's translation relative to its parent. " so I am deducing that both the camera and my new object are children of ie. rootNode (aka parent) and that is why localTranslation "works"… and obviously they are both Spatial I find myself thinking if this works for any Spatials in any location in the tree, but I am guessing it should work… so for example:
root->Z->X->W->K->cam
root->A->B->C
where leftmost are parents and to the right are children of parents…
and if I wanted to move C in front of cam, I would still use localTranslation right? like:
float NunitsAwayFromCam=10f;
Vector3f targetTranslation = cam.getLocation().add(cam.getDirection().mult(NunitsAwayFromCam));
C.setLocalTranslation( targetTranslation );
This would work even if cam and C don't have same common parent? (well they do have root as indirect common parent) but I wonder if when doing ie. ".mult()" above , does the localTranslation get transformed into worldTranslation of sorts? else it wouldn't make sense, unless I'm missing something (as per usual) XD
abugsfriend said:
where leftmost are parents and to the right are children of parents...
and if I wanted to move C in front of cam, I would still use localTranslation right? like:
hi there, no that won't work unless the parent nodes dont have a localTranslation for their own. But you can search the forum for "setWorldTranslation" which lets you find out the the appropriat localTranslation to set so it fits.