Tachyon (current)  Current Main Branch
mainanim.c
Go to the documentation of this file.
1 /*
2  * mainanim.c - This file contains a Tachyon animation demo/driver
3  *
4  * (C) Copyright 1994-2022 John E. Stone
5  * SPDX-License-Identifier: BSD-3-Clause
6  *
7  * $Id: mainanim.c,v 1.16 2022/02/18 18:18:36 johns Exp $
8  *
9  */
10 
11 #include <stdio.h>
12 #include <stdlib.h>
13 #include <string.h>
14 #include <math.h>
15 #include "tachyon.h"
16 
17 int rt_mynode(void); /* proto */
18 
19 #define MAXFRAMES 100
20 #define LOOP 100.0
21 #define LOOP2 50.0
22 #define RAD 6.28
23 
24 #ifdef cube
25 #define RFILE "/cfs/johns/anim/frame"
26 #else
27 #define RFILE "outfile"
28 #endif
29 
30 int main(int argc, char **argv) {
31  SceneHandle scene;
32  int i,j;
33  apivector ctr, ctr1, vect2;
34  apitexture tex1, tex2;
35  apiflt f1, f2;
36  char fname[200];
37  char fname2[200];
38 
39  rt_initialize(&argc, &argv);
40 
41  tex1.col.r=1.0;
42  tex1.col.g=1.0;
43  tex1.col.b=1.0;
44  ctr1.x=5.0;
45  ctr1.y=5.0;
46  ctr1.z=1.0;
47  f1=0.5;
48 
49  tex2.col.r=1.0;
50  tex2.col.g=1.0;
51  tex2.col.b=1.0;
52  tex2.ambient=0.1;
53  tex2.diffuse=0.7;
54  tex2.specular=0.2;
55  tex2.opacity=1.0;
56  tex2.texturefunc=0;
57  f2=1.5;
58 
59  vect2.x=0.0;
60  vect2.y=1.0;
61  vect2.z=0.0;
62 
63  for (i=0; i<MAXFRAMES; i++) {
64  void * txarray[20];
65 
66  scene = rt_newscene();
67  rt_resolution(scene, 320, 240);
68 
69 #ifdef cube
70  if (rt_mynode()==0) printf("Rendering frame %d \n",i);
71 #endif
72 #ifndef cube
73  printf("Rendering frame %d \n",i);
74 #endif
75  ctr1.x= i / 20.0 - 5.0;
76  ctr1.y=5.0;
77  ctr1.z= i / 20.0 + 5.0;
78  tex1.col.r=1.0;
79  tex1.col.g=1.0;
80  tex1.col.b=1.0;
81  txarray[0] = rt_texture(scene, &tex1);
82  rt_light(scene, txarray[0], ctr1, f1);
83 
84  ctr1.x= i / 15.0 - 5.0;
85  ctr1.y=0.0;
86  ctr1.z=15.0;
87  tex1.col.r=0.0;
88  tex1.col.g=0.0;
89  tex1.col.b=1.0;
90  txarray[1] = rt_texture(scene, &tex1);
91  rt_light(scene, txarray[1], ctr1, f1 / 3.0 );
92 
93  j=i;
94  tex2.col.r=1.0;
95  tex2.texturefunc=0;
96  ctr.x=2.0*sin((j*RAD) / LOOP);
97  ctr.z=10.0 + 2.0*cos((j*RAD) / LOOP);
98  ctr.y=-2.0;
99 
100  txarray[2] = rt_texture(scene, &tex2);
101  rt_sphere(scene, txarray[2], ctr, f2);
102 
103  tex2.texturefunc=0;
104  j=i+(MAXFRAMES/3);
105  tex2.col.r=0.5 + 0.5*sin((j*RAD)/ LOOP2);
106  ctr.x=2.0*sin((j*RAD) / LOOP);
107  ctr.z=10.0 + 2.0*cos((j*RAD) / LOOP);
108  ctr.y=-2.0;
109 
110  txarray[3] = rt_texture(scene, &tex2);
111  rt_sphere(scene, txarray[3], ctr, f2);
112 
113  j=i+((MAXFRAMES * 2)/3);
114  tex2.col.r=1.0;
115  tex2.col.b=0.5 + 0.5*sin((j*RAD)/ LOOP2);
116  ctr.x=2.0*sin((j*RAD) / LOOP);
117  ctr.z=10.0 + 2.0*cos((j*RAD) / LOOP);
118  ctr.y=-2.0;
119 
120  txarray[4] = rt_texture(scene, &tex2);
121  rt_sphere(scene, txarray[4], ctr, f2);
122 
123  tex2.col.r=0.0;
124  tex2.col.b=1.0;
125  tex2.ambient=0.0;
126  tex2.diffuse=0.0;
127  tex2.specular=0.99;
128 
129  ctr.x=0.0;
130  ctr.y=-2.0;
131  ctr.z=10.0;
132 
133  txarray[5] = rt_texture(scene, &tex2);
134  rt_sphere(scene, txarray[5], ctr, f2);
135 
136 
137  tex2.diffuse=0.8;
138  tex2.ambient=0.1;
139  tex2.specular=0.2;
140  tex2.col.r=1.0;
141  ctr.y=-7.0;
142 
143  txarray[6] = rt_texture(scene, &tex2);
144  rt_plane(scene, txarray[6], ctr, vect2);
145 
146 
147  sprintf(fname,".%4.4d.tga",i);
148  strcpy(fname2, RFILE);
149  strcat(fname2, fname);
150 
151  rt_outputfile(scene, fname2);
152 
153  rt_renderscene(scene);
154 
155  rt_deletescene(scene);
156 
157 #if 0
158  for (j=0; j<7; j++)
159  free(txarray[j]);
160 #endif
161  }
162 
163  rt_finalize();
164 
165  return 0;
166 }
167 
float g
Green color component.
Definition: tachyon.h:61
float r
Red color component.
Definition: tachyon.h:60
void * rt_texture(SceneHandle sc, apitexture *apitex)
Translate a texture definition into the internal format used by Tachyon, and returns an opaque pointe...
Definition: api.c:933
apicolor col
base object color
Definition: tachyon.h:67
#define MAXFRAMES
Definition: mainanim.c:19
void rt_resolution(SceneHandle voidscene, int hres, int vres)
Set the horizontal and vertical resolution (in pixels) for the specified scene.
Definition: api.c:372
int main(int argc, char **argv)
Definition: mainanim.c:30
#define LOOP
Definition: mainanim.c:20
flt diffuse
diffuse reflection
Definition: tachyon.h:70
flt opacity
how opaque the object is
Definition: tachyon.h:72
flt specular
specular reflection
Definition: tachyon.h:71
#define LOOP2
Definition: mainanim.c:21
#define RAD
Definition: mainanim.c:22
void rt_renderscene(SceneHandle voidscene)
Render the current scene.
Definition: api.c:180
void rt_sphere(SceneHandle scene, void *tex, apivector ctr, flt rad)
Define a sphere with associated texture, center, and radius.
Definition: api.c:1212
int rt_initialize(int *argc, char ***argv)
Initialize Tachyon library, must be first Tachyon API called.
Definition: api.c:70
flt x
X coordinate or direction component.
Definition: tachyon.h:54
flt apiflt
for backward compatibility
Definition: tachyon.h:49
flt y
Y coordinate or direction component.
Definition: tachyon.h:55
SceneHandle rt_newscene(void)
Allocate, initialize, and return a handle for a new scene.
Definition: api.c:698
void rt_outputfile(SceneHandle voidscene, const char *outname)
Set the filename for the output image for the specified scene.
Definition: api.c:350
void rt_deletescene(SceneHandle voidscene)
Destroy and deallocate the specified scene.
Definition: api.c:784
#define RFILE
Definition: mainanim.c:27
void * SceneHandle
Definition: tachyon.h:51
int texturefunc
which texture function to use
Definition: tachyon.h:66
flt ambient
ambient lighting
Definition: tachyon.h:69
void rt_finalize(void)
Shut down Tachyon library for good, at final use before program termination.
Definition: api.c:153
float b
Blue color component.
Definition: tachyon.h:62
void rt_plane(SceneHandle scene, void *tex, apivector ctr, apivector norm)
Define a plane.
Definition: api.c:1186
int rt_mynode(void)
distributed memory parallel node rank
Definition: api.c:49
Tachyon public API function prototypes and declarations used to drive the ray tracing engine...
void * rt_light(SceneHandle voidscene, void *tex, apivector ctr, flt rad)
Define a point light with associated texture, position, and radius.
Definition: api.c:1049
flt z
Z coordinate or direction component.
Definition: tachyon.h:56