Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

In OpenGl ES 2, should I declare just one transformation matrix, and share it across all objects or should I declare a transformation matrix in each object that needs it?

for clarification... something like this:

public class someclass{
   public static float[16] transMatrix = new float[16];
   ...
   public static void translate(int x, int y){
      //do translation here
   }
}
public class someotherclass{
   ...
   void draw(GL10 unused){
      someclass.translate(10,10);
      //draw
   }
}

verses something like this:

public class obj1{
    public static float[16] transMatrix = new float[16];
   ...
   void draw(GL10 unused){
      //translate
      //draw
   }
}
public class obj2{
   public static float[16] transMatrix = new float[16];
   ...
   void draw(GL10 unused){
      //translate
      //draw
   }
}
share|improve this question
add comment

2 Answers 2

up vote 0 down vote accepted

I'm also interested in the general opinion of which one is better. Here's my take on it:

In my OpenGL ES2 engine I have global transformation matrices (one modelview and one projection, obviously). I guess I've done it that way because it resembles how the old pipeline worked. It also makes sense because the way you traverse the scene you can build a stack of matrices (again, similar to the traditional approach) and it's really easy to understand - you can just think of the matrix transformations as camera movement.

On the other hand having a modelview matrix per object may be a pretty good idea. Off the top of my head you get the benefit that you don't need to do matrix calculations in the rendering phase (since it can be set in the physics simulation phase). This means you only have to recalculate these matrices if the object actually moves. It probably has some memory penalty but that's unlikely to matter on today's hardware. It may also allow you to have one transformation matrix for both the graphical and physical representation of the object (this depends on the frameworks you use).

share|improve this answer
add comment

I have a global MVP matrix that my Camera class constructs each update. This gets passed to my rendering classes and then to my shaders. It seem like a lot of unnecessary overhead to have one or more matrices for each object when you can just use global matrices.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.