Problem with a glOrtho change and mouse detection.

Started by EB5473, February 08, 2013, 02:13:46

Previous topic - Next topic

EB5473

Hello all!
I realized my ugly little glOrtho change in order to make it easier for me to understand the the plotting system (top and bottom reversed) was going to be incompatible with systems i couldn't change (like bitmap text rendering within the slick library). I started undertaking the monumental task of changing every single glVertex and glTextCoord command to the new form-until within my button class, i had the weirdest problem with mouse detection. No amount of edits would get it to work right-either malfunctioning and detecting out of place, or not detecting at all. I don't know what im missing, which was why i was hoping you could help.

Code:
MouseDetect:
if ((Mouse.getX() <= this.x + this.sx) && (Mouse.getX() >= this.x) && (Mouse.getY() <= this.y + this.sy) && (Mouse.getY() >= this.y


MouseRender:
GL11.glBegin(GL11.GL_QUADS);
      GL11.glColor3f(this.r, this.g, this.b);
      GL11.glVertex2f(x,y);
      GL11.glVertex2f(x+sx, y);
      GL11.glVertex2f(x + sx, y + sy);
      GL11.glVertex2f(x,y + sy);
      GL11.glEnd();


glOrthoCommand is set to
glOrtho(0,1024,768,0,1,-1);


Anything i'm missing?
Thanks,
-Ethan
Coder, Mastermind, Friend

quew8

I think it's hard to see and problems in so little code, by which I mean that I can't (Also not sure as to what MouseRender does. Is it rendering the mouse itself, rendering for the mouse and if so why? etc...)
I would suggest printing out the variables immediately before the if statement. Then run a few test runs using cases that you know will intersect, some that will half intersect (as in only x or only y) and some that won't at all. Split the if statement up into four individual ones and print the result of each. You can set the position of the mouse with setX, setY (I think?) Look through the variables and results and make sure they are what you expect. If not print them up here and we can take a look.

th3barri3

usually i get my mouse y coord by Mouse.getY() - OrthoHeight with makes the mouse appear to be tracked from the top-right corner. Just stabbing in the dark because i dont know the problem as said above a bit hard to tell the problem with so little code.

EB5473

Sorry it took me so long to get back to you guys,
Thanks for all the advice-my problem stems from Mouse.getY increasing from bottom to top vs. vice versa. I think i've got it licked though.
Thanks again!
Coder, Mastermind, Friend