1 /*
2  * 4VAPROJ.C
3  * This is 4ViewAuto Projection Unit...same as 4View but no axes!
4  * (c)1991 Matt Welsh
5  *
6  * **************************************************************************
7  * You are free to distribute this and all code and documentation for
8  * the package '4VA' in any form, provided you:
9  * 1. Don't sell it.
10  * 2. Keep the copyright notice intact on all modules, compiled versions,
11  *    and documentation.
12  * 3. Give the original author(s) credit if you use this code in your
13  *    own work or base another program on it.
14  * ***************************************************************************
15  */
16 
17 #include "4vahead.h"
18 #include <math.h>
19 
fixangles(params)20 void fixangles(params) transfParams *params; {
21   params->cxy = cos(params->rxy); params->sxy = sin(params->rxy);
22   params->cxz = cos(params->rxz); params->sxz = sin(params->rxz);
23   params->cyz = cos(params->ryz); params->syz = sin(params->ryz);
24   params->cxw = cos(params->rxw); params->sxw = sin(params->rxw);
25   params->cyw = cos(params->ryw); params->syw = sin(params->ryw);
26   params->czw = cos(params->rzw); params->szw = sin(params->rzw);
27 }
28 
deg2rad(ang)29 float deg2rad(ang) float ang; {
30   return (ang * (M_PI/180));
31 }
32 
makeemptyparams()33 void makeemptyparams() {
34   emptyparams.rxy=0; emptyparams.rxz=0; emptyparams.ryz=0;
35   emptyparams.rxw=0; emptyparams.ryw=0; emptyparams.rzw=0;
36   fixangles(&emptyparams);
37   emptyparams.trnx=emptyparams.trny=emptyparams.trnz=emptyparams.trnw=0;
38   emptyparams.sclx=emptyparams.scly=emptyparams.sclz=emptyparams.sclw=1;
39 }
40 
matrix(a,b,sinr,cosr)41 void matrix(a, b, sinr, cosr) float *a; float *b;
42                               float sinr; float cosr;
43 {
44   float tma;
45   tma= *a;
46   *a = (tma * cosr) - (*b * sinr);
47   *b = (tma * sinr) + (*b * cosr);
48 }
49 
transform(thept,params)50 point_t transform(thept, params) point_t thept; transfParams *params; {
51   thept.x *= params->sclx;
52   thept.y *= params->scly;
53   thept.z *= params->sclz;
54   thept.w *= params->sclw;
55 
56   thept.x += params->trnx;
57   thept.y += params->trny;
58   thept.z += params->trnz;
59   thept.w += params->trnw;
60 
61   matrix(&thept.x, &thept.y, params->sxy, params->cxy);
62   matrix(&thept.x, &thept.z, params->sxz, params->cxz);
63   matrix(&thept.y, &thept.z, params->syz, params->cyz);
64   matrix(&thept.x, &thept.w, params->sxw, params->cxw);
65   matrix(&thept.y, &thept.w, params->syw, params->cyw);
66   matrix(&thept.z, &thept.w, params->szw, params->czw);
67 
68   return thept;
69 }
70 
perspective(thept)71 void perspective(thept) point_t *thept; {
72   float mw, mz;
73   mw= w_dist - thept->w; mz= z_dist - thept->z;
74 
75 
76   /* Smash object against screen in case it gets too close. */
77   if (mw < 3.4e-35) {
78     mw = 3.4e-35;
79   }
80 
81   if (mz < 3.4e-35) {
82     mz = 3.4e-35;
83   }
84 
85   /* Perspective over w */
86   thept->x /= mw * (1/w_dist);
87   thept->y /= mw * (1/w_dist);
88   thept->z /= mw * (1/w_dist);
89 
90   /* Perspective over z */
91   thept->x /= mz * (1/z_dist);
92   thept->y /= mz * (1/z_dist);
93 
94 }
95 
project(obj)96 void project(obj) object *obj; {
97 /* This function no longer displays the object. It trnasforms all points and buffers the lines.
98  * It doesn't draw anything. */
99 
100   int i, from, to, x1, y1, x2, y2;
101 
102   for (i=0; i < obj->numpoints; i++) {
103     obj->transpts[i] = transform(obj->pts[i], &obj->params);
104   }
105 
106   if (perspon) {
107     for (i=0; i < obj->numpoints; i++) {
108       perspective(&obj->transpts[i]);
109     }
110   }
111 
112   for (i=0; i < obj->numlines; i++) {
113     from=obj->lns[i].from;
114     to=obj->lns[i].to;
115     x1=(int)(obj->transpts[from].x+CENX);
116     y1=(int)(SIZY-(obj->transpts[from].y+CENY));
117     x2=(int)(obj->transpts[to].x+CENX);
118     y2=(int)(SIZY-(obj->transpts[to].y+CENY));
119     g_bufferline(x1,x2,y1,y2,i);
120   }
121 
122 }
123 
124