Rotate around z only
|
|
Lemieux Primeau
Registered User
Join date: 25 Oct 2006
Posts: 49
|
10-01-2007 07:17
I have a boat and I would like to rotate it based on any given position vector that I provide. However, I only want it rotate around the z axis (as if someone spun it around by its mast). I don't want it to roll (side to side) or pitch (front to back) - I only want yaw.
I'm sure this is simple and has been done a million times - but when it comes to rotations, nothing is simple for me.
I searched the forum for llRotLookAt thinking it might be related, and I found this, but it still rolls and pitchs my boat.
rotation getRotToPointAxisAt(vector axis, vector target) { return llGetRot() * llRotBetween(llVecNorm(axis * llGetRot()), llVecNorm(target - llGetPos())); }
For the "axis" variable, I have used all three possible normalized vectors, <1,0,0>, <0,1,0> and <0,0,1> but none of them lock down the movement around x and y.
Any solutions? Thanks in advance.
|
|
Bloodsong Termagant
Manic Artist
Join date: 22 Jan 2007
Posts: 615
|
10-01-2007 08:41
heyas;
i did some work with z-only rotations reading them from a camera and applying them to an object. i cant dig up the exact script right now (i can later, if the asset server didnt eat it like some of my other scripts)....
but what you want to do is some euler 2 rot conversions back and forth.
so, you have a rotation facing, let's say north. (with whatever x and y rotations too).
rotation rRot = whatever;
convert to a normal, everyday, easy to use and work with euler:
vector vRot = llRot2Euler(rRot);
now you can read the z axis value using vRot.z
if i recall, you just plug the z in on your current rotation. sorta like so:
rotation rCurrentRot = llGetRot(); vector vCurrentRot = llRot2Euler(rCurrentRot);
vCurrentRot.z = vRot.z;
rotation rNewRot = llEuler2Rot(vCurrentRot);
and then apply this rotation.
_____________________
Why Johnny Can't Rotate: http://forums.secondlife.com/showthread.php?t=94705
|
|
Lemieux Primeau
Registered User
Join date: 25 Oct 2006
Posts: 49
|
10-01-2007 08:52
Bloodsong, thanks for the reply.
But how does this work if I am starting with a vector that represents the position of another object in the sim? In other words, I am not starting with a rotation as in your example - I am starting with a position.
I guess the first thing I need to do is get what rotation it would take to face the boat towards the given position. Then from there, use your process of extracting only the z.
What would be the function for that?
|
|
Lemieux Primeau
Registered User
Join date: 25 Oct 2006
Posts: 49
|
10-01-2007 09:21
I'm at work, so I can't actually try this but, with your suggestion in mind, does this look right?
vector vOtherObjectPos;
vector vOurPos = llGetPos();
vector vRequiredRot = llRotBetween(vOurPos, vOtherObjectPos);
vector vOurRot = llRot2Euler(llGetRot());
vOurRot.z = vRequiredRot.z;
llSetRot(llEuler2Rot(vOurRot));
|
|
Lee Ponzu
What Would Steve Do?
Join date: 28 Jun 2006
Posts: 1,770
|
More search...
10-01-2007 09:23
...of these forums. This has been discussed many times. Search for rotation and quaternion.
|
|
Auron Reardon
Registered User
Join date: 30 Jun 2006
Posts: 41
|
10-01-2007 10:33
From: Lee Ponzu ...of these forums. This has been discussed many times. Search for rotation and quaternion. I did. I spent about 45 minutes searching and going through many threads and trying different things - but none of them were exactly this problem. As I said in the first post, I am sure this problem is common - but rotations are such a large general topic that it is hard to find any one solution.
|
|
Lemieux Primeau
Registered User
Join date: 25 Oct 2006
Posts: 49
|
10-01-2007 10:35
From: Lee Ponzu ...of these forums. This has been discussed many times. Search for rotation and quaternion. I did. I spent about 45 minutes searching and going through many threads and trying different things - but none of them were exactly this problem. As I said in the first post, I am sure this problem is common - but rotations are such a large general topic that it is hard to find any one solution.
|
|
Shadow Subagja
Registered User
Join date: 29 Apr 2007
Posts: 354
|
10-01-2007 11:17
look into: llSetStatus(STATUS_ROTATE_X | STATUS_ROTATE_Y, FALSE) ;
or possibly these vehicle flags:
llSetVehicleFlags(VEHICLE_FLAG_NO_DEFLECTION_UP | VEHICLE_FLAG_LIMIT_ROLL_ONLY);
|
|
Lemieux Primeau
Registered User
Join date: 25 Oct 2006
Posts: 49
|
10-01-2007 11:53
From: Shadow Subagja look into: llSetStatus(STATUS_ROTATE_X | STATUS_ROTATE_Y, FALSE) ;
or possibly these vehicle flags:
llSetVehicleFlags(VEHICLE_FLAG_NO_DEFLECTION_UP | VEHICLE_FLAG_LIMIT_ROLL_ONLY); Thanks, Shadow, I'll look into that too. I don't know about the vehicle flag one, but if the set status works as it implies it should, that is probably the way to go assuming it called before and after the setrot (before to lock down x and y and after to free them up again).
|
|
Ed Gobo
ed44's alt
Join date: 20 Jun 2006
Posts: 220
|
10-02-2007 01:20
remember that llSetRot is non physical whereas the set status deals with physical objects.
|
|
Lemieux Primeau
Registered User
Join date: 25 Oct 2006
Posts: 49
|
10-02-2007 06:53
From: Ed Gobo remember that llSetRot is non physical whereas the set status deals with physical objects. Thanks Ed, good point. Unfortunately, I have not been able to combine any of the parts and pieces above into a single solution that works. Let me restate and reduce the problem to its simplest terms. I have a boat that I want to rotate towards and move to various points on the water in the same sim. Those points may have higher or lower z values. Therefore, short of anything to correct it, the boat is going to pitch or roll when rotating. Here is exactly what I'm doing: MoveTheBoat (vector vPointToGoTo) { //first, rotate the boat towards the vPointToGoTo with yaw only: //???????? //second, move the boat to the point: llMoveToTarget(vPointToGoTo, 3); } It is the ???????? line that I need filled in. If anyone can supply that here I would be eternally grateful. Otherwise, if you want to contact me in world, I will pay you for it.
|
|
Lee Ponzu
What Would Steve Do?
Join date: 28 Jun 2006
Posts: 1,770
|
10-02-2007 09:44
How can the z of the target vary? Isn't the water level? Are you saying that you want to use the x and y of the target, but not the z?
|
|
Lemieux Primeau
Registered User
Join date: 25 Oct 2006
Posts: 49
|
10-02-2007 12:01
From: Lee Ponzu How can the z of the target vary? Isn't the water level? Are you saying that you want to use the x and y of the target, but not the z? Hi Lee. The z varies because the points the boat is heading to are not necessarily sitting on the surface of the water. Some are houses on the shore, others are docks and others are bouys. I can't predict the z of the targets other than to say that they are almost always going to be greater than the z of the surface of the water (though, frankly, even that is not absolute). Also, some will be less than the z of the boat (bouys and docks) and others will be greater than the z of the boat (houses). So, for instance, if a bouy is nearby, some of the things I have been trying make the stern of the boat totally lift out of the water so that the bow can point directly point at it. Conversly, when it is nearby a house, the bow will lift up out of the water to point directly at it. And even if the target.z's were on the surface, I assume that means the closer the boat is to them, the more the stern is going to lift out of the water. So, if I understand correctly, I need to ignore rotations around x and y and only do a rotation around z. Again, if I have it right, rotations around the boat's x and y axes are dependent on the target's z position relative to the boat's z position. Given this, I had high hopes for the llSetStatus suggestion - but it resulted in there being no rotation at all. Of course, this is dependent on all the other rotational and vector things I am doing - and there have been a million combinations I've tried. I just haven't hit the right combination yet. While I am trying to make logical sense of he pieces to put them together, it has mostly been trial and error because there is always one piece that I don't understand or isn't completely documented enough for me to figure out.
|
|
Lee Ponzu
What Would Steve Do?
Join date: 28 Jun 2006
Posts: 1,770
|
10-02-2007 13:47
OK, I see. How does this logic sound?
p = my position t = target position
t.z = p.z to bring the target height to exactly my height. Now I won't point up or down.
d = t - p is the vector from me to target
up is my current up vector
left is d % up (or maybe up % d)
newrot = llAxes2Rot( d, up, left ); rotation pointing at new direction, same up, new left.
Of course, this isn't debugged code, but it might help.
|
|
Lee Ponzu
What Would Steve Do?
Join date: 28 Jun 2006
Posts: 1,770
|
I think this will work...
10-02-2007 15:19
vector tPos = target to point at vector pos = llGetPos(); tPos.z = pos.z;
rotation r = llGetRot() * llRotBetween(<1,0,0> * llGetRot(), tPos-pos ); llRotLookAt( r, 1.0, 1.0 );
How it works? I am not sure, this stuff hurts my head. But, I think...
<1,0,0>*llGetRot() is my forward x vector in world coordinates tPos - pos is a vector from me to target, which has been adjusted to have my altitude z. llRotBetween() then gives the amount of rotation needed to go from current to target. r is my current rotation plus this new needed rotataion.
llRotLookAt does the work.
|
|
Lemieux Primeau
Registered User
Join date: 25 Oct 2006
Posts: 49
|
10-02-2007 18:41
Lee that works!! WOOHOO! Thank you so much. For the last two nights I spent 100% of my time on something that is less than 1% of the whole project, lol. But obviously I couldn't have boats doing wheelies across the sim. Thanks again 
|
|
Lee Ponzu
What Would Steve Do?
Join date: 28 Jun 2006
Posts: 1,770
|
Who's da man!!!
10-03-2007 10:06
Oh, wait...not me, I am an androgenous avatar...
|