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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T11:33:35+00:00 2026-05-21T11:33:35+00:00

I’m building a cross-platform game in C++, using OpenGL ES 2.0. The target is

  • 0

I’m building a cross-platform game in C++, using OpenGL ES 2.0. The target is iPhone at the moment. I’m a newbie to coding games, but not a newbie to coding.

I’m confused about how to architect the game. But specifically, I’m asking about how to setup the objects needed to position models in the scene.

I have an object that represents a scene. There are 5 scenes. Only one scene is shown at a time. A scene is like a game level. Each scene has all the code for rendering, game logic, mouse and keyboard handling. Touch-screen handling is handled like a mouse click.

Each Scene has:
It’s own projection matrix.
It’s own “View” matrix — currently not used — always set to the identity matrix
A list of models to render

Each Model has:
The vertex list
A GLSL program to render itself
A texture
A “model” matrix

I use an Orthographic projection matrix.

Since we’re using GLES 2, I have to do just about everything manually. Including the matrices. So I don’t use glPushMatrix, glPopMatrix, glTranslate, etc. They aren’t available. Instead, I have my own functions which operate on my own Matrix objects.

OK here’s where things get weird for me.

1) Setup the projection matrix (using an orthographic matrix)

_math_matrix_ortho(&this->ProjectionMatrix, 0.0, 1.0, 0.0, (float)height / (float)width, -1.0f, 1.0f);

2) Leave the view matrix as the identity matrix

3) Load each model

4) Each model’s “model” matrix is defaults to the identity matrix

5) I now scale each model to make them the right side in proportion to one another. The scaling function adjusts the Model’s “model” matrix.

model->modelMatrix.Scale(0.25, 0.25, 0.25);

6) Move each model into place

model->modelMatrix.Translate(2.0, 0.0, 0.0);

7) Render each model

{
    glUseProgram(this->_program.program);
    GL_CHECK_ERROR();

    glVertexAttribPointer(_positionLoc, 3, GL_FLOAT, GL_FALSE, 0, _vertices );
    GL_CHECK_ERROR();

    glVertexAttribPointer(_texCoordLoc, 2, GL_FLOAT, GL_FALSE, 0, _texCoords);
    GL_CHECK_ERROR();

    glEnableVertexAttribArray(_positionLoc);
    GL_CHECK_ERROR();

    glEnableVertexAttribArray(_texCoordLoc);
    GL_CHECK_ERROR();

    glBindTexture ( GL_TEXTURE_2D, _texture->getGLID() );
    GL_CHECK_ERROR();

    glUniform1i ( _texLoc, 0 );
    GL_CHECK_ERROR();

    glUniformMatrix4fv(_pMatrixLoc, 1, GL_FALSE, SceneManager::getInstance().getCurrentScene().ProjectionMatrix.m);
    GL_CHECK_ERROR();

    glUniformMatrix4fv(_vMatrixLoc, 1, GL_FALSE, this->_vMatrix.m);
    GL_CHECK_ERROR();

    glUniformMatrix4fv(_mMatrixLoc, 1, GL_FALSE, this->_mMatrix.m);
    GL_CHECK_ERROR();

    glDrawArrays ( GL_TRIANGLE_STRIP, 0, 4);
    GL_CHECK_ERROR();
}

What seems odd to me right off: Is it appropriate to be translating the Model’s matrix?

The dicey part comes when I try to glUnProject the mouse/touch-screen coordinates.

1) Get Mouse/Touch-Screen coordinates

2) Un-project them.

Now I have the coordinates relative to the View matrix. Which is the identity matrix. What that means is that x,y coords are translated to a coordinate system where the max vertical and horizonal extents are exactly 1.0.

How do I figure out what object was clicked?

It seems that in order to answer my last question, I need to better understand where I positioned it.

I think I’ve over-designed this. Help.

  • 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-21T11:33:36+00:00Added an answer on May 21, 2026 at 11:33 am

    You can either :

    1 . compute a line intersection with your model, it depends how complex your model is.

    2 . render a label image in an off screen pixmap : instead of drawing with light and textures you use flat colors which are object labels. pick the pointed pixel, the value gives the object. You have to assign labels to objects you want to detect, and a default value for all the others and the background.

    I hope this helps.

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

Sidebar

Related Questions

I need to clean up various Word 'smart' characters in user input, including but
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
i want to parse a xhtml file and display in UITableView. what is the
public static bool CheckLogin(string Username, string Password, bool AutoLogin) { bool LoginSuccessful; // Trim

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.