![]() |
China DOS Union-- Unite DOS · Advance DOS · Grow DOS --Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum |
| Guest | Log in | Register | Members | Search | China DOS Union |
|
中国DOS联盟论坛 The time now is 2026-10-31 06:08 |
47,815 topics / 349,930 posts / today 0 new / 48,290 members |
| DOS开发编程 & 发展交流 (开发室) » A C language graphics library and mathematical library |
| Printable Version 46,615 / 72 |
| Floor61 leafmaple | Posted 2010-12-21 08:18 |
| 新手上路 Posts 2 Credits 4 | |
|
Thanks for sharing
|
|
| Floor62 svols | Posted 2010-12-30 18:56 |
| 新手上路 Posts 1 Credits 2 | |
|
Got it, thanks a lot, LZ!
|
|
| Floor63 angussx | Posted 2011-01-24 12:13 |
| 新手上路 Posts 1 Credits 2 | |
| Floor64 qingwashaoye | Posted 2017-02-01 01:08 |
| 中级用户 Posts 74 Credits 271 | |
|
Top top top top top top top top top top top top top top top top top top top top top top top top top top top top top top top top top
Top top top top top top top top top top top top top top top top top top top top Top top Top top top top top top top top top top top top top top top Top top Top top top top top top top top top top Top top Top top top top top top top Top top top top top top Top top Top top top Top top top top top top top Top Top top top top top top top Top top top top top top top top Top Top top top top top top top top Top top top top Top top Top top top top top top top Top top Top top top Top top top Top top top top top top Top top top top top Top top Top top top top top top top top Top top top top top top Top top top Top top top top Top top top Top top top top top top top top Top top top top top Top top top Top top top Top top top Top top top top top top top top Top top top top top Top top top Top top top Top top top Top top top top top top top top Top top top top top Top top Top top top Top top top Top top top top top top top top Top top top top top Top top Top top top Top top top Top top top top top top top top Top top top top top Top top Top top top Top top top Top top top top top top top top Top top top top top Top top Top top top Top top top Top top top top top top top top Top top top top top Top top top Top top top top Top top top Top top top top top top top top Top top top top top Top top top Top top top top Top top top Top top top Top top top top top top Top top Top top top top Top top top Top top top top Top top top top top top top top Top top Top top top Top top top Top top top top top top Top top top top top top top Top top Top top top top top Top top top top top top top top Top top top top top top Top top top Top top Top top top top top top top top top top top top top top top Top top top top top Top Top top top top top top top top top top top top top top top Top top top top top top top Top Top top top top top top top top top top top top top Top top top top top top top top top Top Top top top top top top top top top top top top Top top top top top top top top top top top top top Top top Top top top top top top top top top top top top top top top top top top top top top top top top top top top top top top top top top |
|
| Floor65 fsyzwuli | Posted 2017-12-06 08:53 |
| 新手上路 Posts 8 Credits 16 | |
|
The materials are so complete! Great!!!
|
|
| Floor66 zzz19760225 | Posted 2017-12-06 15:42 |
| 超级版主 Posts 2,020 Credits 3,673 | |
|
Mathematics and Graphics Library
| |---MATH.INC |---MYGRAPH.INC |---MYHEAD.H |---readme.txt | |---3ddemo.rar |----3DDEMO.C |----3DDEMO.exe |----3DDEMO2.C |----3DDEMO2.exe |----3DDEMO3.C |----3DDEMO3.exe --------------------------------------------------------------------------------------------------- |---MATH.INC /*Math.Inc BY BIANMING 2004-11-24 /* by Bian Ming, Xi'an University of Posts and Telecommunications.*/ /*This is a C language math library written by myself, tested and passed under TC2.0. Please use it with confidence O_o! Specifically added 3D vector operations TDA for drawing vectors in the graphics library. Radians - converts degrees to radians Degrees - converts radians to degrees CosD - cosine in degrees SinD - sine in degrees Power - power a^n Log - log base 10 Exp10 - exp base 10 Sign - negative=-1 positive=1 null=0 IntSign - negative=-1 positive=1 null=0 IntSqrt - integer aquare root IntPower - integer power a^n */ #define Ln10 2.30258509299405E+000 #define Pi 3.1415927 #define PiOver180 1.74532925199433E-002 #define PiUnder180 5.72957795130823E+001 typedef enum {false, true} Boolean; typedef unsigned char Byte; typedef unsigned int Word; int Round(float x) { return((int)(x+0.5)); } int Trunc(float x) { return((int)(x)); } float SqrFP(float x) { return(x*x); } int Sqr(int x) { return(x*x); } float Radians(float Angle) { return(Angle*PiOver180); } float Degrees(float Angle) { return(Angle*PiUnder180); } float CosD(float Angle) { return(cos(Radians(Angle))); } float SinD(float Angle) { return(sin(Radians(Angle))); } float Power(float Base,int E) { float BPower; int t; if(E==0) return(1); else { BPower=1.0; for(t=1;t<=E;t++) BPower*=Base; return(BPower); } } float Log(float x) { return(log(x)/Ln10); } float Exp10(float x) { return(exp(x*Ln10)); } float Sign(float x) { if(x<0) return(-1); if(x>0) return(1); else return(0); } int IntSign(int x) { if(x<0) return(-1); if(x>0) return(1); else return(0); } int IntSqrt(int x) { int OddInt,OldArg,FirstSqrt; OddInt=1; OldArg=x; while(x>=0) { x-=OddInt; OddInt+=2; } FirstSqrt=OddInt >> 1; if(Sqr(FirstSqrt)-FirstSqrt+1 > OldArg) return(FirstSqrt-1); else return(FirstSqrt); } int IntPower(int Base,int E) { int BPower; int t; if(E==0) return(1); else { BPower=1; for(t=1;t<=E;t++) BPower*=Base; return(BPower); } } /*3D vector operations vec - Make Vector three parameters to generate a real vector VecInt - Make Integer Vector three parameters to generate an integer vector UnVec - Get Components of Vector pass real vector x,y,z axes to three numbers UnVecInt - Get Components of Integer Vector pass integer vector x,y,z axes to three numbers VecDot - Vector Dot Product dot product of two vectors VecCross - Vector Cross Product vector cross product VecLen - Vector length vector length VecNormalize - Vector Normalize normalize vector, zero-length vector cannot be normalized VecMatxMult - Vector Matrix Multiple multiply a 4×4 matrix with a vector VecSub - Vector Subtraction assign the difference of two vectors to another vector VecSubInt - Vector Subtraction Integer assign the difference of integer vectors VecAdd - Vector Addition assign the sum of two vectors to another vector VecAdd3 - Vector Addition assign the sum of three vectors to another vector VecCopy - Vector Copy vector copy VecLinComb - Vector Linear Combination C=R*A+S*B VecScalMult - Vector Scalar Multiple real vector multiplied by real number VecScalMultI - Vector Scalar Multiple integer vector multiplied by real number VecScalMultInt- Vector Scalar Multiple and Rounding integer vector multiplied by integer and rounded VecAddScalMult- Vector Add scalar Multiple C=R*A+B VecNull - Vector Null set real vector to zero VecNullInt - Vector Null Integer set integer vector to zero VecElemMult - Vector Element Mulitiple C=R*A*B */ typedef float TDA; typedef int TDIA; typedef float FDA; typedef float Matx4x4; void Vec(float r,float s,float t,TDA a) { a=r;a=s;a=t; } void VecInt(int r,int s,int t,TDIA a) { a=r;a=s;a=t; } void UnVec(TDA a,float *r,float *s,float *t) { *r=a;*s=a;*t=a; } void UnVecInt(TDIA a,int *r,int *s,int *t) { *r=a;*s=a;*t=a; } float VecDot(TDA a,TDA b) { return(a*b+a*b+a*b); } void VecCross(TDA a,TDA b,TDA c) { c=a*b-a*b; c=a*b-a*b; c=a*b-a*b; } float VecLen(TDA a) { return(sqrt(SqrFP(a)+SqrFP(a)+SqrFP(a))); } void VecNormalize(TDA a) { float dist,invdist; dist=VecLen(a); if(!(dist==0.0)) { invdist=1.0/dist; a*=invdist; a*=invdist; a*=invdist; } else { puts("Zero-Length Vectors Cannot be Nomalized!!!"); exit(1); } } void VecMatxMult(FDA a,Matx4x4 Matrix,FDA b) { int mrow, mcol; for(mcol=0;mcol<4;mcol++) { b=0; for(mrow=0;mrow<4;mrow++) b+=a*Matrix; } } void VecSub(TDA a,TDA b,TDA c) { c=a-b; c=a-b; c=a-b; } void VecSubInt(TDIA a,TDIA b,TDIA c) { c=a-b; c=a-b; c=a-b; } void VecAdd(TDA a,TDA b,TDA c) { c=a+b; c=a+b; c=a+b; } void VecAdd3(TDA a,TDA b,TDA c,TDA d) { d=a+b+c; d=a+b+c; d=a+b+c; } void VecCopy(TDA a,TDA b) { b=a; b=a; b=a; } void VecLinComb(float r,TDA a,float s,TDA b,TDA c) { c=r*a+s*b; c=r*a+s*b; c=r*a+s*b; } void VecScalMult(float r,TDA a,TDA b) { b=r*a; b=r*a; b=r*a; } void VecScalMultI(float r,TDIA a,TDA b) { b=r*a; b=r*a; b=r*a; } void VecScalMultInt(float r,TDA a,TDIA b) { b=Round(r*a); b=Round(r*a); b=Round(r*a); } void VecAddScalMult(float r,TDA a,TDA b,TDA c) { c=r*a+b; c=r*a+b; c=r*a+b; } void VecNull(TDA a) { a=0.0; a=0.0; a=0.0; } void VecNullInt(TDIA a) { a=0; a=0; a=0; } void VecElemMult(float r, TDA a,TDA b,TDA c) { c=r*a*b; c=r*a*b; c=r*a*b; } /* ZeroMatrix - zeros the elements of a 4x4 matrix Translate3D - make translation matrix generate a new matrix by linearly transforming a vector to a new position in space Scale3D - make Scaling matrix transform a vector into a matrix Rotate3D - make rotation matrix generate a matrix by rotating a vector ZeroAllMatricies - zeros all matricies used in tranformation Multiply3DMatricies - multiply 2 4x4 matricies multiply two 4x4 matrices PrepareMatrix - prepare the transformation matrix (Tm=S*R*T) generate a complete affine transformation matrix PrepareInvMatrix - prepare the inverse transformation matrix Transform - multiply a vertex by the transformation matrix multiply a vector by the transformation matrix to generate a new vector */ void ZeroMatrix(Matx4x4 a) { int i,j; for(i=0;i<4;i++) for(j=0;j<4;j++) a=0.0; } void Translate3D(float tx, float ty, float tz,Matx4x4 a) { int i; ZeroMatrix(a); for(i=0;i<4;i++) a=1.0; a=-tx; a=-ty; a=-tz; } void Scale3D(float sx,float sy,float sz,Matx4x4 a) { ZeroMatrix(a); a=sx; a=sy; a=sz; a=1.0; } void Rotate3D(int m,float theta, Matx4x4 a) { int m1,m2; float c,s; ZeroMatrix(a); a=1.0; a=1.0; m1=(m%3)+1; m2=(m1%3); m1=-1; c=CosD(theta); s=SinD(theta); a=c; a=s; a=c; a=-s; } void Multiply3DMatricies(Matx4x4 a,Matx4x4 b,Matx4x4 c) { int i,j,k; float ab; for(i=0;i<4;i++) { for(j=0;j<4;j++) { ab=0; for(k=0;k<4;k++) ab+=a*b; c=ab; } } } void MatCopy(Matx4x4 a,Matx4x4 b) { int i,j; for(i=0;i<4;i++) for(j=0;j<4;j++) b=a; } void PrepareMatrix(float tx,float ty,float tz, float sx,float sy,float sz, float rx,float ry,float rz, Matx4x4 XForm) { Matx4x4 m1,m2,m3,m4,m5,m6,m7,m8,m9; Scale3D(sx,sy,sz,m1); Rotate3D(1,rx,m2); Rotate3D(2,ry,m3); Rotate3D(3,rz,m4); Translate3D(tx,ty,tz,m5); Multiply3DMatricies(m2,m1,m6); Multiply3DMatricies(m3,m6,m7); Multiply3DMatricies(m4,m7,m8); Multiply3DMatricies(m5,m8,m9); MatCopy(m9,XForm); } void PrepareInvMatrix(float tx,float ty,float tz, float sx,float sy,float sz, float rx,float ry,float rz, Matx4x4 XForm) { Matx4x4 m1,m2,m3,m4,m5,m6,m7,m8,m9; Scale3D(sx,sy,sz,m1); Rotate3D(1,rx,m2); Rotate3D(2,ry,m3); Rotate3D(3,rz,m4); Translate3D(tx,ty,tz,m5); Multiply3DMatricies(m4,m5,m6); Multiply3DMatricies(m3,m6,m7); Multiply3DMatricies(m2,m7,m8); Multiply3DMatricies(m1,m8,m9); MatCopy(m9,XForm); } void Transform(TDA a,Matx4x4 m,TDA b) { b=m*a+m*a+m*a+m; b=m*a+m*a+m*a+m; b=m*a+m*a+m*a+m; } --------------------------------------------------------------------------------------------------- |---MYGRAPH.INC /*MYGraph.Inc BY BIANMING 2005-11-27 InitGraphics - initialize graphics - Screen initialization, specify the graphics driver path gpath ExitGraphics - sound and wait for key press before exiting grapgics - Call after generating graphics SetAxisZP - Set the graphic origin coordinates, default is (0,439) as the origin SetAxisMid - Set the graphic origin coordinates to the center of the screen Plot - place pixel to screen CylPlot - polar coordinate drawing point method GetPixel - gets pixel - return color from specified point Circle - circle draw routine - draw a circle with given center, radius, and color Line - line draw routine - draw a line from given point to another point with given color ShowAxis - display 2D axes ,set X-Axis color,set Y-Axis color. Title - set up text screen colors - prepare the screen for text output */ int CentreX ,CentreY; /* Origin coordinates*/ int MaxX; /*getmaxx*/ int MaxY; /*getmaxy*/ int MaxXres; int MaxYres; int MaxColor; /*Maximum number of colors*/ void InitGraphics(char *gpath) { int gd=DETECT,gm; initgraph(&gd,&gm,gpath); MaxX=getmaxx(); /*getmaxx*/ MaxY=getmaxy(); /*getmaxy*/ MaxXres=MaxX+1; MaxYres=MaxY+1; MaxColor=getmaxcolor(); CentreX=0; CentreY=MaxY; } void ExitGraphics(void) { sound(1000); delay(500); nosound(); getch(); cleardevice(); closegraph(); } void SetAxisZP(int x,int y) /* Set the graphic origin coordinates, default is (0, 439) as the origin*/ { CentreX=x; CentreY=y; } void SetAxisMid(void) /*Set the graphic origin coordinates to the center of the screen*/ { int x,y; x=MaxX>>1; y=MaxY>>1; SetAxisZP(x,y); } void Plot(int x,int y,unsigned char color) { int ScreenX,ScreenY; ScreenX=x+CentreX; ScreenY=MaxY-(y+CentreY); if((ScreenX>=0)&&(ScreenX<=MaxX)&&(ScreenY>=0)&&(ScreenY<=MaxY)) putpixel(ScreenX,ScreenY,color); } void CylPlot(float R,float Theta,Byte color) { int x,y; Theta=Radians(Theta); x=(int)(R*sin(Theta)); y=(int)(R*cos(Theta)); Plot(x,y,color); } int GetPixel(int x,int y) { int ScreenX,ScreenY; ScreenX=x+CentreX; ScreenY=MaxY-(y+CentreY); if((ScreenX>=0)&&(ScreenX<=MaxX)&&(ScreenY>=0)&&(ScreenY<=MaxY)) return(getpixel(ScreenX,ScreenY)); else return(0); } void Swap(int *first,int *second) { int tmp; tmp=*first; *first=*second; *second=tmp; } void Circle(int x,int y,int radius, Byte color) /*600×480 16 color*/ { int a,af,b,bf,target,r2,asp; asp=94; target=0; a=radius; b=0; r2=Sqr(radius); while(a>=b) { b=Round(sqrt(r2-Sqr(a))); Swap(&target,&b); while(b<target) { af=(asp*a)/100; bf=(asp*b)/100; Plot(x+af,y+b,color); Plot(x+bf,y+a,color); Plot(x-af,y+b,color); Plot(x-bf,y+a,color); Plot(x-af,y-b,color); Plot(x-bf,y-a,color); Plot(x+af,y-b,color); Plot(x+bf,y-a,color); ++b; } --a; } } void Line(int xx1,int yy1,int xx2,int yy2,Byte color) { int LgDelta,ShDelta,Cycle,LgStep,ShStep; LgDelta=xx2-xx1; ShDelta=yy2-yy1; if(LgDelta<0) { LgDelta=-LgDelta; LgStep=-1; } else LgStep=1; if(ShDelta<0) { ShDelta=-ShDelta; ShStep=-1; } else ShStep=1; if(ShDelta<LgDelta) { Cycle=LgDelta>>1; while(xx1!=xx2) { Plot(xx1,yy1,color); Cycle+=ShDelta; if(Cycle>LgDelta) { Cycle-=LgDelta; yy1+=ShStep; } xx1+=LgStep; } Plot(xx1,yy1,color); } else { Cycle=ShDelta>>1; Swap(&LgDelta,&ShDelta); Swap(&LgStep,&ShStep); while(yy1!=yy2) { Plot(xx1,yy1,color); Cycle+=ShDelta; if(Cycle>LgDelta) { Cycle-=LgDelta; xx1+=ShStep; } yy1+=LgStep; } Plot(xx1,yy1,color); } } void ShowAxis(Byte xcolor,Byte ycolor) { Line(-200,0,200,0,xcolor); Line(190,7,200,0,xcolor); Line(190,-7,200,0,xcolor);/*x-axis*/ Line(0,-200,0,200,ycolor); Line(7,190,0,200,ycolor); Line(-7,190,0,200,ycolor);/*y-axis*/ } void Title() { textcolor(YELLOW); textbackground(BLUE); clrscr(); } /*FOR 3D GRAPHICS InitPer - observer location and distances - assign observer coordinates in 3D space Per controls whether it is perspective view true-yes false-no InitPlotting - rotation and tilt angles - initialize variables for 3D graphics MapCoordinates - maps 3D space onto the 2D screen - project 3D points onto the view plane Plot3D - plot a cartesian system point - plot a point with given 3D coordinates and color on the 2D screen CylPlot3D - plot a Cylindrical system point - plot a point with given radius, angle with xy plane, z height, and color on the 2D screen given in Cylindrical coordinate system SphPlot3D - plot a spherical system point - plot a point with spherical coordinates r radius, Theta angle of radius line in xy plane, Phi angle of radius line in xz plane VecLine3D - plots a line from 3D coordinates - draw a 3D line from 3D coordinates parameter 1 as the start point and parameter 2 as the end point with color as the color Line3D - draw a line from (x1,y1,z1)-(x2,y2,z2) Vec3D - draw vector Ball - draw a sphere (x,y,z) center coordinates, R radius, color */ Boolean PerspectivePlot; float Mx,My,Mz,ds; /*Observer coordinates (Mx,My,Mz), distance (ds) assignment*/ void InitPer(Boolean Per,float x,float y,float z,float m) { PerspectivePlot=Per; Mx=x; My=y; Mz=z; ds=m; } float Angl ,Tilt; /* Observer's rotation angle, elevation angle*/ float CosA ,SinA; float CosB ,SinB; float CosACosB,SinASinB; float CosASinB,SinACosB; void InitPlotting(float Ang,float Tlt) { Angl =Ang; Tilt =Tlt; CosA =CosD(Angl); SinA =SinD(Angl); CosB =CosD(Tilt); SinB =SinD(Tilt); CosACosB=CosA*CosB; SinASinB=SinA*SinB; CosASinB=CosA*SinB; SinACosB=SinA*CosB; } void MapCoordinates(float x,float y,float z,int *Xp,int *Yp) { float Xt,Yt,Zt; Xt=(Mx+x*CosA-y*SinA); Yt=(My+x*SinASinB+y*CosASinB+z*CosB); if(PerspectivePlot) { Zt=Mz+x*SinACosB+y*CosACosB-z*SinB; *Xp=Round(ds*Xt/Zt); *Yp=Round(ds*Yt/Zt); } else { *Xp=Round(Xt); *Yp=Round(Yt); } } void Plot3D(float x,float y,float z,Byte Color) { int Xp,Yp; MapCoordinates(x,y,z,&Xp,&Yp); Plot(Xp,Yp,Color); } void CylPlot3D(float Rho,float Theta,float z,Byte Color) { float x,y; Theta=Radians(Theta); x=Rho*cos(Theta); y=Rho*sin(Theta); Plot3D(x,y,z,Color); } void SphPlot3D(float r,float Theta,float Phi,Byte Color) { float x,y,z; Theta=Radians(Theta); Phi=Radians(Phi); x=r*sin(Theta)*cos(Phi); y=r*sin(Theta)*sin(Phi); z=r*cos(Theta); Plot3D(x,y,z,Color); } void VecLine3D(TDA P1,TDA P2,Byte Color)/*draw 3D line with vector*/ { int Xp1,Yp1; int Xp2,Yp2; float x1,y1,z1; float x2,y2,z2; UnVec(P1,&x1,&y1,&z1); UnVec(P2,&x2,&y2,&z2); MapCoordinates(x1,y1,z1,&Xp1,&Yp1); MapCoordinates(x2,y2,z2,&Xp2,&Yp2); Line(Xp1,Yp1,Xp2,Yp2,Color); } void Line3D(float x1,float y1,float z1,float x2,float y2,float z2,int Color) { int Xp1,Yp1; int Xp2,Yp2; MapCoordinates(x1,y1,z1,&Xp1,&Yp1); MapCoordinates(x2,y2,z2,&Xp2,&Yp2); Line(Xp1,Yp1,Xp2,Yp2,Color); } void Vec3D(TDA P1,int Color) /*draw vector P1*/ { int Xp1,Yp1; float x1,y1,z1; UnVec(P1,&x1,&y1,&z1); MapCoordinates(x1,y1,z1,&Xp1,&Yp1); Line(0,0,Xp1,Yp1,Color); } void Ball(int x,int y,int z,int R,Byte color) /*draw a sphere (x,y,z) center coordinates, R radius, color*/ { int Theta,Phi; for(Theta=0;Theta<180;Theta+=20) { for(Phi=0;Phi<180;Phi++) { Plot3D(x+R*CosD(Phi)*CosD(Theta),y+R*CosD(Phi)*SinD(Theta),z+R*SinD(Phi),color); Plot3D(x+R*CosD(Phi)*CosD(Theta),y+R*CosD(Phi)*SinD(Theta),z-R*SinD(Phi),color); } } for(Phi=-80;Phi<90;Phi+=20) { for(Theta=0;Theta<180;Theta++) { Plot3D(x+R*CosD(Phi)*CosD(Theta),y+R*CosD(Phi)*SinD(Theta),z+R*SinD(Phi),color); Plot3D(x+R*CosD(Phi)*CosD(Theta),y-R*CosD(Phi)*SinD(Theta),z+R*SinD(Phi),color); } } Plot3D(x,y,z,color+2); } /* GetPixel3D- gets 3D pixel - return color from specified 3D point COLORS: BLACK 0 黑色 DARKGRAY 8 深灰 BLUE 1 兰色 LIGHTBLUE 9 深兰 GREEN 2 绿色 LIGHTGREEN 10 淡绿 CYAN 3 青色 LIGHTCYAN 11 淡青 RED 4 红色 LIGHTRED 12 淡红 MAGENTA 5 洋红 LIGHTMAGENTA 13 淡洋红 BROWN 6 棕色 YELLOW 14 黄色 LIGHTGRAY 7 淡灰 WHITE 15 白色 */ int GetPixel3D(int x,int y,int z) { int xp,yp; MapCoordinates(x,y,z,&xp,&yp); return(GetPixel(xp,yp)); } /* Set up of Coordinate Axes and color Palette ShowAxis3D - 显示3D坐标轴 And Set Axis color ShowPalette - 在屏幕上画出调色板 */ void ShowAxis3D(Byte xcolor,Byte ycolor,Byte zcolor) { int x,y,z; Line3D(-200, 0,0,200,0,0,xcolor); Line3D(190,-7,0,200,0,0,xcolor); Line3D(190, 7,0,200,0,0,xcolor); /*x-Axis*/ Line3D( 0,-200,0,0,200,0,ycolor); Line3D(-7,190,0,0,200,0,ycolor); Line3D( 7,190,0,0,200,0,ycolor); /*y-Axis*/ Line3D(0 ,0,-200,0,0,200,zcolor); Line3D(0,-7,190,0,0,200,zcolor); Line3D(0, 7,190,0,0,200,zcolor); /*z-Axis*/ } void ShowPalette(void) { int y; Byte Color; for(Color=1;Color<MaxColor;Color++) { for(y=0;y<15;y++) Line(-300,y+15*Color,-290,y+15*Color,Color); } } --------------------------------------------------------------------------------------------------- |---MYHEAD.H #include <stdio.h> #include <dos.h> #include <conio.h> #include <math.h> #include <graphics.h> #include "math.inc" #include "mygraph.inc" --------------------------------------------------------------------------------------------------- |---readme.txt /* by Bian Ming, Xi'an University of Posts and Telecommunications.*/ /*This is a C language graphics library and math library written by myself, tested and passed under TC2.0. Please use it with confidence O_o! All drawing functions draw relative to the adjusted coordinate origin, not the screen origin. Please note this! ! ! The feature is that all drawing functions have color settings added, Specifically added 3D drawing. When doing 3D drawing, you need to initialize the observer's coordinates and distance (InitPer()). Also need to initialize the observer's rotation angle relative to the x-axis and the elevation angle relative to the xy plane (InitPoltting()). Because all 3D drawing functions are drawn relative to this initial value. Note: When including this library, you also need to include stdio.h, dos.h, conio.h, math.h, graphics.h, math.inc these libraries. Here you can also have an include "myhead.h". This file is in the compressed package. You can continue to build your own library on this basis. You can also make any modifications. O_o! Here are a few examples: 3Ddemo.c, 3Ddemo2.c, 3Ddemo3.c. [email protected] qq:53793208 Xi'an University of Posts and Telecommunications South Campus, Class 0303, Electronic Science, Mailbox 75. --------------------------------------------------------------------------------------------------- [ Last edited by zzz19760225 on 2017-12-6 at 15:57 ] |
|
| Floor67 zzz19760225 | Posted 2017-12-06 15:45 |
| 超级版主 Posts 2,020 Credits 3,673 | |
|
3ddemo.rar
|----3DDEMO.C |----3DDEMO.exe |----3DDEMO2.C |----3DDEMO2.exe |----3DDEMO3.C |----3DDEMO3.exe --------------------------------------------------------------------------------------------------- |----3DDEMO.C #include "c:\tc\cexe\myhead.h" #define LEFT 0x4b00 #define RIGHT 0x4d00 #define UP 0x4800 #define DOWN 0x5000 #define ESC 0x011b void ShowXYM(void); void PWM(void); void main(void) { int Theta=240,Phi=12; int key; InitGraphics("c:\\tc\\tc2\\bgi"); SetAxisMid(); while(!(kbhit())) { InitPer(0,0,0,500,50);/*3D Init*/ Theta%=360; Phi %= 90; InitPlotting(Theta,Phi); ShowPalette(); ShowXYM(); ShowAxis3D(BLUE,GREEN,CYAN); PWM(); key=bioskey(0); if(key==LEFT) Theta+=5; if(key==RIGHT) Theta-=5; if(key==UP) Phi +=2; if(key==DOWN) Phi -=2; if(key==ESC) ExitGraphics(); cleardevice(); } } void ShowXYM(void) { int x,y; for(x=-300;x<=300;x+=40) Line3D(x,-300,0,x,300,0,5); for(y=-300;y<=300;y+=40) Line3D(-300,y,0,300,y,0,5); } void PWM(void) { long x,y,z; for(x=-200;x<=200;x+=20) for(y=-200;y<=200;y++) { z=Round(sqrt(x*x+y*y)/2); Plot3D(x,y,z,2); } for(y=-200;y<=200;y+=20) for(x=-200;x<=200;x++) { z=Round(sqrt(x*x+y*y)/2); Plot3D(x,y,z,2); } } --------------------------------------------------------------------------------------------------- |----3DDEMO2.C #include "c:\tc\cexe\myhead.h" #define LEFT 0x4b00 #define RIGHT 0x4d00 #define UP 0x4800 #define DOWN 0x5000 #define ESC 0x011b void ShowXYM(Byte); void PWM(Byte); void Ball(int,int,int,int,Byte); void main(void) { int Theta=240,Phi=12; int key;Byte color=0; InitGraphics("c:\\tc\\tc2\\bgi"); SetAxisMid(); while(!(kbhit())) { InitPer(0,0,0,500,50);/*3D Init*/ Theta%=360; Phi %= 90; InitPlotting(Theta,Phi); ShowPalette(); ShowXYM(color+2); ShowAxis3D(BLUE,YELLOW,CYAN); /* PWM(color+4); */ Line3D(0,0,0,100,100,100,color+4); Ball(100,100,100,100,color+9); key=bioskey(0); if(key==LEFT) Theta+=5; if(key==RIGHT) Theta-=5; if(key==UP) Phi +=2; if(key==DOWN) Phi -=2; if(key==ESC) ExitGraphics(); cleardevice(); } } void ShowXYM(Byte color) { int x,y; for(x=-300;x<=300;x+=40) Line3D(x,-300,0,x,300,0,color); for(y=-300;y<=300;y+=40) Line3D(-300,y,0,300,y,0,color); } void PWM(Byte color) { long x,y,z; for(x=-200;x<=200;x+=20) for(y=-200;y<=200;y++) { z=Round(sqrt(x*x+y*y)/2); Plot3D(x,y,z,color); } for(y=-200;y<=200;y+=20) for(x=-200;x<=200;x++) { z=Round(sqrt(x*x+y*y)/2); Plot3D(x,y,z,color); } } void Ball(int x,int y,int z,int R,Byte color) { int Theta,Phi; for(Theta=0;Theta<180;Theta+=20) { for(Phi=0;Phi<180;Phi++) { Plot3D(x+R*CosD(Phi)*CosD(Theta),y+R*CosD(Phi)*SinD(Theta),z+R*SinD(Phi),color); Plot3D(x+R*CosD(Phi)*CosD(Theta),y+R*CosD(Phi)*SinD(Theta),z-R*SinD(Phi),color); } } for(Phi=-80;Phi<90;Phi+=20) { for(Theta=0;Theta<180;Theta++) { Plot3D(x+R*CosD(Phi)*CosD(Theta),y+R*CosD(Phi)*SinD(Theta),z+R*SinD(Phi),color); Plot3D(x+R*CosD(Phi)*CosD(Theta),y-R*CosD(Phi)*SinD(Theta),z+R*SinD(Phi),color); } } Plot3D(x,y,z,color+2); } --------------------------------------------------------------------------------------------------- |----3DDEMO3.C #include "c:\tc\cexe\myhead.h" #define LEFT 0x4b00 #define RIGHT 0x4d00 #define UP 0x4800 #define DOWN 0x5000 #define ESC 0x011b void ShowXYM(Byte); void Luo(int,int,int,int,Byte); void main(void) { int Theta=240,Phi=12; int key;Byte color=0; InitGraphics("c:\\tc\\tc2\\bgi"); SetAxisMid(); while(!(kbhit())) { InitPer(0,0,0,500,500);/*3D Init*/ Theta%=360; Phi %= 90; InitPlotting(Theta,Phi); ShowPalette(); ShowXYM(color+2); ShowAxis3D(BLUE,YELLOW,CYAN); /* PWM(color+4); */ Line3D(0,0,0,100,100,10,color+4); Luo(100,100,10,40,color+9); key=bioskey(0); if(key==LEFT) Theta+=5; if(key==RIGHT) Theta-=5; if(key==UP) Phi +=2; if(key==DOWN) Phi -=2; if(key==ESC) ExitGraphics(); cleardevice(); } } void ShowXYM(Byte color) { int x,y; for(x=-300;x<=300;x+=40) Line3D(x,-300,0,x,300,0,color); for(y=-300;y<=300;y+=40) Line3D(-300,y,0,300,y,0,color); } void Luo(int x,int y,int z,int r,Byte color) { int i; for(i=0;i<180;i++) { Plot3D(x+r*CosD(i),y+r*SinD(i),z,color); Plot3D(x+r*CosD(i),y-r*SinD(i),z,color); } for(i=0;i<=1800;i++) Plot3D(x+r*CosD(i),y+r*SinD(i),z+i/10,color); Plot3D(x+r*CosD(i),y+r*SinD(i),z,color); } --------------------------------------------------------------------------------------------------- [ Last edited by zzz19760225 on 2017-12-6 at 15:58 ] |
|
| Floor68 black0592 | Posted 2018-01-30 10:04 |
| 新手上路 Posts 1 Credits 2 | |
|
Download and see, thank you ^_^
|
|
| Floor69 zhangxiajun | Posted 2018-01-30 10:14 |
| 新手上路 Posts 4 Credits 8 | |
|
Good stuff
|
|
| Floor70 zhangxiajun | Posted 2018-02-24 16:31 |
| 新手上路 Posts 4 Credits 8 | |
|
Download it and study it carefully
|
|
| Floor71 forrest0111 | Posted 2018-03-19 08:19 |
| 新手上路 Posts 6 Credits 12 | |
|
I don't know if it will help in the future, so I'll just download it first.
|
|
| Floor72 lswd | Posted 2020-02-07 13:38 |
| 初级用户 Posts 26 Credits 56 | |
|
Let me download and try it
|
|
| Floor73 ZyDOS | Posted 2020-10-07 08:18 |
| 新手上路 Posts 1 Credits 2 | |
|
Let me download and try it
|
|
| Prev 1 … 2 3 4 5 |
|
[ Contact the Union admin team -
中国DOS联盟 -
Standard version ] Sponsored by ifanr Inc | © 2001–2023 |