Weird "stretching" object
Hi,
I am rendering a falling cube (it's from an ODE simulation), but for some weird reason the cube appears to "stretch", actually it looks like it gets longer. I don't have an exact value but say, it's 1 x 10 x 1 (width, height, length) as it falls and then shrinks too it's normal size 1 x 1 x 1.
Falling:![[Image: f_Picture1m_0e0e58d.png]](http://img32.picoodle.com/img/img32/8/6/13/f_Picture1m_0e0e58d.png)
Proper size, once landed:
![[Image: f_Picture3m_423cdef.png]](http://img37.picoodle.com/img/img37/8/6/13/f_Picture3m_423cdef.png)
(the small white square is just something i put in to mark the floor)
I've checked the dimensions as it falls and they don't change.
I've tried clearing all the buffers just in case the "stretch" is actually caused by a buffer not clearing properly but that hasn't made a difference.
Does anyone have any ideas as to what might be causing the problem?
I am rendering a falling cube (it's from an ODE simulation), but for some weird reason the cube appears to "stretch", actually it looks like it gets longer. I don't have an exact value but say, it's 1 x 10 x 1 (width, height, length) as it falls and then shrinks too it's normal size 1 x 1 x 1.
Falling:
![[Image: f_Picture1m_0e0e58d.png]](http://img32.picoodle.com/img/img32/8/6/13/f_Picture1m_0e0e58d.png)
Proper size, once landed:
![[Image: f_Picture3m_423cdef.png]](http://img37.picoodle.com/img/img37/8/6/13/f_Picture3m_423cdef.png)
(the small white square is just something i put in to mark the floor)
I've checked the dimensions as it falls and they don't change.
I've tried clearing all the buffers just in case the "stretch" is actually caused by a buffer not clearing properly but that hasn't made a difference.
Does anyone have any ideas as to what might be causing the problem?
Are you continually multiplying the transformation matrix as the frames go on?
All of your drawing code posted may help...
All of your drawing code posted may help...
The way I'm drawing the cube is:
1. Get its position in the ODE world (x, y and z)
2. Get its rotational matrix from ODE and converting it to be an OpenGL matrix
3. I translate the cube using its x, y and z
4. And then glMultMatrixf () the rotational matrix
I've pasted in the code below:
The Render() function. ODE coordinates are defined as the centre of the object's body so I've altered them to draw the cube correctly in OpenGL.
I'm not sure if I'm using glTranslatef() correctly, but my reasoning was that I could draw the cube using a display list, I just haven't gotten around to it yet.
It's melting my face at the moment, I think I spent a bit too long at it today. I might have bitten off more than I can chew with the 3D graphics but this is the first time I've had a problem like this.
1. Get its position in the ODE world (x, y and z)
2. Get its rotational matrix from ODE and converting it to be an OpenGL matrix
3. I translate the cube using its x, y and z
4. And then glMultMatrixf () the rotational matrix
I've pasted in the code below:
Code:
// the update...
Vector3 posn = odeWorld->GetPosition(cubert.getVisual(0).geom);
const dReal *rot = odeWorld->GetRotation(cubert.getVisual(0).geom);
cubert.SetPosition(posn.GetX(), posn.GetY(), posn.GetZ());
cubert.ConvertMatrix(rot);
cubert.Render();
The Render() function. ODE coordinates are defined as the centre of the object's body so I've altered them to draw the cube correctly in OpenGL.
I'm not sure if I'm using glTranslatef() correctly, but my reasoning was that I could draw the cube using a display list, I just haven't gotten around to it yet.
Code:
...
...
float width = GetWidth();
float height = GetHeight();
float length = GetLength();
// top left coordinate of the geometry
float x = GetX() - (width / 2.0f);
float y = GetY() + (height / 2.0f);
float z = GetZ() - (length / 2.0f);
glPushMatrix();
glTranslatef(x, y, z);
glMultMatrixf(rotMatrix);
glBegin(GL_QUADS); // Start Drawing The Cube
// RED
glColor3f(1.0f, 0.0f, 0.0f);
// back wall
glVertex3f(width, y, z); // top right
glVertex3f(x, y, z); // top left
glVertex3f(x, -height, z); // bottom left
glVertex3f(width, -height, z); // bottom right
// front wall
glVertex3f(width, y, length); // top right
glVertex3f(x, y, length); // top left
glVertex3f(x, -height, length); // bottom left
glVertex3f(width, -height, length); // bottom right
// "floor"
glVertex3f(width, -height, z); // top right
glVertex3f(x, -height, z); // top left
glVertex3f(x, -height, length); // bottom left
glVertex3f(width, -height, length); // bottom right
// "roof"
glVertex3f(width, y, z); // top right
glVertex3f(x, y, z); // top left
glVertex3f(x, y, length); // bottom left
glVertex3f(width, y, length); // bottom right
// left wall
glVertex3f(x, y, z); // top right
glVertex3f(x, y, length); // top left
glVertex3f(x, -height, length); // bottom left
glVertex3f(x, -height, z); // bottom right
// right wall
glVertex3f(width, y, z); // top right
glVertex3f(width, y, length); // top left
glVertex3f(width, -height, length); // bottom left
glVertex3f(width, -height, z); // bottom right
glEnd();
glPopMatrix();
}
It's melting my face at the moment, I think I spent a bit too long at it today. I might have bitten off more than I can chew with the 3D graphics but this is the first time I've had a problem like this.
Uhhh, glad I could help?
Your API should be able to spit out an entire transformation matrix which contains the rotation + translation for one smooth glMultMatrix call instead of translate/mult. Not that it matters a whole lot.
