Archived

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

Neen10do

Vectors - where am i going?

Recommended Posts

im having trouble structuring my movement in OOP for my game engine. and i have questions about methods: 1) should i put my movement class in the object class, then allow its parent cGame class call the appropriate functions? 2) addition question: im using directdraw, but a lot of people talk about vectors when on the topic of movement. what are vectors and should i use them for 2d directdraw stuff (there is no rotation, radians etc in my game). the way ive done movement in the past was: sprite.x += sprite.speed; is this wrong? ---------------------- i code therefore i am. Aero DX - Coming to a bored Monitor near you!

Share this post


Link to post
Share on other sites
this will be quite wrong, if youre not moving along the x or y axis. imagine a car thats going 5m/s. its moving to the left, you add 5m after one second and everything is fine. no its turning 45deg and moving left and up. adding 5m to x and y will make it move 7m.

but: did they never tell you about vectors in school? the position of your object (x,y) would be a vector, the direction its moving is a vector (if left the vector would be (1,0))..

you can imagine it as an arrow.. a unit vector has length 1, a point in space can be seen as vector from the origin to the object (though vectors dont have a position and usually are at the origin)

just get a book about linear algebra, that should contain vectors as well as all the things you can do to them (dot product, vector product, etc.)

its not hard to get but think of it like this: it sounds much better to say "im mirroring the direction vector on the y axis" instead of "im doing x=-x" ,-)

Share this post


Link to post
Share on other sites
Think about this, when your car is moving, you have 2 vectors.


1. Direction
2. Position

you also have a value SPEED.

Now, this is the correct way of calculating your POSITION vector

Position.x+=Speed*Direction.x;
Position.y+=Speed*Direction.y;
Position.z+=Speed*Direction.z;


I hope this helped!

Share this post


Link to post
Share on other sites
i understand the part when you go:
Position.x+=Speed

but what is meant by the part when you multply it by Direction.x, is that -1 or positive 1, or what?



----------------------
i code therefore i am.

Aero DX - Coming to a bored Monitor near you!

Share this post


Link to post
Share on other sites
Is everybody ignoring the bit about "no rotation" in the original post?

The short answer is that if you''re not performing arbitrary rotations, and are working in 2D, you probably don''t need to use vectors.

[ MSVC Fixes | STL Docs | SDL | Game AI | Sockets | C++ Faq Lite | Boost
Asking Questions | Organising code files | My stuff | Tiny XML | STLPort]

Share this post


Link to post
Share on other sites