3, using the method of clipping space to extract the plane
In the previous article, we discussed the six-sided extraction of the cones by means of geometrical methods. In this article, we continue to discuss the method of clipping space to extract the plane of the cones.
Assuming that there is a point p= (x,yz,1) in the world coordinate system now, the Modelview matrix is recorded as the M,projection matrix as p. When point P passes through these two matrix transformations to the position of pc= (XC,YC,ZC,WC), i.e.
Because the PC point is represented by the homogeneous coordinates, it is then converted to PCN:
In a regularization clipping space, the center of the Cone is aligned with the origin of the Unit cube, and its six planes are defined by the following planes:
- Left Plane:x ' =-1
- Right plane:x ' = 1
- Top plane:y ' = 1
- Bottom plane:y ' =-1
- Near Plane:z ' =-1
- Far plane:z ' = 1
Then, when the coordinates of pcn= (x ', y ', z ') satisfy the following relationship, the PCN is shown to be inside the cone:
One step forward, there is no regularization of the pc= (XC,YC,ZC), if you want to inside the cone, then its coordinate range is:
Based on this information, we can use world coordinates to set the six plane, for example, when the PC point on the left plane of the "right" side, it must meet:
Continue to push forward, consider the coordinates of point P, remember A=mp, as shown in
The XC and WC coordinates in the point PC can be calculated using the following formula:
The P-point can be represented by the following inequalities on the right side of the left plane of the cone of view:
After the following simple algebraic transformations:
We can get the general equation of the left plane: (ax+by+cz+d=0)
where col1 and Col4 represent the first and fourth columns of the A matrix, respectively.
If we just need to consider a point in the plane to the left or right, then the definition above is sufficient, but in the back we also want to check whether the sphere on the left side of the plane or the right side, this need to calculate the distance between the spherical surface to the plane. It is also necessary to generalize the plane, that is, to find out its general equation.
The right plane can also be obtained in the same way:
Coefficients of the right plane equation:
The remaining planes:
Lower plane
Upper plane
Near plane
Far plane
"Translation" View Frustum culling--3 Clip Space approach–extracting the Planes