[RESOLVED] How much rotation eh?

Hey guys,

So… I have a spaceship with a Vector v1 and a rotation r1. How can I work out the x,y and z rotation required to look at another vector v2?

I don't want to simply use "lookAt()" because I need the values (for my guidance hud that I'm creating).

I've tried taking a look at the "lookAt()" method (if that makes sense!), but I never was clear on why a camera has an up and left vector. I've been messing around with the values to see if I can come up with a solution, but still no good  :(

Sorry for (as usual) being a total noob. By the time I get the hang of this stuff it will be JME4 !!



Well actually this requires quite a bit of math if you really want to understand what you are doing. However for a spaceship mouse steering , i always found it acceptable enough, to jsut apply rotation force on the updown and leftright axis. (apply force at 0,100,0 in direction 1,0,0 for example) actually it creats kinda a freelancer feeling even if it is kinda dirty.

Thanks Phoenix,

i always found it acceptable enough, to jsut apply rotation force on the updown and leftright axis. (apply force at 0,100,0 in direction 1,0,0 for example)

I am so sorry mate, but I don't know what that means in relation to my question!!! I guess I'm not sure what you mean by "apply force".

I do appreciate it's gonna need some hardcore maths, as I did a bit of sniffing of the internet (and it got quite smelly). I'd just kinda hoped there might be some out-of-the-box JME algorithm that did this.

Yours hopefully (again)  :D

Well, as far as I understand Quaternions you need to substract thw want to be roatation and the crrent rotation, then you can convert the difference Quaternion to Euler angles, useing the provided methods.

Thanks again mate…

So I guess my question remains with the "want to be rotation"… How do I find out what that is to point at my object?


I'm by no means good at quaternions, but i've spent countless hours battling them in my own projects.

Could you explain more in detail what you're trying to accomplish?

If you simply want to get the "values" of the rotation, but don't want to turn the ship, you could just call ".lookAt()" with a dummy object (say, a Point) having the same translation as your ship, then get the values through it's rotation.toAngles() which gives you a float[] of its x,y,z values.

Thanks for your comments Rickard, and I had actually tried what you said… But… It doesn't quite work.

All I am trying to do is work out what rotation (x,y,z) is required to point my moving spaceship at a stationary object (a spacestation). Therefore, the x,y,z angles will be constantly changing as I head towards/away etc. But because my rotation doesn't change, the "lookAt" doesn't change either. I kind of need a "lookAt" that takes in to account both my location and rotation. Does that make sense?

Any help on this would be truly greatly received. I'm out of ideas as I didn't concentrate hard in enough in maths lessons at school and now it's paying me back  :x

Sorry for the late reply.

If your position is changed, the result of lookAt() will change also. Can you provide a code snippet that shows how you do it, or how you intend to do it? That might help a bit.

Hey Rickard, I actually had the "Eureka" moment last night.

Step by step, here is what I do…

  • I create an empty (node)

  • I set (clone) the location and rotation of my spaceship to the empty node

  • I call "empty.lookAt(otherObject, Vector3f.UNIT_Y)"

I now have the rotation required from my new empty node to point at the object. I am still working on the necessary maths to subtract that from my spaceships rotation, and I will post that here once I'm a bit clearer.

I think I will create the empty Node at initialisation (rather than every update). I then just reset its location/rotation as and when I need to (it doesn't need to be done every frame). This also means I can use the empty node for looking at multiple objects. Exactly what I need for my radar  :D