Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Rotating a texture to "up"

Paladin Pinion
The other one of 10
Join date: 3 Aug 2007
Posts: 191
03-09-2008 19:50
I have a cube that rotates randomly on any axis. I want its textures to rotate too, so that at least the facing sides are upright (I don't think the top and bottom matter.) I don't know how to calculate that. I have been playing with llRot2Up, which I think may give what I want, but I'm not sure how to change the vector it returns to the angle that llRotateTexture needs. Does anyone know how to do that?
Agent Tairov
Registered User
Join date: 27 Jan 2008
Posts: 17
03-10-2008 10:02
You'll probably have to use some math. You might also want to look into figuring out which faces are which, (llRot2*) and might be able to work something out using that.
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
03-10-2008 14:46
What you basically want is the projection of the global z-axis onto the two local axes (plus or minus) of the face in question. For example, if you picture the cube as "upright" (its local z-axis aligned with the global z-axis) [ EDIT: for purposes of figuring out what face we are talking about; this is not a constraint on the logic below ] and imagine yourself staring at the face for which the local x-axis will be to your right and the local z-axis will be in your "up" direction:

CODE

rotation rot = llGetRot();
vector localX = llRot2Fwd(rot);
vector localY = llRot2Left(rot);
vector localZ = llRot2Up(rot);

float zProjLocalX = localX.z; // Same as <0.0, 0.0, 1.0>*localX
float zProjLocalY = localY.z; // Not used here, but will be for other faces
float zProjLocalZ = localZ.z; // Same as <0.0, 0.0, 1.0>*localZ

float theta;
if (textureRotIsCouterClockwise) // Can't remember at moment ;-)
{
theta = llAtan2(-zProjLocalX, zProjLocalZ);
} else
{
theta = llAtan2(zProjLocalX, zProjLocalZ);
}


I believe that should work like you want anyway. The last calculation (for theta) is going to be different for each face, in terms of both which local axes you use and their sign.

EDIT: I hope your cube is rotating very slowly. Otherwise the hacks to get around script delay are going to be ugly....
Ollj Oh
Registered User
Join date: 28 Aug 2007
Posts: 522
03-11-2008 05:52
I once made a "sculpted prim pancake rounded-plane with some hills rounded corners" and gave the prim an omega rotation and the texture on it (theres only one face for sculpted prim) an omega rotation of the same speed in the opposite direction.

That resulted in some creepy "wobbling goo" effect.
Paladin Pinion
The other one of 10
Join date: 3 Aug 2007
Posts: 191
03-11-2008 10:58
Thank you Hewee, that's very impressive to a math-challenged person like me. Once I saw the word "theta" I started to freeze up. :) At least I know now why my hours of experimenting didn't work -- my math skills just aren't up to the task. I'll play a bit with what you posted though, who knows, I may get lucky.

The timing is flexible, so I can rotate the cube slowly if that's a problem. Thanks again for the remarkable calculations. It's like magic to someone like me.