Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (523)
Games in Android Showcase (127)
games submitted by our members
Games in WIP (591)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Continuous movement, beginner  (Read 2730 times)
0 Members and 1 Guest are viewing this topic.
Offline alvaro

Junior Newbie




Java games rock!


« Posted 2003-11-07 14:41:05 »

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
Offline Orangy Tang

JGO Kernel


Medals: 56
Projects: 11


Monkey for a head


« Reply #1 - Posted 2003-11-07 15:33:30 »

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

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.

[ TriangularPixels.com - Play Growth Spurt, Rescue Squad and Snowman Village ] [ Rebirth - game resource library ]
Offline Jeff

JGO Coder




Got any cats?


« Reply #2 - Posted 2003-11-07 18:52:37 »

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


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.





Got a question about Java and game programming?  Just new to the Java Game Development Community?  Try my FAQ.  Its likely you'll learn something!

http://wiki.java.net/bin/view/Games/JeffFAQ
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline alvaro

Junior Newbie




Java games rock!


« Reply #3 - Posted 2003-11-10 06:16:13 »

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.
Offline Jeff

JGO Coder




Got any cats?


« Reply #4 - Posted 2003-11-10 17:27:09 »

Maybe we have a communication failure, but i have NO idea what you are on about.

Got a question about Java and game programming?  Just new to the Java Game Development Community?  Try my FAQ.  Its likely you'll learn something!

http://wiki.java.net/bin/view/Games/JeffFAQ
Offline KONI

Junior Devvie




Java games rock!


« Reply #5 - Posted 2003-11-30 12:54:51 »

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.
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Gibbo3771 (10 views)
2014-11-24 19:59:16

trollwarrior1 (35 views)
2014-11-22 12:13:56

xFryIx (73 views)
2014-11-13 12:34:49

digdugdiggy (52 views)
2014-11-12 21:11:50

digdugdiggy (46 views)
2014-11-12 21:10:15

digdugdiggy (40 views)
2014-11-12 21:09:33

kovacsa (66 views)
2014-11-07 19:57:14

TehJavaDev (70 views)
2014-11-03 22:04:50

BurntPizza (68 views)
2014-11-03 18:54:52

moogie (83 views)
2014-11-03 06:22:04
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!