Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9157279
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T12:58:36+00:00 2026-06-17T12:58:36+00:00

I have a simple rectangle here in my program on which I had to

  • 0

I have a simple rectangle here in my program on which I had to do hit testing. I am using openFrameworks but I think the problem here is related to OpenGL topics as well.

public class Shape : public class ofNode {
  Shape() {
    container.setFromCenter(getPosition(), 200,100);
    setPosition(ofVec3f(365, 50, 0)); //set the position of the node
    lookAt(ofVec3f(0,0,0));
  }

  virtual void draw() {
    ofRect(container); //the 200/100 rectangle will be drawn as per the container position and dimensions
  }
  ofVec3f getTopLeft() const {
    return getTopLeft() * ofNode::getGlobalTransformMatrix();
  }

  ofVec3f getTopRight() const {}    //similar - getTopRight from container and multiply
  ofVec3f getBottomLeft() const {}  //similar
  ofVec3f getBottomRight() const {} //similar

  bool hitTest(int tx, int ty) {
    // return true if mouse pointer is inside four vertices - hit test logic working fine
  }

  private:
    ofRectagle container;
};

The problem I have here is I am rotating and translating the shape inside my program:

void draw() {
  ofPushMatrix();
  ofTranslate(600,300,0);
  ofRotateY(rotate);
  shape->draw();

  ofCircle(shape->getTopLeft(), 10); //circle is drawn at the rectangle top left vertex on the screen but the coordinates while rotating and drawing do not change (as seen on cout)
  ofCircle(shape->getTopRight(), 10); //similar
  ofCircle(shape->getBottomLeft(), 10); //similar
  ofCircle(shape->getBottomRight(), 10); //similar
  ofPopmatrix();
}

On rotation being changed as in the above draw function, the points do not change. Hence, I do not have the appropriate four vertices for the hit test to figure out if the mouse is inside.
How do I get the position of the points in the screen which can be check against the mouse position for the hit test?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T12:58:37+00:00Added an answer on June 17, 2026 at 12:58 pm

    If you want to test if the mouse pointer is within the limits of the rectangle, I suggest you first transform them into screen space and do the test there, following the general idea I gave you in https://stackoverflow.com/a/14424267/524368

    I’d also say, it’a about time to stop using OpenGL’s builtin matrix manipulation functions. There is absolutely no benefit in using them! Some people think they’d be GPU accelerated, but that’s not the case. As soon as you need those matrices at other points in your program it simply not practical to abuse OpenGL for this. OpenGL is not a math library after all. And in later versions the whole matrix stack has been dropped from OpenGL – good riddance.

    OpenFrameworks comes with a fully featured matrix math library. I strongly suggest you use that. You can feed OpenGL the generated matrices with glLoadMatrix (fixed function pipeline) or glUniformMatrix (shader pipeline).

    You can use it to implement a projection function as outlined by me in that other answer.

    To test if a point lies within the boundaries defined by edges you can use a concept called “half edges”. Say your edges form a star domain loop. Then for each edge in the loop you take the cross product of the point with the edge. If the point is within the shape defined by the loop all the cross products will point into the same direction. Coplanar quadrilaterals (i.e. quadrilateals projected into screen space) always form a star domain.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a problem using opengl on android to draw a simple rectangle. This
I have a simple Javascript program that displays a small rectangle in a canvas.
The Code I have this problem, I am trying to create a simple rectangle
I have my first simple OpenGL program to display 2D images using OpenGL. I'm
I have simple class with width and height member fields which define number of
I have a simple rectangle i have drawn on screen in opengl. My target
I have a simple grid with 3 columns (one of which contains a grid
I have a UIView subclass that draws a simple rectangle with this code: -
Hi everyone I have a compatibility problem with a simple jquery plugin i've done
Here I have a simple class that extends a class in the ACM graphics

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.