|
@@ -3,7 +3,12 @@
|
|
|
#include <iostream>
|
|
|
#include <vector>
|
|
|
|
|
|
-const int NumTriangles = 64770; // (6 faces)(2 triangles/face)
|
|
|
+#define PARAMS_DEBUG_PRINT false
|
|
|
+
|
|
|
+const int texNumTriangles = 64770;
|
|
|
+const int cowNumTriangles = 5804;
|
|
|
+
|
|
|
+const int NumTriangles = texNumTriangles + cowNumTriangles;
|
|
|
const int NumVertices = 3 * NumTriangles;
|
|
|
const int TextureWidth = 256;
|
|
|
const int TextureHeight = 128;
|
|
@@ -47,14 +52,16 @@ GLuint projection; // projection matrix uniform shader variable location
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
|
|
-void load_model(const std::string &file_name) {
|
|
|
+void load_model(const std::string &file_name, bool no_tex = false,
|
|
|
+ float x_offset = 0.0f, float y_offset = 0.0f,
|
|
|
+ float z_offset = 0.0f) {
|
|
|
std::vector<point4> vertices;
|
|
|
std::vector<vec2> tex_cods;
|
|
|
std::fstream s(file_name, std::fstream::in);
|
|
|
+ static int index = 0;
|
|
|
if (!s.is_open()) {
|
|
|
std::cerr << "failed to open" << file_name << std::endl;
|
|
|
} else {
|
|
|
- int index = 0;
|
|
|
std::string t;
|
|
|
float x, y, z;
|
|
|
int a, b, c;
|
|
@@ -62,7 +69,7 @@ void load_model(const std::string &file_name) {
|
|
|
while (s >> t) {
|
|
|
if (t == "v") { // vertices
|
|
|
s >> x >> y >> z;
|
|
|
- vertices.emplace_back(x / 50.0f, z / 50.0f, y / 50.0f, 1.0);
|
|
|
+ vertices.emplace_back(x / 50.0f + x_offset, z / 50.0f + z_offset, y / 50.0f + y_offset, 1.0);
|
|
|
} else if (t == "vt") {
|
|
|
s >> x >> y;
|
|
|
tex_cods.emplace_back(x, y);
|
|
@@ -72,17 +79,30 @@ void load_model(const std::string &file_name) {
|
|
|
b--;
|
|
|
c--;
|
|
|
points[index] = vertices[a];
|
|
|
- tex_coords[index] = tex_cods[a];
|
|
|
+ if (no_tex) {
|
|
|
+ tex_coords[index] = {20.0, 0.0};
|
|
|
+ } else {
|
|
|
+ tex_coords[index] = tex_cods[a];
|
|
|
+ }
|
|
|
index++;
|
|
|
points[index] = vertices[b];
|
|
|
- tex_coords[index] = tex_cods[b];
|
|
|
+ if (no_tex) {
|
|
|
+ tex_coords[index] = {20.0, 0.0};
|
|
|
+ } else {
|
|
|
+ tex_coords[index] = tex_cods[b];
|
|
|
+ }
|
|
|
index++;
|
|
|
points[index] = vertices[c];
|
|
|
- tex_coords[index] = tex_cods[c];
|
|
|
+ if (no_tex) {
|
|
|
+ tex_coords[index] = {20.0, 0.0};
|
|
|
+ } else {
|
|
|
+ tex_coords[index] = tex_cods[c];
|
|
|
+ }
|
|
|
index++;
|
|
|
num++;
|
|
|
}
|
|
|
}
|
|
|
+ std::cout << "Load model:" << file_name << std::endl;
|
|
|
std::cout << "There are " << vertices.size() << "vertice(s)"
|
|
|
<< ", " << tex_cods.size() << "tex cor(s)" << std::endl
|
|
|
<< "There are " << num << "fragment(s)" << std::endl;
|
|
@@ -108,7 +128,7 @@ void load_tex(const std::string &file_name) {
|
|
|
void init() {
|
|
|
load_tex("gc_tex.ppm");
|
|
|
load_model("gc_tex.obj");
|
|
|
-
|
|
|
+ load_model("cow.obj", true, 0.90, 0.05, 0.25); // no tex data in cow obj
|
|
|
// Initialize texture objects
|
|
|
glGenTextures(1, textures);
|
|
|
|
|
@@ -251,8 +271,10 @@ void keyboard(unsigned char key, int mousex, int mousey) {
|
|
|
phi += 0.01;
|
|
|
break;
|
|
|
}
|
|
|
- printf("eye_x,y,z:%f, %f, %f, %f\n", eye_x, eye_y, eye_z, eye_w);
|
|
|
- printf("at_x,y,z:%f, %f, %f, %f\n", at_x, at_y, at_z, at_w);
|
|
|
+ if (PARAMS_DEBUG_PRINT) {
|
|
|
+ printf("eye_x,y,z:%f, %f, %f, %f\n", eye_x, eye_y, eye_z, eye_w);
|
|
|
+ printf("at_x,y,z:%f, %f, %f, %f\n", at_x, at_y, at_z, at_w);
|
|
|
+ }
|
|
|
glutPostRedisplay();
|
|
|
}
|
|
|
|
|
@@ -276,7 +298,7 @@ int main(int argc, char **argv) {
|
|
|
glutDisplayFunc(display);
|
|
|
glutKeyboardFunc(keyboard);
|
|
|
glutMouseFunc(mouse);
|
|
|
- //glutIdleFunc(idle);
|
|
|
+ // glutIdleFunc(idle);
|
|
|
|
|
|
glutMainLoop();
|
|
|
return 0;
|