So, we have Left, Up and Direction vectors, and we want to rotate on the Z axis (which is the Direction, supposedly)
EDIT: Ok, so if you're wondering what are we rotating? the other two axis (X and Y)
We would use radians to rotate by that angle, so I tried this:
q = new Quaternion();
direction=cam.getDirection().normalize();
Vector3f[] axis = new Vector3f[3];
axis[0] = cam.getLeft().normalize();// X
axis[1] = cam.getUp().normalize();// Y
axis[2] = direction;// Z
q.fromAxes( axis );
and now we want to rotate by R radians (angle, that's a float between 0f to 2*FastMath.PI) on the Direction axis (which is Z in this case) and we get the up vector or the Y axis after that rotation, right? (I hope)
q.fromAngleNormalAxis( R, direction );// on Z axis
Vector3f[] axis = new Vector3f[3];
q.toAxes( axis );
Vector3f tmpUp = axis[1];// Y
Now, I may be missing something, but that doesn't work for me, maybe I've a human error somewhere else, but maybe someone could confirm if this way was a good way of doing that? Also I want to make sure that you understand my point of view that the Z axis is not the 0,0,1 or the world's Z axis, instead is the Direction vector (which could be anything)
It works as long as I keep the cam.getUp() as it initially is (presumably 0,1,0) but when I look down it almost seems as if the up vector is kept to 0,1,0 anyway... I can't really explain it...
the direction vector you'd like to use is vector3f.UNIT_Z or so..
normally I'd do (not sure if the name is right..)
vec.rotate( new Quaternion().fromAxisangles( RADIANS, Vector3f.UNIT_Z));
I'm trying to understand, but I'm having issues :)
What is vec from vec.rotate ? I assume it's not Vector3f since it doesn't have a rotate method... but the name of the variable suggests is a vector? And ok you mean fromAngleAxis
But, if vec would be a vector, then I would have to call rotate on both my X and Y vectors from above (the left and up vectors that is cam.getLeft() and cam.getRight()) because I want them both to rotate, but no necessarily on the Z axis of the world (Vector3f.UNIT_Z) instead, on the relative to them Z axis which is the "direction" variable or the cam.getDirection() vector.
The example with the cam vectors is just an example, I don't really want the cam to rotate, ... although I've given up on this after one day of (superficial) trying
EDIT: So what I'm actually really trying to do is something like this in HelloIntersection
- shoot a bullet from the camera which will go in the same direction until it dies (this is what it already does)
- make the bullet do a spiral motion while it goes forward, that is, rotate on it's relative Z axis which is it's direction axis the vector which it follows when going forward and this rotation would be in a circle that has it's ray decreasing... and for that I kind of needed the up vector to be able to position the bullet there and also decrease this vector in time so it would look like the ray was decreasing. But to do this I need to rotate left and up vectors relative to the direction axis.
I would use a sin() function to compute the spiral position relaive to the original traveling vector.
As your traveling direction is z you just use the plain sinus for computing the y position from it and apply this to the local coordinates. My implementation would be a custom controller added to the bullet at creation containing a travel vector (the direction the bullet should travel) and on updating would do
a) update the path traveled (along z) of the controlled object
b) update the x and y offset of the controlled object based on unit sin()
c) eventually start with a multiplier which decreases the nearer the bullet gets to the target (for a spiral effect (broad at start, narrow at the end)) as the sine delivers results for a unit circle (which would be max 1 away)
d) removes itself as soon as the direction has been completed