Stumped...

Blitz3D Forums/Blitz3D Programming/Stumped...

Chroma(Posted 2006) [#1]
I tried for quite awhile to get this right but it appears the exact algorithm is eluding me.

I need to be able to move a moon around a planet with xrot and yrot in the following format.


dist# = 300
xrot# = xrot + 1
yrot# = yrot + 1

PositionEntity moon,0+sin(xrot)*dist,0+sin(yrot)*dist,0+cos(xrot+yrot)*dist


Orbit around the center (xrot) is fine but the yrot orbit swings the moon away from the planet. Any help is appreciated.

**I know I could just put a pivot and do turnentity but I need it to function in this exact manner with sin and cos.


Stevie G(Posted 2006) [#2]
You could use a simple pivot to save you calculating the rotations.

Pivot = createpivot( PLANET )
Dist# = 300
xrot# = xrot + 1
yrot# = yrot + 1

rotateentity Pivot, xrot, 0, yrot
tformpoint 0,0,Dist, Pivot, 0
positionentity Moon, tformedx(), tformedy(), tformedz()

[EDIT] Oops, mybad, no idea why you don't want to use a pivot ... seems you want to everything the hard way for some reason.

Stevie


Chroma(Posted 2006) [#3]
seems you want to everything the hard way for some reason


I don't consider sin and cos hard...but atm I just can't get the right formula. :(


b32(Posted 2006) [#4]
Maybe try this formula, it is for a sphere:
x#=cos(ang1)*cos(ang2)
z#=cos(ang1)*sin(ang2)
y#=sin(ang1)


Chroma(Posted 2006) [#5]
Thanks bram and Stevie. I finally got it to work with slight modifications to the above formulas.

Another 10 min and I was putting in Stevies code to save my sanity.

btw for gee whiz info...the final solution was:

PositionEntity orbit_piv,0+(Sin(xrot2)*Cos(yrot2))*dist,0+Sin(yrot2)*dist,0+(Cos(-xrot2)*Cos(-yrot2))*dist