Faster Spinning with sun angle
|
|
Wyatt Weatherwax
Registered User
Join date: 23 Oct 2007
Posts: 59
|
02-01-2009 21:19
I have not completely tested this because of the 4 hours involved with the passing of the SL day. What I am trying to do is to have an object spin faster as the sun angle increases and then decrease of the angle drops off after noon. No rotation at night. At first i wanted to capture the sun.z value and us it as a multiplier but couldn't figure that out so settled for a couple of > statements which i had to put in descending order. Anyway, there must be a cleaner way to achieve this so I am posting the script. Have at it and thanks for any tips and improvements. //start of script// float spin_rate = -1.00; float roll_rate = 0.00; float yaw_rate = 0.00; rotation adjustment = ZERO_ROTATION; default { state_entry() { //llSay(0, "Hello, Avatar!"  ; } touch_start(integer total_number) { llSay(0,""+(string)llGetSunDirection()); vector sun = llGetSunDirection(); integer isDay = ( sun.z >0 ); integer spinDay = ( sun.z >= 0.  ; integer spinDay1 = ( sun.z >= 0.4); if ( isDay == FALSE){ llSay (0, "Stopped"  ; llTargetOmega( <roll_rate, yaw_rate, spin_rate>*adjustment*0, 2.0, 2.0 ); } else if ( spinDay == TRUE){ llSay(0, "Spin"  ; llTargetOmega( <roll_rate, yaw_rate, spin_rate>*adjustment*3, 2.0, 2.0 ); llSetLocalRot( llGetLocalRot() ); } else if ( spinDay1 == TRUE){ llSay(0, "Spin"  ; llTargetOmega( <roll_rate, yaw_rate, spin_rate>*adjustment*1, 2.0, 2.0 ); llSetLocalRot( llGetLocalRot() ); } } } //End of Script//
|
|
Taff Nouvelle
Virtual Business Owners
Join date: 4 Sep 2006
Posts: 216
|
02-01-2009 22:33
have you thought of using LlGetTimeOfDay , that gives you the time from midnight to midnight, ( or the time from sim reset to the next midnight and then midnight to midnight from then on ) You can work out a calculation on seconds from 2 oclock, midday plus and minus to give you exactly the effect you need.
|
|
Wyatt Weatherwax
Registered User
Join date: 23 Oct 2007
Posts: 59
|
02-02-2009 05:04
i may be misreading the above cause I stayed up to late working the script but I am using the "apparent" SL day (3 hours daylight, 1 hour dark) not the time. Using sun.z the horizon is 0.0, noon is 1.0 and midnight is -1.0 If i knew how to capture sun.z as an integer and work it into the Target Omega spin I'd be fine, the spin rate would increase and decrease during the "day" and be off at night. Without this I am just using a few statement of the angle being either >=0.4 or >=0.8 to give me 4 steps. Crude at best.
|
|
Damanios Thetan
looking in
Join date: 6 Mar 2004
Posts: 992
|
02-02-2009 08:38
Why you need it as an integer? LLTargetOmega uses floats.
Or do you need distinct 'steps' in your rotation speed?
BTW. you can make a float into an integer by casting it.
integer spinrate = 0; if (sun.z > 0) { spinrate = (integer) (sun.z * 10); }
This will give you 10 distinct rotation speeds (0,1,2,3..9).
|
|
Wyatt Weatherwax
Registered User
Join date: 23 Oct 2007
Posts: 59
|
02-02-2009 08:51
Thanks, I still learning the terminolgy so my use of "integer" may not have been the most accurate choice. I will try the script you provided, looking at it I think that will do what I need. Thanks 
|
|
Innula Zenovka
Registered User
Join date: 20 Jun 2007
Posts: 1,825
|
02-02-2009 09:00
From: Wyatt Weatherwax i may be misreading the above cause I stayed up to late working the script but I am using the "apparent" SL day (3 hours daylight, 1 hour dark) not the time. Using sun.z the horizon is 0.0, noon is 1.0 and midnight is -1.0 If i knew how to capture sun.z as an integer and work it into the Target Omega spin I'd be fine, the spin rate would increase and decrease during the "day" and be off at night. Without this I am just using a few statement of the angle being either >=0.4 or >=0.8 to give me 4 steps. Crude at best. Why do you want to capture sun.z as an integer? The speed at which llTargetOmega turns is the vector multiplied by the spinrate, which is a float. I've not tried it, but something based on default { state_entry() { llSetTimerEvent(300); // Check every 5 minutes } timer() { vector sun = llGetSunDirection(); if (sun.z <= 0) //it's night { sun.z=0.0; //so we stop } llTargetOmega(<0.0, 0.0, 1.0>, sun.z, 1.0); } } might work, mightn't it? I don't know much about llGetSunDirection(), though, so you might need to do some sort of correction depending on whether it's am or pm.
|
|
Ruthven Willenov
Darkness in your light
Join date: 16 Jan 2008
Posts: 965
|
02-02-2009 09:10
From: Damanios Thetan Why you need it as an integer? LLTargetOmega uses floats.
Or do you need distinct 'steps' in your rotation speed?
BTW. you can make a float into an integer by casting it.
integer spinrate = 0; if (sun.z > 0) { spinrate = (integer) (sun.z * 10); }
This will give you 10 distinct rotation speeds (0,1,2,3..9). not sure if it will read the integer correctly when it's put into the vector. you may need to re-cast it into a float. also: if (sun.z > 0) can be changed to if (sun.z) FALSE has a value of zero. so anything other than zero will return true, even negative numbers. not sure if that'll work for this effect though. i just saw that you were using a negative number in the original script, but that would end up making it rotate in reverse, so i dunno
|
|
Wyatt Weatherwax
Registered User
Join date: 23 Oct 2007
Posts: 59
|
02-02-2009 09:24
I thought i had tried this but can I use the reported sun.z value from llGetSunDirection directly in the spin equation? Something like:
llTargetOmega( <roll_rate, yaw_rate, sun.z>*adjustment, 2.0, 2.0 );
|
|
Claudius Sewell
Registered User
Join date: 8 Sep 2007
Posts: 8
|
02-02-2009 10:12
If, for example, you want the spinrate (in radians/sec) to equal to sun altitude (in radians) you can try:
float Altitude = llAsin(sun.z); llTargetOmega( <0, 0, 1>, Altitude, 1.0 );
The spinrate will be 0 degrees/sec at rise and set, and about 62 degrees/sec at noon. (Don't expect noon to be at the whole hour, "apparent" SL-sun is little more than a minute ahead of SLTime) The object will rotate around the z-axis <0, 0, 1> and with your script adjusts speed on touch.
Hope this helps..
|
|
Wyatt Weatherwax
Registered User
Join date: 23 Oct 2007
Posts: 59
|
02-02-2009 10:42
Thanks Claudius, I can't wait to try some of these tonight. While I can set a (sun.z <=0) statement to stop the spin, what sort of values get generated wth the radians/sec when the sun is below the horizon? Would using these vaules result in no spin or just a spin in the opposite direction? Also, can the sun.z value be used directly with converison? Like: llTargetOmega( <0, 0, 1>, sun.z, 1.0 );
|
|
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
|
02-02-2009 11:30
A few weeks ago I created a thread about virtual latitude. If you search for "latitude" in the title I think you should find it pretty easily. Anyway, there's a bunch of info in there about how the sun moves.
Essentially, the sun has a very, very strange orbit. There is a "year" which is equal to 11 SL days (44 RL hours). Not only do they TILT the virtual world's axis with the "season" (as in increase/decrease the tilt, not what the real planet does), but they add this fake offset in the LOCAL z direction to make the day about 4 times as long as the night.
If you look at the viewer source code, you'll find that there's also this really funny thing they do in the viewer "for builders". When the sun is close to noon, they just push it down (south, I think) a bit so it isn't too far overhead. But that's PROBABLY not reflected in llGetSunDirection(). It's just the ACTUAL position of the sun in the sky, and the angle of lighting.
But there is one small consolation. The orbit is still symmetrical about the y axis. So noon and midnight occur when the x-component of the sun direction is zero (with noon having a positive z-component).
|
|
Claudius Sewell
Registered User
Join date: 8 Sep 2007
Posts: 8
|
02-02-2009 21:19
From: Wyatt Weatherwax Thanks Claudius, I can't wait to try some of these tonight. While I can set a (sun.z <=0) statement to stop the spin, what sort of values get generated wth the radians/sec when the sun is below the horizon? Would using these vaules result in no spin or just a spin in the opposite direction? Also, can the sun.z value be used directly with converison? Like: llTargetOmega( <0, 0, 1>, sun.z, 1.0 ); Sun at midnight is about -17 degs altitude, if you use this value your object will spin opposite direction of a positive altitude (day). Of course you can replace sun.z in llTargetOmega with llAsin(sun.z), but you probably figured that out by now 
|
|
Wyatt Weatherwax
Registered User
Join date: 23 Oct 2007
Posts: 59
|
02-03-2009 20:36
Here is my final (if that is ever true, LOL) script for this project. Hope others will find it useful. I made this for a radiometer which in RL spins in response to sunlight. On Rez i gave it an initial slow spin so the owner knows it's working. The script checks the sun's position once a minute and increases the speed of the spin as the sun climbs higher and decreases as the sun descends. At sun set the spin stops. Thanks for all the help, it was educational. //Start of Code// default { on_rez(integer start_param) { llSetTimerEvent( 60.0 ); llTargetOmega(<0,0,1>, -0.5, 1.0); } //touch_start(integer total_number) timer() { vector sun = llGetSunDirection(); if(sun.z > 0) { float FLTz = sun.z*-4; //llOwnerSay(""+(string)sun.z); llTargetOmega(<0,0,1>, FLTz, 1.0); //llOwnerSay(""+(string) FLTz); } else { llTargetOmega(<0,0,1>, 0, 1.0); //llOwnerSay("Night"  ; } } } //End of Code//
|