|
@@ -16,6 +16,9 @@ const int TextureHeight = 128;
|
|
|
typedef Angel::vec4 point4;
|
|
|
typedef Angel::vec4 color4;
|
|
|
|
|
|
+// terrain altitude array
|
|
|
+float ter_alt[128][256];
|
|
|
+
|
|
|
// Texture objects and storage for texture image
|
|
|
GLuint textures[1];
|
|
|
|
|
@@ -57,7 +60,28 @@ GLuint projection; // projection matrix uniform shader variable location
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
|
|
-void load_model(const std::string &file_name, bool no_tex = false,
|
|
|
+bool hit_check(GLfloat &x, GLfloat &y, GLfloat &z) {
|
|
|
+ int x_idx = x * 256;
|
|
|
+ int y_idx = y * 256;
|
|
|
+ if (x_idx > 255 || x_idx < 0 || y_idx < 0 || y_idx > 127) {
|
|
|
+ x = 0.0;
|
|
|
+ y = 0.25;
|
|
|
+ z = 0.1;
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ if (PARAMS_DEBUG_PRINT) {
|
|
|
+ printf("%f, %f\n", ter_alt[y_idx][x_idx], z);
|
|
|
+ }
|
|
|
+ if (ter_alt[y_idx][x_idx] >= z) {
|
|
|
+ x = 0.0;
|
|
|
+ y = 0.25;
|
|
|
+ z = 0.1;
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+}
|
|
|
+
|
|
|
+void load_model(const std::string &file_name, bool not_tex = false,
|
|
|
float x_offset = 0.0f, float y_offset = 0.0f,
|
|
|
float z_offset = 0.0f) {
|
|
|
std::vector<point4> vertices;
|
|
@@ -71,11 +95,16 @@ void load_model(const std::string &file_name, bool no_tex = false,
|
|
|
float x, y, z;
|
|
|
int a, b, c;
|
|
|
int num = 0;
|
|
|
+ int idx = 0;
|
|
|
while (s >> t) {
|
|
|
if (t == "v") { // vertices
|
|
|
s >> x >> y >> z;
|
|
|
vertices.emplace_back(x / 50.0f + x_offset, z / 50.0f + z_offset,
|
|
|
y / 50.0f + y_offset, 1.0);
|
|
|
+ if (!not_tex) {
|
|
|
+ *(reinterpret_cast<float*>(ter_alt) + idx) = y / 50.0f;
|
|
|
+ idx++;
|
|
|
+ }
|
|
|
} else if (t == "vt") {
|
|
|
s >> x >> y;
|
|
|
tex_cods.emplace_back(x, y);
|
|
@@ -85,21 +114,21 @@ void load_model(const std::string &file_name, bool no_tex = false,
|
|
|
b--;
|
|
|
c--;
|
|
|
points[index] = vertices[a];
|
|
|
- if (no_tex) {
|
|
|
+ if (not_tex) {
|
|
|
tex_coords[index] = {20.0, 0.0};
|
|
|
} else {
|
|
|
tex_coords[index] = tex_cods[a];
|
|
|
}
|
|
|
index++;
|
|
|
points[index] = vertices[b];
|
|
|
- if (no_tex) {
|
|
|
+ if (not_tex) {
|
|
|
tex_coords[index] = {20.0, 0.0};
|
|
|
} else {
|
|
|
tex_coords[index] = tex_cods[b];
|
|
|
}
|
|
|
index++;
|
|
|
points[index] = vertices[c];
|
|
|
- if (no_tex) {
|
|
|
+ if (not_tex) {
|
|
|
tex_coords[index] = {20.0, 0.0};
|
|
|
} else {
|
|
|
tex_coords[index] = tex_cods[c];
|
|
@@ -295,6 +324,7 @@ void keyboard(unsigned char key, int mousex, int mousey) {
|
|
|
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);
|
|
|
}
|
|
|
+ hit_check(eye_x, eye_y, eye_z);
|
|
|
glutPostRedisplay();
|
|
|
}
|
|
|
|