mirror of
https://github.com/devZoGok/vb01.git
synced 2026-08-26 19:43:30 +00:00
implemented model loading (semi)
This commit is contained in:
+1
-1
@@ -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)
|
||||
|
||||
@@ -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;
|
||||
|
||||
+1
-1
@@ -22,7 +22,7 @@ namespace vb01{
|
||||
private:
|
||||
bool lightingEnabled=false;
|
||||
std::vector<Texture*> diffuseMapTextures,normalMapTextures,specularMapTextures;
|
||||
Shader *shader;
|
||||
Shader *shader=nullptr;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -47,8 +47,9 @@ namespace vb01{
|
||||
vertices[i]=v;
|
||||
}
|
||||
for(int i=0;i<numTris;i++){
|
||||
for(int j=0;j<mesh->mFaces[i].mNumIndices;j++){
|
||||
indices[i+j]=mesh->mFaces[i].mIndices[j];
|
||||
int numFaceIndices=mesh->mFaces[i].mNumIndices;
|
||||
for(int j=0;j<numFaceIndices;j++){
|
||||
indices[numFaceIndices*i+j]=mesh->mFaces[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:"<<importer.GetErrorString()<<endl;
|
||||
exit(-1);
|
||||
|
||||
@@ -41,7 +41,7 @@ namespace vb01{
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
glEnable(GL_STENCIL_TEST);
|
||||
glEnable(GL_CULL_FACE);
|
||||
glCullFace(GL_FRONT_AND_BACK);
|
||||
glCullFace(GL_FRONT);
|
||||
}
|
||||
|
||||
void Root::update(){
|
||||
|
||||
@@ -426,7 +426,7 @@ setPosition camera.h /^ void setPosition(Vector3 position){this->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
|
||||
|
||||
Reference in New Issue
Block a user