🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Rotate a quad on non square screen 2D

Started by
2 comments, last by _WeirdCat_ 3 years, 3 months ago

I need to rotate a quad on the screen, however i can't get good perpendicular vector, as well as the size of an arrow.

Issue with this is that screen height is 2x the screen width and i am not entirely sure how to transform that to new quad vertices that are in screen space (0..1)

Basically i am trying to draw it in screen space coords from 0..1 to maintain arrow size.

Now what you see below is an attempt to draw arrows that are perpendicular to the first white line in index

Since it's 2D i want to stick to line direction and perpendicular vector to that direction

so vertices would look like, none of this work (don't mind arrow dimensions i believe that properly calculated directions will deal with that) basically i am trying to find perpendicular vector, i may calculate wrongly the direction too.

float aspect = screen_height / screen_width;
vec3 line_dir = (line_v[1] - line_v[0]);
line_dir.y = line_dir.y * aspect;
line_dir = normalize( line_dir );
top left relative to line direction.
v[0] = line_center + line_dir * (arrow_height / 2.0);
top right
v[1] = line_center + line_dir * (arrow_height / 2.0) + perpendicular_dir * arrow_width;
bottom right
v[2] = line_center - line_dir * (arrow_height / 2.0) + perpendicular_dir * arrow_width;
bottom left
v[3] = line_center - line_dir * (arrow_height / 2.0);
Advertisement

I guess you also have multiply perpendicular_dir.y with ratio, maybe like so:

vec3 line_dir = (line_v[1] - line_v[0]);

vec3 perp_dir = vec3(line_dir.y, -line_dir.x, 0);
line_dir.y = line_dir.y * aspect;
perp_dir.y = perp_dir.y * aspect;
line_dir = normalize( line_dir );

_WeirdCat_ said:
Basically i am trying to draw it in screen space coords from 0..1 to maintain arrow size.

Probably it's a easier to change this so ratio is handled by projection, and you no longer need to do it manually everywhere. Dealing wih non square resolution is easier than dealing with ratio (nonuniform scale).

Nah can't make it work ?

This topic is closed to new replies.

Advertisement