OpenGl ES: beam selection for multiple objects drawn using the push / pop matrix

I had a question about several objects drawn using push / pop stack.something like this.


    glMatrixMode(GL_MODELVIEW);  
    glLoadIdentity();  
    glTranslatef(x,y,z);  
    glRotate(r,1,0,0);     
        
    glTranslate(-x,-y,-z);


    for (i=0 to 20) objects    
    
      glpushMatrix();    

          draw_object()    
    
      glpopMatrix();    
   
 end
        
    

each object is a unit circle with its own transformation. In this case, how does ray collection work. How should I track the center point of an object to calculate the intersection of rays. I really appreciate any help.

+3
source share
1 answer

You can get the current matrix for each object:

glMatrixMode(GL_MODELVIEW);  
glLoadIdentity();  
glTranslatef(x,y,z);  
glRotate(r,1,0,0);     
        
glTranslate(-x,-y,-z);
    

for (i=0 to 20) objects    
    
  glpushMatrix();    
      ... some matrix transformations specific for the object
      ... and get the final matrix and store it to object member
      glGetFloatv(GL_MODELVIEW_MATRIX, (GLfloat*)&object->modelMatrix);
      draw_object()    
    
  glpopMatrix();  

When crossing rays, simply multiply the matrix of the object with the coordinate of the local center point to get it in the absolute space where the ray is defined.

0
source

Source: https://habr.com/ru/post/1787133/


All Articles