PDA

View Full Version : glGetFloatv not returning what I expect



Bryan Taylor
11-29-2008, 07:20 PM
I have code that renders a stick figure and can render a cloud of points surrounding that stick figure. Now I need to retrieve the point locations. I am using glGetFloatv for this task.

Once I have retrieved the points I attempt to render them to verify that they are correct. They are not correct, and they seem to move when I move the camera, which is odd since the stick figure doesn't move with the camera.

Here is the code that can render or retrieve the points. Does anyone notice anything wrong with it? Keep in mind that the top part of the if statement renders the points correctly.


for (unsigned int p = 0; p < pose.skeleton->point_cloud_rotations.size(); ++p) {
glPushMatrix();
glRotate(pose.skeleton->point_cloud_rotations[p]);
glTranslated(pose.skeleton->bones[B].radius*1.5, 0,
(double)p/pose.skeleton->point_cloud_rotations.size() * pose.skeleton->bones[B].length);

if (render &amp;&amp; show_cloud) {
if (color)
glColor4f(pose.skeleton->bones[B].color.x * 0.8, pose.skeleton->bones[B].color.y * 0.8, pose.skeleton->bones[B].color.z * 0.8, alpha);
gluSphere(quad, pose.skeleton->bones[B].radius / 2.0, 8, 8);
}
else if (!render) {
GLfloat mat[16];
Vector4f origin;
origin.x = 0;
origin.y = 0;
origin.z = 0;
origin.w = 1;
glGetFloatv(GL_MODELVIEW_MATRIX, mat);
pose.points_in_cloud[B][p] = transpose(make_matrix< float, 4, 4 >(mat)) * origin;
}

glPopMatrix();
}


Here is the function that I use to render the points I retrieve using the above code. I there something wrong with this?


void Character::draw_points_in_cloud(Pose const &amp;pose, State const &amp;state) {
glPushMatrix();
glTranslate(state.position);
glRotatef(state.orientation * 180.0f / (float)M_PI, 0.0f, 1.0f, 0.0f);

static GLUquadric *quad = NULL;
if (quad == NULL) {
quad = gluNewQuadric();
}

for (unsigned int b = 0; b < pose.points_in_cloud.size(); ++b) {
for (unsigned int p = 0; p < pose.points_in_cloud[B].size(); ++p) {
glPushMatrix();
glTranslatef(pose.points_in_cloud[B][p].x, pose.points_in_cloud[B][p].y, pose.points_in_cloud[B][p].z);

glColor4f(pose.skeleton->bones[B].color.x * 0.8, pose.skeleton->bones[B].color.y * 0.8, pose.skeleton->bones[B].color.z * 0.8, 1.0f);
gluSphere(quad, pose.skeleton->bones[B].radius / 2.0, 8, 8);
glPopMatrix();
}
}

glPopMatrix();
}


Let me know if I need to post any additional information or be more clear.

Thanks,
Bryan

Bryan Taylor
11-29-2008, 08:19 PM
Nevermind, I fixed it.

There was something wrong. The points were correct, but I needed to load the identity matrix before rendering them.