# Calculation for flipping y coordinates

This topic is 4980 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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?

##### Share on other sites
gluProject is useful for this sort of thing.

##### Share on other sites
I was actually looking for something much less complicated. Something like this:
inline int FlipY(int totalH, int y)
{
//return formula to flip y
}

y = height - y0?

##### Share on other sites
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.

##### Share on other sites
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.

##### Share on other sites
Quote:
 Original post by aewarnickI 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)

##### Share on other sites
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.

##### Share on other sites
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
}

##### Share on other sites
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?

1. 1
Rutin
42
2. 2
3. 3
4. 4
5. 5

• 9
• 26
• 20
• 14
• 14
• ### Forum Statistics

• Total Topics
633384
• Total Posts
3011595
• ### Who's Online (See full list)

There are no registered users currently online

×