Advertisement

From A ( X1,Y1) to B(X2,Y2) dose this work and what dose not work?

Started by September 15, 2007 01:24 PM
1 comment, last by dmatter 17 years, 2 months ago
hi ppl. i´m trying to just do a simple 2d moveTo command. so this is the Math i use so far. X = X1 - X2; Y = Y1 - Y2; X_Pos += X; Y_Pos += Y; and i can get 2 results. 1: the pixel just jumps to the EXAKT kordinats of my B point. just from A to B. and well thats what i want but i actualy want it to move not just jump. 2: it moves in the wrong direction and it actualy Moves but its going fast as hell. and im using C++ // if my description is bad tell me.
hi

If you can read Arabic


Take these lessons

http://www.arabteam2000-forum.com/index.php?showtopic=130727

and

http://www.arabteam2000-forum.com/index.php?showtopic=131334


Or can Translated by (google Translate)


Tell me if you don't understanding that lessons.
Advertisement
Firstly, just to point out that a post on a topic such as this doesn't really belong in the AI forum, preferably you'd post it in For Beginners or else in Math and Physics forum.

Anyway,

One way to achieve what you want is as follows:

xPos = x1;yPos = y1;for (int i = 0; i <= numSteps; i++) {       clearScreen();    drawPixel( xPos, yPos );    xPos += (x2 - x1) / numSteps;    yPos += (y2 - y1) / numSteps;}

And there's also this method:

for (int i = 0; i <= numSteps; i++) {    step = i / numSteps;    xPos = x1 + (x2 - x1) * step;    yPos = y1 + (y2 - y1) * step;    clearScreen();    drawPixel( xPos, yPos );}

This topic is closed to new replies.

Advertisement