Calculation for flipping y coordinates

Started by
8 comments, last by aewarnick 19 years ago
I'm trying to use glScissor and am having trouble calculating the upside down y coordinate. Does anyone know of a formula to calculate what the flipped coordinate would be for a right side up y coordinate?
*C++*->
Advertisement
gluProject is useful for this sort of thing.
I was actually looking for something much less complicated. Something like this:
inline int FlipY(int totalH, int y)
{
//return formula to flip y
}
*C++*->
y = height - y0?
how is gluProject complicated? get the projection matrices and the viewport, and feed them in. Any function you use will need to take those into account anyway.
I will use it later but right now I'm just in ortho mode and the viewport is the whole window. I think a simple formula will be much faster than gluProject.
*C++*->
Quote:Original post by aewarnick
I think a simple formula will be much faster than gluProject.

Faster? Are you really calling glScissor millions of times per frame? (if so.... don't! [smile)
I need to call it for each control (just drawings on main window) in my window per frame otherwise they will draw out of bounds sometimes. I'd probably call it at most 300 times per frame which is the worst case scenerio.
*C++*->
Actually this is a better function definition:
inline int FlipDown(int viewPortH, int rightSizeUpY)
{
//return formula to flip Y from right side up to up side down
}
*C++*->
Kalidor, I think that is right but I had forgot one thing, I'm still drawing up side down so I added one more variable.
inline int FlipDown(int viewPortH, int rightSideUpY, int objHeight)
{
//gluProject
return viewPortH-rightSideUpY-objHeight;
}

I think the code is right but my scissor box isn't working correctly. Is there a problem when calling glScissor box serveral times before glFlush or glFinish is called?
*C++*->

This topic is closed to new replies.

Advertisement