(2D) Mouse click on something glOrtho transformed

Started by
-1 comments, last by mojobojo 8 years, 9 months ago

So I have some c code that can take what I am drawing to the screen and zoom in and out to it. It works fine however I am stumped as to how I will transform the mouse position along with it so I can detect mouse clicks through just a simple point in rectangle check. I am thinking I may need to write my own perspective matrix projection (which I don't know how to do). If using my own matrix math is the way to go perhaps someone could link me to some information that could aid me on writing my own matrix code (preferably without using a library). I haven't quite gotten my head wrapped around the concept of matrices yet.

Uncommenting the sinf make it so the camera zooms in and out in the middle of the screen. Say my mouse is at x=100.0 y=100.0 and OrthoScale is at 0.5 my mouse point scales with the entire area which means I click in the wrong spot.


    r32 OrthoScale = 1.0f; // + sinf(GameState->ElapsedTime);
    r32 ResolutionWidth = 1280.0f;
    r32 ResolutionHeight = 720.0f;
    r32 Left = -ResolutionWidth * 0.5f;
    r32 Right = ResolutionWidth * 0.5f;
    r32 Bottom = ResolutionHeight * 0.5f;
    r32 Top = -ResolutionHeight * 0.5f;

    glOrtho(Left * OrthoScale, Right * OrthoScale, Bottom * OrthoScale, Top * OrthoScale, 0.0, 1.0);
    glTranslatef(-ResolutionWidth * 0.5f, -ResolutionHeight * 0.5f, 0.0f);
    
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();

This topic is closed to new replies.

Advertisement