Hi,
I’m a “traditional programmer” who just has started to do some game programming in Java, but I need som advice, I know there is an algorithm for representing a continuous movement of an object, does anybody know about this algorithm? The only thing I really want to do is some cars running forward at a constant speed, I’ve heard about an algorithm for this, I don’t mean just adding pixels but an algorithm where you use cos(angle) and sin(angle).
I would be grateful for any help I can get.
best regards
Alvaro
[quote] I don’t mean just adding pixels but an algorithm where you use cos(angle) and sin(angle).
I would be grateful for any help I can get.
best regards
Alvaro
[/quote]
Uh, if all you’re doing is moving is a straight line then theres no need to use any sort of trig (where would the ‘angle’ come from anyway?). All you need for a straight line is to add to the current position the time moved over the last frame multiplied by the objects velocity. Then you can simply change the velocity over time to make the object head in different directions.
[quote]Hi,
I’m a “traditional programmer” who just has started to do some game programming in Java, but I need som advice, I know there is an algorithm for representing a continuous movement of an object, does anybody know about this algorithm? The only thing I really want to do is some cars running forward at a constant speed, I’ve heard about an algorithm for this
[/quote]
Um Yeah d1 = d2 = d3.
Given what you derscribe what youa re lookign fro is Newton’s first law: A body in rectilinear motion remains in rectilinear motion until acted on by an unbalanced force.
Or in other words, once you start moving in a straight lien you KEEP moving in that straight line at the ame speed forever unless another force acts on you.
Now if you are talking about wanting to calculate the real forces in nature, such as friction, thats singificantly more complex to simulate accurately. Most games simply put an arbitrary ‘drag’ on the car and leave it at that.
BUT all this is somewhat tangential to games because all games are programmed as discrete time simulations, which is to say the motion is calculated a frame a time in frame-time increments.
So if you are moving dX in the X direction per frame and dY in the Y direction perframe then x = x+dX and y =y+dY per frame. Acceleration is aded as an impulse to dX and dY, drag subtracted.
Hi,
attr: Jeff
regarding Newton,s first law
thank you for your help, I actually knew about this law, but I was interested in the other one, Vectors theory, despite that could you provide me with some code examples?
do you know about some good web sites about game physics but with code examples.
PS:
During the weekend i found out that vector can be used, with an angle of ca. 33 degrees, nice isn’t it. A book called java micro games talks about it.
Maybe we have a communication failure, but i have NO idea what you are on about.
even if I ain’t good in programming I am kinda good at physics so I can try to help you a little bit:
let’s take the case of a straight movement (as you want to do)…all you need to do is start with the acceleration:
Ax = 0
Ay = 0
this means that there is NO acceleration on the x and y axis
let’s move on to the velocity:
Vx = integral(Ax) + V0x (i hope integral is the correct english word)
Vy = integral(Ay) + V0y
As we know, the integral of 0 is a constant so the velocity on the x and y axis is a constant.
From here we can calculate the position from our object with the simple integral of the velocity:
OPx = integral(Vx) + cste
OPy = integral(Vy) + cste
as the integral of a constante is a function: f(x) = x*t, we find that:
OPx = Vx * t + cste
OPy = Vy * t + cste
where the cste is our initial position at t = 0 (t = time).
So a continous movement could be represented by a function where you increment the time and multiply it with the constante velocity of the object. This will immediatly give you the position.
Hope I helped you a bit.