Different speed in two spheres using TurnEntity

Blitz3D Forums/Blitz3D Beginners Area/Different speed in two spheres using TurnEntity

I am making a solar system for experiment but I don't know how to do two or more planets go to different speeds, For Example, variable for mars w\CenterYawAdd#[5] = 1 and variable for earth w\CenterYawAdd#[3] = 2 . How Can I do those two body go to this differents speeds using TurnEntity. O perhaps there were a better way?

I apreciate help for to understanding this question easy for experts coders, but difficult to me actually.

My code:

Graphics3D 640,480,16,2
SetBuffer BackBuffer() 

Global xx#


Type system
	Field name$ [12]
    Field x# [12] 
    Field y# [12]
    Field z# [12]
    Field CenterPitchAdd#[12]
    Field CenterYawAdd#[12]
	Field CenterRollAdd#[12]
End Type

;  variables types
w.system = New system
w\name$ [0] = "Sun"
w\x#[0] = 0
    w\y#[0] = 0
    w\z#[0] = 20
    w\CenterPitchAdd#[0] = 0
    w\CenterYawAdd#[0] = 1
    w\CenterRollAdd#[0] = 0

	w\name$ [3] = "Earth"
	w\x#[3] = 0
	w\y#[3] = 0
	w\z#[3] = 5
	w\CenterPitchAdd#[3] = 0
    w\CenterYawAdd#[3] = 2
    w\CenterRollAdd#[3] = 0
	
    w\name$ [4] = "Moon"
    w\x#[4] = 0 
    w\y#[4] = 0
    w\z#[4] = 5
    w\CenterPitchAdd#[4] = 0
    w\CenterYawAdd#[4] = 1
    w\CenterRollAdd#[4] =0
	
	w\name$ [5] = "Mars"
    w\x#[5] = 0 
    w\y#[5] = 0
    w\z#[5] = 8
    w\CenterPitchAdd#[5] = 0
    w\CenterYawAdd#[5] = 1
    w\CenterRollAdd#[5] =0
	
	
; Entitys
	

	sun=CreateSphere(32)
	ScaleEntity sun, 2, 2, 2
	EntityColor sun,255,255,0 
	
	earth=CreateSphere(32,sun)
	ScaleEntity earth, 1, 1, 1
	EntityColor earth,0,255,0 
	
	moon=CreateSphere(32,earth)
	ScaleEntity moon, .5, .5, .5
	EntityColor moon,100,100,100 
	
    mars=CreateSphere(32,sun)
	ScaleEntity mars, .7, .7, .7
	EntityColor mars,255,0,0 
	
	
	camera=CreateCamera() 
	
	
lite = CreateLight() 
light=CreateLight(1)               ;create ligth


; Main program
While Not KeyDown( 1 ) 

; Change position values depending on key pressed
	
If KeyDown( 203 )=True Then 
For j=0 To 12
w\x#[j]=w\x#[j]-0.1
Next
EndIf

If KeyDown( 205 )=True Then 
For j=0 To 12
w\x#[j]=w\x#[j]+0.1
Next
EndIf

If KeyDown( 208)=True Then 
For j=0 To 12
w\y#[j]=w\y#[j]-0.1
Next
EndIf

If KeyDown( 200 )=True Then 
For j=0 To 12
w\y#[j]=w\y#[j]+0.1
Next
EndIf

If KeyDown( 44 )=True Then 
For j=0 To 12
w\z#[j]=w\z#[j]-0.1
Next
EndIf

If KeyDown( 30 )=True Then 
For j=0 To 12
w\z#[j]=w\z#[j]+0.1
Next
EndIf


LightColor lite,255,0,0
; Position using position values 
PositionEntity sun,w\x#[0],w\y#[0],w\z#[0]
PositionEntity earth,w\x#[3],w\y#[3],w\z#[3]
PositionEntity moon,w\x#[4],w\y#[4],w\z#[4]
PositionEntity mars,w\x#[5],w\y#[5],w\z#[5]


PointEntity lite,moon                     ;light


TurnEntity sun, w\CenterPitchAdd#[0], w\CenterYawAdd#[0], w\CenterRollAdd#[0]
TurnEntity earth, w\CenterPitchAdd#[3], w\CenterYawAdd#[3], w\CenterRollAdd#[3]
; how can I to do mars go to different speed than earth ????

x#=x#+0.1
RotateEntity earth,0,x# ,0  


RenderWorld 



Flip 
Wend 



You're thinking to hard! Try this code, no math, no media, almost no thinking involved. It can even actually get simpler but I've already got it typed. Use the ESC key to quit the program.

Graphics3D 800,600
SetBuffer BackBuffer()						
SeedRnd MilliSecs()	

gods_view = CreateCamera()
MoveEntity gods_view ,0,50,0
TurnEntity gods_view ,90,0,0

suns_light = CreateLight(2)				;create a light source, and make it point light so it acts like a sun
LightRange suns_light, 50				;give it a range
LightColor suns_light, 252,255,2		;and make it yellow light :)


