convert pixel to cm openGL

Asked

Viewed 45 times

0

I need to change an object to where the mouse is clicked, I’m trying to do with a point to start. I already managed to capture the mouse position but it comes in pixel and I need this value in centimeter. Below an excerpt of the code.

gl.glPointSize(5);
gl.glBegin(GL.GL_POINTS);        
gl.glColor3f(0f, 0f, 0f);   
    gl.glVertex2d(p1,p2);            
gl.glEnd();

Function that captures the mouse position in pixel

public void mousePressed(MouseEvent e) {  
System.out.println("Evento do mouse");
switch (e.getButton()) {
    case MouseEvent.BUTTON1:              
       p1= e.getX();
       p2= e.getY();          
       break;   
}

}

  • Larissa, please provide a [mcve] so that it is possible to analyze the code better.

  • Pixel in centimeters is relative. For this you have to know the ratio Pixel by Centimeters or Pixels by Inch. Why you need the measure in centimeters?

  • 1

    I find that doubt very vague, very difficult to try to help with so little information.

  • when clicking with the mouse in any part of the window the drawing (or a part of it) should be redrawn at the point where the mouse was pressed.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.