c++ - Camera is upside down OpenGL -
i'm having issue camera being upside down in opengl. if render objects without setting camera z rotation 180 degrees, objects rendered upside down. maybe has glm?
here's how i'm setting matrices:
//model matrix: mat4 modelmatrix; modelmatrix = translate(modelmatrix, vec3(entity.getposition().x, entity.getposition().y, entity.getposition().z)); modelmatrix = rotate(modelmatrix, (float) (entity.getrotation().x / 180 * pi), vec3(1, 0, 0)); modelmatrix = rotate(modelmatrix, (float) (entity.getrotation().y / 180 * pi), vec3(0, 1, 0)); modelmatrix = rotate(modelmatrix, (float) (entity.getrotation().z / 180 * pi), vec3(0, 0, 1)); modelmatrix = scale(modelmatrix, entity.getscale()); return modelmatrix; //view matrix: mat4 viewmatrix; viewmatrix = rotate(viewmatrix, (float)(camera.getrotation().x / 180 * pi), vec3(1, 0, 0)); viewmatrix = rotate(viewmatrix, (float)(camera.getrotation().y / 180 * pi), vec3(0, 1, 0)); viewmatrix = rotate(viewmatrix, (float)(camera.getrotation().z / 180 * pi), vec3(0, 0, 1)); viewmatrix = translate(viewmatrix, camera.getposition() * vec3(-1, -1, -1)); return viewmatrix; //projection matrix: return glm::perspective(camera.getfieldofview(), display::getwindowaspectratio(), camera.getnearplane(), camera.getfarplane());
and here's draw method:
for (int = 0; < entitymap.size(); i++) { map<gluint, vector<entity>>::iterator iterator(entitymap.begin()); advance(iterator, i); vector<entity> entitybatch = iterator->second; model entitymodel = entitybatch[0].getmodel(); mat4 *modelmatrices = new mat4[entitybatch.size()]; (int j = 0; j < entitybatch.size(); j++) { modelmatrices[j] = maths::createmodelmatrix(entitybatch[j]); } glbindvertexarray(iterator->first); glenablevertexattribarray(0); glenablevertexattribarray(1); glenablevertexattribarray(2); glenablevertexattribarray(3); glenablevertexattribarray(4); glenablevertexattribarray(5); gluint vertexbufferobjectid; glgenbuffers(1, &vertexbufferobjectid); glbindbuffer(gl_array_buffer, vertexbufferobjectid); glbufferdata(gl_array_buffer, sizeof(mat4) * entitybatch.size(), modelmatrices, gl_static_draw); glvertexattribpointer(2, 4, gl_float, gl_false, 4 * sizeof(vec4), (glvoid*)(0 * sizeof(vec4))); glvertexattribpointer(3, 4, gl_float, gl_false, 4 * sizeof(vec4), (glvoid*)(1 * sizeof(vec4))); glvertexattribpointer(4, 4, gl_float, gl_false, 4 * sizeof(vec4), (glvoid*)(2 * sizeof(vec4))); glvertexattribpointer(5, 4, gl_float, gl_false, 4 * sizeof(vec4), (glvoid*)(3 * sizeof(vec4))); glvertexattribdivisor(2, 1); glvertexattribdivisor(3, 1); glvertexattribdivisor(4, 1); glvertexattribdivisor(5, 1); #if enable_indexing gldrawelementsinstanced(gl_triangles, entitymodel.getindexcount(), gl_unsigned_int, 0, entitybatch.size()); #else gldrawarraysinstanced(gl_triangles, 0, entitymodel.getvertexcount(), entitybatch.size()); #endif gldisablevertexattribarray(0); gldisablevertexattribarray(1); gldisablevertexattribarray(2); gldisablevertexattribarray(3); gldisablevertexattribarray(4); gldisablevertexattribarray(5); glbindbuffer(gl_array_buffer, 0); gldeletebuffers(1, &vertexbufferobjectid); glbindvertexarray(0); }
thank help!
the problem projection matrix.
i forgot glm works in radians , didn't convert field of view degrees radians. works fine now.
i have 1 more question. need give glm::perspect
thanks help!
Comments
Post a Comment