aiscape

01-26-2003, 01:24 AM

Hi!

I've written a function that should rotate my object around a defined

point by a defined angle, but somethings wrong with it. When calling this function repeatedly using the same parameters in the windows draw function the motion of my object describes something like an ellipse and its center isn't 0,0,0.

void CMyObject::RotateAroundY(GLdouble _ang, GLdouble _x, GLdouble _y,

GLdouble _z)

{

_ang = _ang * PI / 180.0;

m_yrotationsmatrix[0] = cos(_ang);

m_yrotationsmatrix[2] = -sin(_ang);

m_yrotationsmatrix[8] = sin(_ang);

m_yrotationsmatrix[10] = cos(_ang);

glMatrixMode(GL_MODELVIEW);

glLoadMatrixd(m_modelmatrix);

GLdouble tcx = -(m_modelmatrix[12] - _x);

GLdouble tcy = -(m_modelmatrix[13] - _y);

GLdouble tcz = -(m_modelmatrix[14] - _z);

m_translationsmatrix[12] = tcx;

m_translationsmatrix[13] = tcy;

m_translationsmatrix[14] = tcz;

glMultMatrixd(m_translationsmatrix);

glMultMatrixd(m_yrotationsmatrix);

m_translationsmatrix[12] = -tcx;

m_translationsmatrix[13] = -tcy;

m_translationsmatrix[14] = -tcz;

glMultMatrixd(m_translationsmatrix);

glGetDoublev(GL_MODELVIEW_MATRIX,m_modelmatrix);

}

I've tested these values:

_x,_y,_z = 0;

Initial m_modelmatrix[12] = -3;

m_modelmatrix[13] = 0;

m_modelmatrix[14] = 0;

Any idea what's wrong?

Thanks.

I've written a function that should rotate my object around a defined

point by a defined angle, but somethings wrong with it. When calling this function repeatedly using the same parameters in the windows draw function the motion of my object describes something like an ellipse and its center isn't 0,0,0.

void CMyObject::RotateAroundY(GLdouble _ang, GLdouble _x, GLdouble _y,

GLdouble _z)

{

_ang = _ang * PI / 180.0;

m_yrotationsmatrix[0] = cos(_ang);

m_yrotationsmatrix[2] = -sin(_ang);

m_yrotationsmatrix[8] = sin(_ang);

m_yrotationsmatrix[10] = cos(_ang);

glMatrixMode(GL_MODELVIEW);

glLoadMatrixd(m_modelmatrix);

GLdouble tcx = -(m_modelmatrix[12] - _x);

GLdouble tcy = -(m_modelmatrix[13] - _y);

GLdouble tcz = -(m_modelmatrix[14] - _z);

m_translationsmatrix[12] = tcx;

m_translationsmatrix[13] = tcy;

m_translationsmatrix[14] = tcz;

glMultMatrixd(m_translationsmatrix);

glMultMatrixd(m_yrotationsmatrix);

m_translationsmatrix[12] = -tcx;

m_translationsmatrix[13] = -tcy;

m_translationsmatrix[14] = -tcz;

glMultMatrixd(m_translationsmatrix);

glGetDoublev(GL_MODELVIEW_MATRIX,m_modelmatrix);

}

I've tested these values:

_x,_y,_z = 0;

Initial m_modelmatrix[12] = -3;

m_modelmatrix[13] = 0;

m_modelmatrix[14] = 0;

Any idea what's wrong?

Thanks.