Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Texture Rotation

Happ Macdonald
Registered User
Join date: 25 Sep 2004
Posts: 3
08-20-2005 22:57
So I'm playing with some scripts to do texture rotation now.

I've noticed that no matter what the offset or scale of a texture is, the llRotateTexture() function always seems to rotate around the center of the surface in question. Kind of like this illustration:

http://lightsecond.com/pub/01_texrotate.swf

Is this observation accurate? So, I am wondering, how could you rotate a texture around a different point on the surface? Say the corner, like in here:

http://lightsecond.com/pub/02_texrotate.swf

or maybe even a point not on the surface, like in here:

http://lightsecond.com/pub/03_texrotate.swf

Keep in mind, I don't need a smooth animation effect (though I wouldn't argue with it ;) just a one frame deal, like the llRotateTexture() function but with a custom center.

I took a stab at the math involved and I came up with this script, but it doesn't work so the math must be off base.

Thanks in advance for any advices! :]

float tmp;
float theta;
float dx;
float dy;

float realmod(float a, float b)
{
return( b *((a/b) - llFloor((a/b))) );
}

default
{
state_entry()
{
theta = PI/12;
llScaleTexture(1, 1, ALL_SIDES);
llOffsetTexture(0, 0, ALL_SIDES);
llSay(0, "Hello, Avatar!";);
}

touch_start(integer total_number)
{
tmp = llGetTextureRot(0);
tmp = realmod(tmp + theta, TWO_PI);
llOffsetTexture(
realmod(llSqrt(.5) * llCos(tmp+PI/4) + .5, 1),
realmod(llSqrt(.5) * llSin(tmp+PI/4) + .5, 1),
ALL_SIDES
);
llRotateTexture(tmp, ALL_SIDES);
llSay(0, (string)tmp);
}
}
Eloise Pasteur
Curious Individual
Join date: 14 Jul 2004
Posts: 1,952
08-21-2005 04:43
That would be a no, but depending on the texture you might be able to fake it with a combination of rotation and offset, and maybe scale too.

SL is really poor at letting you rotate things, or rather good at the rotations, but the centres of rotation are always central to the prim and face.

Tricks like cuts might help too.
Wheel Fizz
Registered User
Join date: 26 May 2005
Posts: 36
08-21-2005 06:54
I couldnt get this to work either but the cuts idea sounds good:)
Happ Macdonald
Registered User
Join date: 25 Sep 2004
Posts: 3
08-21-2005 11:37
But isn't there a mathematical trick to let you do it? You see, a rotation about one point combined with an offset is equal to a rotation about a different point. That is what I was trying to do in the script that I posted.

My script works inasfar as you get a rotation about a point other than the center of a face, it's just that I don't seem to have the amount of control I intended over which point that is. In this example I'm trying to make it rotate around the corner but it ends up rotating around.. I dunno, somewhere else?

I feel very strongly that anyone who understood exactly what the rotations do (those seem pretty simple) and also exactly how the offsets work, (and makes fewer math-detail mistakes than I do :) ) could control the rotational center of a texture with ease.

We're working in a simulation engine that makes heavy use of quaternions for pete's sake; we have to have some math geeks in the audience don't we? :D