Z+ Up, X+ Forward
|
|
Trep Cosmo
Registered User
Join date: 3 Mar 2005
Posts: 101
|
04-16-2009 11:13
Hi,
Does anyone know a fairly simple method for using rotations and/or vectors in a crazy combination to rotate an object so that the Z+ axis is always pointing up, X+ is pointing forward (toward a point I've chosen)?
If it could roll on the X axis so that it's sorta banking properly, that'd be cool too.
I'm afraid this is a bit beyond my skill with rotations at this point.
Thanks in advance.
_____________________
"There is no 'I' in team, but there is a 'Me' if you scramble it." -- House
|
|
Tanith Rosenbaum
Registered User
Join date: 10 Sep 2008
Posts: 42
|
04-16-2009 11:31
hey. Depends a bit, could you give us some more info, is the object physical or non-physical? how is it driven? (is it a vehicle?) There's several possibilities depending on these parameters.
|
|
Tyken Hightower
Automagical
Join date: 15 Feb 2006
Posts: 472
|
04-16-2009 12:38
From what you're saying, it sounds like you want the object's x-axis to always be level with the horizon. Or maybe you actually want the object to never roll (this is how it can always be 'upright' on its z-axis). The two requirements to have sort of conflict. Anyways, to do the latter, here's some code: // Remove 'roll' from a rotation's x-axis and return the result (Originally posted on the forums by Seifert Surface, maybe).. rotation upright(rotation current) { vector fwd = llRot2Fwd(current); vector left = llVecNorm(<0.0, 0.0, 1.0> % fwd); return llAxes2Rot(fwd, left, fwd % left); }
|
|
Trep Cosmo
Registered User
Join date: 3 Mar 2005
Posts: 101
|
04-16-2009 12:44
It's a physical object. It can pitch, roll and yaw. I just don't want it to end up upside down. Z+ doesn't need to be exactly straight up.
_____________________
"There is no 'I' in team, but there is a 'Me' if you scramble it." -- House
|
|
Darien Caldwell
Registered User
Join date: 12 Oct 2006
Posts: 3,127
|
04-16-2009 12:57
ah because of the infamous gimbal lock issue. sometimes when you make large angular changes to some axis, another will jump from say, 0 to 180. I know exactly what you mean. Sadly, I don't have a solution. Edit: I see a clue here maybe: /54/63/146184/1.htmlseems using quaternions may help ensure it doesn't happen.
|
|
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
|
04-16-2009 14:36
trying to remember exactly... I belive you check an offset vs object rotation and then apply ether a pitch or roll... I can't think of a simplified version but.... rotation vRot90roll = llEuler2Rot( < PI_BY_TWO, 0, 0> ); vector test = <0,0,1> * llGetRot(); if (test.z < 0){ if (test.y < 0){ llSetRot( vRot90roll * llGetRot() ); }else{ llSetRot( (ZERO_ROTATION / vRot90roll) * llGetRot() ); } }
should be close to the right effect. or you could use PI (180) and just skip the second test set
_____________________
| | . "Cat-Like Typing Detected" | . This post may contain errors in logic, spelling, and | . grammar known to the SL populace to cause confusion | | - Please Use PHP tags when posting scripts/code, Thanks. | - Can't See PHP or URL Tags Correctly? Check Out This Link... | - 
|
|
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
|
04-16-2009 15:17
Hewee's Rotation Tip #1 - Never, ever, EVER use Euler angles.  Seriously, think in terms of which axis you want to rotate around and by what angle, or the direction your coordinate axes (local x, y, and z axes) should be pointing. Then use functions like llAxisAngle2Rot(), llRot2Fwd(), llAxes2Rot(), etc. Even llRotBetween() can be your friend, though it's a little less clear and explicit in some cases and you have to be careful to think about what rotation axis it is going to result in.
|
|
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
|
04-16-2009 18:14
From: Hewee Zetkin Hewee's Rotation Tip #1 - Never, ever, EVER use Euler angles.  =P thats why I converted the euler angle to a rot to give it valid context to operate in (unless you were refering to Dariens comment?) actually, now that I think about it rot between IS the answer if you want a soft limit. gVecUp = ; gFltLimitUp = 80; //-- 90deg from straight up = the horizon
vector vPosDorsal; fEnsureUp( rotation vRotCurrent ){ //-- same as vPosDorsal = llRot2Up( vRotCurrent ); in our case, since object rots are normalized already vPosDorsal = <0.0, 0.0, 1.0> * vRotCurrent;
//-- check if the dorsal position is below our limit if (gFltLimitUp > vPosDorsal.z){ //-- force it up to the limit llSetRot( llRotBetween( vPosDorsal, <vPosDorsal.x, vPosDorsal.y, gFltLimitUP> ) * vRotCurrent ); } }
default{ state_entry(){ gFltLimitUp = llCos( gFltLimitUp * DEG_TO_RAD ); }
//-- the rest to the script //-- call function with: fEnsureUp( llGetRot() ); }
I think this would work... untested. this will take it to the nearest limit angle, so it will usually affect the forward vector... anybody got a simpler one that will only roll?
_____________________
| | . "Cat-Like Typing Detected" | . This post may contain errors in logic, spelling, and | . grammar known to the SL populace to cause confusion | | - Please Use PHP tags when posting scripts/code, Thanks. | - Can't See PHP or URL Tags Correctly? Check Out This Link... | - 
|
|
Trep Cosmo
Registered User
Join date: 3 Mar 2005
Posts: 101
|
04-17-2009 08:29
Wow, looking at this code it looks like this problem is a lot more complicated than I thought.
_____________________
"There is no 'I' in team, but there is a 'Me' if you scramble it." -- House
|
|
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
|
04-17-2009 09:41
If it is a vehicle, use the vertical attractor (VEHICLE_VERTICAL_ATTRACTION_EFFICIENCY and VEHICLE_VERTICAL_ATTRACTION_TIMESCALE). Otherwise, maybe try a weak llRotLookAt() that you update dynamically so it doesn't mess up the forward axis?
|
|
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
|
04-17-2009 16:00
From: Trep Cosmo Wow, looking at this code it looks like this problem is a lot more complicated than I thought. not so much... set a limit for the top to be facing, ceck ing the top is outside, if not move it to that limit... getting that change to be just around the x axis (roll) seems a little harder, but I'm sure I missed something obvious and easy. it's really only 4 lines of code and some variables.
_____________________
| | . "Cat-Like Typing Detected" | . This post may contain errors in logic, spelling, and | . grammar known to the SL populace to cause confusion | | - Please Use PHP tags when posting scripts/code, Thanks. | - Can't See PHP or URL Tags Correctly? Check Out This Link... | - 
|