Jump to content

How do I rotate a prim or linkset along an axis that is not the center?


Asha Arida
 Share

You are about to reply to a thread that has been inactive for 1056 days.

Please take a moment to consider if this thread is worth bumping.

Recommended Posts

Rotating a prim along the X, Y, or Z axis is easy. My question is how do you rotate a prim along a non-standard axis? An example I'm thinking of might be a wing flapping or a door swinging open. These do not rotate along the center but instead the edge of the prim.

 

I imagine there's a fair amount of math involved, and if so what is it? Or is there an easier way to do this that I'm just not seeing?

Link to comment
Share on other sites

It's all explained here: https://wiki.secondlife.com/wiki/Rotation#Rotating_Vectors

There's also a very good tutorial by Grandma Bates at SLU http://www.sluniverse.com/php/vb/tutorials/62479-introduction-rotations-translations-rotation-tutorial.html

So this, for example, is how  I might script a door if, for some reason, I didn't want to path-cut it (works in linked or unlinked prims):    You would need, of course, to play round with the offset and swing if you wanted to rotate it round a different axis.

 

integer intSwing =90;rotation rotSwing;vector vOffset;default{    state_entry()    {       rotSwing = llEuler2Rot(<0.0,0.0,(float)intSwing>*DEG_TO_RAD);  //90 degress on the z axis       vector size = llGetScale();       vOffset = <(size.x*-0.5),(size.y*-0.5),0.0>;//open away from someone standing in front of face 2 -- that is, in front of the prim -- hinged on the left.    }    touch_start(integer total_number)    {         list l = llGetPrimitiveParams([PRIM_POS_LOCAL,PRIM_ROT_LOCAL]);         vector v = llList2Vector(l,0);         rotation r = llList2Rot(l,1);         llSetPrimitiveParams([PRIM_POS_LOCAL,v+(vOffset-vOffset * rotSwing)*r,         PRIM_ROT_LOCAL,rotSwing*r]);         rotSwing.s*=-1;             }}

 

  • Like 1
  • Thanks 1
Link to comment
Share on other sites

  • 8 months later...
  • 3 years later...
On 1/21/2013 at 5:56 PM, Innula Zenovka said:

It's all explained here: https://wiki.secondlife.com/wiki/Rotation#Rotating_Vectors

There's also a very good tutorial by Grandma Bates at SLU http://www.sluniverse.com/php/vb/tutorials/62479-introduction-rotations-translations-rotation-tutorial.html

So this, for example, is how  I might script a door if, for some reason, I didn't want to path-cut it (works in linked or unlinked prims):    You would need, of course, to play round with the offset and swing if you wanted to rotate it round a different axis.

Argh.. the migration to the new IPS forums has messed up my script's formatting

Here is the corrected version:

integer intSwing =90;
rotation rotSwing;
vector vOffset;

default{    

	state_entry(){
	       rotSwing = llEuler2Rot(<0.0,0.0,(float)intSwing>*DEG_TO_RAD);  //90 degrees on the z axis       
	       vector size = llGetScale();       
	       vOffset = <(size.x*-0.5),(size.y*-0.5),0.0>;//open away from someone standing in front of face 2 -- that is, in front of the prim -- hinged on the left.    
       }    

		touch_start(integer total_number){
			list l = llGetPrimitiveParams([PRIM_POS_LOCAL,PRIM_ROT_LOCAL]);
			vector v = llList2Vector(l,0);
			rotation r = llList2Rot(l,1);
			llSetPrimitiveParams([PRIM_POS_LOCAL,v+(vOffset-vOffset * rotSwing)*r,PRIM_ROT_LOCAL,rotSwing*r]);
			
			rotSwing.s*=-1;             
		}
}
 

 

  • Like 1
  • Thanks 2
Link to comment
Share on other sites

  • 5 months later...
On 3/18/2017 at 10:28 AM, Innula Zenovka said:

Argh.. the migration to the new IPS forums has messed up my script's formatting

Here is the corrected version:


integer intSwing =90;
rotation rotSwing;
vector vOffset;

default{    

	state_entry(){
	       rotSwing = llEuler2Rot(<0.0,0.0,(float)intSwing>*DEG_TO_RAD);  //90 degrees on the z axis       
	       vector size = llGetScale();       
	       vOffset = <(size.x*-0.5),(size.y*-0.5),0.0>;//open away from someone standing in front of face 2 -- that is, in front of the prim -- hinged on the left.    
       }    

		touch_start(integer total_number){
			list l = llGetPrimitiveParams([PRIM_POS_LOCAL,PRIM_ROT_LOCAL]);
			vector v = llList2Vector(l,0);
			rotation r = llList2Rot(l,1);
			llSetPrimitiveParams([PRIM_POS_LOCAL,v+(vOffset-vOffset * rotSwing)*r,PRIM_ROT_LOCAL,rotSwing*r]);
			
			rotSwing.s*=-1;             
		}
}
 

 

How do I modify this script so that the door is hinged on the left instead of the right, when facing the door? Appreciate any help, I don't have experience with this.

Thanks.

Link to comment
Share on other sites

  • 3 years later...
On 3/18/2017 at 11:28 PM, Innula Zenovka said:

Argh.. the migration to the new IPS forums has messed up my script's formatting

Here is the corrected version:


integer intSwing =90;
rotation rotSwing;
vector vOffset;

default{    

	state_entry(){
	       rotSwing = llEuler2Rot(<0.0,0.0,(float)intSwing>*DEG_TO_RAD);  //90 degrees on the z axis       
	       vector size = llGetScale();       
	       vOffset = <(size.x*-0.5),(size.y*-0.5),0.0>;//open away from someone standing in front of face 2 -- that is, in front of the prim -- hinged on the left.    
       }    

		touch_start(integer total_number){
			list l = llGetPrimitiveParams([PRIM_POS_LOCAL,PRIM_ROT_LOCAL]);
			vector v = llList2Vector(l,0);
			rotation r = llList2Rot(l,1);
			llSetPrimitiveParams([PRIM_POS_LOCAL,v+(vOffset-vOffset * rotSwing)*r,PRIM_ROT_LOCAL,rotSwing*r]);
			
			rotSwing.s*=-1;             
		}
}
 

 

thank you, you save my day !

Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 1056 days.

Please take a moment to consider if this thread is worth bumping.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
 Share

×
×
  • Create New...