home *** CD-ROM | disk | FTP | other *** search
- #include <stdlib.h>
- #include <malloc.h>
- #include "worlddr.h"
- #include <graph.h>
- #include <math.h>
- #include <stdio.h>
- #include <io.h>
- float tCurnt[9];
- float t3Curnt[16];
-
- struct point3D{
- float x,y,z;
- };
- struct point3D Poly3DType[100];
-
-
- void IdArg(float a[])
- {
- int i;
- int j;
-
- for ( i = 0; i <= 2; ++i ) {
- for ( j = 0; j <= 2; ++j ) {
- a[i*3+j] = 0.0;
- }
- a[i*3+i] = 1.0;
- }
- }
-
- void Concat(float a[],float b[],float c[])
- {
- int i;
- int j;
- float temp[9];
-
- for ( i = 0; i <= 2; ++i ) {
- for ( j = 0; j <= 2; ++j ) {
- temp[i*3+j] = a[i*3+0] * b[j] +
- a[i*3+1] * b[1*3+j] +
- a[i*3+2] * b[2*3+j];
- }
- }
- for (i=0; i <=8; ++i){
- c[i] = temp[i];
- }
- }
-
-
- void Ident(float imatrix[])
- {
- IdArg(imatrix);
- }
-
- void tInit()
- {
- Ident(tCurnt);
- }
-
-
- void Xfrm2P(float x,float y,float *xt,float *yt)
- {
-
- (*xt) = x * tCurnt[0] + y * tCurnt[3] +
- tCurnt[6];
- (*yt) = x * tCurnt[1] + y * tCurnt[4] +
- tCurnt[7];
- *xt = *xt/tCurnt[8];
- *yt = *yt/tCurnt[8];
- }
-
- void WorldTran2(float x,float y)
- {
- float tmpMat[9];
- IdArg(tmpMat);
- tmpMat[6] = x;
- tmpMat[7] = y;
- Concat(tCurnt,tmpMat,tCurnt);
- }
-
- void WorldRotate2(float degree)
- {
- float tmpMat[9];
- double radian;
-
- IdArg(tmpMat);
- radian = degree * 3.1415 / 180.0;
- tmpMat[0] = cos(radian);
- tmpMat[1] = sin(radian);
- tmpMat[3] = -sin(radian);
- tmpMat[4] = cos(radian);
- Concat(tCurnt,tmpMat,tCurnt);
- }
-
- void WorldScale2(float x,float y)
- {
- float tmpMat[9];
-
- IdArg(tmpMat);
- tmpMat[0] = x;
- tmpMat[4] = y;
- Concat(tCurnt,tmpMat,tCurnt);
- }
-
- void Line2Abs(float x,float y)
- {
- float xt;
- float yt;
- Xfrm2P(x,y,&xt,&yt);
- LineWorldAbs(xt,yt);
- }
-
- void Move2Abs(float x,float y)
- {
- float xt;
- float yt;
-
- Xfrm2P(x,y,&xt,&yt);
- MoveWorldAbs(xt,yt);
- }
-
- void Line2Rel(float x,float y)
- {
- float xt;
- float yt;
-
- Xfrm2P(x,y,&xt,&yt);
- LineWorldRel(xt,yt);
- }
-
- void Move2Rel(float x,float y)
- {
- float xt;
- float yt;
-
- Xfrm2P(x,y,&xt,&yt);
- MoveWorldRel(xt,yt);
- }
-
-
- void IdArg3(float a[])
- { int i;
- int j;
-
- for (i = 0; i <= 3; ++i)
- {
- for (j = 0; j <= 3; ++j )
- a[i*4+j] = 0.0;
- a[i*4+i] = 1.0;
- }
- }
-
- void Concat3( float a[],
- float b[],
- float c[] )
- { int i;
- int j;
- float temp[16];
-
- for (i = 0; i <= 3; ++i)
- {
- for (j = 0; j <= 3; ++j )
- temp[i*4+j] = a[i*4+0] * b[j] +
- a[i*4+1] * b[1*4+j] +
- a[i*4+2] * b[2*4+j] +
- a[i*4+3] * b[3*4+j];
- }
- for (i = 0; i <= 15; ++i)
- c[i] = temp[i];
-
- }
-
- void Ident3(float imatrix[])
- {
- IdArg3(imatrix);
- }
-
-
- void tInit3()
- {
- Ident3(t3Curnt);
- }
-
-
- void Xfrm3P(float x,
- float y,
- float z,
- float w,
- float *xt,
- float *yt,
- float *zt,
- float *wt)
- {
- *xt = x * t3Curnt[0] + y * t3Curnt[4] +
- z * t3Curnt[8] + w * t3Curnt[12];
-
- *yt = x * t3Curnt[1] + y * t3Curnt[5] +
- z * t3Curnt[9] + w * t3Curnt[13];
-
- *zt = x * t3Curnt[2] + y * t3Curnt[6] +
- z * t3Curnt[10] + w * t3Curnt[14];
-
- *wt = x * t3Curnt[3] + y * t3Curnt[7] +
- z * t3Curnt[11] + w * t3Curnt[15];
- }
-
- void WorldTran3( float x,
- float y,
- float z)
- {
- float tmp3Mat[16];
-
- IdArg3(tmp3Mat);
- tmp3Mat[12] = x;
- tmp3Mat[13] = y;
- tmp3Mat[14] = z;
- Concat3(t3Curnt,tmp3Mat,t3Curnt);
- }
-
-
- void WorldRotate3( float degree,
- int iAxis)
- {
- float tmp3Mat[16];
- float sign;
- float radian;
- int i1;
- int i2;
- int i;
-
- switch (iAxis){
- case 0: { i1 = 1; i2 = 2; sign = 1.0; }
- break;
- case 1: { i1 = 0; i2 = 2; sign = -1.0; }
- break;
- case 2: { i1 = 0; i2 = 1; sign = 1.0; }
- break;
- default:
- { i1 = 1; i2= 2; };
- break;
- }
- IdArg3(tmp3Mat);
- radian = degree * 3.1415 / 180.0;
-
- tmp3Mat[i1*4+i1] = cos(radian);
- tmp3Mat[i2*4+i2] = tmp3Mat[i1*4+i1];
- tmp3Mat[i1*4+i2] = sign*sin(radian);
- tmp3Mat[i2*4+i1] = -tmp3Mat[i1*4+i2];
- Concat3(t3Curnt,tmp3Mat,t3Curnt);
-
- }
-
-
- void WorldScale3( float x,
- float y,
- float z)
- {
- float tmp3Mat[16];
-
- IdArg3(tmp3Mat);
- tmp3Mat[0] = x;
- tmp3Mat[5] = y;
- tmp3Mat[10] = z;
- Concat3(t3Curnt,tmp3Mat,t3Curnt);
- }
-
- void Persp( float dist )
-
- {
- float tmp3Mat[16];
-
- IdArg3( tmp3Mat );
- tmp3Mat[0] = -dist;
- tmp3Mat[5] = -dist;
- tmp3Mat[11] = 1.0;
- tmp3Mat[15] = -dist;
- Concat3(t3Curnt,tmp3Mat, t3Curnt );
- }
-
- void Line3Abs( float x,
- float y,
- float z)
-
- {
- float xt;
- float yt;
- float zt;
- float wt;
- Xfrm3P(x,y,z, 1.0, &xt,&yt,&zt,&wt);
- xt = xt/wt;
- yt= yt/wt;
- LineWorldAbs(xt,yt);
-
- }
-
- void Move3Abs( float x,
- float y,
- float z)
-
- {
- float xt;
- float yt;
- float zt;
- float wt;
-
- Xfrm3P(x,y,z, 1.0, &xt,&yt,&zt,&wt);
- xt = xt/wt;
- yt= yt/wt;
- MoveWorldAbs(xt,yt);
-
- }
-
- void Line3Rel( float x,
- float y,
- float z)
-
- {
- float xt;
- float yt;
- float zt;
- float wt;
- Xfrm3P(x,y,z, 1.0, &xt,&yt,&zt,&wt);
- xt = xt/wt;
- yt= yt/wt;
- LineWorldRel(xt,yt);
- }
-
- void Move3Rel(float x,
- float y,
- float z)
-
- {
- float xt;
- float yt;
- float zt;
- float wt;
- Xfrm3P(x,y,z, 1.0, &xt,&yt,&zt,&wt);
- xt = xt/wt;
- yt = yt/wt;
- MoveWorldRel(xt,yt);
- }
-
- void Draw3DAxes( float x,
- float y,
- float z)
-
-
- {
- Move3Abs( 0.0,0.0,0.0 );
- Line3Abs( x,0.0,0.0);
- Move3Abs(0.0,0.0,0.0 );
- Line3Abs( 0.0 ,y,0.0 );
- Move3Abs( 0.0,0.0,0.0);
- Line3Abs( 0.0,0.0,z);
-
- }
-
- void PolyFill3D( struct point3D *p, int fillstyle, int fillcolor,int numdat){
- int i;
- float xt,yt,zt,wt;
- float *x,*y;
-
- x = (float *) calloc(numdat,4);
- y = (float *) calloc(numdat,4);
- for (i=0; i <= numdat-1; i++){
-
- Xfrm3P(p[i].x,p[i].y,p[i].z,1.0,&xt,&yt,&zt,&wt);
- x[i] = xt/wt;
- y[i] = yt/wt;
- }
- PolyFillWorldAbs(x,y,fillstyle, fillcolor,numdat);
- free(x); free(y);
- }
-
- void Label3D( char *outstring ){
- outtextXX(outstring);
- }
-
- void Init3D(int crtmod)
- {
- tInit();
- tInit3();
- OneTimeInit(crtmod);
- }
-
- void Close3DGraphics(){
- closegraphics();
- }
-
-