Tachyon (current)  Current Main Branch
hypertex.c
Go to the documentation of this file.
1 /*
2  * hypertex.c - This file contains a Tachyon demo program/driver
3  *
4  * (C) Copyright 1994-2022 John E. Stone
5  * SPDX-License-Identifier: BSD-3-Clause
6  *
7  * $Id: hypertex.c,v 1.14 2022/02/18 18:18:36 johns Exp $
8  *
9  */
10 
11 #include <stdio.h>
12 #include <stdlib.h>
13 #include <math.h>
14 #include <string.h>
15 #include "tachyon.h"
16 
17 int rt_mynode(void); /* proto */
18 
19 #define XRES 352
20 #define YRES 240
21 
22 /* MPEG-1 Resolution */
23 /*
24  *#define XRES 352
25  *#define YRES 240
26  */
27 
28 /* Pro Video Full Frame NTSC
29  * #define XRES 768
30  * #define YRES 576
31  */
32 
33 /* PC VGA, and NTSC Resolution
34  * #define XRES 640
35  * #define YRES 480
36  */
37 
38 #define MAXFRAMES 60
39 #define OPACITY 4.0
40 
41 #define RAD 6.28
42 
43 typedef struct { /* Scalar Volume Visualization Data */
44  int loaded; /* Volume data memory residence flag */
45  int xres; /* volume X axis size */
46  int yres; /* volume Y axis size */
47  int zres; /* volume Z axis size */
48  apiflt opacity; /* opacity per unit length */
49  char name[80]; /* Volume data filename */
50  unsigned char * data; /* pointer to raw byte volume data */
51 } scalarvol;
52 
53 typedef struct {
54  int x;
55  int y;
56 } flm;
57 
58 #ifdef cube
59 #define RFILE "/cfs/johns/anim/frame"
60 #endif
61 #ifndef cube
62 #define RFILE "frame"
63 #endif
64 
65 /* global frame number */
66 static int framenumber=0;
67 
68 apiflt hypertex1(double x, double y, double z) {
69  double value, dist;
70  double xx, yy, zz;
71 
72  xx = x - 0.5;
73  yy = y - 0.5;
74  zz = z - 0.5;
75 
76  dist = sqrt(xx*xx + yy*yy + zz*zz);
77 
78  if (dist < 0.35) {
79  value = 1.0;
80  }
81  else {
82  value = 0.0;
83  }
84 
85  return value;
86 }
87 
88 
89 apiflt hypertex2(double x, double y, double z) {
90  double xx, yy, zz;
91  double dist;
92  double value;
93 
94  xx = x - 0.5;
95  yy = y - 0.5;
96  zz = z - 0.5;
97 
98  dist = sqrt(xx*xx + yy*yy + zz*zz) + (framenumber / 200);
99 
100  value = (1.0 + cos(dist * 48.0) / (2*dist + 1.0)) / 2.0;
101 
102  value = value*value*value;
103 
104  return value;
105 }
106 
107 int main(int argc, char **argv) {
108  SceneHandle scene;
109  int i;
110  int raydepth, antialiasing, verbosemode;
111  apiflt zoom, aspectratio;
112  apivector Ccenter, Cview, Cup;
113  apivector ctr1;
114  apitexture tex1, tex2;
115  apivector min3, max3;
116  apitexture p1;
117  apivector ct1, n1;
118  apiflt xc,yc;
119  void * t1;
120  char fname[1000];
121  char fname2[2000];
122 
123  rt_initialize(&argc, &argv);
124 
125  scene = rt_newscene();
126 
127  aspectratio=1.0; raydepth=8;
128  antialiasing=0; verbosemode=0; zoom=1.0;
129 
130  Ccenter.x=0.0; Ccenter.y=0.0; Ccenter.z=0.0;
131  Cview.x=1.0; Cview.y=0.0; Cview.z=0.0;
132  Cup.x=0.0; Cup.y=0.0; Cup.z=1.0;
133  ctr1.x=2.0; ctr1.y=2.0; ctr1.z=2.0;
134 
135  tex1.col.r=1.0; tex1.col.g=1.0; tex1.col.b=1.0;
136  tex1.ambient=0.5;
137  tex1.diffuse=1.0;
138  tex1.specular=0.0;
139  tex1.opacity=OPACITY;
140  tex1.texturefunc=0;
141  tex2=tex1;
142 
143  min3.x=-1.0; min3.y=-1.0; min3.z=-1.0;
144  max3.x=1.0; max3.y=1.0; max3.z=1.0;
145 
146  p1.col.r=1.0; p1.col.g=1.0; p1.col.b=1.0;
147  p1.ambient=0.3; p1.diffuse=0.8; p1.specular=0.0; p1.opacity=1.0;
148 
149  p1.texturefunc=9;
150  p1.ctr.x=0.0; p1.ctr.y=0.0; p1.ctr.z=0.0;
151  p1.rot.x=0.0; p1.rot.y=0.0; p1.rot.z=0.0;
152  p1.scale.x=0.1; p1.scale.y=0.1; p1.scale.z=0.1;
153  p1.uaxs.x=1.0; p1.uaxs.y=0.0; p1.uaxs.z=0.0;
154  p1.vaxs.x=0.0; p1.vaxs.y=1.0; p1.vaxs.z=0.0;
155 #ifdef cube
156  strcpy((char *) &p1.imap, "/cfs/johns/imaps/leafy261.ppm");
157 #endif
158 #ifndef cube
159  strcpy((char *) &p1.imap, "/disk7/cube/imaps/leafy261.ppm");
160 #endif
161 
162  t1=rt_texture(scene, &p1);
163 
164  for (i=0; i<MAXFRAMES; i++) {
165  rt_initialize(&argc, &argv);
166 
167  sprintf(fname,".%4.4d.tga",i);
168  strcpy(fname2,RFILE);
169  strcat(fname2, fname);
170 
171  framenumber++;
172 
173  if (rt_mynode()==0) printf("Rendering: %s \n",fname2);
174 
175  xc=cos(6.28 * (i + 200) / (1.0 * MAXFRAMES));
176  yc=sin(6.28 * (i + 200) / (1.0 * MAXFRAMES));
177  Ccenter.x = xc*5.2;
178  Ccenter.y = yc*5.2;
179  Cview.x = -xc;
180  Cview.y = -yc;
181 
182  rt_outputfile(scene, fname2);
183  rt_resolution(scene, XRES, YRES);
184  rt_verbose(scene, verbosemode);
185 
186  rt_camera_setup(scene, zoom, aspectratio, antialiasing,
187  raydepth, Ccenter, Cview, Cup);
188 
189  rt_light(scene, rt_texture(scene, &tex1), ctr1, 1.0);
190 
191  rt_extvol(scene, rt_texture(scene, &tex2), min3, max3, 64, hypertex1);
192 
193  ct1.x=0.0; ct1.y=0.0; ct1.z=-1.01;
194  n1.x=0.0; n1.y=0.0; n1.z=1.0;
195  rt_plane(scene, t1, ct1, n1);
196 
197  ct1.x=0.0; ct1.y=1.8; ct1.z=1.8;
198 
199  rt_renderscene(scene);
200  }
201  rt_finalize();
202 
203  return 0;
204 }
205 
float g
Green color component.
Definition: tachyon.h:61
void rt_camera_setup(SceneHandle voidscene, flt zoom, flt aspectratio, int antialiasing, int raydepth, apivector camcent, apivector viewvec, apivector upvec)
Define a camera for a perspective projection, given the specified zoom factor, aspect ratio...
Definition: api.c:229
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
#define YRES
Definition: hypertex.c:20
apicolor col
base object color
Definition: tachyon.h:67
apivector rot
rotation of texture around origin
Definition: tachyon.h:74
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
flt diffuse
diffuse reflection
Definition: tachyon.h:70
flt opacity
how opaque the object is
Definition: tachyon.h:72
int rt_mynode(void)
distributed memory parallel node rank
Definition: api.c:49
flt specular
specular reflection
Definition: tachyon.h:71
#define XRES
Definition: hypertex.c:19
void rt_extvol(SceneHandle scene, void *tex, apivector min, apivector max, int samples, flt(*evaluator)(flt, flt, flt))
Define an axis-aligned volumetric data set, with a user-defined sample evaluation callback function...
Definition: api.c:1152
apivector ctr
origin of texture
Definition: tachyon.h:73
static int framenumber
Definition: hypertex.c:66
char imap[96]
name of image map
Definition: tachyon.h:79
void rt_renderscene(SceneHandle voidscene)
Render the current scene.
Definition: api.c:180
#define OPACITY
Definition: hypertex.c:39
#define MAXFRAMES
Definition: hypertex.c:38
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
int data
Definition: hash.c:23
flt apiflt
for backward compatibility
Definition: tachyon.h:49
flt y
Y coordinate or direction component.
Definition: tachyon.h:55
apivector scale
scale of texture in x,y,z
Definition: tachyon.h:75
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
apivector uaxs
planar map u axis
Definition: tachyon.h:76
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
apivector vaxs
planar map v axis
Definition: tachyon.h:77
int main(int argc, char **argv)
Definition: hypertex.c:107
void rt_finalize(void)
Shut down Tachyon library for good, at final use before program termination.
Definition: api.c:153
#define RFILE
Definition: hypertex.c:62
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
Definition: fire.c:48
apiflt hypertex1(double x, double y, double z)
Definition: hypertex.c:68
Tachyon public API function prototypes and declarations used to drive the ray tracing engine...
apiflt hypertex2(double x, double y, double z)
Definition: hypertex.c:89
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
void rt_verbose(SceneHandle voidscene, int v)
Enables or Disables verbose messages from the Tachyon library during rendering.
Definition: api.c:414