Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Rotate prim while retaining scale

Lex Neva
wears dorky glasses
Join date: 27 Nov 2004
Posts: 1,361
06-22-2006 20:42
This script rotates a prim 90 degrees about an axis while keeping the scale oriented the same way. Have you ever had a time where you hollowed a box prim, only to find that you'd oriented the axes wrong and the hollow was in the wrong side? Correcting this can take several steps and some guesswork. This script makes it easy by reorienting the prim but adjusting the size in each axis so that the overall shape remains the same.

This is also useful for starting with a cylinder and making a tube prim that's shaped exactly the same; just rotate 90 degrees about the Y axis. You can reorient the dimple or cut axes of a sphere, too.

CODE

// Rotate while maintaining scale
//
// This script, when dropped into a prim, will reorient its axes but try to keep its dimensions oriented the same.
// For example, this is useful if you just want to reorient the hollow on a box.
//
// To use, just drop the script into a prim, and choose which (local) axis to rotate about. When you're done,
// click "done", and the script will delete itself.
//
// Concept and implementation by Lex Neva. Free to distribute, modify, turn into a birthday cake, etc, if you
// retain this attribution.

sendDialog(key av) {
llDialog(av, "Rotate how much around which axis?",["90 about X","90 about Y","90 about Z","-90 about X","-90 about Y","-90 about Z","done"],1);
}

default
{
state_entry()
{
sendDialog(llGetOwner());
llListen(1,"","","");
}

touch_start(integer num) {
sendDialog(llDetectedKey(0));
}

listen(integer channel, string name, key id, string message) {
if (id == llGetOwner()
// uncomment the next line to allow group members to use the scripts in shared objects
// otherwise if they drop the script into a shared object they don't own, the script
// won't listen to them
|| llSameGroup(id)
) {

if (message == "done") {
llSay(0,"Rotate script deleting.");
llRemoveInventory(llGetScriptName());
} else {
list parts = llParseString2List(message, [" "],[]);
float degrees = llList2Float(parts,0);
string axisName = llList2String(parts, 2);
vector axis;

if (axisName == "X")
axis = <1,0,0>;
else if (axisName == "Y")
axis = <0,1,0>;
else if (axisName == "Z")
axis = <0,0,1>;

rotation rot = llAxisAngle2Rot(axis, degrees * DEG_TO_RAD);

llSetRot(rot * llGetRot());

// Theoretically I should rotate the scale vector by the inverse of the rotation
// I rotate the prim by... but in practice, it doesn't matter since I'm using 90
// degree rotations and turning negatives to positives.
vector newScale = llGetScale() * rot;

// Correct negative values.

newScale.x = llFabs(newScale.x);
newScale.y = llFabs(newScale.y);
newScale.z = llFabs(newScale.z);

llSetScale(newScale);

sendDialog(id);
}
}
}
}
Nada Epoch
The Librarian
Join date: 4 Nov 2002
Posts: 1,423
Discussion Thread
06-28-2006 08:31
/54/4f/116788/1.html
_____________________
i've got nothing. ;)
Zack Hodgson
Registered User
Join date: 9 Jun 2006
Posts: 2
06-28-2006 13:50
could this be used as a script for a door on a fridge lets say? sorry im total noobish, doing my best to figure this stuff out and i need a script like that