Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

llCos/llSin :S

Daten Thielt
Registered User
Join date: 1 Dec 2006
Posts: 104
05-29-2007 20:12
Hey all, im in the middle of trying to create a nice working solar system, ive exsplored a few ways of doing it but a friend of mine had told me, the only way to get a planet to rotate around a sun and a moon to rotate around the plantet is buy using llCos and llSin, keeping in mind the whole model needs to be link, just wondering if anyone has created anything similar or weather some one could point me in the right direction of coding for it, i have no clue with either of the abouv functions

thanks in advance
Lyn Mimistrobell
(waiting)
Join date: 11 Jan 2007
Posts: 179
05-30-2007 06:44
If you look at a circle, any point on the circle can be found by it's radius:

point(x,y):
x = cos(angle) * radius
y = sin(angle) * radius

In your case, radius will be the distance between the sun and the earth, or between the earth and the moon.

Earth.x = Sun.x + cos(EarthAngle) * SunToEarthDistance;
Earth.y = Sun.y + sin(EarthAngle) * SunToEarthDistance;
Moon.x = Earth.x + cos(MoonAngle) * EarthToMoonDistance;
Moon.y = Earth.y + sin(MoonAngle) * EarthToMoonDistance;

Ofcourse this is very simplistic and assumes a flat solar system, but you should get the idea about COS and SIN.
Milambus Oh
Registered User
Join date: 6 Apr 2007
Posts: 224
05-30-2007 07:12
LSL Info:
http://lslwiki.net/lslwiki/wakka.php?wakka=llCos

General Info:
http://en.wikipedia.org/wiki/Trigonometric_function
http://id.mind.net/~zona/mmts/trigonometryRealms/introduction/rightTriangle/trigRightTriangle.html

Things to remember:
1. Rotations in SL are measured in quaternions. Use llRot2Euler() to convert them into radians (what the llSin/llCos functions want).
http://lslwiki.net/lslwiki/wakka.php?wakka=radian

2. Radians are data type vector.
http://lslwiki.net/lslwiki/wakka.php?wakka=vector

3. You can use dot notation on vectors to get the individual parts.
Example: To get the x part of the current rotation.
rotation rot = llGetRot();
vector radian = llRot2Euler(rot);
float x = radian.x; // This is the rotation around the x axis in radians

4. You can convert radians to degrees by multiplying by RAD_TO_DEG:
http://lslwiki.net/lslwiki/wakka.php?wakka=RAD_TO_DEG

5. Use llEuler2Rot() to convert back from radians to quaternion form.

6. llSetRot() uses -LOCAL- rotations when called from a child prim.


There is probably much, much more that should go here but thats a start.
Ged Larsen
thwarted by quaternions
Join date: 4 Dec 2006
Posts: 294
05-30-2007 07:55
Remember that orbits are NOT circles -- they are ellipses, with the sun essentially being at one of the foci of the ellipse.

The eccentricity of orbits of each planet is different, and of course the time for a full circuit.

The plane of orbits of the planets are not all the same.

And, the velocity of each planet will be different, at different points of the elliptical orbit.

A quick Google search gives this summary: http://hyperphysics.phy-astr.gsu.edu/hbase/kepler.html

Because of all that complexity, a realistic solar system will move horribly unsmoothly, because you will be doing a bunch of calculations AND use llSetPos (and, presumbably, llSetRot, if you want each planet to also rotate, as well as orbit).

If you want a smooth looking solar system, and don't care about accuracy, clever use of llTargetOmega will give you smooth client-side rendering of rotations. The Wiki entry on llTargetOmega even mentions the solar system that's in the welcome area: http://www.lslwiki.net/lslwiki/wakka.php?wakka=llTargetOmega

The sun could be a root prim with a llTargetOmega, and planets would be linked child prims, each llTargetOmega rotating about its own axis. But, all the planets would be in circular orbits, in the same plane. And they would have the same orbit time. (Actually, you could perhaps have multiple overlapping suns, that looked like only one sun, and have each sun linked to a different child prim planet -- then, you could have planets with different rates of orbit and different planes. But, they'd still be circular orbits.)

And, this wouldn't allow a moon rotating around a planet rotating around the sun.

It's a clever little exercise, but the results are rather ... uninspiring in SL.
_____________________
- LoopRez, flexi prim skirt generating tool
- LinkRez, a necklace chain generator
Daten Thielt
Registered User
Join date: 1 Dec 2006
Posts: 104
05-30-2007 17:56
thanks for the replyes everyone, btw im wierd so my solar system is <its corular :P>
hopefully i get this figured out :D