24 if ((points == NULL) || (numpts == 0)) {
32 for (i=1; i<numpts; i++) {
33 a.
x = points[i].
x - points[i-1].
x;
34 a.
y = points[i].
y - points[i-1].
y;
35 a.
z = points[i].
z - points[i-1].
z;
45 const float *points,
int numpts,
float rad) {
49 if ((points == NULL) || (numpts == 0)) {
57 for (i=1; i<numpts; i++) {
59 a[0] = points[addr ] - points[addr - 3];
60 a[1] = points[addr + 1] - points[addr - 2];
61 a[2] = points[addr + 2] - points[addr - 1];
76 xoff=ctr.
x - (wx / 2.0);
77 yoff=ctr.
z - (wy / 2.0);
80 for (yy=0; yy<(n-1); yy++) {
81 for (xx=0; xx<(m-1); xx++) {
82 v0.
x=wx*(xx )/(m*1.0) + xoff;
83 v0.
y=field[(yy )*m + (xx )] + zoff;
84 v0.
z=wy*(yy )/(n*1.0) + yoff;
86 v1.
x=wx*(xx + 1)/(m*1.0) + xoff;
87 v1.
y=field[(yy )*m + (xx + 1)] + zoff;
88 v1.
z=wy*(yy )/(n*1.0) + yoff;
90 v2.
x=wx*(xx + 1)/(m*1.0) + xoff;
91 v2.
y=field[(yy + 1)*m + (xx + 1)] + zoff;
92 v2.
z=wy*(yy + 1)/(n*1.0) + yoff;
94 rt_tri(scene, tex, v1, v0, v2);
96 v0.
x=wx*(xx )/(m*1.0) + xoff;
97 v0.
y=field[(yy )*m + (xx )] + zoff;
98 v0.
z=wy*(yy )/(n*1.0) + yoff;
100 v1.
x=wx*(xx )/(m*1.0) + xoff;
101 v1.
y=field[(yy + 1)*m + (xx )] + zoff;
102 v1.
z=wy*(yy + 1)/(n*1.0) + yoff;
104 v2.
x=wx*(xx + 1)/(m*1.0) + xoff;
105 v2.
y=field[(yy + 1)*m + (xx + 1)] + zoff;
106 v2.
z=wy*(yy + 1)/(n*1.0) + yoff;
108 rt_tri(scene, tex, v0, v1, v2);
125 offset.
x = ctr.
x - (wx / 2.0);
126 offset.
y = ctr.
z - (wy / 2.0);
129 xinc = wx / ((
flt) m-1);
130 yinc = wy / ((
flt) n-1);
133 for (y=0; y<n; y++) {
134 for (x=0; x<m; x++) {
138 field[addr] + offset.
z,
139 y * yinc + offset.
y);
144 for (x=1; x<m; x++) {
145 normals[x] = normals[(n - 1)*m + x] =
rt_vector(0.0, 1.0, 0.0);
147 for (y=1; y<n; y++) {
148 normals[y*m] = normals[y*m + (m-1)] =
rt_vector(0.0, 1.0, 0.0);
150 for (y=1; y<(n-1); y++) {
151 for (x=1; x<(m-1); x++) {
155 -(field[addr + 1] - field[addr - 1]) / (2.0 * xinc),
157 -(field[addr + m] - field[addr - m]) / (2.0 * yinc));
159 VNorm(&normals[addr]);
164 for (y=0; y<(n-1); y++) {
165 for (x=0; x<(m-1); x++) {
168 rt_stri(scene, tex, vertices[addr], vertices[addr + 1 + m], vertices[addr + 1],
169 normals[addr], normals[addr + 1 + m], normals[addr + 1]);
170 rt_stri(scene, tex, vertices[addr], vertices[addr + m], vertices[addr + 1 + m],
171 normals[addr], normals[addr + m], normals[addr + 1 + m]);
181 int xa,
int ya,
int x,
int y,
int xb,
int yb,
182 unsigned int *rndval) {
185 len =
SQRT(wx * wx + wy * wy);
187 if (base[x + (xres*y)]==0.0) {
188 d=(abs(xa - xb) / (xres * 1.0))*wx + (abs(ya - yb) / (yres * 1.0))*wy;
190 v= (base[xa + (xres*ya)] + base[xb + (xres*yb)]) / 2.0 +
194 if (v > (xres + yres)) v=(xres + yres);
195 base[x + (xres * y)]=v;
200 int x1,
int y1,
int x2,
int y2,
unsigned int *rndval) {
203 if (((x2 - x1) < 2) && ((y2 - y1) < 2)) {
return; }
208 adjust(base, xres, yres, wx, wy, x1, y1, x, y1, x2, y1, rndval);
209 adjust(base, xres, yres, wx, wy, x2, y1, x2, y, x2, y2, rndval);
210 adjust(base, xres, yres, wx, wy, x1, y2, x, y2, x2, y2, rndval);
211 adjust(base, xres, yres, wx, wy, x1, y1, x1, y, x1, y2, rndval);
214 if (base[x + xres*y]==0.0) {
215 base[x + (xres * y)]=(base[x1 + xres*y1] + base[x2 + xres*y1] +
216 base[x2 + xres*y2] + base[x1 + xres*y2] )/4.0;
219 subdivide(base, xres, yres, wx, wy, x1, y1 ,x ,y, rndval);
220 subdivide(base, xres, yres, wx, wy, x, y1, x2, y, rndval);
221 subdivide(base, xres, yres, wx, wy, x, y, x2, y2, rndval);
222 subdivide(base, xres, yres, wx, wy, x1, y, x, y2, rndval);
234 field=(
flt *) malloc(totalsize*
sizeof(
flt));
236 for (y=0; y<n; y++) {
237 for (x=0; x<m; x++) {
247 subdivide(field, m, n, wx, wy, 0, 0, m-1, n-1, &rndval);
unsigned int rt_rand(unsigned int *idum)
static void rt_sheightfield(SceneHandle scene, void *tex, apivector ctr, int m, int n, flt *field, flt wx, flt wy)
void rt_landscape(SceneHandle scene, void *tex, int m, int n, apivector ctr, flt wx, flt wy)
Define an auto-generated height field.
static void subdivide(flt *base, int xres, int yres, flt wx, flt wy, int x1, int y1, int x2, int y2, unsigned int *rndval)
static void adjust(flt *base, int xres, int yres, flt wx, flt wy, int xa, int ya, int x, int y, int xb, int yb, unsigned int *rndval)
void rt_heightfield(SceneHandle scene, void *tex, apivector ctr, int m, int n, flt *field, flt wx, flt wy)
Define an axis-aligned height field.
void rt_sphere(SceneHandle scene, void *tex, apivector ctr, flt rad)
Define a sphere with associated texture, center, and radius.
void rt_sphere3fv(SceneHandle scene, void *tex, const float *ctr, float rad)
Define a sphere with associated texture, center, and radius.
double flt
generic floating point number, using double
void rt_tri(SceneHandle voidscene, void *tex, apivector v0, apivector v1, apivector v2)
Define a flat-shaded triangle.
flt x
X coordinate or direction component.
flt y
Y coordinate or direction component.
void rt_fcylinder(SceneHandle scene, void *tex, apivector ctr, apivector axis, flt rad)
Define a finite-length cylinder.
void rt_stri(SceneHandle voidscene, void *tex, apivector v0, apivector v1, apivector v2, apivector n0, apivector n1, apivector n2)
Define a smooth-shaded triangle using interpolated vertex normals.
apivector rt_vector(flt x, flt y, flt z)
Helper function to make vectors.
void rt_fcylinder3fv(SceneHandle scene, void *tex, const float *ctr, const float *axis, float rad)
Define a finite-length cylinder.
void rt_polycylinder(SceneHandle scene, void *tex, apivector *points, int numpts, flt rad)
Define a sequence of connected cylinders.
Tachyon public API function prototypes and declarations used to drive the ray tracing engine...
void rt_polycylinder3fv(SceneHandle scene, void *tex, const float *points, int numpts, float rad)
Define a sequence of connected cylinders.
flt z
Z coordinate or direction component.