* Cast a single ray with origin (ox, oy, oz) and direction * (dx, dy, dz). */
| 151 | * (dx, dy, dz). |
| 152 | */ |
| 153 | void castRay(RTCScene scene, |
| 154 | float ox, float oy, float oz, |
| 155 | float dx, float dy, float dz) |
| 156 | { |
| 157 | /* |
| 158 | * The ray hit structure holds both the ray and the hit. |
| 159 | * The user must initialize it properly -- see API documentation |
| 160 | * for rtcIntersect1() for details. |
| 161 | */ |
| 162 | struct RTCRayHit rayhit; |
| 163 | rayhit.ray.org_x = ox; |
| 164 | rayhit.ray.org_y = oy; |
| 165 | rayhit.ray.org_z = oz; |
| 166 | rayhit.ray.dir_x = dx; |
| 167 | rayhit.ray.dir_y = dy; |
| 168 | rayhit.ray.dir_z = dz; |
| 169 | rayhit.ray.tnear = 0; |
| 170 | rayhit.ray.tfar = std::numeric_limits<float>::infinity(); |
| 171 | rayhit.ray.mask = -1; |
| 172 | rayhit.ray.flags = 0; |
| 173 | rayhit.hit.geomID = RTC_INVALID_GEOMETRY_ID; |
| 174 | rayhit.hit.instID[0] = RTC_INVALID_GEOMETRY_ID; |
| 175 | |
| 176 | /* |
| 177 | * There are multiple variants of rtcIntersect. This one |
| 178 | * intersects a single ray with the scene. |
| 179 | */ |
| 180 | rtcIntersect1(scene, &rayhit); |
| 181 | |
| 182 | printf("%f, %f, %f: ", ox, oy, oz); |
| 183 | if (rayhit.hit.geomID != RTC_INVALID_GEOMETRY_ID) |
| 184 | { |
| 185 | /* Note how geomID and primID identify the geometry we just hit. |
| 186 | * We could use them here to interpolate geometry information, |
| 187 | * compute shading, etc. |
| 188 | * Since there is only a single triangle in this scene, we will |
| 189 | * get geomID=0 / primID=0 for all hits. |
| 190 | * There is also instID, used for instancing. See |
| 191 | * the instancing tutorials for more information */ |
| 192 | printf("Found intersection on geometry %d, primitive %d at tfar=%f\n", |
| 193 | rayhit.hit.geomID, |
| 194 | rayhit.hit.primID, |
| 195 | rayhit.ray.tfar); |
| 196 | } |
| 197 | else |
| 198 | printf("Did not find any intersection.\n"); |
| 199 | } |
| 200 | |
| 201 | void waitForKeyPressedUnderWindows() |
| 202 | { |