Lesson #2: automatic calculation (part one)
Re-reading myself in our first lesson, I think I made a very poor job of explaining vectors. Maybe this site will do it better. I also hope this drawing will help;
View attachment 36605
The formula of the preceding lesson was just an application of the Pythagorean Theorem to 3D distance. The vector length is determined by the distance between RefPoint and the surface on which our polygon stands. The vector coordinates are as long as possible to increase accuracy, the same way an architect protractor is way larger than a first grade schoolboy protractor. The vector length is capable of a precision of six digits after the decimal point, again for accuracy purpose. Back to lesson 2.
By one of these mysteries fathered by the twisted minds of programmers, automation is for humans and "manual" for computers... go figure!
Now that we have saved our souls from eternal mathematical damnation, a word about our savior; the automatic calculation.
How does automatic calculation works? We need to know that, if only to use it wisely.
The "
a" is for "automatic" and "
ai" for "automatic inverted". Basically, automatic calculation will texture the side exterior to
RefPoint and automatic inverted the side interior to
RefPoint if your polygon's vertices are called in a clockwise order. This is, almost
verbatim, the usual formula "experts" are using. I must say, to my own shame, that I never explored thoroughly the automatic calculation. When things were not going my way, I would fiddle around until they did. So this lesson will be as much for me as it is for you; let's learn together, shall we?
We need to turn our "wall" into a "yard" first. This drawing should help you to follow;
View attachment 36606
We will "paint" each interior walls first, then exterior ones. From the exterior, points calling is done clockwise and, when seen from the interior, anticlockwise. Refer to the drawing above;
:BEGINNING
;Yard red and green 10x10x10
Points( 1 ; 8 points
780 0 780 ; 1
780 1560 780 ; 2
780 1560 -780 ; 3
780 0 -780 ; 4
-780 0 780 ; 5
-780 1560 780 ; 6
-780 1560 -780 ; 7
-780 0 -780 ; 8
)
SurfaceColor( 05 F0 ) ;red
Poly( ai 1 2 6 5 ) ;fore int
Poly( ai 8 7 3 4 ) ;aft int
Poly( ai 4 3 2 1 ) ;right int
Poly( ai 5 6 7 8 ) ;left int
SurfaceColor( 06 F0 ) ;green
Poly( a 1 2 6 5 ) ;fore ext
Poly( a 8 7 3 4 ) ;aft ext
Poly( a 4 3 2 1 ) ;right ext
Poly( a 5 6 7 8 ) ;left ext
Return
Interior walls are painted (spoiler alert!!!) red (
05) and exterior walls green (
06). At least, that is what I'm trying to do. So, is it?
View attachment 36607
Yippee! It works! You will note that, by painting the interior walls first, we have eluded bleeds.
Now, we will invert the points' calling order so that they will be called anticlockwise from the exterior and clockwise from the inside. This is to test the "clockwise-anticlockwise" theory which, if right, should gives us green interior and red exterior.
:BEGINNING
;Yard red and green 10x10x10
Points( 1 ; 8 points
780 0 780 ; 1
780 1560 780 ; 2
780 1560 -780 ; 3
780 0 -780 ; 4
-780 0 780 ; 5
-780 1560 780 ; 6
-780 1560 -780 ; 7
-780 0 -780 ; 8
)
SurfaceColor( 05 F0 ) ;red
Poly( ai 5 6 2 1 ) ;fore int
Poly( ai 4 3 7 8 ) ;aft int
Poly( ai 1 2 3 4 ) ;right int
Poly( ai 8 7 6 5 ) ;left int
SurfaceColor( 06 F0 ) ;green
Poly( a 5 6 2 1 ) ;fore ext
Poly( a 4 3 7 8 ) ;aft ext
Poly( a 1 2 3 4 ) ;right ext
Poly( a 8 7 6 5 ) ;left ext
Return
Naaaa... walls remained red inside and green outside.
SCASM does recognize if a polygon's surface is away from
RefPoint (exterior) or facing it (interior) during compilation, no matter if points are called clockwise or anticlockwise. To verify what happened, I have saved the visual code as found in
playground.scx. The first assembly is in
blue, the second in
red.
:L001284
Points( 1 ; 8 points
780 0 780 ; 1
780 1560 780 ; 2
780 1560 -780 ; 3
780 0 -780 ; 4
-780 0 780 ; 5
-780 1560 780 ; 6
-780 1560 -780 ; 7
-780 0 -780 ; 8
)
SurfaceColor( 0x05 0xF0 )
Poly( m 0 0 -32767 -780.000000 1 2 6 5 )
Poly( m 0 0 32767 -780.000000 8 7 3 4 )
Poly( m -32767 0 0 -780.000000 4 3 2 1 )
Poly( m 32767 0 0 -780.000000 5 6 7 8 )
SurfaceColor( 0x06 0xF0 )
Poly( m 0 0 32767 780.000000 1 2 6 5 )
Poly( m 0 0 -32767 780.000000 8 7 3 4 )
Poly( m 32767 0 0 780.000000 4 3 2 1 )
Poly( m -32767 0 0 780.000000 5 6 7 8 )
Return
:L001284
Points( 1 ; 8 points
780 0 780 ; 1
780 1560 780 ; 2
780 1560 -780 ; 3
780 0 -780 ; 4
-780 0 780 ; 5
-780 1560 780 ; 6
-780 1560 -780 ; 7
-780 0 -780 ; 8
)
SurfaceColor( 0x05 0xF0 )
Poly( m 0 0 -32767 -780.000000 5 6 2 1 )
Poly( m 0 0 32767 -780.000000 4 3 7 8 )
Poly( m -32767 0 0 -780.000000 1 2 3 4 )
Poly( m 32767 0 0 -780.000000 8 7 6 5 )
SurfaceColor( 0x06 0xF0 )
Poly( m 0 0 32767 780.000000 5 6 2 1 )
Poly( m 0 0 -32767 780.000000 4 3 7 8 )
Poly( m 32767 0 0 780.000000 1 2 3 4 )
Poly( m -32767 0 0 780.000000 8 7 6 5 )
Return
The "manual" vectoring is exactly the same between both assemblies;
vx,
vz,
vy, and
vector length are unchanged. As long as points are being called in a sequence respecting the perimeter,
SCASM will properly identify exterior-interior orientation. By "respecting the perimeter", I mean clockwise or anticlockwise. For example, the fore wall sequence "
5 2 6 1" would compile but create a "bow-tie" weird look. Go and try it if you want.
These
SCASM SCX are also good examples of what I've tried explaining in the preceding lesson. As all walls are perpendicular to Y or X axis, you see ±32767 as
vx or
vy.
Vector length is always at 780.000000 (the minus sign is only there to indicate direction). For example, in the last assembly, the interior fore wall is at
vy = -32767 and vector length at -780.000000 because the vector is "read" from tip to tail. The same fore wall, but from the exterior, has
vy = 32767 and vector length at 780.000000 simply because now it is "read" from tail to tip. In both cases, vector has the same length. Study these two
SCX carefully until our next lesson.
Next time; Lesson #3: automatic calculation (part two)