Re: vb6 Gravity Simulation
Well?, And all i would want to use is a shape square for ground, and a shape circle for ball....
Re: vb6 Gravity Simulation
Have you any idea what it is that you want to do? Do you want to plot something? Do you want to calculate something? If you know the equation, you can calculate the force on the object. You know that F=ma (you do know that, right?). And you know that v = u+at, so given the starting velocity, you can work out the force and hence the acceleration and hence in a given time interval you can work out the new velocity. You can also use s= ut + 0.5at^2 to get from a given initial velocity and calculated acceleration to a distance moved in a given time step.
Try it, and see how far you get.
zaza
Re: vb6 Gravity Simulation
When it comes to physics in programming, especially in games, Timers are REALLY not the way to go. You are gonna literally need to use real time to pull off accurate physics.
Yes, F = MA, but to break it down into 2D vectors, it's actually this:
F_Net.x = m * a.x
F_Net.y = m * a.y
Where F_Net is the net force, meaning the total amount of forces applied to the object, m is mass, and a is acceleration. But it's gonna need to be twisted around since acceleration is the variable needed:
a.x = F_Net.x / m
a.y = F_Net.y / m
Since this is a gravity simulation, F_Net.y should equal -9.8, or more precisely -9.80665, and the coordinate system in your form should be Cartesian:
If you are confused, I'm simply saying up is in the positive y direction, and right is the positive x direction.
Next, you are gonna need an integration method. There are many out there, such as Forward Euler, Backwards Euler, 2nd order Euler, Velocity-less Verlet, Velocity Verlet, Leapfrog, 2nd order Runge Kutta, 3rd order Runge Kutta, 4th order Runge Kutta, etc. Forward Euler is the easiest, but only 100% accurate linearly. 4th order Runge Kutta is the most accurate linearly as well as angularly. But since you are a beginner at physics, well stick with Forward Euler:
p.x = p.x + v.x * dt
v.x = v.x + a.x * dt
p.y = p.y + v.y * dt
v.y = v.y + a.y * dt
Where dt is the time step size. Be sure to use small step sizes, like somewhere between .01 or .001. I'll provide source code later on. ;0
1 Attachment(s)
Re: vb6 Gravity Simulation
Here's the source code to a nice gravity simulation using Forward Euler integration, with a scalefactor.
Re: vb6 Gravity Simulation
Thats a nice app, could you apply it to "bounce" off of an object?
Re: vb6 Gravity Simulation
You want elasticity you mean? Yeah I can do that for ya. Give me some time to put that in. I was also gonna improve the gravity simulation.
In the mean time, try these other integration methods. 4th order Runge Kutta is the most accurate. ;)
http://www.vbforums.com/showpost.php...8&postcount=56
Re: vb6 Gravity Simulation
Re: vb6 Gravity Simulation
It's turning into a real physics engine apparently! I'm still having issues with elasticity because for some reason, it gets screwed up after a few seconds. Gimme until tommorow and it should be all good.
1 Attachment(s)
Re: vb6 Gravity Simulation
Here it is. Try playing around with the elasticity values. 0.7 looks pretty realistic.
Re: vb6 Gravity Simulation
!AWESOME, great stuff... That is way kool.
Re: vb6 Gravity Simulation
I'll improve it in the meantime and fix that little issue. I still need to add Air Resistance because otherwise it will continue to accelerate. Here's what I mean. If you dropped an elephant and a ball off a tower, without air resistance, they both will hit the ground at the same time.
Re: vb6 Gravity Simulation
I fixed the problem. The timestep wasn't small enough. Make the timestep 1/1000, and make the scalefactor 5000
1 Attachment(s)
Re: vb6 Gravity Simulation
Re: vb6 Gravity Simulation
Its missing force.bas JR :P
Re: vb6 Gravity Simulation
No it's not. It's right there in the zip file. Look again.
Re: vb6 Gravity Simulation
well i havent gone thru the rest of the topic n detail, but i think one soln could be to use a timer and change the coordinates of an object so its "attracted" to another object. to achieve the effect of acceleration you can decrease the timer's interval by some amount, directly proportional to accelaration. it will cause the moving object to mve faster as time passes (and it gets closer to the other object)
Re: vb6 Gravity Simulation
Timers should never be used, especially in a physics engine. ;)
Re: vb6 Gravity Simulation
Re: vb6 Gravity Simulation
Because timers are inaccurate, inconsistant, are NOT real time, get worse the more timers you use and run simutaniously, are very limited, etc. They are just awful, and are never used in commercial games. Found these facts out the hard way throughout my 9 years of VB experience. Managed loops locked at a certain framerate are the way to go. And if you are using DirectX, it handles the framerate for you based on your monitors refresh rate. The only thing good about timers are the fact that it doesn't use much CPU. If you are after making a realtime game engine and physics engine, stay away from timers. ;)