PDA

View Full Version : MODELVIEW matrix values overflowing



starman
06-19-2003, 05:33 PM
Me and my planet simulation again. I'm getting the position of the planet and moon out of the MODELVIEW matrix - elements 12, 13, and 14 - and the z values (element 14) are growing quickly until I get a floating point exception. But the orbit distances I'm using are constant -- I've verified they don't change by logging them -- so I don't see how that could happen. The only thing changing every frame are the year and day rotation values. The render code used by both planet and moon is shown below. I'm stuck here.

void Satellite::render()
{
glPushMatrix();
glRotatef(impl_->year_, 0.0f, 1.0f, 0.0f);
glTranslatef(impl_->orbit_, 0.0f, 0.0f);
glRotatef(impl_->day_, 0.0f, 1.0f, 0.0f);

float m[16];
glMatrixMode(GL_MODELVIEW_MATRIX);
glGetFloatv(GL_MODELVIEW_MATRIX, m);

impl_->position_.x = m[12];
impl_->position_.y = m[13];
impl_->position_.z = m[14];

// Draws the gluSphere
glCallList(impl_->listName_);
glPopMatrix();
}

starman
06-20-2003, 08:23 AM
I actually got this notion of using elements 12, 13, and 14 from the modelview matrix for my moon position from this article:
http://sjbaker.org/steve/omniv/matrices_can_be_your_friends.html

Am I reading something incorrectly there? Assuming my transformations are correct, should this work?