Problem: So, let's say I have a plane3di myPlane that is defined by 3 vertexes:
Vertex 1: -96 -128 -32
Vertex 2: -96 -128 32
Vertex 3: 256 -128 32
Next, let's say I got some vertex that DOES NOT belong to this plain (is not planar): -96, -384, 32
For some reason, myPlane.classifyPointRelation(vertex3di(-96, -384, 32)) returns ISREL3D_PLANAR. And that was for some other values, however 95% of all blocks (I had ~30 of them in my world) were drawn correctly.
To speed things up: the Y values for all 3 myPlane-defining vertexes are the same, that means this plane is parallel to XZ plane. Thus, any poing that has diverent Y value authomatically doesn't belong to myPlane. That's it.
My solution was to make a function for myself to calculate if the point belongs to plain specified by other three points. It is based on matrix principle.
Here is it:
Code: Select all
bool isPointOnPlane(vector3di p1, vector3di p2, vector3di p3, vector3di point)
{
return ((point.X-p1.X)*(p2.Y-p1.Y)*(p3.Z-p1.Z)+
(point.Y-p1.Y)*(p2.Z-p1.Z)*(p3.X-p1.X)+
(point.Z-p1.Z)*(p3.Y-p1.Y)*(p2.X-p1.X)-
(point.Z-p1.Z)*(p2.Y-p1.Y)*(p3.X-p1.X)-
(point.Y-p1.Y)*(p2.X-p1.X)*(p3.Z-p1.Z)-
(point.X-p1.X)*(p2.Z-p1.Z)*(p3.Y-p1.Y))?false:true;
}
Looking forward to reply and willing to contribute if I can
BTW, I use Irrlicht v1.7.3.
Before:
After: