* Create a scene, which is a collection of geometry objects. Scenes are * what the intersect / occluded functions work on. You can think of a * scene as an acceleration structure, e.g. a bounding-volume hierarchy. * * Scenes, like devices, are reference-counted. */
| 82 | * Scenes, like devices, are reference-counted. |
| 83 | */ |
| 84 | RTCScene initializeScene(RTCDevice device) |
| 85 | { |
| 86 | RTCScene scene = rtcNewScene(device); |
| 87 | |
| 88 | /* |
| 89 | * Create a triangle mesh geometry, and initialize a single triangle. |
| 90 | * You can look up geometry types in the API documentation to |
| 91 | * find out which type expects which buffers. |
| 92 | * |
| 93 | * We create buffers directly on the device, but you can also use |
| 94 | * shared buffers. For shared buffers, special care must be taken |
| 95 | * to ensure proper alignment and padding. This is described in |
| 96 | * more detail in the API documentation. |
| 97 | */ |
| 98 | RTCGeometry geom = rtcNewGeometry(device, RTC_GEOMETRY_TYPE_TRIANGLE); |
| 99 | float* vertices = (float*) rtcSetNewGeometryBuffer(geom, |
| 100 | RTC_BUFFER_TYPE_VERTEX, |
| 101 | 0, |
| 102 | RTC_FORMAT_FLOAT3, |
| 103 | 3*sizeof(float), |
| 104 | 3); |
| 105 | |
| 106 | unsigned* indices = (unsigned*) rtcSetNewGeometryBuffer(geom, |
| 107 | RTC_BUFFER_TYPE_INDEX, |
| 108 | 0, |
| 109 | RTC_FORMAT_UINT3, |
| 110 | 3*sizeof(unsigned), |
| 111 | 1); |
| 112 | |
| 113 | if (vertices && indices) |
| 114 | { |
| 115 | vertices[0] = 0.f; vertices[1] = 0.f; vertices[2] = 0.f; |
| 116 | vertices[3] = 1.f; vertices[4] = 0.f; vertices[5] = 0.f; |
| 117 | vertices[6] = 0.f; vertices[7] = 1.f; vertices[8] = 0.f; |
| 118 | |
| 119 | indices[0] = 0; indices[1] = 1; indices[2] = 2; |
| 120 | } |
| 121 | |
| 122 | /* |
| 123 | * You must commit geometry objects when you are done setting them up, |
| 124 | * or you will not get any intersections. |
| 125 | */ |
| 126 | rtcCommitGeometry(geom); |
| 127 | |
| 128 | /* |
| 129 | * In rtcAttachGeometry(...), the scene takes ownership of the geom |
| 130 | * by increasing its reference count. This means that we don't have |
| 131 | * to hold on to the geom handle, and may release it. The geom object |
| 132 | * will be released automatically when the scene is destroyed. |
| 133 | * |
| 134 | * rtcAttachGeometry() returns a geometry ID. We could use this to |
| 135 | * identify intersected objects later on. |
| 136 | */ |
| 137 | rtcAttachGeometry(scene, geom); |
| 138 | rtcReleaseGeometry(geom); |
| 139 | |
| 140 | /* |
| 141 | * Like geometry objects, scenes must be committed. This lets |
no test coverage detected