🎉 Celebrating 25 Years of GameDev.net! 🎉
Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!
glu functions and sqrt, trig?
Slowly porting to Brew, and I've just hit a snag.
I use gluPespective, and gluLookAt to position my camera. But these are not available in OpenGL ES right? So I have to write my own routines?
Also, the AEEStdLib header doesn't provide sqrt or trig. Is there anywhere else I can find this, or do I need to roll my own here as well?
This is my lookat function:
Coder beware however, I only use it once in my program right at the start, so it hasn't been extensivly tested.
For trig and sqrt you are on your own. I would suggest implementing your trig stuff as lookup tables, google will provide you with more example code than you will ever read.
Alan
LookAt(GLfixed eyex, GLfixed eyey, GLfixed eyez, GLfixed centerx, GLfixedt centery, GLfixed centerz, GLfixed upx, GLfixed upy, GLfixed upz) { GLfixed forward[3], side[3], up[3]; GLfixed m[4][4]; forward[0] = centerx - eyex; forward[1] = centery - eyey; forward[2] = centerz - eyez; normalizex(forward); up[0] = upx; up[1] = upy; up[2] = upz; crossf(forward, up, side); normalizef(side); crossf(side, forward, up); SetIdentity(&m[0][0]); m[0][0] = side[0]; m[1][0] = side[1]; m[2][0] = side[2]; m[0][1] = up[0]; m[1][1] = up[1]; m[2][1] = up[2]; m[0][2] = -forward[0]; m[1][2] = -forward[1]; m[2][2] = -forward[2]; glMultMatrixx(&m[0][0]); glTranslatex(-eyex, -eyey, -eyez);}
Coder beware however, I only use it once in my program right at the start, so it hasn't been extensivly tested.
For trig and sqrt you are on your own. I would suggest implementing your trig stuff as lookup tables, google will provide you with more example code than you will ever read.
Alan
personally i preffer not using gluLookAt or something like that because it's computationally extensive. and for trig, you have to manage yourself:)
/*-------------------------------------------------------------------------------* * M A C R O S * *-------------------------------------------------------------------------------*/typedef __int64 int64;typedef unsigned __int64 uint64;#define memcpy MEMCPY#define Q_FACTOR 16#define X v[0]#define Y v[1]#define Z v[2]#define W v[3]/*-------------------------------------------------------------------------------* * B E G I N P R O G R A M * *-------------------------------------------------------------------------------*//*===========================================================================FUNCTION: xxgluCopyMatrixFx DESCRIPTION: This funtion copy one matrix to another PROTOTYPE: void xxgluCopyMatrixFx( int32 from[4][4], int32 to[4][4] ) PARAMETERS: from[4][4] : copy from this matrix to[4][4] : copy to this matrix DEPENDENCIES none RETURN VALUE none ===========================================================================*/void xxgluCopyMatrixFx( int32 from[4][4], int32 to[4][4] ){ memcpy(to, from, sizeof(int32[4][4]));}/*===========================================================================FUNCTION: xxgluCrossFx DESCRIPTION: this function performs a vector cross product PROTOTYPE: void xxgluCrossFx( int32 *n, int32 *a, int32 *b ) PARAMETERS: n : pointer to int32, result of the vector cross product a, b : pointer to int32, input of the vector cross product DEPENDENCIES none RETURN VALUE none ===========================================================================*/void xxgluCrossFx( int32 *n, int32 *a, int32 *b ){ n[0] = (int32)((((int64)a[1]*b[2]) - ((int64)a[2]*b[1]))>>Q_FACTOR); n[1] = (int32)((((int64)a[2]*b[0]) - ((int64)a[0]*b[2]))>>Q_FACTOR); n[2] = (int32)((((int64)a[0]*b[1]) - ((int64)a[1]*b[0]))>>Q_FACTOR); }/*===========================================================================FUNCTION: xxgluDotFx DESCRIPTION: this function perform a vector dot product PROTOTYPE: int32 xxgluDotFx( int32 v1[3], int32 v2[3] ) PARAMETERS: v1[3], v2[3] : dot product input vector DEPENDENCIES none RETURN VALUE return Q16 vector dot product of input parameter v1[3] and v2[3] ===========================================================================*/int32 xxgluDotFx( int32 v1[3], int32 v2[3] ){ return (int32)(((int64)((int64)v1[0]*v2[0]) + ((int64)v1[1]*v2[1]) + ((int64)v1[2]*v2[2]))>>Q_FACTOR);}/*===========================================================================FUNCTION: xxgluSqrtFx DESCRIPTION: this function perform square root PROTOTYPE: int32 xxgluSqrtFx(int32 val) PARAMETERS: val : input value for the square root function DEPENDENCIES none RETURN VALUE return Q16 square root of input parameter val ===========================================================================*/int32#define step(shift) if((0x40000000l >> shift) + sqrtVal <= val) { val -= (0x40000000l >> shift) + sqrtVal; sqrtVal = (sqrtVal >> 1) | (0x40000000l >> shift); } else { sqrtVal = sqrtVal >> 1; }xxgluSqrtFx(int32 val){// Note: This fast square root function only works with an even Q_FACTOR int32 sqrtVal = 0; step(0); step(2); step(4); step(6); step(8); step(10); step(12); step(14); step(16); step(18); step(20); step(22); step(24); step(26); step(28); step(30); if(sqrtVal < val) { ++sqrtVal; } sqrtVal <<= (Q_FACTOR)/2; return(sqrtVal);}/*===========================================================================FUNCTION: my2gl_Norm DESCRIPTION: this function nomalize a vector PROTOTYPE: int my2gl_Norm(int32 a[3]) PARAMETERS: a : pointer to a vector DEPENDENCIES none RETURN VALUE return the normalized vector of parameter a ===========================================================================*/int my2gl_Norm(int32 a[3]){ int32 n, oon; n = (int32)(((int64)a[0]*a[0]+(int64)a[1]*a[1]+(int64)a[2]*a[2])>>Q_FACTOR); n = xxgluSqrtFx(n); if (n==0) return 0; oon = (int32)(((int64)1<<(Q_FACTOR<<1)) / n); a[0] = (int32)(((int64)a[0] * oon)>>Q_FACTOR); a[1] = (int32)(((int64)a[1] * oon)>>Q_FACTOR); a[2] = (int32)(((int64)a[2] * oon)>>Q_FACTOR); return n;}/*===========================================================================FUNCTION: xxgluUnitFx DESCRIPTION: this function calucate the unit vector PROTOTYPE: int32 xxgluUnitFx( int32 vin[3], int32 vout[3] ) PARAMETERS: vin[3] : input vector vout[3] : output vector DEPENDENCIES none RETURN VALUE return Q16 unit vector of parameter vin[3] ===========================================================================*/int32 xxgluUnitFx( int32 vin[3], int32 vout[3] ){ memcpy(vout, vin, (sizeof(int32)*3)); return(my2gl_Norm(vout));}/*===========================================================================FUNCTION: xxgluLookAtMatrixFx DESCRIPTION: this function perform gluLookAt function PROTOTYPE: void xxgluLookAtMatrixFx(int32 *m, int32 ex, int32 ey, int32 ez, int32 atx, int32 aty, int32 atz, int32 ux, int32 uy, int32 uz) PARAMETERS: m : pointer to the viewing matrix ex, ey, ez : eye position in x, y and z atx, aty, atz : look at poisition in x, y and z ux, uy, uz : up vector in x, y and zDEPENDENCIES none RETURN VALUE none ===========================================================================*/void xxgluLookAtMatrixFx(int32 *m, int32 ex, int32 ey, int32 ez, int32 atx, int32 aty, int32 atz, int32 ux, int32 uy, int32 uz){ int32 vEye[3]; int32 vDir[3]; int32 vUp[3]; int32 vRight[3]; //get viewing vector vDir[0] = atx - ex; vDir[1] = aty - ey; vDir[2] = atz - ez; xxgluUnitFx(vDir, vDir); //get right vector vUp[0] = ux; vUp[1] = uy; vUp[2] = uz; xxgluCrossFx(vRight,vDir,vUp); xxgluUnitFx(vRight, vRight); //get up vector xxgluCrossFx(vUp,vRight,vDir); xxgluUnitFx(vUp, vUp); //other 3 components vEye[0] = ex; vEye[1] = ey; vEye[2] = ez; *(m+0) = vRight[0]; *(m+4) = vRight[1]; *(m+8) = vRight[2]; *(m+12) = -xxgluDotFx(vRight,vEye); *(m+1) = vUp[0]; *(m+5) = vUp[1]; *(m+9) = vUp[2]; *(m+13) = -xxgluDotFx(vUp,vEye); *(m+2) = -vDir[0]; *(m+6) = -vDir[1]; *(m+10) = -vDir[2]; *(m+14) = xxgluDotFx(vDir,vEye); *(m+3) = 0; *(m+7) = 0; *(m+11) = 0; *(m+15) = 1 << Q_FACTOR;}#undef X #undef Y #undef Z #undef W
It is made by QUALCOMM.
[Edited by - easefly on November 18, 2004 9:43:19 PM]
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement