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 >
Wrap
Text File
|
1996-11-13
|
4KB
|
146 lines
//Copyright 1996 Brian+Aidan Cully
//All rights reserved
#include "ConicWindow.h"
#include "Graphics.h"
#include "MenuHandler.h"
SInt8 TConicWindow::RespondResizeSelf( const Rect &oldRect, const Rect &newRect ) {
TOffScreen::RespondResizeSelf( oldRect, newRect );
::InvalRect( &oldRect );
}
void TConicWindow::DrawSelf() {
Rect winRect = GetWindowPort( window )->portRect;
OffsetRect( &winRect, -winRect.left, -winRect.top );
EraseRect( &winRect );
DrawConic();
DrawPlane();
}
SInt8 TConicWindow::DrawConic() {
int surf;
p3d temp;
p2d opoint,point,obpoint,bpoint, center;
Rect drawRect = GetWindowPort( window )->portRect;
OffsetRect( &drawRect, -drawRect.top, -drawRect.left );
drawRect.right -= 15;
drawRect.bottom -= 15;
DrawAxis();
point = P3dT2d(conic->conic[0], drawRect);
bpoint = P3dT2d(conic->conic[1], drawRect);
temp.x = 0;
temp.y = 0;
temp.z = 0;
center = P3dT2d( temp, drawRect );
for(surf = 0;surf<=CONICPARTS;surf+=2) {
opoint = point;
obpoint = bpoint;
point = P3dT2d(conic->conic[surf], drawRect);
bpoint = P3dT2d(conic->conic[surf+1], drawRect);
putline(opoint.x,opoint.y,point.x,point.y,0xFF00);
putline(point.x, point.y, center.x, center.y, 0xFF );
putline(center.x, center.y, bpoint.x, bpoint.y, 0xFF );
putline(obpoint.x,obpoint.y,bpoint.x,bpoint.y,0xFF00);
}
}
SInt8 TConicWindow::DrawPlane() {
Rect drawRect = GetWindowPort( window )->portRect;
p2d point, opoint;
int surf;
OffsetRect( &drawRect, -drawRect.top, -drawRect.left );
drawRect.right -= 15;
drawRect.bottom -= 15;
point = P3dT2d(plane->plane[0], drawRect);
for (surf = 0;surf<=3;surf++) {
opoint = point;
point = P3dT2d(plane->plane[surf], drawRect);
putline(opoint.x,opoint.y,point.x,point.y,0x7f0000);
}
opoint = P3dT2d(plane->plane[0], drawRect);
putline(opoint.x,opoint.y,point.x,point.y,0x7f0000);
}
SInt8 TConicWindow::DrawAxis() {
p3d x,y,z,bx,by,bz;
p2d xax,yax,zax,bxax,byax,bzax;
unsigned pattern;
Rect drawRect = GetWindowPort( window )->portRect;
OffsetRect( &drawRect, -drawRect.left, -drawRect.top );
drawRect.right -= 15;
drawRect.bottom -= 15;
bx.x = -10; bx.y = 0; bx.z = 0;
by.x = 0; by.y = -10; by.z = 0;
bz.x = 0; bz.y = 0; bz.z = -10;
x.x = 10; x.y = 0; x.z = 0;
y.x = 0; y.y = 10; y.z = 0;
z.x = 0; z.y = 0; z.z = 10;
bxax = P3dT2d(bx, drawRect);
xax = P3dT2d(x, drawRect);
putline(bxax.x,bxax.y,xax.x,xax.y,0xff0000);
puttextxy(xax.x,xax.y,"\px");
byax = P3dT2d(by, drawRect);
yax = P3dT2d(y, drawRect);
putline(byax.x,byax.y,yax.x,yax.y,0xff00);
puttextxy(yax.x,yax.y,"\py");
bzax = P3dT2d(bz, drawRect);
zax = P3dT2d(z, drawRect);
putline(bzax.x,bzax.y,zax.x,zax.y,0xffff);
puttextxy(zax.x,zax.y,"\pz");
}
SInt8 TConicWindow::MakeActive( Boolean active ) {
inherited::MakeActive( active );
DrawGrowIcon( window );
CheckItem( GetMenuHandle( m_WINDOW ), mw_CONIC, active );
return( true );
}
SInt8 TConicWindow::DoUpdate() {
TOffScreen::DoUpdate();
::DrawGrowIcon( window );
}
p2d TConicWindow::P3dT2d( p3d coord3d, Rect scaleRect ) {
p3d eyec;
p2d coord2d;
Point center;
Rect tRect = scaleRect;
::OffsetRect( &tRect, -scaleRect.left, -scaleRect.top );
center.h = tRect.right/2+scaleRect.left;
center.v = tRect.bottom/2+scaleRect.top;
eyec.x = -1 * coord3d.x*theta.GetSinAngle() + coord3d.y*theta.GetCosAngle();
eyec.y = -1 * coord3d.x*theta.GetCosAngle()*phi.GetCosAngle() -
coord3d.y*theta.GetSinAngle()*phi.GetCosAngle() + coord3d.z*phi.GetSinAngle();
eyec.z = -1 * coord3d.x*phi.GetSinAngle()*theta.GetCosAngle() -
coord3d.y*phi.GetSinAngle()*theta.GetSinAngle() - coord3d.z*phi.GetCosAngle() + D;
coord2d.x = (d/S) * (eyec.x/eyec.z);
coord2d.y = (d/S) * (eyec.y/eyec.z);
coord2d.x = (coord2d.x * tRect.right/3)+center.h;
coord2d.y = coord2d.y * -tRect.bottom/3+center.v;
return(coord2d);
}
Boolean TConicWindow::Init( TInitStruct *vals ) {
TDocWindow::Init( vals );
theta.SetAngle( ((TConicInit*)vals)->theta );
phi.SetAngle( ((TConicInit*)vals)->phi );
d = 45000;
D = 32767;
S = 10;
}