• Create Account

## Camera Intilization in OpenGL ES 2.0

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

4 replies to this topic

### #1maheshbinny  Members

118
Like
0Likes
Like

Posted 11 May 2012 - 03:42 AM

Can somebody help me intilizarion of camera in OpenGL ES 2.0

I mean matrix calculation for Camera LookAt, Position and Up vector ?

Mahesh

### #2EngineCoder  Members

246
Like
1Likes
Like

Posted 11 May 2012 - 09:43 AM

Here's my lookat() implementation:
void Matrix::makeLookAt( const Vec3& aEye, const Vec3& aCenter, const Vec3& aUp, float* aMatrix )
{
assert( aMatrix );
Vec3 forward = aCenter - aEye;
forward.normalize();

Vec3 right = forward.cross( aUp );
right.normalize();

const Vec3 up = right.cross( forward );

aMatrix[ 0 ] = right.x;
aMatrix[ 4 ] = right.y;
aMatrix[ 8 ] = right.z;
aMatrix[ 12 ] = 0;

aMatrix[ 1 ] = up.x;
aMatrix[ 5 ] = up.y;
aMatrix[ 9 ] = up.z;
aMatrix[13 ] = 0;

aMatrix[ 2 ] = -forward.x;
aMatrix[ 6 ] = -forward.y;
aMatrix[10 ] = -forward.z;
aMatrix[14 ] = 0;

aMatrix[ 3 ] = aMatrix[ 7 ] = aMatrix[ 11 ] = 0.0f;
aMatrix[15 ] = 1.0f;
float translate[ 16 ];
Matrix::identity( translate );
translate[ 12 ] = -aEye.x;
translate[ 13 ] = -aEye.y;
translate[ 14 ] = -aEye.z;

multiply( translate, aMatrix, aMatrix );
}


My iOS 3D action/hacking game: http://itunes.apple....73873?ls=1&mt=8
Blog

### #3clb  Members

2143
Like
0Likes
Like

Posted 11 May 2012 - 11:43 AM

In MathGeoLib float3x4 class, you can find an implementation of a LookAt matrix. The derivation is identical, up to translation, to the function float3x3::LookAt, and the code and documentation on how it is done is available here. This matrix will map from the local space of the object (object==camera in this case) to the world space, so for the camera, this mapping will be a View->World space mapping. To produce a World->View space mapping as is usually needed, take the inverse of the resulting matrix.

Edited by clb, 11 May 2012 - 11:44 AM.

Me+PC=clb.demon.fi | C++ Math and Geometry library: MathGeoLib, test it live! | C++ Game Networking: kNet | 2D Bin Packing: RectangleBinPack | Use gcc/clang/emcc from VS: vs-tool | Resume+Portfolio | gfxapi, test it live!

### #4maheshbinny  Members

118
Like
0Likes
Like

Posted 14 May 2012 - 04:26 AM

Here's my lookat() implementation:

void Matrix::makeLookAt( const Vec3& aEye, const Vec3& aCenter, const Vec3& aUp, float* aMatrix )
{
assert( aMatrix );
Vec3 forward = aCenter - aEye;
forward.normalize();

Vec3 right = forward.cross( aUp );
right.normalize();

const Vec3 up = right.cross( forward );

aMatrix[ 0 ] = right.x;
aMatrix[ 4 ] = right.y;
aMatrix[ 8 ] = right.z;
aMatrix[ 12 ] = 0;

aMatrix[ 1 ] = up.x;
aMatrix[ 5 ] = up.y;
aMatrix[ 9 ] = up.z;
aMatrix[13 ] = 0;

aMatrix[ 2 ] = -forward.x;
aMatrix[ 6 ] = -forward.y;
aMatrix[10 ] = -forward.z;
aMatrix[14 ] = 0;

aMatrix[ 3 ] = aMatrix[ 7 ] = aMatrix[ 11 ] = 0.0f;
aMatrix[15 ] = 1.0f;
float translate[ 16 ];
Matrix::identity( translate );
translate[ 12 ] = -aEye.x;
translate[ 13 ] = -aEye.y;
translate[ 14 ] = -aEye.z;

multiply( translate, aMatrix, aMatrix );
}


Thank you very much

### #5sjhalayka  Members

1064
Like
0Likes
Like

Posted 14 May 2012 - 09:39 AM