00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #ifndef GEOMETER_H
00013 #define GEOMETER_H
00014
00015 #include "CyberX3D.h"
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040 using namespace CyberX3D;
00041
00042 namespace csl {
00043
00044 #define EXPAND(a) a##_x, a##_y, a##_z
00045 #define ZERO(a) ((a##_x == 0.0f) && (a##_y == 0.0f) && (a##_z == 0.0f))
00046 #define SET(a, x, y, z) \
00047 a##_x = x; \
00048 a##_y = y; \
00049 a##_z = z;
00050 #define VECTOR_COPY(d, s) \
00051 d##_x = s##_x;\
00052 d##_y = s##_y;\
00053 d##_z = s##_z;
00054 #define SCALAR_PRODUCT(p, s, a) \
00055 p##_x = s * a##_x;\
00056 p##_y = s * a##_y;\
00057 p##_z = s * a##_z;
00058 #define DOT_PRODUCT(a, b) \
00059 (a##_x*b##_x + a##_y*b##_y + a##_z*b##_z)
00060 #define CROSS_PRODUCT(p, a, b) \
00061 p##_x = a##_y * b##_z - a##_z * b##_y; \
00062 p##_y = a##_z * b##_x - a##_x * b##_z; \
00063 p##_z = a##_x * b##_y - a##_y * b##_x;
00064 #define COMPONENTWISE_PRODUCT(p, a, b) \
00065 p##_x = a##_x * b##_x;\
00066 p##_y = a##_y * b##_y;\
00067 p##_z = a##_z * b##_z;
00068 #define VECTOR_SCALE(p, s) \
00069 p##_x *= s;\
00070 p##_y *= s;\
00071 p##_z *= s;
00072 #define VECTOR_SUM(s, a, b) \
00073 s##_x = a##_x + b##_x;\
00074 s##_y = a##_y + b##_y;\
00075 s##_z = a##_z + b##_z;
00076 #define VECTOR_ADD(s, a) \
00077 s##_x += a##_x;\
00078 s##_y += a##_y;\
00079 s##_z += a##_z;
00080 #define VECTOR_DIFF(s, a, b) \
00081 s##_x = a##_x - b##_x;\
00082 s##_y = a##_y - b##_y;\
00083 s##_z = a##_z - b##_z;
00084 #define MAGNITUDE(a) \
00085 sqrt(a##_x*a##_x + a##_y*a##_y + a##_z*a##_z)
00086 #define PROJECT(p, t, a, b, n, s) \
00087 VECTOR_DIFF(p, a, b) \
00088 if (ZERO(p)) \
00089 { \
00090 if (s == DOT_PRODUCT(n, a)) \
00091 { \
00092 t = 0.5f; \
00093 VECTOR_COPY(p, a) \
00094 } \
00095 else \
00096 { \
00097 t = 1e38f; \
00098 p##_x = 1e38f; \
00099 p##_y = 1e38f; \
00100 p##_z = 1e38f; \
00101 } \
00102 } \
00103 else \
00104 { \
00105 t = (s - DOT_PRODUCT(n, b)) / DOT_PRODUCT(n, p); \
00106 VECTOR_SCALE(p, t) \
00107 VECTOR_ADD(p, b) \
00108 }
00109 #define REFLECT(r, t, a, n, s) \
00110 t = s - DOT_PRODUCT(n, a); \
00111 t += t; \
00112 SCALAR_PRODUCT(r, t, n) \
00113 VECTOR_ADD(r, a)
00114 #define XYROTATE(r, a, phi) \
00115 r##_x = a##_x*cos(phi) - a##_y*sin(phi); \
00116 r##_y = a##_x*sin(phi) + a##_y*cos(phi); \
00117 r##_z = a##_z;
00118
00119
00120 typedef struct {
00121
00122 double distance;
00123 double hangle;
00124 double vangle;
00125
00126 } soundray;
00127
00128
00129 typedef struct {
00130
00131 int num_vertices;
00132 int allocated_vertices;
00133 int* vertex_indices;
00134 float normal_x;
00135 float normal_y;
00136 float normal_z;
00137 float offset;
00138 float* bounding_normals_x;
00139 float* bounding_normals_y;
00140 float* bounding_normals_z;
00141 float* bounding_offsets;
00142
00143 void dump(float*, float*, float*);
00144
00145 } polygon;
00146
00147
00148 class Geometer
00149 {
00150
00151 soundray* current_rayset;
00152 int num_rays;
00153 int rayset_spaces;
00154 float max_ray_length;
00155 float source_x;
00156 float source_y;
00157 float source_z;
00158 float ear_x;
00159 float ear_y;
00160 float ear_z;
00161 float ear_hangle;
00162 float* vertices_x;
00163 float* vertices_y;
00164 float* vertices_z;
00165 int* vertices_num_polygons;
00166 int** vertices_polygon_indices;
00167 int num_vertices;
00168 int allocated_vertices;
00169 polygon* polygons;
00170 int num_polygons;
00171 int allocated_polygons;
00172
00173 void traverse(SceneGraph& sg);
00174 void traverse(Node* n, SceneGraph& sg);
00175
00176 void apply_transform(int starting_point, CyberX3D::TransformNode* transform_node);
00177
00178
00179 bool _check_ray(float from_x, float from_y, float from_z,
00180 float to_x, float to_y, float to_z,
00181 polygon* exempta, polygon* exemptb);
00182 int _find_rays(int depth, float vsrc_x, float vsrc_y, float vsrc_z,
00183 float last_distance=0.0);
00184
00185 public:
00186
00187 bool fileIsValid;
00188
00189 Geometer();
00190 ~Geometer();
00191
00192 void set_range(float r);
00193 void set_source(float x, float y, float z);
00194 void set_ear(float x, float y, float z, float direction);
00195 void set_polygons(polygon* w, int n);
00196 void set_everything(char* filename);
00197 void set_everything_using_VRML(char* filename);
00198
00199 soundray* find_rays();
00200 int number_of_rays() { return num_rays; }
00201 };
00202
00203 }
00204
00205 #endif