Aiming Balls
Blitz3D Forums/Blitz3D Programming/Aiming Balls
| ||
| In my little code snippet below, the ball has starting coords and vectors for each axis, shouldn't there be some combination of functions which can simulate the ball rolling in the direction of its' vectors? Please help if you can... ;********************************** Function BallPhysics (Ball.Ball_Object) If ball\y =< Ball\yMin# Then Ball\y = Ball\yMin# Ball\dy = -Ball\dy Ball\dy = Ball\dy * Ball\elasticity End If If Ball\x =< Ball\xMin# Then Ball\x = Ball\xMin# Ball\dx = -Ball\dx Ball\dx = Ball\dx * Ball\elasticity End If If Ball\x >= Ball\xMax# Then Ball\x = Ball\xMax# Ball\dx = -Ball\dx Ball\dx = Ball\dx * Ball\elasticity End If If Ball\z =< Ball\zMin# Then Ball\z = Ball\zMin# Ball\dz = -Ball\dz Ball\dz = Ball\dz * Ball\elasticity End If If Ball\z >= Ball\zMax# Then Ball\z = Ball\zMax# Ball\dz = -Ball\dz Ball\dz = Ball\dz * Ball\elasticity End If If Ball\y >= Ball\yMin# Then Ball\dy = Ball\dy + GRAVITY End If Ball\x = Ball\x + Ball\dx Ball\z = Ball\z + Ball\dz Ball\y = Ball\y + Ball\dy Ball\dx = Ball\dx - (Ball\dx*Ball\friction) Ball\dz = Ball\dz - (Ball\dz*Ball\friction) ;Move ball to new coords PositionEntity Ball\Entity, Ball\x, Ball\y, Ball\z ;pitch#=VectorPitch(Ball\dx, Ball\dy, Ball\dz) ;yaw#=VectorYaw(Ball\dx, Ball\dy, Ball\dz) ;roll#=0 ;Rotate mesh to give appearance of rolling ;RotateEntity Ball\Entity, pitch#, Yaw#, 0, 1 End Func |
| ||
| This is one way to do it but it only works on a flat board. You need a texture (texture.jpg) to see the ball rotate. What I do below is make a pivot (visualized in the example) and move it accordingly to the degrees of the balls orientation, then I just point the ball at the pivot and turn the ball. It's kinda cheating but it works well :)
Graphics3D 640,480,16,2
Global camera = CreateCamera()
Global camzoom#=10.0
CameraZoom camera,camzoom#
CameraRange camera,1,(400 * camzoom#)+4000
PositionEntity camera,0,0,-500
sphere=CreateSphere(15)
texture=LoadTexture("texture.jpg")
EntityTexture sphere,texture
PositionEntity sphere,0,0,500
RotateEntity sphere,0,0,0
ScaleEntity sphere,15,15,15
pivot=CopyEntity(sphere)
ScaleEntity pivot,5,5,5
WireFrame 0:HidePointer
SetBuffer BackBuffer()
While Not KeyDown(1)
pivx=(MouseX()-320)/3:pivy=(240-MouseY())/3
PositionEntity pivot,pivx,pivy,500
PointEntity sphere,pivot,0
If pivx < 0 Then TurnEntity sphere,180,180,0
If pivx=0 And pivy>0 Then TurnEntity sphere,0,0,90
If pivx=0 And pivy<0 Then TurnEntity sphere,0,0,270
TurnEntity sphere,0,0,z
z=z+5:z=z Mod 360
RenderWorld
Color 255,255,255
Text 10,10,"Rotate z= "+z
Text 10,30,"Pivot x= "+pivx
Text 10,50,"Pivot y= "+pivy
Flip
Wend
End
|
| ||
| Thanks Wedoe! I didn't usee your sample but your idea moved me in the right direction! |