|
Sayonara Altamura
Registered User
Join date: 28 Jan 2007
Posts: 5
|
10-30-2007 06:07
Hello friends,
I always seem to have to ask about rotation issues... you'd think by now I'd understand it...
Here's my problem. It's very simple. I have a vehicle, a boat (Physical and Phantom), and I want to turn it towards another object, let's call it "theTarget" for the moment. theTarget is too far away to link to. My question is, how do I convert theTarget's location with respect to my boat into a rotation quaternion so I can use functions like llRotTarget()? I have it's position with respect to my boat's position, but I don't understand how I can obtain its rotation quaternion with respect to the forward orientation of my boat.
I do understand about Euler2Rot... do I need to convert the relative displacement vector between my boat and theTarget to an Euler format? How do I do this?
I'm sure I'm missing something really obvious, but after several hours of struggling with the problem, I've decided to try the experts!
Sayonara
|
|
Django Yifu
Beat Island Gaffer
Join date: 7 May 2007
Posts: 189
|
10-30-2007 06:44
I have found this post extremely helpful in recent projects. http://rpgstats.com/wiki/index.php?title=LlLookAtIs great for rotating objects so a certain face points in one direction. I think it should work with physical objects.
_____________________
Tread softly upon the Earth for you walk on my face.
|
|
Tyken Hightower
Automagical
Join date: 15 Feb 2006
Posts: 472
|
10-30-2007 07:40
From: Sayonara Altamura Hello friends,
I always seem to have to ask about rotation issues... you'd think by now I'd understand it...
Here's my problem. It's very simple. I have a vehicle, a boat (Physical and Phantom), and I want to turn it towards another object, let's call it "theTarget" for the moment. theTarget is too far away to link to. My question is, how do I convert theTarget's location with respect to my boat into a rotation quaternion so I can use functions like llRotTarget()? I have it's position with respect to my boat's position, but I don't understand how I can obtain its rotation quaternion with respect to the forward orientation of my boat.
I do understand about Euler2Rot... do I need to convert the relative displacement vector between my boat and theTarget to an Euler format? How do I do this?
I'm sure I'm missing something really obvious, but after several hours of struggling with the problem, I've decided to try the experts!
Sayonara First, about llEuler2Rot and friends - this function converts a vector to a rotation strictly in terms of type. It's not a vector whose components are directions, it's a vector whose components are actually angles. The two things you really need to do this are the vector that points from your boat to the target (for example, llDetectedPos - llGetPos in a sensor) and the vector that represents the boat's 'forward' axis. The latter is determined by root prim of the boat. When I build something where rotation is a factor, I generally make it easy on myself by having the root prim's x-axis in the positive direction face the direction I want to be 'forward' for the whole object (thus the 'forward' vector would be <1.0, 0.0, 0.0>, but what's really important is that you're able to determine this vector in your object. Now that you have these, we pour on the awesome. Using the methods listed on the rpgstats article is sort of misleading; it'll point your object at the target, yes, but your object won't be 'upright.' So as another solution, we'll construct a rotation that will, using llAxes2Rot. The first parameter for this function, the 'forward' vector, is the vector pointing from your boat to the target. The 'left' vector parameter is the cross product of the global z-axis (<0.0, 0.0, 1.0>  and 'forward' vector. The 'up' vector parameter is the cross product of the 'forward' and 'left' vectors. Then you shove it all into the function, and the result is the rotation for your object to face its target - assuming your object's 'forward' vector is <1.0, 0.0, 0.0> as I mentioned above. If it's not, then the easiest way to fix this is to find the rotation between your forward axis and <1.0, 0.0, 0.0>, using our friend llRotBetween, then rotate *that* by the result of llAxes2Rot, llSetRot it, and you're done.
|
|
Sayonara Altamura
Registered User
Join date: 28 Jan 2007
Posts: 5
|
11-17-2007 12:45
This is a very nice solution Tyken - I finally got around to trying it out, and it works like a charm. Thanks a million!
|