Translating a 2d circle to a 3D enviroment
Blitz3D Forums/Blitz3D Beginners Area/Translating a 2d circle to a 3D enviroment
| ||
Hi, I need to be able to caclucate a semi-circular path around an object so I can sling-shot an object around another. I understand the use of cin/cos in a 2d world to create to create a circular or eliptical path. But how would I translate into a 3D world? I need to be able to do it so that whatever angle & direction you approach the item from you always slingshot around it and come out in the direction you came from (i.e approach from the top, slingshot and come out the bottom heading back in the same direction). I am guessing you would work out the angle of approach (which I think I can do) and then caluate a slingshot path with cos/sin and then somehow rotate that path to suit. Any ideas or thoughts on how best to do this? I have tried to use pivots before but that didn't seem to work as I couldn't unparent my object, reparent it to the object to be slingshot'ed around and then reparent to the original pivot (which was also supposed to be slung around at the same time). Many thanks. MAx |
| ||
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 |
| ||
I am guessing you would work out the angle of approach (which I think I can do) and then caluate a slingshot path with cos/sin and then somehow rotate that path to suit. Funny, your guessing is what I suggested in your other thread!?! lol |
| ||
But you did it on a 2D level. I wondered if this was the best approach for a 3F enviroment. You misunderstood what I was saying. |
| ||
You can easily translate the motions into 3d space :o) |