added 3d plotting

This commit is contained in:
Lauchmelder 2021-12-22 15:45:52 +01:00
parent 5f0e8f9c6e
commit 918f51dc14
16 changed files with 301 additions and 248 deletions

View file

@ -0,0 +1,15 @@
#pragma once
struct Rect
{
float x, y;
float w, h;
};
struct BoundingBox
{
float x, y, z;
float w, h, d;
};
typedef BoundingBox BBox;

View file

@ -13,6 +13,11 @@ public:
void SetScale(const glm::vec3&) = delete;
void Scale(const glm::vec3&) = delete;
inline void LookAt(const glm::vec3& target)
{
transformation = glm::lookAt(position, target, glm::vec3(0.0f, 1.0f, 0.0f));
}
inline const glm::mat4& GetView() const
{
return transformation;
@ -40,6 +45,11 @@ public:
{
projection = glm::perspective(glm::radians(fov), aspect, zNear, zFar);
}
inline void Update(float fov, float aspect, float zNear, float zFar)
{
projection = glm::perspective(glm::radians(fov), aspect, zNear, zFar);
}
};
class OrthogonalCamera : public CameraBase
@ -49,4 +59,9 @@ public:
{
projection = glm::ortho(left, right, bottom, top, zNear, zFar);
}
inline void Update(float left, float right, float bottom, float top, float zNear, float zFar)
{
projection = glm::ortho(left, right, bottom, top, zNear, zFar);
}
};

View file

@ -23,7 +23,7 @@ public:
Drawable(const Drawable& other) = delete;
void operator=(const Drawable& other) = delete;
virtual void InitializeShader(const CameraBase& camera) const = 0;
virtual void PreRender(const CameraBase& camera) const { };
void Draw(const CameraBase& camera) const;
void SetPrimitiveType(PrimitiveType type);

View file

@ -3,7 +3,7 @@
void Drawable::Draw(const CameraBase& camera) const
{
shader->Use();
InitializeShader(camera);
PreRender(camera);
vao->Render(static_cast<unsigned int>(type));
}

View file

@ -1,7 +1,7 @@
#include "backend/Transformable.hpp"
Transformable::Transformable() :
position(0.0f), scale(1.0f), orientation(0.0, 0.0, 0.0, 1.0)
position(0.0f), scale(1.0f), orientation(glm::vec3(0.0, 0.0, 0.0))
{
CalculateTransformationMatrix();
}
@ -41,6 +41,11 @@ void Transformable::SetRotation(const glm::vec3& axis, float angle)
void Transformable::SetRotation(const glm::vec3& eulerAngles)
{
/*orientation = glm::quat(0.0f, 0.0f, 0.0f, 1.0f);
orientation = glm::rotate(orientation, eulerAngles.x, glm::vec3(1.0f, 0.0f, 0.0f));
orientation = glm::rotate(orientation, eulerAngles.y, glm::vec3(0.0f, 1.0f, 0.0f));
orientation = glm::rotate(orientation, eulerAngles.z, glm::vec3(0.0f, 0.0f, 1.0f));*/
orientation = glm::quat(eulerAngles);
CalculateTransformationMatrix();
}
@ -71,7 +76,7 @@ void Transformable::Scale(const glm::vec3& factor)
void Transformable::CalculateTransformationMatrix()
{
transformation = glm::mat4(1.0f);
transformation = glm::translate(transformation, -position);
transformation *= glm::toMat4(orientation);
transformation = glm::translate(transformation, position);
transformation *= glm::mat4(orientation);
transformation = glm::scale(transformation, scale);
}