I made a small change to the vector.bb it is slightly more accurate and realistic change the funtion thus:
Then I did this to see:
MASS seems to be a part of the problem... monkey with that and see...
For some reason velocity adds at some point(possibly because of mass be applied wrongly I am uncertain!)... which is why I squelched magnitude a bit...
RZ
Function Vector_Magnitude#(v.Vector) Return Sqr((v\x * v\x) + (v\y * v\y) + (v\z * v\z)) / 2 End Functionand run it now!!!
Then I did this to see:
;// Gravity and Bounce Example Graphics3D 800,600 SetBuffer BackBuffer() Include "vector.bb" ;// Camera and Lights camera = CreateCamera() PositionEntity camera,0,1,-20 light=CreateLight() RotateEntity light,90,0,0 ;// Set Gravity meters per sec g% = -9 ; changed it to flat number ;// Ball Parameters ball = CreateSphere() ScaleEntity ball,0.5,0.5,0.5 mass% = 10 ; for a bit of fun plane=CreatePlane() grass_tex=LoadTexture( "tmp11.jpg" ) EntityTexture plane,grass_tex EntityAlpha plane,0.5 PositionEntity plane,0,0,-.5 ; make plane a mirror mirror=CreateMirror() ;// Set Initial Forces and Vectors vFor.vector = vector() ;force vector vAcc.vector = vector() ;acceleration vector vVel.vector = vector() ;velocity vector vPos.vector = vector(0,15,0) ;position vector NewTime = MilliSecs() OldTime = NewTime ;// Main Loop While Not KeyHit(1) Cls NewTime = MilliSecs() delta# = Float (NewTime - OldTime) / 1000 OldTime = NewTime FPS = 1 / delta ;// Reset Forces to Zero Each Cycle Vector_Reset vFor ;// Calculate Gravity grav% = g * mass ; so you can show it vFor\y = g * mass ;// Collision If vPos\y < 0 Then Collided = True If Collided = True speed% = Vector_Magnitude(vVel) collided = False vFor\y = -vFor\y * speed% / 2 * mass% vVel\y = 0 EndIf ;// Up Arrow Key applies 100 force upwards If KeyDown(200) Then vFor\y = 100 If KeyHit(57) = True Then vPos.vector = vector(0,15,0) ;Vector_PositionEntity ball,vPos EndIf ;// Calc New Acc, Vel, and Pos Vector_DivideScalar vAcc,vFor,mass Vector_AddTimeStep vVel,vAcc,delta Vector_AddTimeStep vPos,vVel,delta ;// Position the Ball Vector_PositionEntity ball,vPos UpdateWorld RenderWorld ;// Show What's Happening Text 5,5,"FPS=" + FPS Text 5,30,"Speed=" + Int(Vector_Magnitude(vVel)) Text 5,60,"Grav: "+grav Vector_Show(vFor,5,100,"Force: ") Vector_Show(vAcc,5,175,"Acc: ") Vector_Show(vVel,5,250,"Vel: ") Vector_Show(vPos,5,325,"Pos: ") Flip Wend End
MASS seems to be a part of the problem... monkey with that and see...
For some reason velocity adds at some point(possibly because of mass be applied wrongly I am uncertain!)... which is why I squelched magnitude a bit...
RZ