Global p_sun = CreatePivot()			;create a sun pivot
sun = CreateSphere()					;create the actual sun
EntityFX sun,1							;this object won't pick up point light, so make it full bright 
EntityColor sun, 255,255,0				;make it yellow
ScaleEntity sun, 2,2,2					;make it big :)

Global p_mercury = CreatePivot(p_sun)	;create a mercury pivot parented to the sun pivot
mercury = CreateSphere(8,p_mercury)		;create a mercury and parent it to the mercury pivot
PositionEntity mercury, 0,0,2.7			;move it away from the sun
EntityColor mercury,255,80,0			;set it's color
ScaleEntity mercury, .25,.25,.25		;scale it to look right

Global p_venus = CreatePivot(p_sun)		;go on and create a pivot for venus, and parent it to the sun pivot as well
venus = CreateSphere(16,p_venus)		;and so on... same as above
PositionEntity venus, 0,0,4
EntityColor venus, 255,279,73
ScaleEntity venus, .4,.4,.4

Global p_earth = CreatePivot(p_sun)		;do this for all planets down the line
Global earth = CreateSphere(16,p_earth)
PositionEntity earth, 0,0,6.5
EntityColor earth,  43,68,255
ScaleEntity earth, .5,.5,.5

Global p_luna = CreatePivot(earth)		;i add a moon pivot to the earth also right here, parent it to the earth
luna = CreateSphere(16, p_luna)			;add a sphere for the actual moon
PositionEntity luna, 0,0,2				;position it
ScaleEntity luna, .2,.2,.2				;scale it


Global p_mars= CreatePivot(p_sun)
mars = CreateSphere(16,p_mars)
PositionEntity mars, 0,0,10
EntityColor mars, 168,48,40
ScaleEntity mars, .45,.45,.45

Global p_saturn= CreatePivot(p_sun)		
saturn = CreateSphere(16,p_saturn)
	rings = CreateSphere(16,saturn)	;parent a new primitive to saturn
	ScaleEntity rings, 1.3,.05,1.3	;expand it out and smash it down
	EntityColor rings, 196,90,75		;give it a color
PositionEntity saturn, 0,0,18
EntityColor saturn, 225,198,57
ScaleEntity saturn, 1.1,1.1,1.1

Global p_jupiter= CreatePivot(p_sun)
jupiter = CreateSphere(16,p_jupiter)
PositionEntity jupiter, 0,0,22
EntityColor jupiter, 215,107,61
ScaleEntity jupiter, 1.5,1.5,1.5

Global p_uranus = CreatePivot(p_sun)
uranus = CreateSphere(16,p_uranus)
PositionEntity uranus, 0,0,26
EntityColor uranus, 107,177,215
ScaleEntity uranus, .8,.8,.8

Global p_neptune = CreatePivot(p_sun)
neptune = CreateSphere(16,p_neptune)
PositionEntity neptune, 0,0,30
EntityColor neptune, 89,102,215
ScaleEntity neptune, .8,.8,.8

Global p_pluto = CreatePivot(p_sun)		;pluto isn't officially a planet anymore, but thats what they taught us in school years ago
pluto = CreateSphere(16,p_pluto)
PositionEntity pluto, 0,0,36
EntityColor pluto, 40,56,73
ScaleEntity pluto, .3,.3,.3




;----
;MAIN (and only) LOOP
;____
While Not KeyDown(1)

planet_rotation()		;this function rotates each one 
	
RenderWorld
;UpdateWorld 
Flip 0

Wend 
;----
;END MAIN LOOP
;____

			;assign each pivot a rotation amount
			

Function planet_rotation()
	TurnEntity p_mercury,   0,.131,0,1		;rotate mercury fast...
	TurnEntity p_venus, 	0,.087,0,1		;venus is just a bit slower...
	TurnEntity p_earth, 	0,.067,0,1		;and so on.... 
	TurnEntity p_mars, 		0,.053,0,1
	TurnEntity p_saturn,	0,.039,0,1
	TurnEntity p_jupiter,	0,.032,0,1
	TurnEntity p_uranus,	0,.021,0,1
	TurnEntity p_neptune,	0,.015,0,1
	TurnEntity p_pluto, 	0,.009,0,1		
		
	TurnEntity earth,      0,.1,0			;turn the earth so the moon revolves
End Function 



Yes Drak, your are rigth. It is hard to me becouse I am new in Blitz3D and new in making types and it is hard to me still. And I was too confused last 3 days for this question.

I see your code is better than mine and more clear, and now I am going to sleep, but tomorrow I will experiment with your example and I am sure that I will be able to understand it and to adapt to for my purpose.

A good example!!! Thanks a lot!!!

P.S. Might want to check an astronomy book for accurate rotations. A Jupiter day is less than 10 hours, while Venus' day is longer than its year!

In my case, it does not matter actualy becouse I only am doing code for experiment with Blitz3D and its 3D commands. This solar system is only a way to be a little more skilled in 3D world.
I am trying with ideas extracted from real world or it would be to difficult to understand concept of 3D.

A true astronomy program is too far to do by me still. I know it.