home *** CD-ROM | disk | FTP | other *** search
/ Otherware / Otherware_1_SB_Development.iso / mac / util / screensa / afterdar / 3dbounci.cpt / 3D Bouncing Ball ƒ / FixedThreeDeeCalls.inc1.p < prev    next >
Encoding:
Text File  |  1992-06-04  |  3.4 KB  |  90 lines

  1. PROCEDURE SetThreeDeePoint (var tempPt : ThreeDeePoint; x, y, z : real);
  2. BEGIN
  3.     tempPt.x := X2Fix(x);
  4.     tempPt.y := X2Fix(y);
  5.     tempPt.z := X2Fix(z);
  6. END;
  7.  
  8. PROCEDURE ThreeDeeToTwoDee(theWorld : ThreeDeeWorld; aThreeDeePoint : ThreeDeePoint; var a2DPoint : point);
  9.     VAR
  10.         x1, y1, z1            : fixed;
  11.         x2, y2, z2            : fixed;
  12.         tempFixed                : fixed;
  13. BEGIN
  14.     with theWorld
  15.         do begin
  16.             x1 := (screenCenter.x - aThreeDeePoint.x);
  17.             y1 := (screenCenter.y - aThreeDeePoint.y);
  18.             z1 := (eyeLocation.z - aThreeDeePoint.z);
  19.             z2 := (screenCenter.z - aThreeDeePoint.z);
  20.             
  21.             x2 := FixDiv(FixMul(x1, z2), z1);
  22.             y2 := FixDiv(FixMul(y1, z2), z1);
  23.             
  24.             x2 := FixMul(x1, FixDiv(z2, z1));
  25.             y2 := FixMul(y1, FixDiv(z2, z1));
  26.             
  27.             tempFixed := x2 + screenCenter.x - x1;
  28.             a2DPoint.h := Fix2Long(tempFixed);    
  29.             tempFixed := y2 + screenCenter.y - y1;
  30.             a2DPoint.v := Fix2Long(tempFixed);    
  31.         end;
  32. END;
  33.  
  34. PROCEDURE ScaleRect (var tempRect : rect; scaleFactor : real);
  35.     VAR
  36.         itsCenter        : point;
  37.         itsWidth        : integer;
  38.         itsHeight        : integer;
  39. BEGIN
  40.     itsWidth := (tempRect.right - tempRect.left);
  41.     itsHeight := (tempRect.bottom - tempRect.top);
  42.     itsCenter.h := tempRect.left + (itsWidth div 2);
  43.     itsCenter.v := tempRect.top + (itsHeight div 2);
  44.     
  45.     tempRect.left := round(itsCenter.h - (itsWidth * scaleFactor) / 2);
  46.     tempRect.top := round(itsCenter.v - (itsHeight * scaleFactor) / 2);
  47.  
  48.     tempRect.right := tempRect.left + round(itsWidth * scaleFactor);
  49.     tempRect.bottom := tempRect.top + round(itsHeight * scaleFactor);
  50. END;
  51.  
  52. PROCEDURE SetupThreeDeeWorld (var tempWorld : ThreeDeeWorld; monitorRect : rect);
  53.     VAR
  54.         monitorWidth    : real;
  55.         monitorHeight    : real;
  56.         monitorDepth    : real;
  57. BEGIN
  58.     with tempWorld
  59.         do begin
  60.             monitorHeight := monitorRect.bottom - monitorRect.top;
  61.             monitorWidth := monitorRect.right - monitorRect.left;
  62.             monitorDepth := monitorWidth;
  63.             SetThreeDeePoint(eyeLocation, (monitorWidth / 2), 0, -200);
  64.             SetThreeDeePoint(screenCenter, (monitorWidth / 2), (monitorHeight / 4), -50);
  65.             SetThreeDeePoint(eyeLocation, (monitorWidth / 2), -200, -500);
  66.             SetThreeDeePoint(screenCenter, (monitorWidth / 2), (monitorHeight / 4), -100);
  67.             
  68.             {SetThreeDeePoint(eyeLocation, 0, 100, 0);
  69.             SetThreeDeePoint(screenCenter, 0, 100, 50);}
  70.             screenRect := monitorRect;
  71.             
  72.             SetThreeDeePoint(frontTopLeft, monitorRect.left, monitorRect.top, 0);
  73.             SetThreeDeePoint(frontTopRight, monitorRect.right, monitorRect.top, 0);
  74.             SetThreeDeePoint(frontBotLeft, monitorRect.left, monitorRect.bottom, 0);
  75.             SetThreeDeePoint(frontBotRight, monitorRect.right, monitorRect.bottom, 0);
  76.             SetThreeDeePoint(backTopLeft, monitorRect.left, monitorRect.top, monitorDepth);
  77.             SetThreeDeePoint(backTopRight, monitorRect.right, monitorRect.top, monitorDepth);
  78.             SetThreeDeePoint(backBotLeft, monitorRect.left, monitorRect.bottom, monitorDepth);
  79.             SetThreeDeePoint(backBotRight, monitorRect.right, monitorRect.bottom, monitorDepth);
  80.  
  81.         {    SetThreeDeePoint(frontTopLeft, -monitorWidth, monitorWidth, -monitorWidth);
  82.             SetThreeDeePoint(frontTopRight, monitorWidth, monitorWidth, -monitorWidth);
  83.             SetThreeDeePoint(frontBotLeft, -monitorWidth, 0, -monitorWidth);
  84.             SetThreeDeePoint(frontBotRight, monitorWidth, 0, -monitorWidth);
  85.             SetThreeDeePoint(backTopLeft, -monitorWidth, monitorWidth, monitorWidth);
  86.             SetThreeDeePoint(backTopRight, monitorWidth, monitorWidth, monitorWidth);
  87.             SetThreeDeePoint(backBotLeft, -monitorWidth, 0, monitorWidth);
  88.             SetThreeDeePoint(backBotRight, monitorWidth, 0, monitorWidth);    }
  89.         end;
  90. END;