Size a Triangle in place.

Blitz3D Forums/Blitz3D Programming/Size a Triangle in place.

Get each verticy X,Y, and Z values for the triangle:

X1# = first verticy X location
Y1# = first verticy Y location
Z1# = first verticy Z location

X2# = second verticy X location
Y2# = second verticy Y location
Z2# = second verticy Z location

X3# = third verticy X location
Y3# = third verticy Y location
Z3# = third verticy Z location

Then average each together:

CenterX# = (X1+X2+X3)/3
CenterY# = (Y1+Y2+Y3)/3
CenterZ# = (Z1+Z2+Z3)/3

Then find the tanget space values for these verticies:

TanX1# = X1 - CenterX
TanY1# = Y1 - CenterY
TanZ1# = Z1 - CenterZ

TanX2# = X2 - CenterX
TanY2# = Y2 - CenterY
TanZ2# = Z2 - CenterZ

TanX3# = X3 - CenterX
TanY3# = Y3 - CenterY
TanZ3# = Z3 - CenterZ

Then apply your scaleing factor (1 = same size, .5 = half size, 2 = twice the size, etc..)

TanX1 = TanX1 * scale
TanY1 = TanY1 * scale
TanZ1 = TanZ1 * scale

TanX2 = TanX2 * scale
TanY2 = TanY2 * scale
TanZ2 = TanZ2 * scale

TanX3 = TanX3 * scale
TanY3 = TanY3 * scale
TanZ3 = TanZ3 * scale

Then apply this to the triangle verticies...you do this by transforming (adding) the scaled tangent space X,Y,Z to the center X,Y,Z...which gives you the location the original verticies should be located at

First verticy new X = TanX1 + CenterX
First verticy new Y = TanY1 + CenterY
First verticy new Z = TanZ1 + CenterZ

Second verticy new X = TanX2 + CenterX
Second verticy new Y = TanY2 + CenterY
Second verticy new Z = TanZ2 + CenterZ

Third verticy new X = TanX3 + CenterX
Third verticy new Y = TanY3 + CenterY
Third verticy new Z = TanZ3 + CenterZ


pretty simple...