suo_alex

02-21-2003, 07:36 PM

My code is like the following. All the data are proven to be correct and the single SoftTranslatef() is also correct.

/**

* Get the look at matrix and store it into the matrix.

*

* NOTE : here the matrix is stored rather than multiplied.

*

* eye_x : the x coordinate of the eye point.

* eye_y : the y coordinate of the eye point.

* eye_z : the z coordinate of the eye point.

* center_x : the x coordinate of the center point.

* center_y : the y coordinate of the center point.

* center_z : the z coordinate of the center point.

* up_x : the x coordiante of the up vector.

* up_y : the y coordiante of the up vector.

* up_z : the z coordiante of the up vector.

* *m : the matrix to be stored.

*/

void SoftGl::SoftLookAt(GLfloat eye_x, GLfloat eye_y, GLfloat eye_z,

GLfloat center_x, GLfloat center_y, GLfloat center_z,

GLfloat up_x, GLfloat up_y, GLfloat up_z, GLfloat *m)

{

GLfloat head_vector[3];

GLfloat roll_vector[3];

GLfloat up_vector[3];

head_vector[0] = center_x - eye_x;

head_vector[1] = center_y - eye_y;

head_vector[2] = center_z - eye_z;

up_vector[0] = up_x;

up_vector[1] = up_y;

up_vector[2] = up_z;

//get the effect of rotate first

GeoUtility::Normalize(head_vector);

GeoUtility::Normalize(up_vector);

GeoUtility::XProduct(head_vector, up_vector, roll_vector);

GeoUtility::Normalize(roll_vector);

memset(m, 0, 16 * sizeof(GLfloat));

memcpy(m, roll_vector, 3 * sizeof(GLfloat));

memcpy(m + 4, up_vector, 3 * sizeof(GLfloat));

memcpy(m + 8, head_vector, 3 * sizeof(GLfloat));

m[15] = 1;

//then multiply the translation

//notice that the translation is to the reverse direction

SoftTranslatef(-eye_x, -eye_y, -eye_z, m);

}

However, when I tried this code with a single translation to the positive direction of z axis, the [10] position of the matrix is -1, while the matrix got from OpenGL stack is 1.

Anyone can tell me what is the problem of the above code? I really was confused.

Thank you very much.

/**

* Get the look at matrix and store it into the matrix.

*

* NOTE : here the matrix is stored rather than multiplied.

*

* eye_x : the x coordinate of the eye point.

* eye_y : the y coordinate of the eye point.

* eye_z : the z coordinate of the eye point.

* center_x : the x coordinate of the center point.

* center_y : the y coordinate of the center point.

* center_z : the z coordinate of the center point.

* up_x : the x coordiante of the up vector.

* up_y : the y coordiante of the up vector.

* up_z : the z coordiante of the up vector.

* *m : the matrix to be stored.

*/

void SoftGl::SoftLookAt(GLfloat eye_x, GLfloat eye_y, GLfloat eye_z,

GLfloat center_x, GLfloat center_y, GLfloat center_z,

GLfloat up_x, GLfloat up_y, GLfloat up_z, GLfloat *m)

{

GLfloat head_vector[3];

GLfloat roll_vector[3];

GLfloat up_vector[3];

head_vector[0] = center_x - eye_x;

head_vector[1] = center_y - eye_y;

head_vector[2] = center_z - eye_z;

up_vector[0] = up_x;

up_vector[1] = up_y;

up_vector[2] = up_z;

//get the effect of rotate first

GeoUtility::Normalize(head_vector);

GeoUtility::Normalize(up_vector);

GeoUtility::XProduct(head_vector, up_vector, roll_vector);

GeoUtility::Normalize(roll_vector);

memset(m, 0, 16 * sizeof(GLfloat));

memcpy(m, roll_vector, 3 * sizeof(GLfloat));

memcpy(m + 4, up_vector, 3 * sizeof(GLfloat));

memcpy(m + 8, head_vector, 3 * sizeof(GLfloat));

m[15] = 1;

//then multiply the translation

//notice that the translation is to the reverse direction

SoftTranslatef(-eye_x, -eye_y, -eye_z, m);

}

However, when I tried this code with a single translation to the positive direction of z axis, the [10] position of the matrix is -1, while the matrix got from OpenGL stack is 1.

Anyone can tell me what is the problem of the above code? I really was confused.

Thank you very much.