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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T20:32:14+00:00 2026-05-21T20:32:14+00:00

I have an opengl c++ project I’m working on, where I draw a player

  • 0

I have an opengl c++ project I’m working on, where I draw a player and a ball in his right hand. At first I want to make the ball follow the player’s hand movement by setting ball position. After some time I need to make the ball travel using kinematics eqations. I get the player right hand transform matrix using (I do this the moment I draw the player):

glGetFloatv(GL_MODELVIEW_MATRIX, ball->transformMatrix);

and then the moment I draw the ball I try to do:

glLoadMatrixf(ball->transformMatrix);
glTranslated(0, 0, 0);
glCallList(lists[BALL]);

this works perfect and ball drawn at place.

The problem is when I need to move the ball

x += velocityX*dt;
y += velocityY*dt + gravity*dt*dt;
z += velocityZ*dt;

velocityY += gravity*dt;

the movement is relative not to player transform but the global. I tried many ways to solve this but none works.

So how is it possible for me to calculate properly the x, y, z of the ball so I can translate the ball after it left the player hand?

Edit:

I’ve managed to recieve the ball coordinates by multiplying ball->transformMatrix with the vector {0, 0, 0, 1} the result storing in world vector, after that calling (the moment I draw the ball):

glGetFloatv(GL_MODELVIEW_MATRIX, currentTransformMatrix);

then inversing currentTransformMatrix and multiplying inverse with world vector. The result is the ball proper coordinates {x, y, z}.

  • 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-21T20:32:14+00:00Added an answer on May 21, 2026 at 8:32 pm

    You need to transform back to the player’s hand position; invert the transformation from hand to world. Since OpenGL is not a math library, you need to either implement the matrix math yourself of use some 3rd party linear math library.

    EDIT due to comment:

    What you transform is the velocity and acceleration into the ball’s local coordinate system. Both velocity and gravity are just “directive” vectors, so the transformation is independent of the position of the ball in the world (well the gravity may change, but that’s no issue here). So you need the inverse transform from world to ball space, that is independent from position. This is the very same problem like transforming normals (jsut the other way round) => so you need to take the transposed inverse of the inverted matrix (Explained in detail here http://www.lighthouse3d.com/tutorials/glsl-tutorial/the-normal-matrix/ ). However you already have the inverse of that inverse; it’s the ball->world matrix itself. So you just have to transpose the modelview matrix, multiply velocity and gravity vectors with that and apply them in the ball’s local space.

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

Sidebar

Related Questions

I have done a graphics project using OpenGL and now I want to convert
I'm working on a (c++, opengl) project where I need to have lots of
I have been working on a project of OpenGL. Here I just display a
I'm working on an openGL project and have chosen to use GLUI for my
I'm working on a project that uses OpenGL 4.0 shaders. I have to supply
I'm working on a OpenGL project and I want at least a little lighting
Good Day I want to start a opengl project, mainly to follow the Nehe
I am working on an OpenGL project in C++, and I want to learn
I have an iPhone OpenGL-ES 1.1 project that renders simple 3D models. If I
I am working on an OpenGL project for a computer graphics course, and I

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.