adds a cube to the scene */
| 36 | |
| 37 | /* adds a cube to the scene */ |
| 38 | unsigned int addCube (RTCDevice device_i, RTCScene scene_i, const Vec3fa& pos) |
| 39 | { |
| 40 | /* create a triangulated cube with 12 triangles and 8 vertices */ |
| 41 | RTCGeometry mesh = rtcNewGeometry (device_i, RTC_GEOMETRY_TYPE_TRIANGLE); |
| 42 | |
| 43 | /* set vertices */ |
| 44 | Vec3fa* vertices = (Vec3fa*) rtcSetNewGeometryBuffer(mesh, RTC_BUFFER_TYPE_VERTEX, 0, RTC_FORMAT_FLOAT3, sizeof(Vec3fa), 8); |
| 45 | vertices[0].x = pos.x + -1; vertices[0].y = pos.y + -1; vertices[0].z = pos.z + -1; |
| 46 | vertices[1].x = pos.x + -1; vertices[1].y = pos.y + -1; vertices[1].z = pos.z + +1; |
| 47 | vertices[2].x = pos.x + -1; vertices[2].y = pos.y + +1; vertices[2].z = pos.z + -1; |
| 48 | vertices[3].x = pos.x + -1; vertices[3].y = pos.y + +1; vertices[3].z = pos.z + +1; |
| 49 | vertices[4].x = pos.x + +1; vertices[4].y = pos.y + -1; vertices[4].z = pos.z + -1; |
| 50 | vertices[5].x = pos.x + +1; vertices[5].y = pos.y + -1; vertices[5].z = pos.z + +1; |
| 51 | vertices[6].x = pos.x + +1; vertices[6].y = pos.y + +1; vertices[6].z = pos.z + -1; |
| 52 | vertices[7].x = pos.x + +1; vertices[7].y = pos.y + +1; vertices[7].z = pos.z + +1; |
| 53 | |
| 54 | /* set triangles */ |
| 55 | int tri = 0; |
| 56 | Triangle* triangles = (Triangle*) rtcSetNewGeometryBuffer(mesh, RTC_BUFFER_TYPE_INDEX, 0, RTC_FORMAT_UINT3, sizeof(Triangle), 12); |
| 57 | |
| 58 | // left side |
| 59 | triangles[tri].v0 = 0; triangles[tri].v1 = 2; triangles[tri].v2 = 1; tri++; |
| 60 | triangles[tri].v0 = 1; triangles[tri].v1 = 2; triangles[tri].v2 = 3; tri++; |
| 61 | |
| 62 | // right side |
| 63 | triangles[tri].v0 = 4; triangles[tri].v1 = 5; triangles[tri].v2 = 6; tri++; |
| 64 | triangles[tri].v0 = 5; triangles[tri].v1 = 7; triangles[tri].v2 = 6; tri++; |
| 65 | |
| 66 | // bottom side |
| 67 | triangles[tri].v0 = 0; triangles[tri].v1 = 1; triangles[tri].v2 = 4; tri++; |
| 68 | triangles[tri].v0 = 1; triangles[tri].v1 = 5; triangles[tri].v2 = 4; tri++; |
| 69 | |
| 70 | // top side |
| 71 | triangles[tri].v0 = 2; triangles[tri].v1 = 6; triangles[tri].v2 = 3; tri++; |
| 72 | triangles[tri].v0 = 3; triangles[tri].v1 = 6; triangles[tri].v2 = 7; tri++; |
| 73 | |
| 74 | // front side |
| 75 | triangles[tri].v0 = 0; triangles[tri].v1 = 4; triangles[tri].v2 = 2; tri++; |
| 76 | triangles[tri].v0 = 2; triangles[tri].v1 = 4; triangles[tri].v2 = 6; tri++; |
| 77 | |
| 78 | // back side |
| 79 | triangles[tri].v0 = 1; triangles[tri].v1 = 3; triangles[tri].v2 = 5; tri++; |
| 80 | triangles[tri].v0 = 3; triangles[tri].v1 = 7; triangles[tri].v2 = 5; tri++; |
| 81 | |
| 82 | rtcCommitGeometry(mesh); |
| 83 | unsigned int geomID = rtcAttachGeometry(scene_i,mesh); |
| 84 | rtcReleaseGeometry(mesh); |
| 85 | return geomID; |
| 86 | } |
| 87 | |
| 88 | /* adds a ground plane to the scene */ |
| 89 | unsigned int addGroundPlane (RTCDevice device_i, RTCScene scene_i) |
no test coverage detected