1 #ifndef _V3D_H
2 #define _V3D_H
3 
4 #include <math.h>
5 #include <stdlib.h>
6 #include <stdio.h>
7 
8 #include "mathtools.h"
9 
10 typedef struct {
11     float x,y,z;
12 } v3d;
13 
14 typedef struct {
15     int x,y;
16 } v2d;
17 
18 typedef struct {
19     double x,y;
20 } v2g;
21 
22 /*
23  * projete le vertex 3D sur le plan d'affichage
24  * retourne (0,0) si le point ne doit pas etre affiche.
25  *
26  * bonne valeur pour distance : 256
27  */
28 #define V3D_TO_V2D(v3,v2,width,height,distance) \
29 { \
30   int Xp, Yp; \
31   if (v3.z > 2) { \
32 	 F2I((distance * v3.x / v3.z),Xp) ; \
33  	 F2I((distance * v3.y / v3.z),Yp) ; \
34  	 v2.x = Xp + (width>>1); \
35 	 v2.y = -Yp + (height>>1); \
36   } \
37   else v2.x=v2.y=-666; \
38 }
39 
40 void v3d_to_v2d(v3d *src, int nbvertex, int width, int height, float distance, v2d *v2_array);
41 
42 /*
43  * rotation selon Y du v3d vi d'angle a (cosa=cos(a), sina=sin(a))
44  * centerz = centre de rotation en z
45  */
46 #define Y_ROTATE_V3D(vi,vf,sina,cosa)\
47 {\
48  vf.x = vi.x * cosa - vi.z * sina;\
49  vf.z = vi.x * sina + vi.z * cosa;\
50  vf.y = vi.y;\
51 }
52 
53 /*
54  * translation
55  */
56 #define TRANSLATE_V3D(vsrc,vdest)\
57 {\
58  vdest.x += vsrc.x;\
59  vdest.y += vsrc.y;\
60  vdest.z += vsrc.z;\
61 }
62 
63 #define MUL_V3D(lf,v) {v.x*=lf;v.y*=lf;v.z*=lf;}
64 
65 #endif
66