# Mouse directional movement

So this is what I’m working on…

## I’m using a 2D system to pull in the screen coordinates and I translate them into openGL coordinates. I create a line at the center with the center being (0,0) and then the end point being the open GL screen coordinate. It looks fine. Then i wanted to translate the line around on the screen with the keyboard. Ok So I apply a Translation matrix on it. That works fine, it translates around with every key press and still rotates about the right origin.

PushMatrix

Translate(transVec[0],transVec[1], 0)
DrawLine

## PopMatrix

Some Variables:

mTransVec[2] = translation vector. x = [0] & y = [1].
mLineEnd[2] = Lines endpoints, openGL coords, in an array. x = [0] & y = [1].
Angle = the rotational angle that the line is at from the origin in degree’s or rads

The Problem:
I’m trying to figure out the math or some way with translation and rotation matrices that when I hit a key to go “forward” that the line will go in the direction/angle the line is pointing.

I’m so lost as to how to do this… been trying a lot so far with rotation, using the angle of rotation and then some how tranlate it along that angle by rotating it… ahhh not working It likes to keep going in circles. =\

Any help or direction of the math behind having the object follow where the cursor is would help so dearly. Thanks.

I wouldn’t store the angle of the line. I would take the end coordinate of the line (the point not at the origin) and store that as the direction vector of the line. You could normalize this if you really want to. When you want to move the line along itself, you add some multiple of that vector to both endpoints, then redraw.

I don’t understand the last part of the problem: what exactly does moving the line have to do with cursor movement?

Thank you very much… it clicked like a seat belt once you said direction vector… GAH! I really was just at a lost on what to look up for that, nothing was clicking =\

so yeah the last part, the line follows the cursor when a key is pressed. Then when i release the key the line stays stationary but is able to rotate about in a 360 degree from where it is stopped. But i got that once i added the darn directional vector.

Next is correctly moving the camera. Thanks!