PDA

View Full Version : How do I?



ironduke
05-12-2001, 06:45 PM
I wish to create a cad like interface using glortho or gluortho2d, the problem is how do I make y coordinates like windows coordinates?

(this means increase downwards instead of upwards)

thanx

MCote79
05-12-2001, 08:29 PM
You could rotate your coordinate system so that the positive y axis is downward. I don't think this puts the origin at the top left of the screen though. I might be wrong.

zed
05-13-2001, 12:47 AM
http://www.3dgamedev.com/resources/openglfaq.txt
----------------------------------------------------------------------
Subject 4.03: How do I set up OpenGL matrix stack for rasterization-only?

Something like:
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glViewport(0, 0, width, height); /* viewport size in pixels */

will mean that the 3D point (0,0,0) is in the center of the viewport,
and that
(1,1,0) is the top-right corner of the viewport.

To get a 1:1 pixel mapping, with (0,0,0) in the top-left of the
viewport and (width,height,0) in the bottom-right, do this:
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glScalef(2.0f / (float)width, -2.0f / (float)height, 1.0f);
glTranslatef(-((float)width / 2.0f), -((float)height / 2.0f), 0.0f);
glViewport(0, 0, width, height); /* viewport size in pixels */

T2k
05-13-2001, 02:45 AM
its easier use glOrtho and set bottom to maxy and top to 0 so you have at the top 0 and at the bottom of the viewport maxy ...

dans
05-13-2001, 03:11 AM
when you get your mouse position say now it is returning mousey = 10

now just do this
mousey = screen_size_y - mousey;

ironduke
05-13-2001, 09:40 AM
Originally posted by T2k:
its easier use glOrtho and set bottom to maxy and top to 0 so you have at the top 0 and at the bottom of the viewport maxy ...

Thanx that worked lustfully.