|
roxxkatt Xue
Junior Member
Join date: 8 Aug 2008
Posts: 5
|
08-10-2008 00:35
so ive been trying to set a multiprim objects x and y rotations to 0, while leaving z alone been unsuccessful so far, ive been in SL for 3 days, and have my vehicles half working... ive tried all of these //rotation rot = llGetRot(); //rot.x = 0; //llSetRot(rot); //llSetLocalRot(rot); //list rot = llGetPrimitiveParams([PRIM_ROTATION]); rotation rot = llGetRot(); //rotation rot = llGetLocalRot(); rot.x = 0; rot.y = 0; llSetPrimitiveParams([PRIM_ROTATION, rot]); llSay(0,"rotation set"  ; i get the set msg, but rotation remains unchanged does it not work because im sitting on it? or what
|
|
roxxkatt Xue
Junior Member
Join date: 8 Aug 2008
Posts: 5
|
08-10-2008 17:41
update: vector asd = <0,90,0>; vector zxc = asd * DEG_TO_RAD; qwe = llEuler2Rot(zxc); } touch_start(integer total_number) { llSetRot(llGetRot()*qwe); //llSay(0,(string)llGetRot()); llWhisper(0,"touch rotation set"  ; } doesnt work either, get the msg, no rotation
|
|
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
|
08-10-2008 19:08
Try this: (Compiled and tested to some degree in-world.) rotation levelRotation(rotation oldRot) { vector xOld = llRot2Fwd(oldRot); vector yOld = llRot2Left(oldRot); vector xNew; vector yNew; if (1.0-llFabs(xOld.z) < 0.01) { xNew = llVecNorm(<yOld.y, -yOld.x, 0.0>); // yOld % z yNew = <-xNew.y, xNew.x, 0.0>; // z % xNew } else { yNew = llVecNorm(<-xOld.y, xOld.x, 0.0>); // z % xOld xNew = <yNew.y, -yNew.x, 0.0>; // yNew % z } return llAxes2Rot(xNew, yNew, <0.0, 0.0, 1.0>); }
default { touch_start(integer total_number) { llSetRot(levelRotation(llGetRot())); } }
|
|
roxxkatt Xue
Junior Member
Join date: 8 Aug 2008
Posts: 5
|
08-11-2008 20:59
and also, how do radian degrees work? why is there -4- variables?
not that im ever going to use it >_>
and also, my chair controls stop working once it leaves the ground, even if it lands again
|
|
Jaxx Tardis
Registered User
Join date: 9 Oct 2006
Posts: 11
|
08-20-2008 11:33
Rotations in SL and many other computer 3d environments are calculated off of Quaternions which, while nifty are baffling to most without a degree in calculus. http://en.wikipedia.org/wiki/QuaternionA simple code snip shows how to do absolute rotations, handy for making objects face east, north, up, etc. vector eul = <0,0,45>; //45 degrees around the z-axis, in Euler form eul *= DEG_TO_RAD; //convert to radians rotation quat = llEuler2Rot(eul); //convert to quaternion llSetRot(quat); //rotate the object Not sure what's wrong with your vehicle stopping to function after leaving the ground, I haven't done much (read: anything) with the actual vehicle code in SL, generally just rockets based on llApplyImpulse. The radian is a unit of plane angle, equal to 180/pi degrees, or about 57.2958 degrees. Wikipedia has interesting articles about both Quaternion and Radian mathematics.
|
|
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
|
08-20-2008 12:10
From: Jaxx Tardis Wikipedia has interesting articles about both Quaternion and Radian mathematics. In particular, the following section is quite relevant and understandable in my opinion, and pertains directly to SL. http://en.wikipedia.org/wiki/Quaternions_and_spatial_rotation#Parametrizing_the_space_of_rotations_with_quaternionsThe only other thing you really have to understand is that multiplying a vector by a quaternion in LSL is the equivalent of the whole expression q*v*(q^-1); it performs the whole transformation, so you don't have to worry about all the mechanics underneath (all that extra stuff the article talks about after giving you the important formula involving sin(alpha/2) and cos(alpha/2) ).  In other words, the MOST you might want to know about quaternions to use them for rotation in SL is that: rotation rot = llAxisAngle2Rot(axis, alpha);
// is equivalent to:
rot.x = axis.x*llSin(alpha/2); rot.y = axis.y*llSin(alpha/2); rot.z = axis.z*llSin(alpha/2); rot.s = llCos(alpha/2);
|