Translating a 2d circle to a 3D enviroment

Blitz3D Forums/Blitz3D Beginners Area/Translating a 2d circle to a 3D enviroment

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

Personally I would do this using proper gravitation physics as it would look nicer / more realistic. Using your previous program as a basis, I knocked this up quickly to give you a start ...

Press SPACE to reset.

Stevie

Graphics3D 640,480,32,1

Global camera = CreateCamera()
PositionEntity camera, 0,50,0
RotateEntity camera, 90,0,0

Global Sphere = CreateSphere()
EntityColor Sphere,255,0,0
Tmp = CreateSphere( 8 , Sphere )
ScaleEntity Tmp, 5, 5, 5
EntityAlpha Tmp, .25

Global CubePiv = CreatePivot()
Global Cube = CreateCube( CubePiv )
EntityColor Cube, 0,0,255

Global RotationSpeed# = 2.0
Global RotationTimer
Global RotationDirection

RESET()

While Not KeyDown(1)

	If KeyHit(57) RESET()
	
	UPDATE()
	
	RenderWorld()
	Flip
	
Wend

;==================================================================
;==================================================================
;==================================================================

Function UPDATE()

	If GetParent( CubePiv ) = Sphere
		If RotationTimer <= ( 180 / RotationSpeed )
			TurnEntity Sphere, 0 , RotationDirection * RotationSpeed , 0
			RotationTimer = RotationTimer + 1
		Else
			EntityParent( CubePiv, 0 )
			RotationTimer = -1
		EndIf
	Else
		If EntityDistance( CubePiv, Sphere ) < 5 And RotationTimer = 0
			TFormPoint 0,0,0,CubePiv, Sphere
			If TFormedX() < 0 
				RotationDirection = 1
			Else
				RotationDirection = - 1
			EndIf
			EntityParent CubePiv, Sphere
		Else
			MoveEntity CubePiv, 0,0,.25
		EndIf
	EndIf
	
	TurnEntity Cube, 0,5,0
	
End Function	

;==================================================================
;==================================================================
;==================================================================

Function RESET()

	EntityParent CubePiv, 0
	RotationTimer = 0
	RotateEntity Sphere, 0 , Rand(-180,180 ) , 0
	RotateEntity CubePiv, 0 , EntityYaw( Sphere ) - 180 , 0
	TFormPoint 4 * ( Rand(0,1) * 2 - 1 ) ,0,Rand(30,50 ), Sphere, 0
	PositionEntity CubePiv, TFormedX(), TFormedY(), TFormedZ()

End Function