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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T05:11:57+00:00 2026-06-16T05:11:57+00:00

I am using OpenGL ES 2.0 and the latest iOS. I have a 3D

  • 0

I am using OpenGL ES 2.0 and the latest iOS.

I have a 3D model that I wish the user to be able to select different parts of the model by tapping on the screen. I have found this tutorial on converting a pixel-space screen coordinate to a world-space ray, and have implemented a ray-AABB intersection test to determine the intersection portion of the model.

I get some hits on the model at seemingly random sections of the model. So I need to debug this feature, but I don’t really know where to start.

I can’t exactly draw a line representing the ray (since it is coming out of the camera it will appear as a point), so I can see a couple of ways of debugging this:

  1. Check the bounding boxes of the model sections. So is there an easy way with OGL ES to draw a bounding box given a min and max point?

  2. draw some 3D object along the path of the ray. This seems more complicated.

  3. Actually debug the raycast and intersection code. This seems like the hardest to accomplish since the algorithms are fairly well known (I took the intersection test straight ouf of my Real-Time Collision Detection book).

If anyone can help, or wants me to post some code, I could really use it.

Here is my code for converting to world space:

- (IBAction)tappedBody:(UITapGestureRecognizer *)sender
{
    if ( !editMode )
    {
        return;
    }
    CGPoint tapPoint = [sender locationOfTouch:0 inView:self.view];
    const float tanFOV = tanf(GLKMathDegreesToRadians(65.0f*0.5f));
    const float width = self.view.frame.size.width,
                height = self.view.frame.size.height,
                aspect = width/height,
                w_2 = width * 0.5,
                h_2 = height * 0.5;

    CGPoint screenPoint;
    screenPoint.x = tanFOV * ( tapPoint.x / w_2 - 1 ) / aspect;
    screenPoint.y = tanFOV * ( 1.0 - tapPoint.y / h_2 );

    GLKVector3 nearPoint = GLKVector3Make(screenPoint.x * NEAR_PLANE, screenPoint.y * NEAR_PLANE, NEAR_PLANE );
    GLKVector3 farPoint = GLKVector3Make(screenPoint.x * FAR_PLANE, screenPoint.y * FAR_PLANE, FAR_PLANE );

    GLKVector3 nearWorldPoint = GLKMatrix4MultiplyVector3( _invViewMatrix, nearPoint );
    GLKVector3 farWorldPoint = GLKMatrix4MultiplyVector3( _invViewMatrix, farPoint );

    GLKVector3 worldRay = GLKVector3Subtract(farWorldPoint, nearWorldPoint);
    NSLog(@"Model matrix: %@", NSStringFromGLKMatrix4(_modelMatrix));
    worldRay = GLKVector4Normalize(worldRay);

    [male intersectWithRay:worldRay fromStartPoint:nearWorldPoint];

    for ( int i =0; i < 3; ++i )
    {
        touchPoint[i] = nearWorldPoint.v[i];
    }
}

And here’s how I get the matrices:

- (void)update
{
//  _rotation = 0;

    float aspect = fabsf(self.view.bounds.size.width / self.view.bounds.size.height);
    GLKMatrix4 projectionMatrix = GLKMatrix4MakePerspective(GLKMathDegreesToRadians(65.0f), aspect, NEAR_PLANE, FAR_PLANE);

    self.effect.transform.projectionMatrix = projectionMatrix;
    GLKMatrix4 baseModelViewMatrix = GLKMatrix4MakeTranslation(0.0f, 0.0f, -5.0f);

    // Compute the model view matrix for the object rendered with ES2
    _viewMatrix = GLKMatrix4MakeTranslation(0.0f, 0.0f, 0.0f);
    _modelMatrix = GLKMatrix4Rotate(baseModelViewMatrix, _rotation, 0.0f, 1.0f, 0.0f);
    _modelViewMatrix = GLKMatrix4Rotate(_viewMatrix, _rotation, 0.0f, 1.0f, 0.0f);
    _modelViewMatrix = GLKMatrix4Multiply(baseModelViewMatrix, _modelViewMatrix);

    _invViewMatrix = GLKMatrix4Invert(_viewMatrix, NULL);
    _invMVMatrix = GLKMatrix4Invert(_modelViewMatrix, NULL);

    _normalMatrix = GLKMatrix3InvertAndTranspose(GLKMatrix4GetMatrix3(_modelViewMatrix), NULL);

    _modelViewProjectionMatrix = GLKMatrix4Multiply(projectionMatrix, _modelViewMatrix);

    male.modelTransform = _modelMatrix;

    if ( !editMode )
    {
        _rotation += self.timeSinceLastUpdate * 0.5f;
    }
}
  • 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-06-16T05:11:59+00:00Added an answer on June 16, 2026 at 5:11 am

    I’m not sure why this fixed the problem I was having but changing

    screenPoint.x = tanFOV * ( tapPoint.x / w_2 - 1 ) / aspect;
    

    to

    screenPoint.x = tanFOV * ( tapPoint.x / w_2 - 1 ) * aspect;
    

    and

    GLKVector4 nearPoint = GLKVector4Make(screenPoint.x * NEAR_PLANE, screenPoint.y * NEAR_PLANE, NEAR_PLANE, 1 );
    GLKVector4 farPoint = GLKVector4Make(screenPoint.x * FAR_PLANE, screenPoint.y * FAR_PLANE, FAR_PLANE, 1 );
    

    to

    GLKVector4 nearPoint = GLKVector4Make(screenPoint.x * NEAR_PLANE, screenPoint.y * NEAR_PLANE, -NEAR_PLANE, 1 );
    GLKVector4 farPoint = GLKVector4Make(screenPoint.x * FAR_PLANE, screenPoint.y * FAR_PLANE, -FAR_PLANE, 1 );
    

    seems to have fixed the raycasting issue. Still not sure why my view matrix seems to be indicating that the camera is looking down the positive Z-axis, but my objects are translated negative along the z axis

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

Sidebar

Related Questions

Using OpenGL ES 2.0 on iOS 4 . I have an OpenGL view that
I write a 3D model display program using OpenGL、Qt、C++.But I found something strange.That is
I am using OpenGL to render a model of an object that is rotationally-symmetric
Using OpenGL ES I am rendering a simple cube class that draws it at
I'm using OpenGL to render polygons. I notice that if I minimize the program
I'm using OpenGL ES in my iPhone application and sometimes during startup the screen
I have a problem using opengl on android to draw a simple rectangle. This
Im using OpenGL for an app that im trying to make. I've been learning
I am new to using OpenGL with Qt Creator and I have been playing
When using openGL in Java (in bindings like jogl), do you have to worry

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.