home *** CD-ROM | disk | FTP | other *** search
/ ftp.mactech.com 2010 / ftp.mactech.com.tar / ftp.mactech.com / online / source / cpp / graphics / Conics.sit.hqx / Conics / Sources / ConicWindow.cpp < prev    next >
Text File  |  1996-11-13  |  4KB  |  146 lines

  1. //Copyright 1996 Brian+Aidan Cully
  2. //All rights reserved
  3.  
  4. #include "ConicWindow.h"
  5. #include "Graphics.h"
  6. #include "MenuHandler.h"
  7.  
  8. SInt8 TConicWindow::RespondResizeSelf( const Rect &oldRect, const Rect &newRect ) {
  9.     TOffScreen::RespondResizeSelf( oldRect, newRect );
  10.     ::InvalRect( &oldRect );
  11. }
  12.  
  13. void TConicWindow::DrawSelf() {
  14.     Rect winRect = GetWindowPort( window )->portRect;
  15.  
  16.     OffsetRect( &winRect, -winRect.left, -winRect.top );
  17.     EraseRect( &winRect );
  18.     DrawConic();
  19.     DrawPlane();
  20. }
  21.  
  22. SInt8 TConicWindow::DrawConic() {
  23.     int surf;
  24.     p3d temp;
  25.     p2d opoint,point,obpoint,bpoint, center;
  26.     Rect drawRect = GetWindowPort( window )->portRect;
  27.  
  28.     OffsetRect( &drawRect, -drawRect.top, -drawRect.left );
  29.     drawRect.right -= 15;
  30.     drawRect.bottom -= 15;
  31.     DrawAxis();
  32.     point = P3dT2d(conic->conic[0], drawRect);
  33.     bpoint = P3dT2d(conic->conic[1], drawRect);
  34.     temp.x = 0;
  35.     temp.y = 0;
  36.     temp.z = 0;
  37.     center = P3dT2d( temp, drawRect );
  38.     for(surf = 0;surf<=CONICPARTS;surf+=2) {
  39.         opoint = point;
  40.         obpoint = bpoint;
  41.         point = P3dT2d(conic->conic[surf], drawRect);
  42.         bpoint = P3dT2d(conic->conic[surf+1], drawRect);
  43.         putline(opoint.x,opoint.y,point.x,point.y,0xFF00);
  44.         putline(point.x, point.y, center.x, center.y, 0xFF );
  45.         putline(center.x, center.y, bpoint.x, bpoint.y, 0xFF );
  46.         putline(obpoint.x,obpoint.y,bpoint.x,bpoint.y,0xFF00);
  47.     }
  48. }
  49.  
  50. SInt8 TConicWindow::DrawPlane() {
  51.     Rect drawRect = GetWindowPort( window )->portRect;
  52.     p2d point, opoint;
  53.     int surf;
  54.  
  55.     OffsetRect( &drawRect, -drawRect.top, -drawRect.left );
  56.     drawRect.right -= 15;
  57.     drawRect.bottom -= 15;
  58.  
  59.     point = P3dT2d(plane->plane[0], drawRect);
  60.     for (surf = 0;surf<=3;surf++) {
  61.         opoint = point;
  62.         point = P3dT2d(plane->plane[surf], drawRect);
  63.         putline(opoint.x,opoint.y,point.x,point.y,0x7f0000);
  64.     }
  65.     opoint = P3dT2d(plane->plane[0], drawRect);
  66.     putline(opoint.x,opoint.y,point.x,point.y,0x7f0000);
  67. }
  68.  
  69. SInt8 TConicWindow::DrawAxis() {
  70.     p3d x,y,z,bx,by,bz;
  71.     p2d xax,yax,zax,bxax,byax,bzax;
  72.     unsigned pattern;
  73.     Rect drawRect = GetWindowPort( window )->portRect;
  74.  
  75.     OffsetRect( &drawRect, -drawRect.left, -drawRect.top );
  76.     drawRect.right -= 15;
  77.     drawRect.bottom -= 15;
  78.     bx.x = -10; bx.y = 0; bx.z = 0;
  79.     by.x = 0; by.y = -10; by.z = 0;
  80.     bz.x = 0; bz.y = 0; bz.z = -10;
  81.  
  82.     x.x = 10; x.y = 0; x.z = 0;
  83.     y.x = 0; y.y = 10; y.z = 0;
  84.     z.x = 0; z.y = 0; z.z = 10;
  85.  
  86.     bxax = P3dT2d(bx, drawRect);
  87.     xax = P3dT2d(x, drawRect);
  88.     putline(bxax.x,bxax.y,xax.x,xax.y,0xff0000);
  89.     puttextxy(xax.x,xax.y,"\px");
  90.  
  91.     byax = P3dT2d(by, drawRect);
  92.     yax = P3dT2d(y, drawRect);
  93.     putline(byax.x,byax.y,yax.x,yax.y,0xff00);
  94.     puttextxy(yax.x,yax.y,"\py");
  95.  
  96.     bzax = P3dT2d(bz, drawRect);
  97.     zax = P3dT2d(z, drawRect);
  98.     putline(bzax.x,bzax.y,zax.x,zax.y,0xffff);
  99.     puttextxy(zax.x,zax.y,"\pz");
  100. }
  101.  
  102. SInt8 TConicWindow::MakeActive( Boolean active ) {
  103.     inherited::MakeActive( active );
  104.     DrawGrowIcon( window );
  105.     CheckItem( GetMenuHandle( m_WINDOW ), mw_CONIC, active );
  106.     return( true );
  107. }
  108.  
  109. SInt8 TConicWindow::DoUpdate() {
  110.     TOffScreen::DoUpdate();
  111.     ::DrawGrowIcon( window );
  112. }
  113.  
  114. p2d TConicWindow::P3dT2d( p3d coord3d, Rect scaleRect ) {
  115.     p3d eyec;
  116.     p2d coord2d;
  117.     Point center;
  118.     Rect tRect = scaleRect;
  119.  
  120.     ::OffsetRect( &tRect, -scaleRect.left, -scaleRect.top );
  121.     center.h = tRect.right/2+scaleRect.left;
  122.     center.v = tRect.bottom/2+scaleRect.top;
  123.  
  124.     eyec.x = -1 * coord3d.x*theta.GetSinAngle() + coord3d.y*theta.GetCosAngle();
  125.     eyec.y = -1 * coord3d.x*theta.GetCosAngle()*phi.GetCosAngle() -
  126.      coord3d.y*theta.GetSinAngle()*phi.GetCosAngle() + coord3d.z*phi.GetSinAngle();
  127.     eyec.z = -1 * coord3d.x*phi.GetSinAngle()*theta.GetCosAngle() -
  128.      coord3d.y*phi.GetSinAngle()*theta.GetSinAngle() - coord3d.z*phi.GetCosAngle() + D;
  129.  
  130.     coord2d.x = (d/S) * (eyec.x/eyec.z);
  131.     coord2d.y = (d/S) * (eyec.y/eyec.z);
  132.  
  133.     coord2d.x = (coord2d.x * tRect.right/3)+center.h;
  134.     coord2d.y = coord2d.y * -tRect.bottom/3+center.v;
  135.  
  136.     return(coord2d);
  137. }
  138.  
  139. Boolean TConicWindow::Init( TInitStruct *vals ) {
  140.     TDocWindow::Init( vals );
  141.     theta.SetAngle( ((TConicInit*)vals)->theta );
  142.     phi.SetAngle( ((TConicInit*)vals)->phi );
  143.     d = 45000;
  144.     D = 32767;
  145.     S = 10;
  146. }