PDA

View Full Version : OpenglES 1.1 for ARMv4i. Problem with LooktAt!!



lucasescucha
01-07-2010, 06:59 AM
Hi, i'm Lucas. I'm have a problem. When i use the LookAt function (make by me) in c# over a ARMv4i, Opengl draw any thing. Draw erroneous images. Here are the code that i'm usign:



public static unsafe void LookAtd(double centerx, double centery, double centerz, double eyex,
double eyey, double eyez, double upx, double upy, double upz)
{
var forward = new double[3];
var side = new double[3];
var up = new double[3];
var m = new float[4, 4];

forward[0] = eyex - centerx;
forward[1] = eyey - centery;
forward[2] = eyez - centerz;

//normalizef(forward)
var r = Math.Sqrt(forward[0]*forward[0] + forward[1]*forward[1] +
forward[2]*forward[2]);

if (r == 0.0f)
return;

r = 1.0f/r;

forward[0] *= r;
forward[1] *= r;
forward[2] *= r;
//fin normalizef(forward)

up[0] = upx;
up[1] = upy;
up[2] = upz;

//crossf(forward, up, side)
side[0] = forward[1]*up[2] - forward[2]*up[1];
side[1] = forward[2]*up[0] - forward[0]*up[2];
side[2] = forward[0]*up[1] - forward[1]*up[0];
//fin crossf(forward, up, side)

//normalizef(side)
r = Math.Sqrt(side[0]*side[0] + side[1]*side[1] +
side[2]*side[2]);

if (r == 0.0f)
return;

r = 1.0f/r;

side[0] *= r;
side[1] *= r;
side[2] *= r;

up[0] = upx;
up[1] = upy;
up[2] = upz;
//fin normalizef(side)

//crossf(side, forward, up)
up[0] = side[1]*forward[2] - side[2]*forward[1];
up[1] = side[2]*forward[0] - side[0]*forward[2];
up[2] = side[0]*forward[1] - side[1]*forward[0];
//fin crossf(side, forward, up)

//__identf(&m[0][0])
m[0, 3] = m[1, 3] = m[2, 3] = m[3, 0] = m[3, 1] = m[3, 2] = 0;

m[3, 3] = 1;
//fin __identf(&m[0][0])

m[0, 0] = (float)side[0];
m[1, 0] = (float)side[1];
m[2, 0] = (float)side[2];

m[0, 1] = (float)up[0];
m[1, 1] = (float)up[1];
m[2, 1] = (float)up[2];

m[0, 2] = (float)-forward[0];
m[1, 2] = (float)-forward[1];
m[2, 2] = (float)-forward[2];

fixed (float* punterom = m)
{
gl.MultMatrixf(punterom);
}

gl.Translatef((float)-centerx, (float)-centery, (float)-centerz);
}

and the lookat call:


gl.MatrixMode(gl.GL_MODELVIEW);
gl.LoadIdentity();
LookAtf(a,b,c,d,e,f,0,0,1);


Please help me!!!. i don't now what can be the problem. Possible be a overflow or a math problem (matrix multiplication), and sorry i don't now english very much, i'm from Argentina. A lot of thank you!!!!