Jump to content

Sun Earth Simulation


EnCore Mayne
 Share

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

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

Recommended Posts

i'm not sure whether it's possible, so where best to ask...?

i'm thinking of crafting a simulation of the Earth's rotation around the Sun. simple enough if the Earth's polar rotation isn't considered. i can do that much. however, i'm also considering having the Earth's proper 23.5 degree axial tilt maintained too. in that lies the rub.

is there some code to lock the Earth prim's orientation while being attached to the rotating Sun? (as i have it so far, i've got an animated texture on the Earth that simulates daily rotations but no way to ensure the north pole is always at a fixed orientation.)

sunearth.thumb.png.2b693aa01ddeeb592366e6833cc8948c.png

Edited by EnCore Mayne
Link to comment
Share on other sites

for some odd reason i've yet to fathom, i'm using

llSetLinkPrimitiveParamsFast(LINK_THIS,[PRIM_ROT_LOCAL, quaternionchange * quaternionangle]);

for the sun's rotation. it's set for a touch event that increments the rotation quaternionchange using a clever snippet that i have where i can input human sensible angles (floats) into a code that requires the dreaded rotation. as such:

quaternionchange = llEuler2Rot(<-newangle, 0.0, 0.0> * DEG_TO_RAD);

the newangle is currently set for 22.5° so i can see visually how the set appears in testing.

i've attempted several forgettable failures to get the Earth's axial tilt to stay put while the sun (and attached earth) wheel merrily about. each one ending with more weirdness than the last.

essentially, as the idea stands now, i'm sending a llMessageLinked to the earth everytime the set is touched. that's handled in the Earth's code to maintain its orientation by using:

llSetLinkPrimitiveParamsFast(LINK_THIS,[PRIM_ROTATION, stable ] );

the stable variable is initiallized in the state_entry as stable = llGetLocalRot();

