#### Archived

This topic is now archived and is closed to further replies.

# OpenGL The most efficient way to do camera? (partly opengl)

This topic is 5719 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I''m working for a extremely low performance system with OpenGL (please don''t ask) and I have found out that every single matrix multiplication and inverse counts. The problem is that I can''t access natural calls(rotatef/translatef) of OpenGL, because of the fact that I have to convert floats through buffers and I''m trying to minimize the buffer overhead. The fact that I can''t use rotatef reduces out quaternions since if I want to use them I have to convert them into a matrix anyway to work with the multMatrixf/loadMatrixf calls. My current solution is one where I have my own rotate call, which mimics rotatef and builds rotation matrix and then multiplies the view matrix with the rotation matrix. This way I can avoid manually matrix creep relatively easy. Euler angles would be another method, but I haven''t implemented it at all, but after I took a look into my math books it seems to be that eulers can result "lock" relatively easy. And finally, does anyone remember the optimization code to get direction vector directly out of the matrix. I remember there was this optimization in one of the graphics gems, which I saw at store. I''m wondering which "method" takes the least calculations.

##### Share on other sites
Even if every multiply counts, the cost of a camera transform should still be minimal compared to transforming your vertices.

One option is to do T&L yourself. You can use quaternions here, and simply do the rotation manually, with quaternion-vector multiplication: v'' = q*v*q-1

##### Share on other sites
Yes I understand, it struck me pretty hard that even the simplest mouse move required 2 matrix multiplications, not to take into account that I have to make my own rotation matrix.

##### Share on other sites
Are you that really hard up for clock cyles??? I mean, the camera is only setup once, how bad could it be? My camera code for instance does 2 matrix multiplies and used to do an inverse (SUPER expensive) but I did a trick where I kept the camera at the origin and subtracted the object pos from the camera pos when rendering entitys (I think OGL handles camera like this anyways). This allowed me to do a transpose (cheap) versus the inverse since the inverse of a rotation matrix is it''s transpose (and it is only a rotation matrix since I keep it at origin). You could use tricks like this, but have you actually tested doing like, 6 or so multiplys in a row? If your code is bottlenecked by a few mat mults, you''re screwed anyways man, might as well write you code in asm.

To get your lookat, take the first column, right, take second, up, take third (I might have the last two mixed up - it''s late).
You build your lookat matrix doing this, and then use the dot product of those values to build the translation (4th) column.

No idea what you''re talking about converting calls through buffers, but I bet those can get expensive (whatever you do that for). Besides, guess what glRotatef does anyways. It builds a matrix

Sounds like you''ve got worse bottlenecks to worry about than matrix math.

"Love all, trust a few. Do wrong to none." - Shakespeare

Dirge - Aurelio Reis
www.CodeFortress.com
Current Causes:
Nissan sues Nissan

##### Share on other sites
euler angles will only work for basic first person style, because in angles you cant store the order in which your rotations happened. for fps style it doesnt matter (rotate around y first, then x).

how are you storing object positions? do you rotate/translate them every frame (probably expensive) or store their position/orientation (either matrix or quaternion)?

thinking about the one at flipcode the cheapest way seems to store everything as quaternions, adjust the objects quat with your cam quat, convert that to a matrix and load it to the stack (will have the least work for transformations and no matrix multiplication).

##### Share on other sites
The thing is I''m not working with c++, but java/java bytecode hence the buffers.

I use quaternions for interpolation and each one of the 3d objects has position and current orientation, it is pretty tricky, but I can save a few calculations this way as opposed of having object matrix.

Anyhow, Dirge, do you mean dot product of vectors UVN? That is not the optimization I''m talking about, but anyhow thanks.

##### Share on other sites
Just wondering... what are the specs of this system?!

##### Share on other sites
It''s 33MHz - faster than any human

##### Share on other sites
It is this old unix/linux server where I try to make simple vector mud with java/opengl.

The processor is dual something processors(not sure what, either pentium 200 or sun processors) with "brand new" hercules accelerator and about 128 usable ram. It currently runs campus mud without any problems and all of the players have these shitty computers connected to it. It is on 24-7 and the players "never" log off. I''m trying to make graphical UI to it so that we can get more players.

I know I could do this with C, but I don''t want to. I like to see what java is capable of.

##### Share on other sites
The thing is, Quaternion equations are not THAT efficient. Storage is what they are awesome for, but normal operations are just as expensive. For instance, to create a q oriented at a yaw, pitch, and roll, you''re doing already using two of the most expensive operations, cos, and sin about 3 times each (6 times total) + 18 muls + 18 basic arithmitic op''s (add, sub, assign). Then you still have to multiply this by another q (not so expensive, but it adds up). I can accomplish virtually the same thing by rotating a matrix on the x, y, and z, then multing them together (yeah, by this point I''m around the same computation count, but I can also pull back my camera back a little by multing it by a translation mat). Nevermind you still have to convert it to a matrix. Bottom line, don''t use q unless you are experiencing gimbal lock, need smooth slerping, or are desperate for storage space (perfect for bones).

I was describing how to compose a lookat matrix. The dots for the 4th column is not an optimization, it''s required. You dot the negative of the x, y, and z columns with the position of the cam.

"Love all, trust a few. Do wrong to none." - Shakespeare

Dirge - Aurelio Reis
www.CodeFortress.com
Current Causes:
Nissan sues Nissan

1. 1
2. 2
3. 3
Rutin
15
4. 4
5. 5

• 13
• 26
• 10
• 11
• 9
• ### Forum Statistics

• Total Topics
633723
• Total Posts
3013556
×