Game Development Reference
In-Depth Information
These structs will be used in the next procedures as array elements. The p1..p3 variables will contain vertices
in 2D or 3D spaces. They are needed to store information about the triangle's edges to find the right ones to swap or
delete from the Delaunay triangulation mesh.
fn ut_compareAngle v1 v2 =
(
if(v1.z < v2.z) then return -1
else return 1
)
The function ut_compareAngle will be used to compare the angles between the Voronoi cell center and its
surrounding vertices to find the right order to get a proper convex polygon. MAXScript lets the user define his own
compare function to sort arrays containing complex elements. According to the MAXScript documentation, the qsort
command takes the array and a comparison function as input. This comparison procedure will take two values as
arguments and return 0 if the values are equivalent, -1 if the first value is less than the second value, and 1 in the
other case.
fn ut_compareVx v1 v2 =
(
if(v1.x < v2.x) then return -1
else if(v1.x > v2.x) then return 1
else return 0
)
The ut_compareVx procedure will be used to compare two vertices and order their array along X axis values.
fn ut_isInsideCircumcircle p t &circumCircle =
(
--check for the coincidence
if( abs(t.p1.y - t.p2.y) == 0 and abs(t.p2.y - t.p3.y) == 0 ) then
(
print("error, coincidence\n");
return false
)
if(abs(t.p2.y - t.p1.y) == 0) then
(
m2 = -(t.p3.x - t.p2.x) / (t.p3.y - t.p2.y)
mx2 = (t.p2.x + t.p3.x) / 2.0
my2 = (t.p2.y + t.p3.y) / 2.0
circumCircle.x = (t.p2.x + t.p1.x) / 2.0
circumCircle.y = m2 * (circumCircle.x - mx2) + my2
)
else if ( abs(t.p3.y-t.p2.y) == 0 ) then
(
m1 = - (t.p2.x-t.p1.x) / (t.p2.y-t.p1.y)
mx1 = (t.p1.x + t.p2.x) / 2.0
my1 = (t.p1.y + t.p2.y) / 2.0
circumCircle.x = (t.p3.x + t.p2.x) / 2.0
circumCircle.y = m1 * (circumCircle.x - mx1) + my1
)
Search WWH ::




Custom Search