Results 1 to 2 of 2

Thread: Convert mouse point to box2d point in opengl

  1. #1
    Junior Member Newbie
    Join Date
    Sep 2009
    Posts
    3

    Convert mouse point to box2d point in opengl

    Hi,
    I want to convert mouse point on window to a point in box2D engine and I don't have those magic numbers to convert x and y regardless of screen resolution.
    I'm using windows calls to get mouse input and opengl to draw stuff.

    So box2d has this function ConvertScreenToWorld but i dont want to use GLUT to get those magic numbers...

    For me the closest aproximation looks like this
    b2Vec2 ConvertScreenToWorld(int32 x, int32 y)
    {
    float32 u = -x / 10.0;
    float32 v = y / 10.0;
    u+= GLwidth /20;
    v-= GLheight/20;
    u *= cameradistance/72.5;//for default opengl frustrum
    v *= cameradistance/72.5;
    b2Vec2 p(u,v);
    return p;
    }
    Its for default settings of openGL and 800x600 res.


    Does OpenGL have something to help me with this or do i need to guess numebers for every resolution to transform point from screen?
    Can glFrustum or projection matrix be helpfull?

    plz don't send to box2d forum

  2. #2
    Member Contributor
    Join Date
    Jan 2001
    Posts
    82

    Re: Convert mouse point to box2d point in opengl

    I think gluUnProject will do what you need.

Similar Threads

  1. Replies: 9
    Last Post: 03-09-2018, 10:33 AM
  2. Convert 3d point to 2d always flat to camera
    By ax2638 in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 01-13-2016, 11:19 AM
  3. Convert point sprites to a shape on a globe
    By Landon in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 07-27-2011, 12:22 PM
  4. Drawing a Point that follows the mouse :)
    By ekosha in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 11-22-2007, 05:59 PM
  5. convert a point 2D to a point3D
    By imported_Francisco in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 08-06-2004, 06:58 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean