Skip to main content
gamedev.net
🔒 Locked

Problem with glMultMatrix

Started by FreaknBIgPanda Jun 15, 2010 at 2:15 PM 0 replies 1.2k views
Original Post
FreaknBIgPanda
FreaknBIgPanda
I've been playing around with OpenGL recently and I've run into a problem that I seem unable to solve... I think I'm missing something basic about how OpenGL handles the matrix stack.

Basically what I'm trying to do right now is implement a virtual 'trackball' on my screen so that the user can manipulate the displayed model. I'm trying to do rotations, basically what happens is the user clicks inside the virtual trackball and then drags to a position inside the trackball tracing out a vector inside a virtual sphere. A rotation is applied around this vector the angle of which is the length of the vector in radians.

So here's the code that's messing up:

	if(matrix[1]) {	glMultMatrixd(matrix);}glRotated(rot_vector.length()*57.2957795, rot_vector[0], rot_vector[1], rot_vector[2]);glGetDoublev(GL_MODELVIEW_MATRIX, matrix);


If I take out the glMultMatrixd is works as expected but the rotation isn't persistent, i.e on the next mouse click the model gets reset to the center of the screen regardless of the rotation I applied b4. I want the rotation to be persistent so that the user can click again and the model will rotate around this new vector. With the above code it gets really crazy like the rotations go waaay outside of the viewport. a very small rotation produces huge results.

I was trying to save the matrix with the GetDoublev and then load it on the next frame (above code is called every frame) but it's not working. Anyone have any suggestions?

Thanks in advance!!
21st Century Moose
21st Century Moose
I bet you have ATI hardware!

Change glMultMatrixd and glRotated to the -f versions and try it. Also use glGetFloatv, not glGetDoublev. And generally switch to using floats instead of doubles; OpenGL will like you a lot better for it (it uses floats internally, so you're better off using them yourself).
Direct3D has need of instancing, but we do not. We have plenty of glVertexAttrib calls. 

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.