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
/
DrawWindows.cpp
< prev
next >
Wrap
Text File
|
1996-11-13
|
6KB
|
200 lines
//Copyright 1996 Brian+Aidan Cully
//All rights reserved
#include <math.h>
#include <Quickdraw.h>
#include <Menus.h>
#include "DrawWindows.h"
#include "Graphics.h"
#include "MenuHandler.h"
#include "StrStuff.h"
SInt8 TEquWindow::DXDivY( int x, int y, unsigned char *num, unsigned char *den ) {
MoveTo( x, y );
DrawString( num );
MoveTo( x, y+3 );
Line( 40, 0 );
MoveTo( x, y+12+6 );
DrawString( den );
}
void TEquWindow::DrawSelf() {
EraseRect( &qd.screenBits.bounds );
float a,b,npang;
int dec,sign,deccount;
Str32 astr,bstr;
MoveTo(20,20);
npang = fmod(plane->GetAngle(),180);
if (npang == 0) {
a = pow(plane->GetDistance(),2);
StrCpy( astr, gcvt(a,5) );
DrawString("\px^2 + y^2 =");
DrawString(astr);
} else if ((npang == 45) || (npang == 135)) {
a = 4*plane->GetDistance()/2;
if( npang == 135 )
a = -a;
DrawString("\px^2 = ");
StrCpy( astr, gcvt( a, 5 ) );
DrawString(astr);
DrawString("\py");
} else if ((npang < 45) || (npang > 135)) {
a = plane->GetDistance()/cos(plane->GetAngle()*_PI/180);
a = fabs(a);
b = plane->GetDistance()*tan((45-plane->GetAngle())*_PI/180);
b += plane->GetDistance()*tan((45+(plane->GetAngle())*_PI/180));
b /= 2;
b = fabs(b);
StrCpy( astr, gcvt( a, 5 ) );
DXDivY( 20, 20, "\px^2", astr );
StrCpy( bstr, gcvt( b, 5 ) );
DXDivY( 80, 20, "\py^2", bstr );
MoveTo( 70, 28 );
DrawString("\p+");
Move(47,0);
DrawString("\p= 1");
} else {
a = plane->GetDistance()/plane->GetSinAngle();
a = fabs(a);
b = plane->GetDistance()*tan((45-plane->GetAngle())*_PI/180);
b += (plane->GetDistance()*tan((45+plane->GetAngle())*_PI/180));
b /= 2;
b = fabs(b);
StrCpy( astr, gcvt( a, 5 ) );
DXDivY( 20, 20, "\py^2", astr );
StrCpy( bstr, gcvt( b, 5 ) );
DXDivY( 80, 20, "\px^2", bstr );
MoveTo( 70, 28 );
DrawString( "\p-" );
Move(54,0);
DrawString("\p= 1");
}
}
SInt8 TEquWindow::MakeActive( Boolean active ) {
inherited::MakeActive( active );
CheckItem( GetMenuHandle( m_WINDOW ), mw_EQU, active );
return( true );
}
void TInstructWindow::DrawSelf() {
puttextxy(10,12,"\pUp - Rotate Axis Up" );
puttextxy(10,24,"\pLeft - Rotate Axis Left");
puttextxy(10,36,"\pRight - Rotate Axis Right");
puttextxy(10,48,"\pDown - Rotate Axis Down");
puttextxy(10,60,"\pW - Rotate Plane Clockwise");
puttextxy(10,72,"\pZ - Rotate Plane Counter-Clockwise");
puttextxy(10,84,"\p- - Move Plane Toward Origin");
puttextxy(10,96,"\p+ - Move Plane From Origin");
}
SInt8 TInstructWindow::MakeActive( Boolean active ) {
inherited::MakeActive( active );
CheckItem( GetMenuHandle( m_WINDOW ), mw_INSTRUCT, active );
if( active )
DisableItem( GetMenuHandle( m_EDIT ), me_COPY );
else
EnableItem( GetMenuHandle( m_EDIT ), me_COPY );
return( true );
}
void TPlotWindow::DrawSelf() {
DrawIntersect();
}
SInt8 TPlotWindow::DrawAxis() {
Rect drawRect = ::GetWindowPort( window )->portRect;
::OffsetRect( &drawRect, -drawRect.left, -drawRect.top );
putline(0,drawRect.bottom/2,drawRect.right,drawRect.bottom/2,0xff0000);
puttextxy(drawRect.right-12,drawRect.bottom/2,"\px");
putline(drawRect.right/2,0,drawRect.right/2,drawRect.bottom,0xff00);
puttextxy(drawRect.right/2,drawRect.bottom-8,"\py");
}
SInt8 TPlotWindow::DrawIntersect() {
int numint,border[8],numtint,numbint;
p2d inter2,ptint[180],pbint[180],point,opoint;
p3d inter3;
Rect drawRect;
drawRect = ::GetWindowPort( window )->portRect;
::OffsetRect( &drawRect, -drawRect.left, -drawRect.top );
::EraseRect( &drawRect );
DrawAxis();
numtint = 0;
numbint = 0;
for(numint=0;numint<conic->tnumint;numint++) {
inter3 = conic->conic[conic->intersect[numint]];
inter2.x = inter3.x;
inter2.y = plane->GetCosAngle()*inter3.y + plane->GetSinAngle()*inter3.z;
if ((int)(fmod((float)(conic->intersect[numint]),2.0)) == 0) {
ptint[numtint].x = inter2.x;
ptint[numtint].y = inter2.y;
numtint++;
} else {
pbint[numbint].x = inter2.x;
pbint[numbint].y = inter2.y;
numbint++;
}
}
if (numbint < conic->tnumint) {
point.x = ptint[0].x;
point.y = ptint[0].y;
point.x *= drawRect.right/12;
point.x += drawRect.right/2;
point.y *= -drawRect.bottom/12;
point.y += drawRect.bottom/2;
for(numint=0;numint<numtint;numint++) {
opoint = point;
point.x = ptint[numint].x;
point.y = ptint[numint].y;
point.x *= drawRect.right/12;
point.x += drawRect.right/2;
point.y *= -drawRect.bottom/12;
point.y += drawRect.bottom/2;
if ((opoint.y == point.y) || (opoint.x == point.x)) {
opoint.x = point.x;
opoint.y = point.y;
}
putline(opoint.x,opoint.y,point.x,point.y,0xff);
}
}
if (numtint < conic->tnumint) {
point.x = pbint[0].x;
point.y = pbint[0].y;
point.x *= drawRect.right/12;
point.x += drawRect.right/2;
point.y *= -drawRect.bottom/12;
point.y += drawRect.bottom/2;
for(numint=0;numint<numbint;numint++) {
opoint = point;
point.x = pbint[numint].x;
point.y = pbint[numint].y;
point.x *= drawRect.right/12;
point.x += drawRect.right/2;
point.y *= -drawRect.bottom/12;
point.y += drawRect.bottom/2;
if ((opoint.y == point.y) || (opoint.x == point.x)) {
opoint.x = point.x;
opoint.y = point.y;
}
putline(opoint.x,opoint.y,point.x,point.y,0xff);
}
}
}
SInt8 TPlotWindow::MakeActive( Boolean active ) {
inherited::MakeActive( active );
CheckItem( GetMenuHandle( m_WINDOW ), mw_PLOT, active );
return( true );
}
SInt8 TPlotWindow::RespondResizeSelf( const Rect &oldRect, const Rect &newRect ) {
TOffScreen::RespondResizeSelf( oldRect, newRect );
::InvalRect( &oldRect );
}