Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Calculating Rotations

Rock Vacirca
riches to rags
Join date: 18 Oct 2006
Posts: 1,093
03-30-2008 02:33
Hi guys,

I am trying to script four prims to make apyramid shape, and I am having all kinds of trouble with calculating rotations.

I even tried it manually without success, and I am sure there must be a simple formula for working it out, if anyone has it.

Imagine a flat square prim on the ground, the base. Imagine then a prim 2x2x10 and I want to place that at one corner of the base, and the other end touching the highest apex point of the base that it can.

I have worked out the rotations mathematically. I need to rotate the prim first horizontally by 45 degrees (315 degrees), then rotate it vertically by 63.435 degrees (296.565 degrees).

The first rotation is simple enough, but if I then go to Local coordinates, and rotate the prim vertically, then all the rotations go haywire. The prim itself looks fine, but the axis i am rotating on does not show the 63.435 degrees I am looking for, and the axis I have not rotated on now has a value in it.

Does anyone know how to turn rotations in 2 axes into 3 axes values?

Many thanks for any advice here. I will cross post this in the building forum too, as this is applaciable to both scripting and building.

TIA

Rock
Dekka Raymaker
thinking very hard
Join date: 4 Feb 2007
Posts: 3,898
03-30-2008 07:32
sorry re read your post and my answer wasn't what you were looking for.
Mrc Homewood
Mentor of Randomness
Join date: 24 Feb 2007
Posts: 779
03-30-2008 09:56
not 100% sure what you mean but try this i use callahans script all the time for my movement based scripts with alot of tweeking ;p


CODE

---------------
-Movements-
---------------

vector r_open = <-179.99371, -89.18843, 90.04463>; // Rotations in degrees relative to root prim
vector r_closed = <-90.00000, 0.00001, 90.00000>;

vector p_open = <-1.09680, -4.07110, -0.17270>; // Postition in meters relative to root prim
vector p_closed = <-3.17590, 7.17000, 0.28680>; // Postition in meters relative to root prim

key sound = "c263e31a-14f4-fb1b-fc37-0707269a573a"; // the UUID of the sound the wings will make opening or closing.

integer close_on_rez = TRUE; // Change to false to have it open on rez

// ======================================================= Nothing from here down needs modding (unless you're chaning the command this script responds to).

rotation LocalRot(rotation localrot)
{
rotation LocRot = localrot / ( (ZERO_ROTATION / llGetLocalRot()) * llGetRot());
return LocRot;
}

open()
{
llTriggerSound(sound,1.0);
llSetPrimitiveParams([PRIM_ROTATION, LocalRot(llEuler2Rot(r_open * DEG_TO_RAD)), PRIM_POSITION, p_open]);
}

close()
{
llTriggerSound(sound,1.0);
llSetPrimitiveParams([PRIM_ROTATION, LocalRot(llEuler2Rot(r_closed * DEG_TO_RAD)), PRIM_POSITION, p_closed]);
}

default
{
state_entry()
{
if (close_on_rez)
{
close();
}
else
{
open();
}
}

on_rez(integer rez)
{
llResetScript();
}

link_message(integer send, integer num, string msg, key id)
{
if ( msg == "(open command)" )
{
open();
}
else if ( msg == "(close command)" )
{
close();
}
}
}


----------------------
-Getting Locations-
----------------------

default
{
state_entry()
{
llSay(0, "Base rotation: " + (string)(llRot2Euler(llGetLocalRot())*RAD_TO_DEG) );
llSay(0, "Base Position: " + (string)llGetLocalPos());
llRemoveInventory(llGetScriptName());
}
}