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 6851047
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T01:11:59+00:00 2026-05-27T01:11:59+00:00

I want to be able to get the coordinates of an object (e.g. triangle)

  • 0

I want to be able to get the coordinates of an object (e.g. triangle) after it’s been translated and rotated, the reason i want to do this is so that later i can do collision detection and calculate the distance between objects using the coordinates. I think I might have to use gluProject but not sure. Also what are the differences between the different coordinate spaces e.g. world, object etc.

I’ve got some code below it’s a circle in the middle of a square, how would i detect when the circle touches one of the edges, i can move it round using the up,down,left, right keys it just changes the x or y coordinates, but i just want to be able to do some basic collision detection and I don’t know how to do it.

glPushMatrix();
    glColor3f(0.0f, 1.0f, 0.0f);
    glTranslatef(0.0f, 0.0f, -5.0f);

    glScalef(0.5f, 0.5f, 0.0f);
    glBegin(GL_POLYGON); 
        glVertex3f(-5.0f, -5.0f, 0.0f);
        glVertex3f(5.0f, -5.0f, 0.0f);
        glVertex3f(5.0f, 5.0f, 0.0f);
        glVertex3f(-5.0f, 5.0f, 0.0f);
    glEnd();
glPopMatrix();

glPushMatrix();


    glColor3f(1.0f, 0.0f, 0.0f);
    glTranslatef(x, y, -20.0f);

    glBegin(GL_POINTS);
        glVertex3f(-5, -5, 10.0f);
    glEnd();

    GLUquadricObj *qobj = gluNewQuadric();
    gluQuadricDrawStyle(qobj, GLU_FILL);
    gluSphere(qobj, 1.0f, 20, 20);
    gluDeleteQuadric(qobj);
glPopMatrix();
  • 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-05-27T01:12:00+00:00Added an answer on May 27, 2026 at 1:12 am

    Also what are the differences between the different coordinate spaces e.g. world, object etc.

    This is mostly a matter of convention, but:

    • Model space (= local space) is the coordinate space of a specific model, relative to its “center”. If you have a file with a model, the coordinates are centered around some point of it (e.g. it’s geometrical center, its base, anything actually).

    • Scene space (= world space) is the coordinate space relative to an arbitrary point of your scene

    • Eye space (= view space) is the space where the camera is at point (0,0,0), x faces right, y faces up and z faces out of the screen (-z = deeper)

    • Clip space is where (-1,-1,*) is the bottom left corner of the viewport, (1,1,*) is the top right corner of the viewport, and the Z coordinate in (-1,1) indicates just the depth (again smaller Z = deeper). (Fragments

    • Screen space (= window coordinates) is the same as above, except that the coordinates are rescaled from -1..1 to pixel-based values matching the range of the current viewport and depth range.

    You transform coordinates from model space to scene space by multiplying (in OpenGL conventions usually left-multiplying) by a model matrix (which contains the information on where the model is on the scene). If you have a scene hierarchy, there can be many “stacked” model matrices for an object (placement of the sword relative to an arm, arm relative to a knight, knight relative to the scene).

    Then you transform the coordinates to eye space by multiplying by a view matrix (usually connected to a “camera” object).

    After that, using a projection matrix you transform those coords to the screen space, so that OpenGL would map these coords to actual screen pixels (depending on the viewport setting).

    Some facts:

    • Model and view matrices usually contain translation, rotation and/or scaling, while projection matrix usually contains a perspective transformation, which makes the objects further from the screen appear smaller.

    • Old OpenGL (2.x and earlier) required you to put the matrices on two “matrix stacks”:

      • GL_MODELVIEW stack which should contain View*Model (or View*Model1*Model2…*ModelN),
      • GL_PROJECTION stack which sould contain only the Projection matrix.

    These could just as well be single matrices, not stacks, but the stack (along with glPushMatrix and glPopMatrix) was introduced to let the programmer “save and load” them easily. Only the “topmost” matrix from each stack is used in calculations.

    The projection matrix is usually created with gluPerspective or equivalent. The view matrix can be made with gluLookAt (or similarly to model matrices), and the model matrices can be easily assembled using glTranslate, glRotate and glScale.

    (note: OpenGL 3.1+ removed these features, allowing you to use any matrices and any conventions you prefer)


    Knowing that:

    I want to be able to get the coordinates of an object (e.g. triangle) after it’s been translated and rotated, the reason i want to do this is so that later i can do collision detection and calculate the distance between objects using the coordinates

    A reasonable way to calculate all your physics is to do them in scene space.

    Hence if you have a model (e.g. a triangle mesh), to obtain the position of any its vertex in scene space, you need to left-multiply it by only the model’s model matrix (or in case of the hierarchy, by all its model matrices).


    About gluProject, in case you wondered- it is a convenience method which allows you to multiply a set of coordinates by the current PROJECTION*MODELVIEW and performs viewport transformation to see where it would end up in screen space, and gluUnProject does the reverse.

    Ref: http://www.opengl.org/resources/faq/technical/transformations.htm

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

Sidebar

Related Questions

I want to be able to get the current bound object in the ItemTemplate
I want to be able to get something similar to this.. I want to
I want to be able to get different array values in my ajax callback
I want to be able to do the following: get '/:slug' do haml :page
I want to get week Start Date of a week. I am able to
I want to be able to write code like this: HWND hwnd = <the
I want my users to be able to specify their locations so that I
How can I get a perfect isometric perspective in Silverlight ? I want to
How can one get the coordinates of a mouse click inside a panel? For
In my application i am able to get coordinates of my current location. But

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.