Public feed
#725096
// Specify positions of all clipping planes
// - this is called from WorldView.draw()
// - it calls placeClipPlane() below 6 times -- once for each
// side of the view volume
public void placeClipPlanes(GL gl)
{
gl.glPushMatrix();
gl.glTranslated(-Camera.tx(), -Camera.ty(), -Camera.tz());
gl.glRotated(-Camera.roll(), 0.0, 0.0, 1.0);
gl.glRotated(-Camera.yaw(), 0.0, 1.0, 0.0);
gl.glRotated(-Camera.pitch(), 1.0, 0.0, 0.0);
placeClipPlane(gl, 5, new Point3d(Camera.right(),Camera.bottom(),Camera.near()),
new Point3d(Camera.right(),Camera.top(),Camera.near()),
new Point3d(Camera.left(),Camera.top(),Camera.near()));
gl.glPopMatrix();
}
// Specify position of one particular clipping plane given 3
// points on the plane ordered counter-clockwise
void placeClipPlane(GL gl, int plane, Point3d p1, Point3d p2, Point3d p3)
{
// Plane equation Ax + By + Cz + D stored as [A,B,C,D]
double[] eqn = new double[4];
// Compute the plane equation from the 3 points -- fill in eqn[]
//
Vector3d v1 = new Vector3d(p1);
Vector3d v2 = new Vector3d(p3);
v1.sub(p2);
v2.sub(p2);
Vector3d normal = new Vector3d();
normal.cross(v1,v2);
normal.normalize();
eqn[0]=normal.x;
eqn[1]=normal.y;
eqn[2]=normal.z;
eqn[3]=-(p1.x*normal.x+p1.y*normal.y+p1.z*normal.z);
System.out.println(" " + p1.z);
// Specify the clipping plane
gl.glClipPlane(plane, eqn, 0);
}