|
Johnnytreadlightly Nightfire
Registered User
Join date: 1 Jun 2008
Posts: 11
|
05-19-2009 16:47
Playing with door scripts again and I'm in need of a little advice. Due to some building constraints I'm trying to get my door prim to rotate approximately 45 degrees. Now all of the door scripts I've looked at for help are using PI and PI_BY_TWO as the rotation angles. What I need to do is take PI_BY_TWO and halve it again....I'll admit I did try PI_BY_FOUR LOL. I think my head is going to explode with all this trigonometry!! Please Help!! here's the code I'm working on, forgive the sloppieness please.
***Smooth Rotating Door with Auto Close***
float autoCloseTime = 20.0;
// how long to take to rotate float ROT_TIME=1.0;
// axis to rotate around vector ROT_AXIS=<0,0,1>; vector initial_angle = <0, 0, 90> ; // angle in radians to rotate float ROT_ANGLE=PI_BY_TWO;
// initial rotation
default { state_entry() { // this needs to be a unit vector ROT_AXIS = llVecNorm(ROT_AXIS);
// get the process started llSetRot(llEuler2Rot (initial_angle * DEG_TO_RAD) * llAxisAngle2Rot(ROT_AXIS, ROT_ANGLE)); state unflipped; } }
state unflipped { state_entry() { llTargetOmega(ROT_AXIS,-ROT_ANGLE/ROT_TIME,1); llSleep(ROT_TIME); llTargetOmega(ROT_AXIS,0,1); llSetLocalRot(llEuler2Rot (initial_angle * DEG_TO_RAD)); }
touch_start(integer total_number) { {llTriggerSound("2cc74235-cf66-b805-be00-33f673ba5e6c",1.0); state flipped;} } }
state flipped { state_entry() {
llSetTimerEvent(autoCloseTime); llTargetOmega(ROT_AXIS,ROT_ANGLE/ROT_TIME,1); llSleep(ROT_TIME); llTargetOmega(ROT_AXIS,0,1); llSetLocalRot(llEuler2Rot (initial_angle * DEG_TO_RAD) * llAxisAngle2Rot(ROT_AXIS, ROT_ANGLE)); }
timer() { state unflipped; }
touch_start(integer total_number) { {llTriggerSound("2cc74235-cf66-b805-be00-33f673ba5e6c",1.0); state unflipped;} } }
|
|
Anti Antonelli
Deranged Toymaker
Join date: 25 Apr 2006
Posts: 1,091
|
05-19-2009 19:33
Well you could always just plug in the number you want for ROT_ANGLE, PI/4 is approximately 0.7854
_____________________
Designer of sensual, tasteful couple's animations - for residents who take their leisure time seriously.  http://slurl.com/secondlife/Brownlee/203/110/109/ 
|
|
Kayaker Magic
low carbonated footprint
Join date: 11 Sep 2008
Posts: 109
|
05-19-2009 19:42
PI_BY_TWO is just a name that resolves into a constant. It was defined to make it unnecessary for you to actually do the divide PI/2.0 over and over again in your code. Who knows, Mono may be optimizing PI/4.0 into a constant for you and this really isn’t an issue any more. Just use PI/4.0 (good documentation), define your own float PI_BY_FOUR=0.7854, use that number everywhere in your code or whatever combination feels good to you. Math isn’t supposed to hurt!
|
|
Innula Zenovka
Registered User
Join date: 20 Jun 2007
Posts: 1,825
|
05-19-2009 19:45
Could you not just declare float ROT_ANGLE and then calculate its value in state_entry()? ROT_ANGLE = 45*DEG_TO_RAD; ;
|
|
Johnnytreadlightly Nightfire
Registered User
Join date: 1 Jun 2008
Posts: 11
|
05-19-2009 19:52
/me slaps his forehead. ITS SOO SIMPLE!! I've been pluggin everything in for almost 4 hours. I even tried to rotate the owner  kiddin. THANK YOU SO MUCH...I can finally move onto the rest of the build. Gulp.
|
|
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
|
05-19-2009 21:48
I use a pattern like this: float ROT_ANGLE;
integer initialized = FALSE; init() { if (initialized) { return; } initialized = TRUE;
ROT_ANGLE = 0.25*PI; ... }
default { state_entry() { init(); ... } }
|
|
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
|
05-20-2009 00:15
you can track you changes with duplication of code in states by using a boolean value test instead of the state, and using either ZERO_ROTATION / Rot2Apply or use your boolean to multiply parts that are added in only for that state.
_____________________
| | . "Cat-Like Typing Detected" | . This post may contain errors in logic, spelling, and | . grammar known to the SL populace to cause confusion | | - Please Use PHP tags when posting scripts/code, Thanks. | - Can't See PHP or URL Tags Correctly? Check Out This Link... | - 
|