Paul C
Paul C

Reputation: 27

OpenGL Drawing 2 vectors with a given angle between them

I'm trying to draw in OpenGL 2 vectors with a given angle (in radians) between them, something like this:

enter image description here

I managed to draw the vectors but I'm not sure how to place them at the specific angle:

glBegin(GL_LINES);  // Vx
glColor4f(1, .5, 0, 1);
glVertex3f(0, 0, 0);
glVertex3f(0, vectorYRScalingValue, 0);  // vectorYRScalingValue is 5.0
glEnd();
glBegin(GL_LINES);  // Vy
glColor4f(1, .5, 0, 1);
glVertex3f(0, 0, 0);
glVertex3f(0, vectorYRScalingValue, 0);
glEnd();

Upvotes: 0

Views: 227

Answers (1)

Summit
Summit

Reputation: 2268

If β is the angle to be rotated in radians.

We rotate this vector anticlockwise around the origin.

float c = cos(β);
float s = sin(β);

NewX = x * c - y * s; 
NewY = x * s + y * c;

Upvotes: 0

Related Questions