unfortunately, that doesn't work to reset the Earth prim's orientation back to the original rotation (as it has in other funtime playthings i've created). anyone have any ideas to achieve the intended stablility of the Earth prim?

as far as using a llGetTime() i'm not sure real time's gonna work for this simulation. i was thinking a full "yearly" rotation could be discernable to a user's given moment of attention.

Edited by EnCore Mayne
Link to comment
Share on other sites

Huh, I never really thought about it before, but 365 rotations per year is /fast/.

vector offset = <0,0,1.5>; // general offset from root prim.
float year_factor = 240.0; // length of a 'year' in seconds.

integer link_sun   = 2; // should calculate these in state_entry, but I'm too lazy for this demo.
integer link_earth = 3;
integer link_moon  = 4; 

vector year_to_orbit(float t,float r, float cycles, float inclination)
{
    inclination = llSin(inclination)*r; // convert from radians to absolute distance above earth-sun plane.
    float angle = t*cycles*TWO_PI;
    return <r*llCos(angle),r*llSin(angle),inclination*llCos(angle)>;
}
rotation year_to_earth_orientation(float t)
{   return
        llAxisAngle2Rot(<0,0,1>,t*365.24*TWO_PI) * // daily rotation.
        llAxisAngle2Rot(<0,1,0>,23.4*DEG_TO_RAD); // axial tilt.
}
rotation year_to_sun_orientation(float t)
{   return
        llAxisAngle2Rot(<0,0,1>,t*(365.24/28.0)*TWO_PI); // very approximate, not accurate sun rotation.
}
rotation year_to_moon_orientation(float t)
{   return
        llAxisAngle2Rot(<0,0,1>,t*13.364*TWO_PI);
}
default
{
    state_entry()
    {
        year_factor = 1/year_factor; // the inverse is more efficient for calculation.
        llSetTimerEvent(0.044);
        llSetLinkPrimitiveParamsFast(link_sun,[PRIM_POS_LOCAL,offset]);
    }
    timer()
    {
        float t = llGetTime()*year_factor;
        vector pos_earth = offset+year_to_orbit(t, 1.5, 1, 0);
        vector pos_moon = pos_earth + year_to_orbit(t, 0.5, 13.364, 15.4*DEG_TO_RAD);
        llSetLinkPrimitiveParamsFast(link_earth,
        [   PRIM_ROT_LOCAL, year_to_earth_orientation(t),
            PRIM_POS_LOCAL, pos_earth,
            
            PRIM_LINK_TARGET, link_sun,
            PRIM_ROT_LOCAL, year_to_sun_orientation(t),
            PRIM_LINK_TARGET, link_moon,
            PRIM_POS_LOCAL, pos_moon,
            PRIM_ROT_LOCAL, year_to_moon_orientation(t) // no final ','
        ]);
    }
    touch_end(integer n)
    {   llResetTime();
    }
}

(assumes you have 4 prims linked together, script in the root prim)

Edited by Quistess Alpha
added the moon.
Link to comment
Share on other sites

that looks absolutely devine Tessa. i knew it might turn out complicated, but trigonometry! i never!

having a quick look over, i'll give it a go laterz, i can't suss exactly why it is there needs to be 3 prims. don't tell me you can get a moon working too. (a hush blankets the audience)

as to the daily revolution of the earth, if indeed it's within the code to accomplish said feat, i'm sure i can alter some of the bits to simulate a pleasing, if not totally accurate rendition.

Link to comment
Share on other sites

1 hour ago, EnCore Mayne said:

i can't suss exactly why it is there needs to be 3 prims. don't tell me you can get a moon working too. (a hush blankets the audience)

Sure, I can add the moon (edited previous post), I more meant it as a general demonstration of how to do the thing, but looking up approximate values for constants on Wikipedia was kinda fun.

It's a weird mix of general and specific functions, (orbit takes the specific axial tilt as a parameter, whereas orientation functions have parameters written inside) but that's more or less the gist of it. no guarantees as to the accuracy of anything. 

Oh, and the reason you need an extra prim is because it's useful to have an absolute reference frame. You could try reworking it with the sun as the reference frame, but then you'd have to rotate it with texture animation rather than actual rotation.

Also, If you want accurate shadows for eclipses, you might need to add a tidally locked projector around the sun.

(like this. . .)

vector offset = <0,0,1.5>; // general offset from root prim.
float year_factor = 240.0; // length of a 'year' in seconds.

float time_offset;

integer link_sun   = 2; // should calculate these in state_entry, but I'm too lazy for this demo.
integer link_earth = 3;
integer link_moon  = 4;
integer link_projector = 5;

vector year_to_orbit(float t,float r, float cycles, float inclination)
{
    inclination = llSin(inclination)*r; // convert from radians to absolute distance above earth-sun plane.
    float angle = t*cycles*TWO_PI;
    return <r*llCos(angle),r*llSin(angle),inclination*llCos(angle)>;
}
rotation year_to_earth_orientation(float t)
{   return
        llAxisAngle2Rot(<0,0,1>,t*365.24*TWO_PI) * // daily rotation.
        llAxisAngle2Rot(<0,1,0>,23.4*DEG_TO_RAD); // axial tilt.
}
rotation year_to_sun_orientation(float t)
{   return
        llAxisAngle2Rot(<0,0,1>,t*(365.24/28.0)*TWO_PI); // very approximate, not accurate sun rotation.
}
rotation year_to_moon_orientation(float t)
{   return
        llAxisAngle2Rot(<0,0,1>,t*13.364*TWO_PI);
}
rotation year_to_projector_orientation(float t,vector pos_earth)
{   
    pos_earth.z = 0;
    return
        llRotBetween(<0,0,-1>,pos_earth);
}
default
{
    state_entry()
    {
        year_factor = 1/year_factor; // the inverse is more efficient for calculation.
        llSetTimerEvent(0.044);
        llSetLinkPrimitiveParamsFast(link_sun,
        [   PRIM_POS_LOCAL,offset,
            PRIM_SIZE, <0.5,0.5,0.5>,
            
            PRIM_LINK_TARGET, link_projector,
            PRIM_POS_LOCAL, offset,
            PRIM_SIZE, <0.6,0.6,0.6>,
            PRIM_COLOR, ALL_SIDES, <1,1,1>, 0.0, // turn invisible
            PRIM_PROJECTOR, "32bfbcea-24b1-fb9d-1ef9-48a28a63730f", 1.57, 0, 0, // "blank sun" from library folder.
            
            PRIM_LINK_TARGET, link_earth,
            PRIM_SIZE, <0.12,0.12,0.12>,
            
            PRIM_LINK_TARGET, link_moon,
            PRIM_SIZE, <0.04,0.04,0.04>
            ]);
        llSetLinkPrimitiveParamsFast(link_projector,[PRIM_POS_LOCAL,offset]);
    }
    timer()
    {
        float t = llGetTime()*year_factor;
        vector pos_earth = offset+year_to_orbit(t, 2.5, 1, 0);
        vector pos_moon = pos_earth + year_to_orbit(t, 0.5, 13.364, 15.4*DEG_TO_RAD);
        llSetLinkPrimitiveParamsFast(link_earth,
        [   PRIM_ROT_LOCAL, year_to_earth_orientation(t),
            PRIM_POS_LOCAL, pos_earth,
            
            PRIM_LINK_TARGET, link_sun,
            PRIM_ROT_LOCAL, year_to_sun_orientation(t),
            
            PRIM_LINK_TARGET, link_projector,
            PRIM_ROT_LOCAL, year_to_projector_orientation(t,pos_earth),
            
            PRIM_LINK_TARGET, link_moon,
            PRIM_POS_LOCAL, pos_moon,
            PRIM_ROT_LOCAL, year_to_moon_orientation(t) // no final ','
        ]);
    }
    touch_end(integer n)
    {   llResetTime();
    }
}

Need to get back to productive things at some point. . .

Edited by Quistess Alpha
  • Like 1
Link to comment
Share on other sites

thanks for spending your time helping Tessa. i'm not quite sure how you would classify it on the productive scale, but it's really really benefitted me. if i recall, weren't you looking for someone to aid you in developing some code to get an .anim importer working? i've got plenty of .anim files should you ever need them just holler.

now, in the hope that i don't bore you or fail to challenge your astute abilities i put your code to work and came away with a couple of issues.

i haven't toyed with it much, so i'll get back to fiddling with it, but i'm absolutely certain i can't make it do what i want with what you've shared. if you come back i'll give you some details.

Link to comment
Share on other sites

10 hours ago, EnCore Mayne said:

thanks for spending your time helping Tessa. i'm not quite sure how you would classify it on the productive scale, but it's really really benefitted me. if i recall, weren't you looking for someone to aid you in developing some code to get an .anim importer working? i've got plenty of .anim files should you ever need them just holler.

now, in the hope that i don't bore you or fail to challenge your astute abilities i put your code to work and came away with a couple of issues.

i haven't toyed with it much, so i'll get back to fiddling with it, but i'm absolutely certain i can't make it do what i want with what you've shared. if you come back i'll give you some details.

lol, no need to butter me up that much, I'd be happy to help debug and refine it a bit more, but I'm not sure if the forums aren't the best medium for an in-depth back and forth on specific issues.

Perhaps we could pick a time to meet in-world, and I'd be more than happy to trade for some .anim files, especially if you have a non-looped 'static pose' that doesn't move many bones. (The anim project is a bit on my backburner though. So many ideas and it's hard to focus on more than one thing at once)

Link to comment
Share on other sites

gotcha, i will suspend with the accolades.

no need for resolving the issues i was having. i've addressed what anomolies i encountered to my awefilled delight. (repressed admiration blurb here.) if anyone else runs into this thread i should say that the Earth's spherical texture was a real bugaboo. seems those prims have to be painted with the X axes as the poles. your code has the Earth's Z axis as the poles. believe me, i coulda used a shoulder to cry on. but i figured it out. changing:

rotation year_to_earth_orientation(float t)
{   return
        llAxisAngle2Rot(<1,0,0>,t*365.24*TWO_PI) * // daily rotation.
        llAxisAngle2Rot(<0,1,0>,-66.5*DEG_TO_RAD); // axial tilt.
}

hit me up inworld if my "buttering-up" turns into reciprocal generosity. i'm good for somethings, you just have to find out what.

  • Like 1
Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 821 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...