Help me, it’s the second day I can’t understand why my 3d scene is not displayed correctly, the planes are not overlapping, why, it’s not clear.
class Camera {
public:
glm::quat camera_quat;
GLfloat x = 0.5, y = 6.5, z = -60;
GLfloat centerx = 0.5, centery = 0, centerz = 1;
GLfloat rotx = 1, roty = 0, rotz = 0;
};
struct point3d {
float x, y, z;
};
class Scene {
public:
Camera* camera = new Camera();
};
float speedx = 0;
struct coordinate {
float x, y, z;
coordinate(float a, float b, float c) : x(a), y(b), z(c) {};
};
float angle = 0.0;
Scene* scene = new Scene();
std::vector <Object3D>* objects3D = new std::vector < Object3D>();
float offset = 0;
bool loaded = false;
void display(void)
{
if (!loaded) {
loader.LoadFile("map3.obj", objects3D);
loaded = true;
}
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
int height = glutGet(GLUT_WINDOW_HEIGHT);
int width = glutGet(GLUT_WINDOW_WIDTH);
gluPerspective(60.0f, (double)width / (double)height, 0.0f, 300.0f);
glm::mat4 myMatrix;
glm::vec4 myVector;
float key_pitch = 5, key_yaw = 0, key_roll = 0;
glm::quat key_quat = glm::quat(glm::vec3(key_pitch, key_yaw, key_roll));
key_pitch = key_yaw = key_roll = 0;
scene->camera->camera_quat = key_quat * scene->camera->camera_quat;
scene->camera->camera_quat = glm::normalize(scene->camera->camera_quat);
glm::mat4 rotate = glm::mat4_cast(scene->camera->camera_quat);
glm::mat4 translate = glm::mat4(1.0f);
glm::vec3 eyeVector(0, 0, 0);
translate = glm::translate(translate, -eyeVector);
glm::mat4 viewMatrix = rotate * translate;
glMatrixMode(GL_MODELVIEW); //WATCH FROM HERE ----------------------------------->
glLoadIdentity();
gluLookAt(scene->camera->x, scene->camera->y, scene->camera->z, scene->camera->x + scene->camera->rotx, scene->camera->y + scene->camera->roty, scene->camera->z + scene->camera->rotz, 0, 1, 0);
glMatrixMode(GL_MODELVIEW);
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
for (int i = 0; i < objects3D->size(); i++)
{
for (int k = 0; k < objects3D->at(i).vertex.size(); k++)
{
glEnable(GL_TEXTURE_2D);
glColor3d(1, 1, 1);
glBindTexture(GL_TEXTURE_2D, objects3D->at(i).texture);
glBegin(GL_POLYGON);
for (int j = 0; j < objects3D->at(i).vertex.at(k).size(); j++)
{
glTexCoord2d(objects3D->at(i).vertex.at(k).at(j).TextureCoordinate.X, objects3D->at(i).vertex.at(k).at(j).TextureCoordinate.Y);
glVertex3f(objects3D->at(i).vertex.at(k).at(j).Position.X, objects3D->at(i).vertex.at(k).at(j).Position.Y, objects3D->at(i).vertex.at(k).at(j).Position.Z);
}
glEnd();
glDisable(GL_TEXTURE_2D);
}
}
glutSwapBuffers();
glutPostRedisplay();
}
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);
glutInitWindowPosition(100, 100);
glutInitWindowSize(400, 400);
glutCreateWindow("game");
glutDisplayFunc(display);
glutMainLoop();
}
Here’s the scene itself, you see, for example, the fence behind the house is properly drawn, but the windows on the back of the house is not right, they shouldn’t have drawn what to do? ((((((((