edge turning algorithm

About Truespace Archives

These pages are a copy of the official truespace forums prior to their removal somewhere around 2011.

They are retained here for archive purposes only.

edge turning algorithm // Scriptorium

1  |  

Post by Jack Edwards // Apr 10, 2007, 11:53pm

Jack Edwards
Total Posts: 4062
pic
Here's an edge turning algorithm I came up with. Wanted to get it down in pseudo code before I forget it. If we can get the direct access to the mesh question solved I think this should be quickly implementable.

Given 2 triangles (hopefully adjacent):

tri1 should share 2 verts with tri2 (otherwise they are not adjacent and there's nothing to do.)

which means that the two non shared verts would become the two shared verts and each tri would get one of the previously shared verts.

put simply:
(Defining shared as old shared, and not shared as the old not shared)

sh1 = Shared
sh2 = other shared
ns1 = not shared 1
ns2 = not shared 2

tri1 = ns1 -> ns2 -> sh1
tri2 = ns2 -> ns1 -> sh2

Unless I'm wrong that should put both sets of normals in the same direction -- whether or not it's the right direction... *shrug* lol

So solving for sh1, sh2, ns1:

sh1 = -1; // test val to check if found
ns1 = -1; // test val to check if found
for (i=0; i<3; i++)
{
bShared = false;
for (j=0; j<3; j++)
{
if (tri1(i) == tri2(j)) {
bShared = true;
if (sh1 == -1) { sh1 = i; }
else if (sh != i) { sh2 = i; }
}
}
if (!bShared) { ns1 = i; }
}


and solving for ns2:


ns2 = -1
for (i=0; i<3; i++)
{
bShared = false;
for (j=0; j<3; j++)
{
if (tri2(i) == tri1(j)) {
bShared = true;
}
}
if (!bShared) { ns2 = i; }
}


Just add some checks before assigning the values and that sould be pretty much it...

-Jack.
Awportals.com is a privately held community resource website dedicated to Active Worlds.
Copyright (c) Mark Randall 2006 - 2024. All Rights Reserved.
Awportals.com   ·   ProLibraries Live   ·   Twitter   ·   LinkedIn