Scene8\r
Scene9\r
\r
-\r
-SUB ComputeShadeValue (txOne, tyOne, tzOne, txTwo, tyTwo, tzTwo, txThree, tyThree, tzThree, colorResult)\r
+SUB ComputeShadeValue (point1X, point1Y, point1Z, point2X, point2Y, point2Z, point3X, point3Y, point3Z, shadeValue)\r
'\r
-' Computes a "shade" or brightness value stored in 'colorResult' by:\r
-' 1) Assigning local copies of the point coordinates.\r
-' 2) Rotating them around multiple axes via GetAngle and RotatePoint.\r
-' 3) Computing a distance 'distCalc' to adjust brightness.\r
+' Computes a brightness value for a 3D triangle based on distance from viewer.\r
+' The algorithm:\r
+' 1. Makes local copies of the three points\r
+' 2. Applies three sequential rotations to simulate 3D perspective\r
+' 3. Calculates distance from viewer to determine shading\r
'\r
- xLocalOne = txOne\r
- yLocalOne = tyOne\r
- zLocalOne = tzOne\r
+ xLocalOne = point1X\r
+ yLocalOne = point1Y\r
+ zLocalOne = point1Z\r
\r
- xLocalTwo = txTwo\r
- yLocalTwo = tyTwo\r
- zLocalTwo = tzTwo\r
+ xLocalTwo = point2X\r
+ yLocalTwo = point2Y\r
+ zLocalTwo = point2Z\r
\r
- xLocalThree = txThree\r
- yLocalThree = tyThree\r
- zLocalThree = tzThree\r
+ xLocalThree = point3X\r
+ yLocalThree = point3Y\r
+ zLocalThree = point3Z\r
\r
- ' First rotation\r
+ ' First rotation around Y-axis\r
GetAngle xLocalOne, yLocalOne, xLocalTwo, yLocalTwo, angleTemp1\r
RotatePoint xLocalOne, yLocalOne, xLocalTwo, yLocalTwo, -angleTemp1\r
RotatePoint xLocalOne, yLocalOne, xLocalThree, yLocalThree, -angleTemp1\r
\r
- ' Second rotation\r
+ ' Second rotation around X-axis\r
GetAngle yLocalOne, zLocalOne, yLocalTwo, zLocalTwo, angleTemp2\r
angleTemp2 = angleTemp2 + globalPi / 2\r
RotatePoint yLocalOne, zLocalOne, yLocalTwo, zLocalTwo, -angleTemp2\r
RotatePoint yLocalOne, zLocalOne, yLocalThree, zLocalThree, -angleTemp2\r
\r
- ' Third rotation\r
+ ' Third rotation around Z-axis\r
GetAngle xLocalOne, zLocalOne, xLocalThree, zLocalThree, angleTemp3\r
angleTemp3 = angleTemp3 + globalPi / 2\r
RotatePoint xLocalOne, zLocalOne, xLocalTwo, zLocalTwo, -angleTemp3\r
RotatePoint xLocalOne, zLocalOne, xLocalThree, zLocalThree, -angleTemp3\r
\r
- xOffset = xLocalOne\r
- yOffset = yLocalOne\r
- zOffset = zLocalOne + 30\r
-\r
- RotatePoint xLocalOne, zLocalOne, xOffset, zOffset, angleTemp3\r
- RotatePoint yLocalOne, zLocalOne, yOffset, zOffset, angleTemp2\r
- RotatePoint xLocalOne, yLocalOne, xOffset, yOffset, angleTemp1\r
-\r
- ' The distance 'distCalc' is used to compute 'colorResult'\r
- xLocalOne = txOne + 20\r
- yLocalOne = tyOne + 10\r
- distCalc = SQR((xLocalOne - xOffset) ^ 2 + (yLocalOne - yOffset) ^ 2)\r
- colorResult = 49 - distCalc\r
- IF colorResult < 0 THEN colorResult = 0\r
+ ' Calculate distance from viewer to determine shading\r
+ viewerX = xLocalOne\r
+ viewerY = yLocalOne\r
+ viewerZ = zLocalOne + 30\r
+\r
+ RotatePoint xLocalOne, zLocalOne, viewerX, viewerZ, angleTemp3\r
+ RotatePoint yLocalOne, zLocalOne, viewerY, viewerZ, angleTemp2\r
+ RotatePoint xLocalOne, yLocalOne, viewerX, viewerY, angleTemp1\r
+\r
+ ' Compute distance from viewer to first point\r
+ distanceX = point1X + 20\r
+ distanceY = point1Y + 10\r
+ distance = SQR((distanceX - viewerX) ^ 2 + (distanceY - viewerY) ^ 2)\r
+ shadeValue = 49 - distance\r
+ IF shadeValue < 0 THEN shadeValue = 0\r
END SUB\r
\r
-\r
SUB DrawRoundedBox (xOne, yOne, xTwo, yTwo)\r
'\r
' Draws a soft-edged rectangular box by fading pixel colors around its edges.\r