source: trunk/source/geometry/solids/test/X11RayTracer/main.c@ 1353

Last change on this file since 1353 was 1350, checked in by garnier, 15 years ago

update to last version 4.9.4

File size: 1.8 KB
Line 
1#include "main.h"
2#include "torus.h"
3#include <signal.h>
4#include <unistd.h>
5#include <assert.h>
6#include <math.h>
7
8double cos(double x);
9double sin(double x);
10
11#define EPSILON 1e-8
12#define NBCERCLES 36
13#define NBPOINTS 36
14
15#define RAYON 100
16
17int NbAff = 0;
18double *px,*py,*pz;
19
20void alarme (int sig)
21{
22 printf("NbAff = %d\n",NbAff);
23 NbAff = 0;
24 alarm (10);
25}
26
27
28int main (int argc,char *argv[]) {
29
30 if (argc > 1) {
31 printf("%s\n",argv[0]);
32 printf("%s\n",argv[1]);
33 if (strcmp(argv[1],"BVM") == 0) {
34 printf("BVM only\n");
35 BVM_ONLY = 1;
36 }
37 }
38
39 /* Init X11 for 24 bpp */
40
41 init_x ();
42
43 /* Set up the alarm */
44
45 signal (SIGALRM,alarme);
46 alarm (10);
47
48 while (event_x()) {
49 refresh ();
50 aff ();
51 }
52
53 for(;;);
54 /* Free */
55
56 free (px);
57 free (py);
58 free (pz);
59
60 /* Close X */
61
62 close_x();
63
64 /* End */
65
66 exit (0);
67}
68
69void aff () {
70 NbAff ++;
71 XPutImage(dis,win,gc,xim,0,0,0,0,W,H);
72
73}
74
75void refresh () {
76 int i,j;
77 long int V,R ;
78 double d;
79 static int t=1;
80
81 double zoom = 0.20 + 0.01*t;
82 double theta = 0.15 + 0.05*t;
83
84 Intersect Inter ;
85
86 memset ( buffer , 0 , 4*W*H );
87
88 for (j=0;j<H;j++)
89 for (i=0;i<W;i++)
90 {
91 //fprintf(stderr,"%d %d\n",i,j);
92
93 R = 0;
94
95 Inter.dx = -1.0*cos(theta);
96 Inter.dy = 0.0;
97 Inter.dz = -1.0*sin(theta);
98
99 Inter.x = (65.0)*cos(theta) + 0.20*(i - W/2)*sin(theta); //45.0
100 Inter.y = 0.20*(j - H/2) ;
101 Inter.z = (65.0)*sin(theta) + 0.20*(i - W/2)*(-cos(theta));
102
103 Inter.R0 = 20.0; //20.0; //20.0 25
104 Inter.R1 = 24.0; //14.0; //4.0 19.0
105 Inter.phi = 0.0;
106 Inter.deltaphi = M_PI;
107 d = DistanceToTorus (&Inter);
108
109 if (d < 0)
110 {
111 V = 0;
112 R = 255 ;
113 } else {
114 V = d*2;//4 16 32
115 }
116 if (V > 255) {
117 V = 255 ;
118 }
119
120 if (V < 0) V = 0 ;
121 buffer[4*(i*H+j)+0] = V;
122 buffer[4*(i*H+j)+1] = V;
123 buffer[4*(i*H+j)+2] = V+R;
124 }
125 t ++;
126}
127
Note: See TracBrowser for help on using the repository browser.