Tachyon (current)  Current Main Branch
animskull.c
Go to the documentation of this file.
1 /*
2  * animskull.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: animskull.c,v 1.13 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 typedef struct { /* Scalar Volume Visualization Data */
20  int loaded; /* Volume data memory residence flag */
21  int xres; /* volume X axis size */
22  int yres; /* volume Y axis size */
23  int zres; /* volume Z axis size */
24  apiflt opacity; /* opacity per unit length */
25  char name[80]; /* Volume data filename */
26  unsigned char * data; /* pointer to raw byte volume data */
27 } scalarvol;
28 
29 #define MAXFRAMES 100
30 #define RAD 6.28
31 
32 #ifdef cube
33 #define RFILE "/cfs/johns/anim/frame"
34 #endif
35 
36 #ifndef cube
37 #define RFILE "outfile"
38 #endif
39 
40 int main(int argc, char **argv) {
41  SceneHandle scene;
42  int i;
43  int xres, yres, raydepth, antialiasing, verbosemode;
44  apiflt zoom, aspectratio;
45  apivector Ccenter, Cview, Cup;
46  apivector ctr1;
47  apitexture tex1, tex2;
48  apivector min3, max3;
49  scalarvol vol;
50  apiflt xc,yc;
51  char fname[1000];
52  char fname2[2000];
53 
54  rt_initialize(&argc, &argv);
55 
56  scene = rt_newscene();
57 
58  xres=256; yres=256;
59  aspectratio=1.0; raydepth=18;
60  antialiasing=1; verbosemode=0; zoom=1.0;
61 
62  Ccenter.x=0.0; Ccenter.y=0.0; Ccenter.z=-8.0;
63  Cview.x=0.0; Cview.y=0.0; Cview.z=1.0;
64  Cup.x=0.0; Cup.y=-1.0; Cup.z=0.0;
65  ctr1.x=20.0; ctr1.y=20.0; ctr1.z=-40.0;
66 
67  tex1.col.r=1.0; tex1.col.g=1.0; tex1.col.b=1.0;
68  tex1.ambient=1.0;
69  tex1.diffuse=0.0;
70  tex1.specular=0.0;
71  tex1.opacity=8.0;
72  tex1.texturefunc=0;
73  tex2=tex1;
74 
75  min3.x=-1.0; min3.y=-1.0; min3.z=-0.40;
76  max3.x=1.0; max3.y=1.0; max3.z=0.40;
77 
78  vol.loaded=0;
79 
80  for (i=0; i<MAXFRAMES; i++) {
81  sprintf(fname,".%4.4d.tga",i);
82  strcpy(fname2,RFILE);
83  strcat(fname2, fname);
84 
85  rt_initialize(&argc, &argv);
86  if (rt_mynode()==0) printf("Rendering: %s \n",fname2);
87 
88  xc=cos(6.28 * i / (1.0 * MAXFRAMES));
89  yc=sin(6.28 * i / (1.0 * MAXFRAMES));
90  Ccenter.x = xc*3.0;
91  Ccenter.z = yc*3.0;
92  Cview.x = -xc;
93  Cview.z = -yc;
94 
95  rt_outputfile(scene, fname2);
96  rt_resolution(scene, xres, yres);
97  rt_verbose(scene, verbosemode);
98 
99  rt_camera_setup(scene, zoom, aspectratio, antialiasing,
100  raydepth, Ccenter, Cview, Cup);
101 
102  rt_light(scene, rt_texture(scene, &tex1), ctr1, 1.0);
103 
104  rt_scalarvol(scene, rt_texture(scene, &tex2), min3, max3, 256, 256, 100,
105  "/disk7/cube/vol/head.256x256x109", &vol);
106 
107  rt_renderscene(scene);
108  }
109  rt_finalize();
110 
111  return 0;
112 }
113 
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
apicolor col
base object color
Definition: tachyon.h:67
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
flt specular
specular reflection
Definition: tachyon.h:71
int loaded
Definition: animskull.c:20
int main(int argc, char **argv)
Definition: animskull.c:40
void rt_renderscene(SceneHandle voidscene)
Render the current scene.
Definition: api.c:180
void rt_scalarvol(SceneHandle scene, void *tex, apivector min, apivector max, int xs, int ys, int zs, const char *fname, void *voidvol)
Define an axis-aligned scalar volumetric data set, loaded from a file.
Definition: api.c:1146
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
#define MAXFRAMES
Definition: animskull.c:29
#define RFILE
Definition: animskull.c:37
int xres
Definition: animskull.c:21
int zres
Definition: animskull.c:23
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
Tachyon public API function prototypes and declarations used to drive the ray tracing engine...
int yres
Definition: animskull.c:22
int rt_mynode(void)
distributed memory parallel node rank
Definition: api.c:49
apiflt opacity
Definition: animskull.c:24
unsigned char * data
Definition: animskull.c:26
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