Add assimp to load everything!

This commit is contained in:
Skia 2016-06-04 17:16:32 +02:00
parent f1aeec891b
commit 4354c402a1
4 changed files with 6245 additions and 7 deletions

View file

@ -2,6 +2,7 @@ CC=g++
FLAGS=-Wall -g
INCLUDE=-I.
LIBS=-lassimp
TARGET=IN55.exe
@ -12,7 +13,7 @@ OBJECTS=$(SOURCES:.cpp=.o)
$(TARGET): $(OBJECTS) *.h
@echo "Builing the whole project"
$(CC) -o $(TARGET) $(OBJECTS) -lGL -lglut -lGLU
$(CC) $(OBJECTS) -lGL -lglut -lGLU $(LIBS) -o $(TARGET)
%.o: %.cpp
@echo "Compiling .cpp files"

View file

@ -13,8 +13,8 @@ class Camera
/* Camera constructor */
Camera()
{
eyePos = Vec3(0.0f, 0.0f, 5.0f);
centerPos = Vec3(0.0f, 0.0f, 0.0f);
eyePos = Vec3(0.0f, 0.0f, 3.0f);
centerPos = Vec3(0.0f, 0.0f, -5.0f);
upVector = Vec3(0.0f, 1.0f, 0.0f);
}

View file

@ -7,10 +7,17 @@
#include <GL/glut.h>
#include <GL/gl.h>
// assimp include files. These three are usually needed.
#include <assimp/cimport.h>
#include <assimp/scene.h>
#include <assimp/postprocess.h>
#include <model.h>
#include <camera.h>
#include <vectors.h>
const struct aiScene* scene;
Model m;
Camera c;
@ -28,6 +35,64 @@ void initGL() {
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); // Nice perspective corrections
}
void recursive_render (const struct aiScene *sc, const struct aiNode* nd)
{
unsigned int i;
unsigned int n = 0, t;
aiMatrix4x4 m = nd->mTransformation;
// update transform
aiTransposeMatrix4(&m);
glPushMatrix();
glMultMatrixf((float*)&m);
// draw all meshes assigned to this node
for (; n < nd->mNumMeshes; ++n) {
const struct aiMesh* mesh = scene->mMeshes[nd->mMeshes[n]];
// apply_material(sc->mMaterials[mesh->mMaterialIndex]);
if(mesh->mNormals == NULL) {
glDisable(GL_LIGHTING);
} else {
glEnable(GL_LIGHTING);
}
for (t = 0; t < mesh->mNumFaces; ++t) {
const struct aiFace* face = &mesh->mFaces[t];
GLenum face_mode;
switch(face->mNumIndices) {
case 1: face_mode = GL_POINTS; break;
case 2: face_mode = GL_LINES; break;
case 3: face_mode = GL_TRIANGLES; break;
default: face_mode = GL_POLYGON; break;
}
glBegin(face_mode);
for(i = 0; i < face->mNumIndices; i++) {
int index = face->mIndices[i];
if(mesh->mColors[0] != NULL)
glColor4fv((GLfloat*)&mesh->mColors[0][index]);
if(mesh->mNormals != NULL)
glNormal3fv(&mesh->mNormals[index].x);
glVertex3fv(&mesh->mVertices[index].x);
}
glEnd();
}
}
// draw all children
for (n = 0; n < nd->mNumChildren; ++n) {
recursive_render(sc, nd->mChildren[n]);
}
glPopMatrix();
}
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
@ -38,12 +103,13 @@ void display()
glLoadIdentity();
c.updateCamera();
m.display();
angle += 0.1;
glRotatef(angle, 0, 1, 0);
recursive_render(scene, scene->mRootNode);
glutSwapBuffers();
}
/* Timer to refresh every 15ms */
void timer(int value) {
glutPostRedisplay();
@ -62,10 +128,17 @@ void reshape(GLsizei width, GLsizei height) {
int main(int argc, char** argv)
{
m = Model();
// m = Model();
// m.loadFile(argv[1]);
c = Camera();
m.loadFile(argv[1]);
scene = aiImportFile(argv[1],aiProcessPreset_TargetRealtime_MaxQuality);
if (!scene) {
return 1;
}
// m.printVertex();
glutInit(&argc, argv);
@ -78,6 +151,7 @@ int main(int argc, char** argv)
initGL();
glutTimerFunc(0, timer, 0);
glutMainLoop();
aiReleaseImport(scene);
return 0;
}

6163
res/Dragon 2.5_dae.dae Normal file

File diff suppressed because one or more lines are too long