llLookAt to specify face and top?
|
|
Delete Button
Registered User
Join date: 17 Jan 2009
Posts: 5
|
04-19-2009 08:06
As I understand it llLookAt will have a face of the prim look at the vector, with a specific face always facing up (being the top)... Is there a way to adjust the llLookAt to use a different face, and define which other face is supposed to look up (or be the top)?
An example is if I use a cube and color each side a different color (red, orange, yellow, green, blue, purple) and have a sensor setup to llLookAt my position, the orange face will always look at me, and the red side will be facing up (the top). But if I wanted the blue side facing me, with purple facing up (or being the top), how would I go about doing that?
Thanks in advance!
P.S. Please no whack fixes like attach another prim with the script in there rotated to face in the proper direction, thanks again!
|
|
Ruthven Willenov
Darkness in your light
Join date: 16 Jan 2008
Posts: 965
|
04-19-2009 09:10
i've never used it, but i think you can use llRotLookAt. take a look at the example on the wiki page. http://www.lslwiki.net/lslwiki/wakka.php?wakka=llLookAt
|
|
Briana Dawson
Attach to Mouth
Join date: 23 Sep 2003
Posts: 5,855
|
04-19-2009 09:11
Delete Button <3 <3 <3 
|
|
Delete Button
Registered User
Join date: 17 Jan 2009
Posts: 5
|
04-19-2009 09:46
I've looked at that as well, but I can never get the proper top, to remain facing up. 
|
|
Johan Laurasia
Fully Rezzed
Join date: 31 Oct 2006
Posts: 1,394
|
04-19-2009 09:57
just perform offset rotations after doing the llLookAt().
_____________________
My tutes http://www.youtube.com/johanlaurasia
|
|
Rolig Loon
Not as dumb as I look
Join date: 22 Mar 2007
Posts: 2,482
|
04-19-2009 10:05
Take a look at  . You may find something you can use in llRot2Left, llRot2Up, and llRot2Fwd.
_____________________
It's hard to tell gender from names around here but if you care, Rolig = she. And I exist only in SL, so don't ask....  Look for my work in XStreetSL at 
|
|
Boss Spectre
Registered User
Join date: 5 Sep 2005
Posts: 229
|
04-19-2009 12:15
From: Delete Button From: Ruthven Willenov i've never used it, but i think you can use llRotLookAt. take a look at the example on the wiki page.  I've looked at that as well, but I can never get the proper top, to remain facing up.  The sample code on that page allows you to point in the direction of any positive axis. If the face you wish to aim is on the wrong side, you might try inverting the appropriate axis: From: someone // AXIS_* constants, represent the unit vector 1 unit on the specified axis. vector AXIS_UP = <0,0,1>; vector AXIS_LEFT = <0,1,0>; vector AXIS_FWD = <1,0,0>;
// inverted axes: vector AXIS_DOWN = <0,0,-1>; vector AXIS_RIGHT = <0,-1,0>; vector AXIS_BACK = <-1,0,0>; llRotLookAt and llLookAt give no guarantee about any particular face pointing "up" while aiming another face at a vector. I'm curious, is it your wish to aim a particular side at a target, *as well as* keeping the object "level"? If so, you'll want to rotate the desired side to up, and then set the Z coord of your target the same as your object... that way it won't tilt or roll when it does the LookAt
|
|
Delete Button
Registered User
Join date: 17 Jan 2009
Posts: 5
|
04-19-2009 12:31
From: Rolig Loon Take a look at  . You may find something you can use in llRot2Left, llRot2Up, and llRot2Fwd. I've tried tinkering with the llRot2* functions, and was unable to achieve my final goal. Your link is helpful for determining which face is facing up, but not when specifying which face should be pointing to the vector and which face should be up.
|
|
Delete Button
Registered User
Join date: 17 Jan 2009
Posts: 5
|
04-19-2009 12:38
From: Boss Spectre The sample code on that page allows you to point in the direction of any positive axis. If the face you wish to aim is on the wrong side, you might try inverting the appropriate axis:
llRotLookAt and llLookAt give no guarantee about any particular face pointing "up" while aiming another face at a vector. I'm curious, is it your wish to aim a particular side at a target, *as well as* keeping the object "level"? If so, you'll want to rotate the desired side to up, and then set the Z coord of your target the same as your object... that way it won't tilt or roll when it does the LookAt I basically have a scultped prim, which I need to look at a specific vector, and it not be upside down, etc. and still facing the proper direction. I can achieve this easily by making a cone and putting the script in there and attaching it rotated properly to make the effect I'm looking for, but would really not have to attach that additional prim. Right now, the belly of the item faces me, and the face of the item is facing up...
|
|
Delete Button
Registered User
Join date: 17 Jan 2009
Posts: 5
|
04-19-2009 12:39
From: Johan Laurasia just perform offset rotations after doing the llLookAt(). Then it'll look one way, and then another... Doesn't seem like a smooth suggestion.
|
|
Rolig Loon
Not as dumb as I look
Join date: 22 Mar 2007
Posts: 2,482
|
04-19-2009 13:00
From: Delete Button I've tried tinkering with the llRot2* functions, and was unable to achieve my final goal. Your link is helpful for determining which face is facing up, but not when specifying which face should be pointing to the vector and which face should be up. I guess I don't understand the question, then. Is the problem that you don't know which faces are numbered 1, 2, 3, 4, 5, 6? Or ..... ? It seems as if you ought to be able to rotate any face in any direction you want, so long as you have them labelled. 
_____________________
It's hard to tell gender from names around here but if you care, Rolig = she. And I exist only in SL, so don't ask....  Look for my work in XStreetSL at 
|
|
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
|
04-19-2009 17:53
starting from any random rotation, llLookAt and llRotLookAt only care about one face, fwd(+x), which means that the y and z faces my end up anywhere.
however if you use llSetStatus( STATUS_ROTATE_X, FALSE ) that should remove your problem rolling around the X axis, you can also lock the y axis to make it only turn around the z
then you just use an offset in the opposite direction to get your vector or rotation for a particular side facing a direction either pre calculat the radius or use a vector conversion that points x in the proper direction for your other specified face to point at what you want
of just edit the damn sculpty to face forward on the + x axis and make your life a lot simpler
_____________________
| | . "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... | - 
|
|
Ruthven Willenov
Darkness in your light
Join date: 16 Jan 2008
Posts: 965
|
04-19-2009 22:48
/me giggles From: Void Singer
of just edit the damn sculpty to face forward on the + x axis and make your life a lot simpler
|
|
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
|
04-20-2009 02:28
From: Ruthven Willenov /me giggles well it's true! (and can usually be done in almost any image editor that will save to a format SL will upload) simple instructions for changing sculpt facing around the Z axis: load sculptmap into image editor divide the number of degrees clockwise you want to spin the sculpt by 360, then multiple by the width of the sculpt, round to an even number. note the original size of the sculptmap, double it's width and place a second copy next to it so that it repeats twice in the same image. crop the image to the original size using using the number you got from the degrees as the left bound. save and re upload to SL (I may have reversed the direction or rotation, but IIRC this works just fine)
_____________________
| | . "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... | - 
|
|
Jesse Barnett
500,000 scoville units
Join date: 21 May 2006
Posts: 4,160
|
04-20-2009 04:46
and you can also just add a another small prim in as the root prim with the script in it.
_____________________
I (who is a she not a he) reserve the right to exercise selective comprehension of the OP's question at anytime. From: someone I am still around, just no longer here. See you across the aisle. Hope LL burns in hell for archiving this forum
|
|
Boss Spectre
Registered User
Join date: 5 Sep 2005
Posts: 229
|
Solution
04-20-2009 04:49
I have found a method to aim X at a target without roll (X rotation), and I have no idea if there is a better way. This feels like brute force, but it works, and I haven't encountered any gimbal lock. What I do is find the the yaw (Z rotation) to the target, like this (code from a sensor() event): vector tangent = llVecNorm(llDetectedPos(0) - llGetPos()); rotation yaw = llRotBetween(<1., 0., 0.>, <tangent.x, tangent.y, 0.> ;
yaw now contains the rotation on Z to point toward the target in the Z plane. Then I find the pitch by subtracting the yaw from my tangent, this way: rotation pitch = llRotBetween(<1., 0., 0.>, tangent / yaw);
now I can look down X at the target without any roll: llRotLookAt(pitch * yaw, 1., 1.);
This seems to work quite well. Finally, if I want to point another axis at the target instead of X, I just have to find the rotation required to point that axis due East, by rotating the prim in Edit and looking at the rotation. For example if I want to point Y instead of X, I find that the rotation to point Y to the East is <0, 0, 270>. Then I simply rotate this by my pitch + yaw rotation ... to replace the last line above this would be: llRotLookAt(llEuler2Rot(<0., 0., 270.> * DEG_TO_RAD) * (pitch * yaw), 1., 1.);
Of course, the offset rotation doesn't need to be calculated each time, so I'd store that in a global. The whole thing looks like this:
//-- this needs to be initialized in state_entry because it needs code //-- to allow us to enter a rotation in degrees. rotation gBaseRot = ZERO_ROTATION;
default { state_entry() { //-- offset to aim down an arbitrary axis, //-- INSERT YOUR DESIRED EAST-FACING ROTATION HERE gBaseRot = llEuler2Rot(<0., 0., 270.> * DEG_TO_RAD); llSensorRepeat("", llGetOwner(), AGENT, 96.0, PI, 1.0); } //-- included for tidiness changed(integer change) { if (change & CHANGED_OWNER) llResetScript(); } sensor(integer count) { //-- no need to iterate, we're only sensing for one agent vector tangent = llVecNorm(llDetectedPos(0) - llGetPos()); rotation yaw = llRotBetween(<1., 0., 0.>, <tangent.x, tangent.y, 0.>); rotation pitch = llRotBetween(<1., 0., 0.>, tangent / yaw); llRotLookAt(gBaseRot * (pitch * yaw), 1., 1.); } }
This method also lets you use non-square axes for the base orientation, for example to point a tapered cube with an edge pointing up, you'd use the rotation <0, 90, 45>. Now that we have an algorithm, does anyone know a better way to calculate this? I'm totally open to optimization. ~Boss
|
|
Boss Spectre
Registered User
Join date: 5 Sep 2005
Posts: 229
|
Solution Update
04-20-2009 05:45
I have adapted the Seifert Surface method for removing roll, to include the arbitrary offset axis:
//-- this needs to be initialized in state_entry because it needs code, //-- to allow degrees to be used. rotation gBaseRot = ZERO_ROTATION;
// 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); }
default { state_entry() { //-- offset to aim down an arbitrary axis, //-- INSERT YOUR DESIRED EAST-FACING ROTATION HERE gBaseRot = llEuler2Rot(<0., 90., 45.> * DEG_TO_RAD); llSensorRepeat("", llGetOwner(), AGENT, 96.0, PI, 1.0); } //-- included for tidiness changed(integer change) { if (change & CHANGED_OWNER) llResetScript(); } sensor(integer count) { //-- no need to iterate, we're only sensing for one agent vector tangent = llVecNorm(llDetectedPos(0) - llGetPos()); llRotLookAt(gBaseRot * upright(llRotBetween(<1., 0., 0.>, tangent)), 1, 1); } }
This appears to work too,. I have no idea if it's any better, but I like the mojo of it. Any optimization gurus out there? Let's go make some gun turrets!! ~Boss
|