PDA

View Full Version : opengl cpu transormations



blubee
01-06-2016, 10:48 AM
Why am I getting these strange clipping issues rotating a quad on the cpu. It seems to be getting clipped out of the far plane.


typedef struct {
float angle_in_rad;
GLshort vertex_count;
GLfloat vertices[12];
GLfloat colors[16];
GLshort indices[6];
GLfloat tex_coords[8];
}r2d_quad;


I setup my view matrix with the like this:
eye: 0,0,0
center: 0, 0, -1
up: 0, 1, 0

then I translate it along the x 160units the 240units along the y axis.



( 1.000000 0.000000 0.000000 160.000000 )
( 0.000000 1.000000 0.000000 240.000000 )
( 0.000000 0.000000 1.000000 -20.000000 )
( 0.000000 0.000000 0.000000 1.000000 )
proj matrix:
( 0.006250 0.000000 0.000000 -1.000000 )
( 0.000000 0.004167 0.000000 -1.000000 )
( 0.000000 0.000000 -0.020020 -1.002002 )
( 0.000000 0.000000 0.000000 1.000000 )


when I rotate the quad along all three axis at once, it seems to be getting clipped on the far plane.

When I take a look at the quad's vertex position they are like this:


( -1.155303 -57.152637 -41.619965 )
( -14.622830 -40.532307 56.065014 )
( 1.155303 57.152637 41.619965 )
( 14.622830 40.532307 -56.065014 )


I don't see why there would be any clipping.

If I change my view matrix to something very large like translating the view matrix to -100 and making the projection matrix near 0.0 and far 1000.0 then the clipping disappears.


view matrix:
( 1.000000 0.000000 0.000000 160.000000 )
( 0.000000 1.000000 0.000000 240.000000 )
( 0.000000 0.000000 1.000000 -100.000000 )
( 0.000000 0.000000 0.000000 1.000000 )
proj matrix:
( 0.006250 0.000000 0.000000 -1.000000 )
( 0.000000 0.004167 0.000000 -1.000000 )
( 0.000000 0.000000 -0.002000 -1.000200 )
( 0.000000 0.000000 0.000000 1.000000 )


why do i need to set my view volume so large for such a simple scene not to get clipped by the far plane?