adds a cube to the scene */
| 21 | |
| 22 | /* adds a cube to the scene */ |
| 23 | unsigned int addCube (RTCScene scene_i, const Vec3fa& d, unsigned int mask) |
| 24 | { |
| 25 | /* create a triangulated cube with 12 triangles and 8 vertices */ |
| 26 | RTCGeometry mesh = rtcNewGeometry(g_device, RTC_GEOMETRY_TYPE_TRIANGLE); |
| 27 | |
| 28 | /* set vertices and vertex colors */ |
| 29 | Vertex* vertices = (Vertex*) rtcSetNewGeometryBuffer(mesh,RTC_BUFFER_TYPE_VERTEX,0,RTC_FORMAT_FLOAT3,sizeof(Vertex),8); |
| 30 | data.vertex_colors[0] = Vec3fa(0,0,0); vertices[0].x = -1 + d.x; vertices[0].y = -1 + d.y; vertices[0].z = -1 + d.z; |
| 31 | data.vertex_colors[1] = Vec3fa(0,0,1); vertices[1].x = -1 + d.x; vertices[1].y = -1 + d.y; vertices[1].z = +1 + d.z; |
| 32 | data.vertex_colors[2] = Vec3fa(0,1,0); vertices[2].x = -1 + d.x; vertices[2].y = +1 + d.y; vertices[2].z = -1 + d.z; |
| 33 | data.vertex_colors[3] = Vec3fa(0,1,1); vertices[3].x = -1 + d.x; vertices[3].y = +1 + d.y; vertices[3].z = +1 + d.z; |
| 34 | data.vertex_colors[4] = Vec3fa(1,0,0); vertices[4].x = +1 + d.x; vertices[4].y = -1 + d.y; vertices[4].z = -1 + d.z; |
| 35 | data.vertex_colors[5] = Vec3fa(1,0,1); vertices[5].x = +1 + d.x; vertices[5].y = -1 + d.y; vertices[5].z = +1 + d.z; |
| 36 | data.vertex_colors[6] = Vec3fa(1,1,0); vertices[6].x = +1 + d.x; vertices[6].y = +1 + d.y; vertices[6].z = -1 + d.z; |
| 37 | data.vertex_colors[7] = Vec3fa(1,1,1); vertices[7].x = +1 + d.x; vertices[7].y = +1 + d.y; vertices[7].z = +1 + d.z; |
| 38 | |
| 39 | /* set triangles and face colors */ |
| 40 | int tri = 0; |
| 41 | Triangle* triangles = (Triangle*) rtcSetNewGeometryBuffer(mesh,RTC_BUFFER_TYPE_INDEX,0,RTC_FORMAT_UINT3,sizeof(Triangle),12); |
| 42 | |
| 43 | // left side |
| 44 | data.face_colors[tri] = Vec3fa(1,0,0); triangles[tri].v0 = 0; triangles[tri].v1 = 1; triangles[tri].v2 = 2; tri++; |
| 45 | data.face_colors[tri] = Vec3fa(1,0,0); triangles[tri].v0 = 1; triangles[tri].v1 = 3; triangles[tri].v2 = 2; tri++; |
| 46 | |
| 47 | // right side |
| 48 | data.face_colors[tri] = Vec3fa(0,1,0); triangles[tri].v0 = 4; triangles[tri].v1 = 6; triangles[tri].v2 = 5; tri++; |
| 49 | data.face_colors[tri] = Vec3fa(0,1,0); triangles[tri].v0 = 5; triangles[tri].v1 = 6; triangles[tri].v2 = 7; tri++; |
| 50 | |
| 51 | // bottom side |
| 52 | data.face_colors[tri] = Vec3fa(0.5f); triangles[tri].v0 = 0; triangles[tri].v1 = 4; triangles[tri].v2 = 1; tri++; |
| 53 | data.face_colors[tri] = Vec3fa(0.5f); triangles[tri].v0 = 1; triangles[tri].v1 = 4; triangles[tri].v2 = 5; tri++; |
| 54 | |
| 55 | // top side |
| 56 | data.face_colors[tri] = Vec3fa(1.0f); triangles[tri].v0 = 2; triangles[tri].v1 = 3; triangles[tri].v2 = 6; tri++; |
| 57 | data.face_colors[tri] = Vec3fa(1.0f); triangles[tri].v0 = 3; triangles[tri].v1 = 7; triangles[tri].v2 = 6; tri++; |
| 58 | |
| 59 | // front side |
| 60 | data.face_colors[tri] = Vec3fa(0,0,1); triangles[tri].v0 = 0; triangles[tri].v1 = 2; triangles[tri].v2 = 4; tri++; |
| 61 | data.face_colors[tri] = Vec3fa(0,0,1); triangles[tri].v0 = 2; triangles[tri].v1 = 6; triangles[tri].v2 = 4; tri++; |
| 62 | |
| 63 | // back side |
| 64 | data.face_colors[tri] = Vec3fa(1,1,0); triangles[tri].v0 = 1; triangles[tri].v1 = 5; triangles[tri].v2 = 3; tri++; |
| 65 | data.face_colors[tri] = Vec3fa(1,1,0); triangles[tri].v0 = 3; triangles[tri].v1 = 5; triangles[tri].v2 = 7; tri++; |
| 66 | |
| 67 | rtcSetGeometryVertexAttributeCount(mesh,1); |
| 68 | rtcSetSharedGeometryBuffer(mesh,RTC_BUFFER_TYPE_VERTEX_ATTRIBUTE,0,RTC_FORMAT_FLOAT3,data.vertex_colors,0,sizeof(Vec3fa),8); |
| 69 | rtcSetGeometryMask(mesh,mask); |
| 70 | |
| 71 | rtcCommitGeometry(mesh); |
| 72 | unsigned int geomID = rtcAttachGeometry(scene_i,mesh); |
| 73 | rtcReleaseGeometry(mesh); |
| 74 | return geomID; |
| 75 | } |
| 76 | |
| 77 | /* adds a ground plane to the scene */ |
| 78 | unsigned int addGroundPlane (RTCScene scene_i) |
no test coverage detected