/******************************************************* * PROCEDURES TO DRAW A 3D CURVE IN SPACE X,Y,Z * * ---------------------------------------------------- * * Ref.: "From Unit GRAPH3D.PAS By Robert DONY - MASSON * * Paris, 1990 - Graphisme dans le plan et dans * * l'espace en Turbo Pascal 4.0" [BIBLI 12]. * * * * Visual C++ Release By J-P Moreau, Paris. * * (www.jpmoreau.fr) * *******************************************************/ #include "stdafx.h" #include #define echelle 1.35 #define bord 15 #define perspective 1 #define parallele 2 double de,phi,rho,theta; double aux1,aux2,aux3,aux4; double aux5,aux6,aux7,aux8; double xobs,yobs,zobs; double xproj,yproj; int xscreen,xscreenold,yscreen,yscreenold; int projection; int MaxX, MaxY; int xgclot,xdclot,ybclot,yhclot; //define client drawing zone in screen pixels void Cloture(int c1,int c2,int c3,int c4) { xgclot=c1; xdclot=c2; ybclot=c3; yhclot=c4; } //calculate auxiliary projection variables void InitProj() { double pi,th,ph; pi=3.1415926535; th=pi*theta/180; ph=pi*phi/180; aux1=sin(th); aux2=sin(ph); aux3=cos(th); aux4=cos(ph); aux5=aux3*aux2; aux6=aux1*aux2; aux7=aux3*aux4; aux8=aux1*aux4; } //projection to screen (xproj,yproj) void Projette(double x,double y,double z) { xobs=-x*aux1+y*aux3; yobs=-x*aux5-y*aux6+z*aux4; if (projection==perspective) { zobs=-x*aux7-y*aux8-z*aux2+rho; xproj=de*xobs/zobs; yproj=de*yobs/zobs; } else { xproj=de*xobs; yproj=de*yobs; } } void DrawLine(CClientDC *P,int ix1,int iy1,int ix2,int iy2) { P->MoveTo(ix1,iy1); P->LineTo(ix2,iy2); } //draw a line from current point xscreenold,yscreenold void LineXYZ(CClientDC *P,double x,double y,double z) { Projette(x,y,z); xscreen=(int) floor(xproj*echelle+(MaxX/2)); yscreen=(int) floor((MaxY/2)-yproj); if (xscreen>=0 && xscreen<=MaxX && yscreen>=0 && yscreen <=MaxY) { DrawLine(P,xscreenold,yscreenold,xscreen,yscreen); //update current point xscreenold=xscreen; yscreenold=yscreen; } } //change current point with pen up void MoveXYZ(double x,double y,double z) { Projette(x,y,z); xscreen=(int) floor(xproj*echelle+(MaxX/2)); yscreen=(int) floor((MaxY/2)-yproj); xscreenold=xscreen; yscreenold=yscreen; } //draw a frame around drawing zone void Bordure(CClientDC *P) { DrawLine(P,bord,bord,MaxX-bord,bord); DrawLine(P,MaxX-bord,bord,MaxX-bord,MaxY-bord); DrawLine(P,MaxX-bord,MaxY-bord,bord,MaxY-bord); DrawLine(P,bord,MaxY-bord,bord,bord); } //draw 3 axes Ox,Oy,Oz void Axes(CClientDC *P,double x,double y,double z) { MoveXYZ(0,0,0); LineXYZ(P,x,0,0); xscreen+=5; yscreen+=5; P->TextOut(xscreen,yscreen,"X",1); MoveXYZ(0,0,0); LineXYZ(P,0,y,0); xscreen+=5; yscreen+=5; P->TextOut(xscreen,yscreen,"Y",1); MoveXYZ(0,0,0); LineXYZ(P,0,0,z); xscreen+=10; yscreen-=5; P->TextOut(xscreen,yscreen,"Z",1); } //end of file graph3d.cpp