Skip to main content
gamedev.net
🔒 Locked

Doing without gluLookAt?

Started by Specchum 6 replies 13k views
Original Post
Specchum
Specchum
We are using OpenGL ES for a mobile project. The problem is that there is no gluLookAt function since GLUT is not available in our case. Now, I'm trying to develop a FPS camera and is the routine have calculated a forward, right and up vector to maintain my camera orientation. So far, so good. However, how do I build my camera matrix with these three vectors without gluLookAt? I read something about using the inverse camera transforms or something like that, but frankly, it all went right over my head! Anyone care to tell me how to go about this?
"There is no dark side of the moon." - Pink Floyd
Seroja
Seroja
Don't know about OpenGL ES, but I'll try to help.

One idea would be to calculate your own modelview matrix and place it on stack instead of calling any view routine. Apply necessary transformation to your matrix.

But as you already have vectors calculated, you can use glTranslate and glRotate instead of gluLookAt.

Tell me what exactly vectors you have (what each of them represent) and I'll try to help you with the transformations.
Brother Bob
Brother Bob
gluLookAt is not a part of GLUT, but GLU. Don't know if you have GLU though, but missing GLUT does not mean missing gluLookAt.

Anyway, if you still want to implement your own, you can download the source for Mesa, which includes, if I'm not mistaken, two complete implementations of the GLU library. Have a look there how they do it.
Promag
Promag
Quote:
Original post by Specchum
... The problem is that there is no gluLookAt function since GLUT is not available in our case. ...


gluLookAt belongs to GLU not GLUT.

You must understand geometry transformations and matrix manipulation before doing you LookAt version.

Jernej.L
Jernej.L
if you want glulookat without glu look into opengl sample implementation from SGI, but if you want here is my pascal equivalent of their code, sorry about weird syntax highlightning but gamedev forums have no pascal highlighter it seems:

[source=pascal]// this is glulookat equivalent translated from ogl-sample.// matrix should be single but i use single precisionprocedure normalize(var v: array of single);varr: single;beginr:= sqrt(v[0] * v[0] + v[1] * v[1] + v[2] * v[2]);if (r = 0) then exit;v[0]:= v[0] / r;v[1]:= v[1] / r;v[2]:= v[2] / r;end;procedure crossp(var v1, v2, result: array of single);beginresult[0]:= v1[1]*v2[2] - v1[2]*v2[1];result[1]:= v1[2]*v2[0] - v1[0]*v2[2];result[2]:= v1[0]*v2[1] - v1[1]*v2[0];end;procedure LookAt(eyex, eyey, eyez, centerx, centery, centerz, upx, upy, upz: single);vari: integer;forw, side, up: array[0..2] of single;m: TMatrix4f;beginforw[0]:= centerx - eyex;forw[1]:= centery - eyey;forw[2]:= centerz - eyez;up[0]:= upx;up[1]:= upy;up[2]:= upz;normalize(forw);(* Side:= forw x up *)crossp(forw, up, side);normalize(side);(* Recompute up as: up:= side x forw *)crossp(side, forw, up);m:= IdentityHmgMatrix;m[0][0]:= side[0];m[0][1]:= side[1];m[0][2]:= side[2];m[1][0]:= up[0];m[1][1]:= up[1];m[1][2]:= up[2];m[2][0]:= -forw[0];m[2][1]:= -forw[1];m[2][2]:= -forw[2];glMultMatrixf(@m);glTranslated(-eyex, -eyey, -eyez);end;
Projects: Top Down City: http://mathpudding.com/
Trienco
Trienco
Quote:
Original post by Specchum
Now, I'm trying to develop a FPS camera and is the routine have calculated a forward, right and up vector to maintain my camera orientation.


If you already got that you wouldn't want to have gluLookAt throw away half your results and rebuild the matrix, anyway.

Your camera matrix is already there: right/up/forward/position.

Now you want to transform everything the other way, ie. you want to load the inverse of this matrix as modelview before rendering your scene. That part was basically posted, but to make it easier and more OpenGL matrix like you need to know that your typical transformation matrix (assuming normalized right/up/fwd vectors) is very user friendly. Transpose the 3x3 rotational part and transform the old position by the new rotation.

So, with Transform being your camera matrix in the usual ogl way (0-4:right, 5-8:up, etc. actually, I like having extra pointers called right,up,fwd into the array for clarities sake).

float viewmatrix[16]={	Transform[0], Transform[4], -Transform[8], 0,	Transform[1], Transform[5], -Transform[9], 0,	Transform[2], Transform[6], -Transform[10], 0,	-(Transform[0]*Transform[12] + Transform[1]*Transform[13] + Transform[2]*Transform[14]),	-(Transform[4]*Transform[12] + Transform[5]*Transform[13] +	Transform[6]*Transform[14]),						  	Transform[8]*Transform[12] + Transform[9]*Transform[13] + Transform[10]*Transform[14], 1};or:float viewmatrix[16]={	right.x, up.x, -fwd.x, 0,	right.y, up.y, -fwd.y, 0,	right.z, up.z, -fwd.z, 0,	-(right.x*pos.x + right.y*pos.y + right.z*pos.z),	-(up.x*pos.x + up.y*pos.y + up.z*pos.z, 	fwd.x*pos.x + fwd.y*pos.y + fwd.z*pos.z, 1};


Note that z/fwd is inverted and the new position coords are simply -(pos dot old_axis).
f@dzhttp://festini.device-zero.de

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.