2 #ifndef LVR2_UTIL_SYNTHETIC_HPP 3 #define LVR2_UTIL_SYNTHETIC_HPP 25 std::vector<float> vertices;
26 std::vector<unsigned int> face_indices;
29 float long_inc =
M_PI /
static_cast<float>(num_long + 1);
30 float lat_inc = (2 *
M_PI) / static_cast<float>(num_lat);
36 vertices.push_back(sin(0.0) * cos(0.0));
37 vertices.push_back(sin(0.0) * sin(0.0));
38 vertices.push_back(cos(0.0));
41 for(
int i=0; i<num_lat; i++)
52 face_indices.push_back(id_bl);
53 face_indices.push_back(id_tl + 1);
54 face_indices.push_back(id_tr + 1);
57 for(
int i=0; i<num_long; i++)
59 float alpha = long_inc * (i+1);
61 for(
int j=0; j<num_lat; j++)
63 float beta = lat_inc * (j+1);
65 vertices.push_back(sin(alpha) * cos(beta));
66 vertices.push_back(sin(alpha) * sin(beta));
67 vertices.push_back(cos(alpha));
72 int id_bl = num_lat * (i-1) + j;
73 int id_br = num_lat * (i-1) + j + 1;
74 int id_tl = num_lat * (i) + j;
75 int id_tr = num_lat * (i) + j + 1;
86 face_indices.push_back(id_br + 1);
87 face_indices.push_back(id_bl + 1);
88 face_indices.push_back(id_tl + 1);
91 face_indices.push_back(id_tl + 1);
92 face_indices.push_back(id_tr + 1);
93 face_indices.push_back(id_br + 1);
99 vertices.push_back(sin(
M_PI) * cos(2.0 *
M_PI));
100 vertices.push_back(sin(
M_PI) * sin(2.0 *
M_PI));
101 vertices.push_back(cos(
M_PI));
103 int num_vertices = vertices.size() / 3;
104 for(
int i=num_vertices-1-num_lat; i<num_vertices-1; i++)
108 int id_tl = num_vertices-1;
115 face_indices.push_back(id_br);
116 face_indices.push_back(id_bl);
117 face_indices.push_back(id_tl);
122 floatArr vertex_arr(
new float[vertices.size()]);
123 indexArray index_arr(
new unsigned int[face_indices.size()]);
125 for(
int i=0; i<vertices.size(); i++)
127 vertex_arr[i] = vertices[i];
130 for(
int i=0; i<face_indices.size(); i++)
132 index_arr[i] = face_indices[i];
136 dst_mesh->setVertices(vertex_arr, vertices.size() / 3);
137 dst_mesh->setFaceIndices(index_arr, face_indices.size() / 3);
146 #endif // LVR2_UTIL_SYNTHETIC_HPP std::shared_ptr< MeshBuffer > MeshBufferPtr
boost::shared_array< unsigned int > indexArray
boost::shared_array< float > floatArr
MeshBufferPtr genSphere(int num_long=50, int num_lat=50)
The MeshBuffer Mesh representation for I/O modules.