Rendering other models.

master
sigonasr2 1 year ago
parent 14b50a5bbf
commit e3becbaaab
  1. 3
      .gitignore
  2. BIN
      Lighting/Dolphin_HighPolyUV.png
  3. 12
      Lighting/ImportedModel.cpp
  4. 24
      Lighting/main.cpp

3
.gitignore vendored

@ -13,6 +13,8 @@
# User-specific files (MonoDevelop/Xamarin Studio) # User-specific files (MonoDevelop/Xamarin Studio)
*.userprefs *.userprefs
StandfordDragon.obj
# Mono auto generated files # Mono auto generated files
mono_crash.* mono_crash.*
@ -361,3 +363,4 @@ MigrationBackup/
# Fody - auto-generated XML schema # Fody - auto-generated XML schema
FodyWeavers.xsd FodyWeavers.xsd
/Lighting/StandfordDragon.mtl

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 MiB

@ -16,7 +16,9 @@ ImportedModel::ImportedModel(const char *filePath) {
for (int i = 0; i < numVertices; i++) { for (int i = 0; i < numVertices; i++) {
vertices.push_back(glm::vec3(verts[i*3], verts[i*3+1], verts[i*3+2])); vertices.push_back(glm::vec3(verts[i*3], verts[i*3+1], verts[i*3+2]));
texCoords.push_back(glm::vec2(tcs[i*2], tcs[i*2+1])); if(texCoords.size()>0){
texCoords.push_back(glm::vec2(tcs[i*2], tcs[i*2+1]));
}
normalVecs.push_back(glm::vec3(normals[i*3], normals[i*3+1], normals[i*3+2])); normalVecs.push_back(glm::vec3(normals[i*3], normals[i*3+1], normals[i*3+2]));
} }
} }
@ -68,15 +70,17 @@ void ModelImporter::parseOBJ(const char *filePath) {
getline(oneCornerSS, n, '/'); getline(oneCornerSS, n, '/');
int vertRef = (stoi(v) - 1) * 3; int vertRef = (stoi(v) - 1) * 3;
int tcRef = (stoi(t) - 1) * 2;
int normRef = (stoi(n) - 1) * 3; int normRef = (stoi(n) - 1) * 3;
triangleVerts.push_back(vertVals[vertRef]); triangleVerts.push_back(vertVals[vertRef]);
triangleVerts.push_back(vertVals[vertRef + 1]); triangleVerts.push_back(vertVals[vertRef + 1]);
triangleVerts.push_back(vertVals[vertRef + 2]); triangleVerts.push_back(vertVals[vertRef + 2]);
textureCoords.push_back(stVals[tcRef]); if(t.length()>0){
textureCoords.push_back(stVals[tcRef + 1]); int tcRef = (stoi(t) - 1) * 2;
textureCoords.push_back(stVals[tcRef]);
textureCoords.push_back(stVals[tcRef + 1]);
}
normals.push_back(normVals[normRef]); normals.push_back(normVals[normRef]);
normals.push_back(normVals[normRef + 1]); normals.push_back(normVals[normRef + 1]);

@ -33,10 +33,10 @@ float lightAmbient[4] = { 0.0f, 0.0f, 0.0f, 1.0f };
float lightDiffuse[4] = { 1.0f, 1.0f, 1.0f, 1.0f }; float lightDiffuse[4] = { 1.0f, 1.0f, 1.0f, 1.0f };
float lightSpecular[4] = { 1.0f, 1.0f, 1.0f, 1.0f }; float lightSpecular[4] = { 1.0f, 1.0f, 1.0f, 1.0f };
float* matAmb = utils::silverAmbient(); float* matAmb = utils::goldAmbient();
float* matDif = utils::silverDiffuse(); float* matDif = utils::goldDiffuse();
float* matSpe = utils::silverSpecular(); float* matSpe = utils::goldSpecular();
float matShi = utils::silverShininess(); float matShi = utils::goldShininess();
float* matAmb2 = utils::jadeAmbient(); float* matAmb2 = utils::jadeAmbient();
float* matDif2 = utils::jadeDiffuse(); float* matDif2 = utils::jadeDiffuse();
@ -50,7 +50,7 @@ GLuint pyrTex;
Sphere sphere(48); Sphere sphere(48);
Torus torus(1.0,0.5,48); Torus torus(1.0,0.5,48);
ImportedModel shuttle("shuttle.obj"); ImportedModel shuttle("StanfordDragon.obj");
void setupVertices(void) { void setupVertices(void) {
glGenVertexArrays(1, vao); glGenVertexArrays(1, vao);
@ -130,8 +130,10 @@ void setupVertices(void) {
pvalues.push_back(vertices[i].x); pvalues.push_back(vertices[i].x);
pvalues.push_back(vertices[i].y); pvalues.push_back(vertices[i].y);
pvalues.push_back(vertices[i].z); pvalues.push_back(vertices[i].z);
tvalues.push_back(uvs[i].s); if(uvs.size()>0){
tvalues.push_back(uvs[i].t); tvalues.push_back(uvs[i].s);
tvalues.push_back(uvs[i].t);
}
nvalues.push_back(normals[i].x); nvalues.push_back(normals[i].x);
nvalues.push_back(normals[i].y); nvalues.push_back(normals[i].y);
nvalues.push_back(normals[i].z); nvalues.push_back(normals[i].z);
@ -274,9 +276,9 @@ void display(GLFWwindow* window, double currentTime) {
//vMat=glm::lookAt(glm::vec3{camera.x,camera.y,camera.z},{0,-3,0},{0,1,0}); //vMat=glm::lookAt(glm::vec3{camera.x,camera.y,camera.z},{0,-3,0},{0,1,0});
mMat=glm::translate(glm::mat4(1.0f),{0.f,-2.f,0.f}); mMat=glm::translate(glm::mat4(1.0f),{0.f,-8.f,0.f});
mMat=glm::rotate(mMat,float(currentTime/4),{0.f,1.f,0.2f}); mMat=glm::rotate(mMat,float(currentTime/4),{0.f,1.f,0.f});
mMat=glm::scale(mMat,{7,7,7}); mMat=glm::scale(mMat,{60,60,60});
mvMat=vMat*mMat; mvMat=vMat*mMat;
invTrMat=glm::transpose(glm::inverse(mvMat)); invTrMat=glm::transpose(glm::inverse(mvMat));
@ -298,7 +300,7 @@ void display(GLFWwindow* window, double currentTime) {
invTrMat=glm::transpose(glm::inverse(mvMat)); invTrMat=glm::transpose(glm::inverse(mvMat));
DrawTorus(); //DrawTorus();
} }
int main(void) { int main(void) {

Loading…
Cancel
Save