home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / Modula / Source / ThreeDee / ThreeDee.MOD < prev   
Text File  |  1984-12-31  |  2KB  |  88 lines

  1. IMPLEMENTATION MODULE ThreeDee;
  2.  
  3. FROM QuickDrawTypes IMPORT Point;
  4. FROM MathLib1       IMPORT sin, cos, entier;
  5. FROM MathConst      IMPORT RadConst;
  6. FROM ThreeDee       IMPORT Point3D;
  7.  
  8. VAR
  9.   cosRX, cosRY, cosRZ, sinRX, sinRY, sinRZ: REAL;
  10.   scalX, scalY, scalZ: REAL;
  11.   tranX, tranY, tranZ: REAL;
  12.   projectionZ, srceZ: REAL;
  13.   xiXo, xiYo, xiZo, 
  14.   yiXo, yiYo, yiZo, 
  15.   ziXo, ziYo, ziZo: REAL;
  16.  
  17. PROCEDURE SetPoint3D( x, y, z: REAL; VAR p: Point3D );
  18. BEGIN
  19.   WITH p DO X:=x; Y:=y; Z:=z; END;
  20. END SetPoint3D;
  21.  
  22. PROCEDURE SetRSM; (* calculate rotation+scale transform *)
  23. BEGIN
  24.   xiXo:=scalX * cosRY*cosRZ;
  25.   xiYo:=scalX * cosRY*sinRZ;
  26.   xiZo:=scalX * (-sinRY);
  27.   
  28.   yiXo:=scalY * (sinRX*sinRY*cosRZ - cosRX*sinRZ);
  29.   yiYo:=scalY * (cosRX*cosRZ + sinRX*sinRY*sinRZ);
  30.   yiZo:=scalY * sinRX*cosRY;
  31.   
  32.   ziXo:=scalZ * (sinRX*sinRZ + cosRX*sinRY*cosRZ);
  33.   ziYo:=scalZ * (cosRX*sinRY*sinRZ - cosRZ*sinRX);
  34.   ziZo:=scalZ * cosRX*cosRY;
  35. END SetRSM;
  36.  
  37. PROCEDURE SetRot( rotX, rotY, rotZ: REAL );
  38. BEGIN
  39.   rotX:=RadConst*rotX; cosRX:=cos( rotX ); sinRX:=sin( rotX );
  40.   rotY:=RadConst*rotY; cosRY:=cos( rotY ); sinRY:=sin( rotY );
  41.   rotZ:=RadConst*rotZ; cosRZ:=cos( rotZ ); sinRZ:=sin( rotZ );
  42.   SetRSM;
  43. END SetRot;
  44.  
  45. PROCEDURE SetScale( scaleX, scaleY, scaleZ: REAL );
  46. BEGIN
  47.   scalX:=scaleX; scalY:=scaleY; scalZ:=scaleZ;
  48.   SetRSM;
  49. END SetScale;
  50.  
  51. PROCEDURE SetTranslation( transX, transY, transZ: REAL );
  52. BEGIN
  53.   tranX:=transX; tranY:=transY; tranZ:=transZ;
  54. END SetTranslation;
  55.  
  56. PROCEDURE SetPerspective( screenZ, sourceZ: REAL );
  57. BEGIN
  58.   projectionZ:=screenZ-sourceZ;
  59.   srceZ:=sourceZ;
  60. END SetPerspective;
  61.  
  62. PROCEDURE TransformSRT( in: Point3D; VAR out: Point3D );
  63. BEGIN
  64.   WITH in DO
  65.     out.X:=tranX + X*xiXo + Y*yiXo + Z*ziXo;
  66.     out.Y:=tranY + X*xiYo + Y*yiYo + Z*ziYo;
  67.     out.Z:=tranZ + X*xiZo + Y*yiZo + Z*ziZo;
  68.   END; (*WITH*)
  69. END TransformSRT;
  70.  
  71. PROCEDURE Project( in: Point3D; VAR out: Point );
  72. VAR
  73.   effectiveZ: REAL;
  74. BEGIN
  75.   WITH in DO
  76.     effectiveZ:=Z-srceZ;
  77.     IF ABS(effectiveZ) < 0.0001 THEN effectiveZ:=0.0001; END;
  78.     out.h:=entier(projectionZ*X/effectiveZ);
  79.     out.v:=entier(projectionZ*Y/effectiveZ);
  80.   END; (*WITH*)
  81. END Project;
  82.  
  83. BEGIN
  84.   SetTranslation( 0.0, 0.0, 0.0 );
  85.   SetPerspective( 100.0, -100.0 );
  86.   scalX:=1.0; scalY:=1.0; scalZ:=1.0;
  87.   SetRot( 0.0, 0.0, 0.0 );
  88. END ThreeDee.