From fd09cbf762bae63a6e22a3322d21f8124dee034f Mon Sep 17 00:00:00 2001 From: devZoGok Date: Sun, 1 Sep 2019 22:44:13 +0300 Subject: [PATCH] implemented model loading (semi) --- CMakeLists.txt | 2 +- main.cpp | 26 +++++++++----------------- material.h | 2 +- mesh.cpp | 2 +- model.cpp | 7 ++++--- root.cpp | 2 +- tags | 2 +- 7 files changed, 18 insertions(+), 25 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 07f89f1..dfe8f3c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,7 +10,7 @@ link_directories(/usr/lib/) set(CMAKE_BUILD_TYPE Debug) set(math quaternion.cpp vector.cpp) -set(render camera.cpp light.cpp main.cpp material.cpp mesh.cpp model.cpp node.cpp quad.cpp quaternion.cpp root.cpp shader.cpp texture.cpp vector.cpp) +set(render camera.cpp light.cpp material.cpp mesh.cpp model.cpp node.cpp quad.cpp root.cpp shader.cpp texture.cpp) add_executable(vb01 main.cpp ${render} ${math}) target_link_libraries(vb01 glfw) diff --git a/main.cpp b/main.cpp index d77eae4..3af31c3 100644 --- a/main.cpp +++ b/main.cpp @@ -14,25 +14,17 @@ int main(){ Root *root=Root::getSingleton(); root->start(800,600); - Vector3 v1[]={Vector3(2,2,.5),Vector3(.5,.5,.5)}; - Vector3 v2[]={Vector3(-.0,0,2),Vector3(.5,0,-2)}; - for(int i=0;i<1;i++){ - //Model *node=new Model("/home/dominykas/c++/FSim/jet00.obj"); - //node->setObject(q); - //Material *mat=new Material(); - //mat->addDiffuseMap("/home/dominykas/c++/FSim/woodChips.jpg"); - //mat->setLightingEnabled(false); - //node->setMaterial(mat); - //root->getRootNode()->attachChild(node); - Quad *q=new Quad(v1[i]); - Node *n=new Node(v2[i]); - n->attachMesh(q); + Vector3 v1[]={Vector3(.2,.2,.2),Vector3(.5,.5,.5)}; + Vector3 v2[]={Vector3(-.5,0,-2),Vector3(.0,0,0)}; + + //Quad *q=new Quad(v1[1]); + Model *n=new Model("/home/dominykas/c++/FSim/jet00.obj"); Material *mat=new Material(); - mat->addDiffuseMap("/home/dominykas/c++/FSim/woodChips.jpg"); + mat->addDiffuseMap("/home/dominykas/c++/FSim/defaultTexture.jpg"); mat->setLightingEnabled(false); - q->setMaterial(mat); + n->setMaterial(mat); + //n->attachMesh(q); root->getRootNode()->attachChild(n); - } Camera *cam=Root::getSingleton()->getCamera(); cam->setPosition(Vector3(0,0,-5)); @@ -44,7 +36,7 @@ int main(){ l1->setInnerAngle(glm::radians(40.)); l1->setOuterAngle(glm::radians(60.)); l1->setType(Light::POINT); - root->getRootNode()->addLight(l1); + //root->getRootNode()->addLight(l1); while(true) root->update(); return 0; diff --git a/material.h b/material.h index 81e57ff..2bf2cea 100644 --- a/material.h +++ b/material.h @@ -22,7 +22,7 @@ namespace vb01{ private: bool lightingEnabled=false; std::vector diffuseMapTextures,normalMapTextures,specularMapTextures; - Shader *shader; + Shader *shader=nullptr; }; } diff --git a/mesh.cpp b/mesh.cpp index 00b8a8c..76e7d0d 100644 --- a/mesh.cpp +++ b/mesh.cpp @@ -53,7 +53,7 @@ namespace vb01{ Vector3 dir=cam->getDirection(),up=cam->getUp(),camPos=cam->getPosition(); mat4 model=translate(mat4(1.),vec3(pos.x,pos.y,pos.z)); - model=rotate(model,38.f,vec3(1,0,0)); + model=rotate(model,13.f,vec3(0,1,0)); mat4 view=lookAt(vec3(camPos.x,camPos.y,camPos.z),vec3(camPos.x+dir.x,camPos.y+dir.y,camPos.z+dir.z),vec3(up.x,up.y,up.z)); mat4 proj=perspective(radians(fov),width/height,nearPlane,farPlane); //proj=ortho(0.f,800.f,0.f,-600.f,nearPlane,farPlane); diff --git a/model.cpp b/model.cpp index dbce2ee..77fc0b4 100644 --- a/model.cpp +++ b/model.cpp @@ -47,8 +47,9 @@ namespace vb01{ vertices[i]=v; } for(int i=0;imFaces[i].mNumIndices;j++){ - indices[i+j]=mesh->mFaces[i].mIndices[j]; + int numFaceIndices=mesh->mFaces[i].mNumIndices; + for(int j=0;jmFaces[i].mIndices[j]; } } //if(mesh->mMaterialIndex>=0){ @@ -59,7 +60,7 @@ namespace vb01{ Model::Model(string path) : Node(){ Importer importer; - const aiScene *scene=importer.ReadFile(path,aiProcess_Triangulate | aiProcess_FlipUVs | aiProcess_GenNormals); + const aiScene *scene=importer.ReadFile(path,aiProcess_Triangulate | aiProcess_FlipUVs | aiProcess_GenNormals); if(!scene||scene->mFlags&AI_SCENE_FLAGS_INCOMPLETE||!scene->mRootNode){ cout<<"Failed to load model:"<position=posi setPosition light.h /^ inline void setPosition(Vector3 pos){this->pos=pos;}$/;" f class:vb01::Light typeref:typename:void setType light.h /^ inline void setType(Type t){this->type=t;}$/;" f class:vb01::Light typeref:typename:void setVec3 shader.cpp /^ void Shader::setVec3(vec3 vec, string var){$/;" f class:vb01::Shader typeref:typename:void -shader material.h /^ Shader *shader;$/;" m class:vb01::Material typeref:typename:Shader * +shader material.h /^ Shader *shader=nullptr;$/;" m class:vb01::Material typeref:typename:Shader * size stb_image.h /^ stbi_uc size[257];$/;" m struct:__anon84e4e8860708 typeref:typename:stbi_uc[257] size stb_image.h /^ stbi_uc size[288];$/;" m struct:__anon84e4e8860b08 typeref:typename:stbi_uc[288] size stb_image.h /^ stbi_uc size,type,channel;$/;" m struct:__anon84e4e8861108 typeref:typename:stbi_uc