#### Archived

This topic is now archived and is closed to further replies.

# How to move objects in a line

This topic is 5811 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi, I am trying to display an object on the screen, and move it from one point to another. My approach is to use a line drawing algorithm, and instead of drawing a pixel at each point, just draw the object. (Is there any other way?). I have spent hours looking around at various algorithms, such as the Digital Differential Analyzer and Bresenham''s method. All of them have one major problem, they are written for a viewing system where 1 unit equals 1 pixel. In OpenGL, the coordintate system uses floating point values, where the window reaches from -1.0 - 1.0. I could not figure out how to modify the algorithms to work with OpenGL because they rely on a decision variable that decides what part of the line to draw. That variable relies on the integer properties of pixels. I also couldn''t find it on the web either. I am using a standard line drawing method now to move the object, y = mx + b. Nice and simple, but the object moves quicker on lines that are near straight. I desperately need to know how to extend the Brisenham or DDA method to OpenGL so I can get the object to move smoothly for any type of line. Please help, thanks Pontius Pilate

##### Share on other sites
If you just want to move an object from point A to point B over an interval of n seconds, then the position P at time t is given by:

P = A + (B-A) * ((t - t0) / n)

Where t0 is the time when the object started moving.

##### Share on other sites
Why in the world didn''t I think of that? So simple. Guess I just got too bogged down in the fancy line algorithms to realize the obvious. How silly. Thanks a million

Pontius Pilate

##### Share on other sites
Or, even more obvious/simple:

x_pos=-1.0f;

/* include this line in a function called by a timer, so you will have a constant frame rate. */
for(x=start_frame;x

1. 1
Rutin
26
2. 2
3. 3
4. 4
5. 5

• 9
• 11
• 10
• 13
• 20
• ### Forum Statistics

• Total Topics
632948
• Total Posts
3009386
• ### Who's Online (See full list)

There are no registered users currently online

×