parent
55274ec3cf
commit
8dd2f2b292
3 changed files with 16 additions and 60 deletions
|
@ -19,7 +19,7 @@ void main()
|
||||||
vec3 Eye = normalize(-vertex);
|
vec3 Eye = normalize(-vertex);
|
||||||
vec3 Reflected = normalize(reflect( -lightPosition, normal));
|
vec3 Reflected = normalize(reflect( -lightPosition, normal));
|
||||||
|
|
||||||
vec3 IAmbient = vec3(0.2f);
|
vec3 IAmbient = vec3(0.05f);
|
||||||
|
|
||||||
if (materialKind == 6) {
|
if (materialKind == 6) {
|
||||||
// sun: shines by itself
|
// sun: shines by itself
|
||||||
|
|
|
@ -13,10 +13,7 @@ namespace endofthejedi {
|
||||||
|
|
||||||
class Camera {
|
class Camera {
|
||||||
public:
|
public:
|
||||||
Camera()
|
Camera() : m_aspectRatio(1.0), m_zoom(1.0), m_position(0.0, 0.0, 0.0), m_angles(0.0, 0.0, 0.0), m_dirty(true)
|
||||||
: m_aspectRatio(1.0), m_fov(util::deg2rad(90.0))
|
|
||||||
, m_zoom(1.0), m_position(0.0, 0.0, 0.0), m_angles(0.0, 0.0, 0.0)
|
|
||||||
, m_dirty(true)
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,7 +22,7 @@ namespace endofthejedi {
|
||||||
// << 1 scales down
|
// << 1 scales down
|
||||||
// 1 is neutral
|
// 1 is neutral
|
||||||
// >> 1 makes things bigger
|
// >> 1 makes things bigger
|
||||||
void setZoom(float zoom)
|
void setCameraZoom(float zoom)
|
||||||
{
|
{
|
||||||
if (zoom != m_zoom) {
|
if (zoom != m_zoom) {
|
||||||
m_zoom = zoom;
|
m_zoom = zoom;
|
||||||
|
@ -33,18 +30,8 @@ namespace endofthejedi {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// set field of view.
|
|
||||||
// degree or radian? find it out.
|
|
||||||
void setFov(float fov)
|
|
||||||
{
|
|
||||||
if (fov != m_fov) {
|
|
||||||
m_fov = fov;
|
|
||||||
m_dirty = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// position of the camera in world space
|
// position of the camera in world space
|
||||||
void setPosition(const glm::vec3 &pos)
|
void setCameraPosition(const glm::vec3 &pos)
|
||||||
{
|
{
|
||||||
if (pos != m_position) {
|
if (pos != m_position) {
|
||||||
m_position = pos;
|
m_position = pos;
|
||||||
|
@ -53,7 +40,7 @@ namespace endofthejedi {
|
||||||
}
|
}
|
||||||
|
|
||||||
// some angles (in rad) for the camera.
|
// some angles (in rad) for the camera.
|
||||||
void setAngles(const glm::vec3 &angles)
|
void setCameraAngles(const glm::vec3 &angles)
|
||||||
{
|
{
|
||||||
if (angles != m_angles) {
|
if (angles != m_angles) {
|
||||||
m_angles = angles;
|
m_angles = angles;
|
||||||
|
@ -62,18 +49,18 @@ namespace endofthejedi {
|
||||||
}
|
}
|
||||||
|
|
||||||
// all three arguments.
|
// all three arguments.
|
||||||
void setPositionAnglesZoom(const glm::vec3 &position, const glm::vec3 &angles, float zoom)
|
void setCameraPositionAnglesZoom(const glm::vec3 &position, const glm::vec3 &angles, float zoom)
|
||||||
{
|
{
|
||||||
setZoom(zoom);
|
setCameraZoom(zoom);
|
||||||
setPosition(position);
|
setCameraPosition(position);
|
||||||
setAngles(angles);
|
setCameraAngles(angles);
|
||||||
}
|
}
|
||||||
|
|
||||||
float fov() const { return m_fov; }
|
float zoom() const { return m_zoom; }
|
||||||
float zoom() const { return m_zoom; }
|
const glm::vec3 &position() const { return m_position; }
|
||||||
const glm::vec3 &position() const { return m_position; }
|
const glm::vec3 &angles() const { return m_angles; }
|
||||||
const glm::vec3 &angles() const { return m_angles; }
|
|
||||||
float aspectRatio() const { return m_aspectRatio; }
|
float aspectRatio() const { return m_aspectRatio; }
|
||||||
|
|
||||||
void setAspectRatio(float r)
|
void setAspectRatio(float r)
|
||||||
{
|
{
|
||||||
|
@ -105,33 +92,14 @@ namespace endofthejedi {
|
||||||
|
|
||||||
//float a = 2.0*M_PI*m_lastTime/10.0;
|
//float a = 2.0*M_PI*m_lastTime/10.0;
|
||||||
//float s = glm::mod(m_lastTime, 5.0f)/1.0f;
|
//float s = glm::mod(m_lastTime, 5.0f)/1.0f;
|
||||||
view = glm::scale(view, glm::vec3(m_zoom, m_zoom, m_zoom));
|
|
||||||
view = glm::translate(view, m_position);
|
view = glm::translate(view, m_position);
|
||||||
view = glm::rotate(view, m_angles.x, glm::vec3(1.0f, 0.0f, 0.0f));
|
view = glm::scale(view, glm::vec3(m_zoom/m_aspectRatio, m_zoom, m_zoom));
|
||||||
view = glm::rotate(view, m_angles.y, glm::vec3(0.0f, 1.0f, 0.0f));
|
|
||||||
view = glm::rotate(view, m_angles.z, glm::vec3(0.0f, 0.0f, 1.0f));
|
|
||||||
|
|
||||||
// Generates a really hard-to-read matrix, but a normal, standard 4x4 matrix nonetheless
|
m_viewMatrix = view;
|
||||||
glm::mat4 projectionMatrix = glm::perspective(
|
|
||||||
// The horizontal Field of View, in degrees : the amount of
|
|
||||||
// "zoom". Think "camera lens". Usually between 90° (extra
|
|
||||||
// wide) and 30° (quite zoomed in)
|
|
||||||
m_fov,
|
|
||||||
|
|
||||||
m_aspectRatio, // aspect ratio
|
|
||||||
0.1f, // near clipping plane
|
|
||||||
100.0f // far clipping plane
|
|
||||||
);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//m_viewMatrix = view;
|
|
||||||
m_viewMatrix = projectionMatrix * view;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
float m_aspectRatio;
|
float m_aspectRatio;
|
||||||
float m_fov;
|
|
||||||
float m_zoom;
|
float m_zoom;
|
||||||
glm::vec3 m_position;
|
glm::vec3 m_position;
|
||||||
glm::vec3 m_angles;
|
glm::vec3 m_angles;
|
||||||
|
|
|
@ -142,19 +142,7 @@ namespace endofthejedi {
|
||||||
//std::cout<<"setting aspect ratio: " << m_aspectRatio << std::endl;
|
//std::cout<<"setting aspect ratio: " << m_aspectRatio << std::endl;
|
||||||
glUniform1f(m_shader_game_objects.location("aspectRatio"), m_aspectRatio);
|
glUniform1f(m_shader_game_objects.location("aspectRatio"), m_aspectRatio);
|
||||||
|
|
||||||
// test code to move the camera
|
|
||||||
float t = 2.0*M_PI*m_lastTime/10.0;
|
|
||||||
float r = 0.5;
|
|
||||||
glm::vec3 pos = glm::vec3(r*sin(t), r*cos(t), 0.0f);
|
|
||||||
m_camera.setPosition(pos);
|
|
||||||
|
|
||||||
// test code to rotate the camera
|
|
||||||
float a = t;
|
|
||||||
m_camera.setAngles(glm::vec3(0.0f, a, 0.0f));
|
|
||||||
|
|
||||||
// must be done once each frame
|
|
||||||
m_camera.refresh();
|
m_camera.refresh();
|
||||||
|
|
||||||
auto *ptr = glm::value_ptr(m_camera.viewMatrix());
|
auto *ptr = glm::value_ptr(m_camera.viewMatrix());
|
||||||
|
|
||||||
glUniformMatrix4fv(m_shader_game_objects.location("view"), 1, GL_FALSE, ptr);
|
glUniformMatrix4fv(m_shader_game_objects.location("view"), 1, GL_FALSE, ptr);
|
||||||
|
|
Loading…
Reference in a new issue