---------------------------------------------------------------------------- */
| 213 | |
| 214 | /* ---------------------------------------------------------------------------- */ |
| 215 | void recursive_render (const C_STRUCT aiScene *sc, const C_STRUCT aiNode* nd) |
| 216 | { |
| 217 | unsigned int i; |
| 218 | unsigned int n = 0, t; |
| 219 | C_STRUCT aiMatrix4x4 m = nd->mTransformation; |
| 220 | |
| 221 | /* update transform */ |
| 222 | aiTransposeMatrix4(&m); |
| 223 | glPushMatrix(); |
| 224 | glMultMatrixf((float*)&m); |
| 225 | |
| 226 | /* draw all meshes assigned to this node */ |
| 227 | for (; n < nd->mNumMeshes; ++n) { |
| 228 | const C_STRUCT aiMesh* mesh = scene->mMeshes[nd->mMeshes[n]]; |
| 229 | |
| 230 | apply_material(sc->mMaterials[mesh->mMaterialIndex]); |
| 231 | |
| 232 | if(mesh->mNormals == NULL) { |
| 233 | glDisable(GL_LIGHTING); |
| 234 | } else { |
| 235 | glEnable(GL_LIGHTING); |
| 236 | } |
| 237 | |
| 238 | for (t = 0; t < mesh->mNumFaces; ++t) { |
| 239 | const C_STRUCT aiFace* face = &mesh->mFaces[t]; |
| 240 | GLenum face_mode; |
| 241 | |
| 242 | switch(face->mNumIndices) { |
| 243 | case 1: face_mode = GL_POINTS; break; |
| 244 | case 2: face_mode = GL_LINES; break; |
| 245 | case 3: face_mode = GL_TRIANGLES; break; |
| 246 | default: face_mode = GL_POLYGON; break; |
| 247 | } |
| 248 | |
| 249 | glBegin(face_mode); |
| 250 | |
| 251 | for(i = 0; i < face->mNumIndices; i++) { |
| 252 | int index = face->mIndices[i]; |
| 253 | if(mesh->mColors[0] != NULL) |
| 254 | glColor4fv((GLfloat*)&mesh->mColors[0][index]); |
| 255 | if(mesh->mNormals != NULL) |
| 256 | glNormal3fv(&mesh->mNormals[index].x); |
| 257 | glVertex3fv(&mesh->mVertices[index].x); |
| 258 | } |
| 259 | |
| 260 | glEnd(); |
| 261 | } |
| 262 | |
| 263 | } |
| 264 | |
| 265 | /* draw all children */ |
| 266 | for (n = 0; n < nd->mNumChildren; ++n) { |
| 267 | recursive_render(sc, nd->mChildren[n]); |
| 268 | } |
| 269 | |
| 270 | glPopMatrix(); |
| 271 | } |
| 272 |
no test coverage detected