Пытаюсь сделать specular lighting, но получается какая-то фигня: в шейдер необходимо передать мировые координаты камеры, но я даже не уверен, что правильно их возвращаю из класса:
#include "camera.h"
camera::camera(glm::vec3 pos, glm::vec3 tar, glm::vec3 up)
{
this->Position = pos;
this->Target = tar;
this->Up = up;
this->view = glm::lookAt(pos,tar,up);
}
glm::mat4 camera::getViewMatrix()
{
return this->view;
}
void camera::rotate(float angle, glm::vec3 axe)
{
this->view = glm::translate(this->view,this->Target);
this->view = glm::rotate(this->view,angle,axe);
this->view = glm::translate(this->view,-this->Target);
this->Position=glm::vec3(this->view * glm::vec4(this->Position,0.0f));
this->Target=glm::vec3(glm::vec4(this->Target,0.0f) * this->view);
}
void camera::translate(glm::vec3 tr)
{
this->view = glm::translate(this->view,tr);
this->Position=glm::vec3(this->view * glm::vec4(this->Position,0.0f));
this->Target=glm::vec3(glm::vec4(this->Target,0.0f) * this->view);
}
glm::vec3 camera::getPosition()
{
return this->Position;
}
void draw_scene()
{
glClear ( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
view = c1->getViewMatrix();
mvp = proj * view * model;
glm::vec3 world_eye = glm::vec3(proj * glm::vec4(c1->getPosition(),0.0f));
glUniformMatrix4fv(mvpLoc,1,GL_FALSE,glm::value_ptr(mvp));
glUniformMatrix4fv(worldLoc,1,GL_FALSE,glm::value_ptr(model));
glUniformMatrix4fv(viewLoc,1,GL_FALSE,glm::value_ptr(proj * view));
glUniform1f(samp,0);
glUniform1f(diffInt,l1.diffInt);
glUniform1f(ambInt,l1.ambInt);
glUniform3fv(dir,1,glm::value_ptr(l1.dir));
glUniform3fv(eyeLoc,1,glm::value_ptr(world_eye));
glUniform3fv(color,1,glm::value_ptr(l1.color));
glUniform1f(powerLoc,power);
glUniform1f(specIntLoc,specInt);
glBindVertexArray(VAO);
glDrawElements(GL_TRIANGLES,18,GL_UNSIGNED_INT,0);
SDL_GL_SwapWindow(mainwindow);
SDL_GL_SwapBuffers();
SDL_Delay(20);
}