Hi All,
I have a dumb question here but just can’t seem to figure it out. I have my matrices setup as follows
GL.glViewport(x, y, width, height);
GL.glMatrixMode(GL.GL_PROJECTION); GL.glLoadIdentity();
GL.glOrtho(0,640,0,480,1000000,-1000000);
GL.glMatrixMode(GL.GL_MODELVIEW);
GL.glLoadIdentity();
this is using JOGL (Java) by the way any way I am submitting a series of vertices and they get clipped when I think they should not (I’ve been using the feedback buffer to check this). I use the following to submit the vertices
gl.glBegin(GL.GL_LINE_LOOP);
gl.glColor4f(1,1,0,1.0f/3.0f);
gl.glVertex4f(ptaa[0],ptaa[1],ptaa[2],ptaa[3]);
gl.glVertex4f(ptbb[0],ptbb[1],ptbb[2],ptbb[3]);
gl.glVertex4f(ptdd[0],ptdd[1],ptdd[2],ptdd[3]);
gl.glVertex4f(ptcc[0],ptcc[1],ptcc[2],ptcc[3]);
gl.glEnd();
where ptaa - ptdd are generated. If I submit them in the following form with out dividing across by H as follows
ptaa [-261.3766 -261.37653 -2624.2202 -5.2275305]
ptbb [-3201.8552 -271.3437 -2724.2903 -5.426873]
ptcc [-239.51077 -2059.7922 -2404.688 -4.790215]
ptdd [-2924.6704 -2131.539 -2488.448 -4.957068]
They are culled (not displayed). However, if I divide across by H and submit them then as follows
ptaa [50.00001 50.0 501.99997 1.0]
ptbb [590.0 50.000004 502.0 1.0]
ptcc [50.000004 429.99994 502.0 1.0]
ptdd [590.00006 429.99997 501.99997 1.0]
then they are displayed fine. So my question is when does the clipping occur it seems it happens before the divide by H? So how do I alter the clip volume to allow these kind of vertices through. Ideally I want to submit my points in the following for and have a matrix perform the projection. In this case the points will be submitted as follows
pta [0.7680671 0.52067035 5.2275305 1.0]
ptb [6.625495 0.54052526 5.426873 1.0]
ptc [0.7247276 4.103172 4.790215 1.0]
ptd [6.073568 4.2460938 4.957068 1.0]
and the transformation matrix is given by
[-502.0 -0.0 -0.25 125.5]
[-0.0 -502.0 -0.0 0.0]
[-0.0 -0.0 -502.0 0.0]
[-0.0 -0.0 -1.0 0.0]
which project a point throught a center of projection unto a plane to produce the point ptaa-ptdd used before. But if I use this as my model view matrix the points are clipped just like the first set. This matrix is produced by the followin routine
/**
* Projects a point unto a plane via a ray starting at the center of projection
* @param COP center of projection
* @param plane plane coefficients ax + by + cz + d = 0
* @param M resulting matrix to perform projection
*/
public static void MProjectToPlane4x4(float[] COP,float[] plane,float[] M)
{
float NCOP = DotProduct3D(plane,COP);
M[0] = NCOP + plane[3] - COP[0]*plane[0]; M[4] = -COP[0]*plane[1]; M[ 8] = -COP[0]*plane[2]; M[12] = -COP[0]*plane[3];
M[1] = -COP[1]*plane[0]; M[5] = NCOP + plane[3] - COP[1]*plane[1]; M[ 9] = -COP[1]*plane[2]; M[13] = -COP[1]*plane[3];
M[2] = -COP[2]*plane[0]; M[6] = -COP[2]*plane[1]; M[10] = NCOP + plane[3] - COP[2]*plane[2]; M[14] = -COP[2]*plane[3];
M[3] = -plane[0]; M[7] = -plane[1]; M[11] = -plane[2]; M[15] = NCOP;
}
Does anyone have a idea as to how to get around this?
Regards,
William Leeson