1 /* 2 Copyright (c) 2005-2021 Intel Corporation 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 /* 18 The original source for this example is 19 Copyright (c) 1994-2008 John E. Stone 20 All rights reserved. 21 22 Redistribution and use in source and binary forms, with or without 23 modification, are permitted provided that the following conditions 24 are met: 25 1. Redistributions of source code must retain the above copyright 26 notice, this list of conditions and the following disclaimer. 27 2. Redistributions in binary form must reproduce the above copyright 28 notice, this list of conditions and the following disclaimer in the 29 documentation and/or other materials provided with the distribution. 30 3. The name of the author may not be used to endorse or promote products 31 derived from this software without specific prior written permission. 32 33 THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS 34 OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 35 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 36 ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY 37 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 38 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 39 OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 40 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 41 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 42 OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 43 SUCH DAMAGE. 44 */ 45 46 /***************************************************************************** 47 * api.h - The declarations and prototypes needed so that 3rd party driver * 48 * code can run the raytracer. Third party driver code should * 49 * only use the functions in this header file to interface with * 50 * the rendering engine. * 51 *************************************************************************** */ 52 53 /* 54 * $Id: api.h,v 1.2 2007-02-22 17:54:15 Exp $ 55 */ 56 57 /********************************************/ 58 /* Types defined for use with the API calls */ 59 /********************************************/ 60 61 #ifdef USESINGLEFLT 62 typedef float apiflt; /* generic floating point number */ 63 #else 64 typedef double apiflt; /* generic floating point number */ 65 #endif 66 67 typedef void *SceneHandle; 68 69 typedef struct { 70 int texturefunc; /* which texture function to use */ 71 color col; /* base object color */ 72 int shadowcast; /* does the object cast a shadow */ 73 apiflt ambient; /* ambient lighting */ 74 apiflt diffuse; /* diffuse reflection */ 75 apiflt specular; /* specular reflection */ 76 apiflt opacity; /* how opaque the object is */ 77 vector ctr; /* origin of texture */ 78 vector rot; /* rotation of texture around origin */ 79 vector scale; /* scale of texture in x,y,z */ 80 vector uaxs; /* planar map u axis */ 81 vector vaxs; /* planar map v axis */ 82 char imap[96]; /* name of image map */ 83 } apitexture; 84 85 /******************************************************************* 86 * NOTE: The value passed in apitexture.texturefunc corresponds to 87 * the meanings given in this table: 88 * 89 * 0 - No texture function is applied other than standard lighting. 90 * 1 - 3D checkerboard texture. Red & Blue checkers through 3d space. 91 * 2 - Grit texture, roughens up the surface of the object a bit. 92 * 3 - 3D marble texture. Makes a 3D swirl pattern through the object. 93 * 4 - 3D wood texture. Makes a 3D wood pattern through the object. 94 * 5 - 3D gradient noise function. 95 * 6 - I've forgotten :-) 96 * 7 - Cylindrical Image Map **** IMAGE MAPS REQUIRE the filename 97 * 8 - Spherical Image Map of the image be put in imap[] 98 * 9 - Planar Image Map part of the texture... 99 * planar requires uaxs, and vaxs.. 100 * 101 *******************************************************************/ 102 103 /********************************************/ 104 /* Functions implemented to provide the API */ 105 /********************************************/ 106 107 vector rt_vector(apiflt x, apiflt y, apiflt z); /* helper to make vectors */ 108 color rt_color(apiflt r, apiflt g, apiflt b); /* helper to make colors */ 109 110 void rt_initialize(); /* reset raytracer, memory deallocation */ 111 void rt_finalize(void); /* close down for good.. */ 112 113 SceneHandle rt_newscene(void); /* allocate new scene */ 114 void rt_deletescene(SceneHandle); /* delete a scene */ 115 void rt_renderscene(SceneHandle); /* raytrace the current scene */ 116 void rt_outputfile(SceneHandle, const char *outname); 117 void rt_resolution(SceneHandle, int hres, int vres); 118 void rt_verbose(SceneHandle, int v); 119 void rt_rawimage(SceneHandle, unsigned char *rawimage); 120 void rt_background(SceneHandle, color); 121 122 /* Parameter values for rt_boundmode() */ 123 #define RT_BOUNDING_DISABLED 0 124 #define RT_BOUNDING_ENABLED 1 125 126 void rt_boundmode(SceneHandle, int); 127 void rt_boundthresh(SceneHandle, int); 128 129 /* Parameter values for rt_displaymode() */ 130 #define RT_DISPLAY_DISABLED 0 131 #define RT_DISPLAY_ENABLED 1 132 133 void rt_displaymode(SceneHandle, int); 134 135 void rt_scenesetup(SceneHandle, char *, int, int, int); 136 /* scene, output filename, horizontal resolution, vertical resolution, 137 verbose mode */ 138 139 void rt_camerasetup(SceneHandle, apiflt, apiflt, int, int, vector, vector, vector); 140 /* camera parms: scene, zoom, aspectratio, antialiasing, raydepth, 141 camera center, view direction, up direction */ 142 143 void *rt_texture(apitexture *); 144 /* pointer to the texture struct that would have been passed to each 145 object() call in older revisions.. */ 146 147 void rt_light(void *, vector, apiflt); /* add a light */ 148 /* light parms: texture, center, radius */ 149 150 void rt_sphere(void *, vector, apiflt); /* add a sphere */ 151 /* sphere parms: texture, center, radius */ 152 153 void rt_scalarvol(void *, vector, vector, int, int, int, char *, void *); 154 155 void rt_extvol(void *, vector, vector, int, apiflt (*evaluator)(apiflt, apiflt, apiflt)); 156 157 void rt_box(void *, vector, vector); 158 /* box parms: texture, min, max */ 159 160 void rt_plane(void *, vector, vector); 161 /* plane parms: texture, center, normal */ 162 163 void rt_ring(void *, vector, vector, apiflt, apiflt); 164 /* ring parms: texture, center, normal, inner, outer */ 165 166 void rt_tri(void *, vector, vector, vector); 167 /* tri parms: texture, vertex 0, vertex 1, vertex 2 */ 168 169 void rt_stri(void *, vector, vector, vector, vector, vector, vector); 170 /* stri parms: texture, vertex 0, vertex 1, vertex 2, norm 0, norm 1, norm 2 */ 171 172 void rt_heightfield(void *, vector, int, int, apiflt *, apiflt, apiflt); 173 /* field parms: texture, center, m, n, field, wx, wy */ 174 175 void rt_landscape(void *, int, int, vector, apiflt, apiflt); 176 177 void rt_quadsphere(void *, vector, apiflt); /* add quadric sphere */ 178 /* sphere parms: texture, center, radius */ 179 180 void rt_cylinder(void *, vector, vector, apiflt); 181 182 void rt_fcylinder(void *, vector, vector, apiflt); 183 184 void rt_polycylinder(void *, vector *, int, apiflt); 185 186 /* new texture handling routines */ 187 void rt_tex_color(void *voidtex, color col); 188 189 #define RT_PHONG_PLASTIC 0 190 #define RT_PHONG_METAL 1 191 void rt_tex_phong(void *voidtex, apiflt phong, apiflt phongexp, int type); 192