Attempt to get a triangle moving
This commit is contained in:
parent
7687b0d1c8
commit
7901413d7b
|
@ -1,5 +1,6 @@
|
|||
#include "simpleengine/gfx/texture.h"
|
||||
#include "simpleengine/shapes/2d/square.h"
|
||||
#include "simpleengine/vector.h"
|
||||
#include <simpleengine/gfx/shader.h>
|
||||
#include <simpleengine/renderable.h>
|
||||
#include <simpleengine/event/event.h>
|
||||
|
@ -43,13 +44,13 @@ int main(int argc, char *argv[]) {
|
|||
simpleengine::gfx::Texture crate_texture("resources/container.jpg", true, true);
|
||||
|
||||
std::vector<simpleengine::Vertex> vertices = {
|
||||
{glm::vec3(-0.5f, -0.5f, 0.f), glm::vec3(1.f, 0.f, 0.f), glm::vec2(0.f, 0.f)}, // bottom left
|
||||
{glm::vec3(0.5f, -0.5f, 0.f), glm::vec3(0.f, 1.f, 0.f), glm::vec2(1.f, 0.f)}, // bottom right
|
||||
{glm::vec3(0.f, 0.5f, 0.f), glm::vec3(0.f, 0.f, 1.f), glm::vec2(0.5f, 1.0f)}, // top
|
||||
{ simpleengine::Vectorf(-0.5f, -0.5f, 0.f), glm::vec3(1.f, 0.f, 0.f), glm::vec2(0.f, 0.f) }, // bottom left
|
||||
{ simpleengine::Vectorf(0.5f, -0.5f, 0.f), glm::vec3(0.f, 1.f, 0.f), glm::vec2(1.f, 0.f) }, // bottom right
|
||||
{ simpleengine::Vectorf(0.f, 0.5f, 0.f), glm::vec3(0.f, 0.f, 1.f), glm::vec2(0.5f, 1.0f) }, // top
|
||||
};
|
||||
|
||||
auto tri = std::make_shared<simpleengine::shapes_2d::Triangle>(base_shader_program, vertices);
|
||||
tri->set_texture(wall_texture);
|
||||
//tri->set_texture(wall_texture);
|
||||
game.add_event(tri);
|
||||
|
||||
/* std::vector<simpleengine::Vertex> vertices = {
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
#include "../../gfx/shader.h"
|
||||
#include "../../gfx/texture.h"
|
||||
#include "../../optional.h"
|
||||
#include "../../translatable.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
|
@ -38,7 +39,6 @@ namespace simpleengine::shapes_2d {
|
|||
void set_texture(gfx::Texture texture);
|
||||
|
||||
virtual void update(const float& delta_time) override;
|
||||
|
||||
virtual void render(std::shared_ptr<GLFWwindow> target) override;
|
||||
};
|
||||
}
|
|
@ -0,0 +1,128 @@
|
|||
#pragma once
|
||||
|
||||
#include <glm/detail/qualifier.hpp>
|
||||
#include <glm/glm.hpp>
|
||||
#include <glm/gtc/matrix_transform.hpp>
|
||||
#include <glm/gtc/type_ptr.hpp>
|
||||
|
||||
namespace simpleengine {
|
||||
template<typename VectorType = float>
|
||||
class Vector {
|
||||
private:
|
||||
glm::vec<3, VectorType, glm::defaultp> inner_vec;
|
||||
public:
|
||||
Vector(VectorType x, VectorType y, VectorType z) : inner_vec(x, y, z) {
|
||||
|
||||
}
|
||||
|
||||
Vector(glm::vec<3, VectorType, glm::defaultp> glm_vec) : inner_vec(glm_vec) {
|
||||
|
||||
}
|
||||
|
||||
Vector(const glm::vec<3, VectorType, glm::defaultp>& glm_vec) : inner_vec(glm_vec) {
|
||||
|
||||
}
|
||||
|
||||
operator glm::vec<3, VectorType, glm::defaultp>() const {
|
||||
return inner_vec;
|
||||
}
|
||||
|
||||
VectorType& x() {
|
||||
return inner_vec.x;
|
||||
}
|
||||
|
||||
VectorType& y() {
|
||||
return inner_vec.y;
|
||||
}
|
||||
|
||||
VectorType& z() {
|
||||
return inner_vec.z;
|
||||
}
|
||||
|
||||
void set_x(const VectorType x) {
|
||||
inner_vec.x = x;
|
||||
}
|
||||
|
||||
void set_y(const VectorType y) {
|
||||
inner_vec.y = y;
|
||||
}
|
||||
|
||||
void set_z(const VectorType z) {
|
||||
inner_vec.z = z;
|
||||
}
|
||||
|
||||
Vector<VectorType> operator+(const Vector<VectorType>& vector) {
|
||||
this->inner_vec += vector.inner_vec;
|
||||
}
|
||||
|
||||
Vector<VectorType> operator-(const Vector<VectorType>& vector) {
|
||||
this->inner_vec -= vector.inner_vec;
|
||||
}
|
||||
|
||||
void translate(const Vector<VectorType>& vector) {
|
||||
this += vector;
|
||||
}
|
||||
|
||||
void translate(const VectorType& x, const VectorType& y, const VectorType& z) {
|
||||
this->inner_vec.x += x;
|
||||
this->inner_vec.y += y;
|
||||
this->inner_vec.z += z;
|
||||
}
|
||||
|
||||
void translate_x(const VectorType x) {
|
||||
this->inner_vec.x += x;
|
||||
}
|
||||
|
||||
void translate_y(const VectorType y) {
|
||||
this->inner_vec.y += y;
|
||||
}
|
||||
|
||||
void translate_z(const VectorType z) {
|
||||
this->inner_vec.z += z;
|
||||
}
|
||||
|
||||
glm::mat4 rotation_matrix(float degrees, glm::vec3 rotation_axis) const {
|
||||
glm::mat4 trans = glm::mat4(1.0f);
|
||||
trans = glm::rotate(trans, glm::radians(degrees), rotation_axis);
|
||||
return trans;
|
||||
}
|
||||
|
||||
glm::mat4 rotation_x_matrix(float degrees) const {
|
||||
return rotation_axis(degrees, glm::vec3(1.f, 0.f, 0.f));
|
||||
}
|
||||
|
||||
glm::mat4 rotation_y_matrix(float degrees) const {
|
||||
return rotation_axis(degrees, glm::vec3(0.f, 1.f, 0.f));
|
||||
}
|
||||
|
||||
glm::mat4 rotation_z_matrix(float degrees) const {
|
||||
return rotation_axis(degrees, glm::vec3(0.f, 0.f, 1.f));
|
||||
}
|
||||
|
||||
void rotate(float degrees, glm::vec3 rotation_axis) {
|
||||
glm::mat4 trans = glm::mat4(1.0f);
|
||||
trans = glm::rotate(trans, glm::radians(degrees), rotation_axis);
|
||||
this->inner_vec = trans * this->inner_vec;
|
||||
}
|
||||
|
||||
void rotate_x(float degrees) {
|
||||
rotate(degrees, glm::vec3(1.f, 0.f, 0.f));
|
||||
}
|
||||
|
||||
void rotate_y(float degrees) {
|
||||
rotate(degrees, glm::vec3(0.f, 1.f, 0.f));
|
||||
}
|
||||
|
||||
void rotate_z(float degrees) {
|
||||
rotate(degrees, glm::vec3(0.f, 0.f, 1.f));
|
||||
}
|
||||
|
||||
void scale(float scalar) {
|
||||
glm::mat4 trans = glm::mat4(1.0f);
|
||||
trans = glm::scale(trans, glm::vec3(scalar, scalar, scalar));
|
||||
this->inner_vec = trans * this->inner_vec;
|
||||
}
|
||||
};
|
||||
|
||||
typedef Vector<float> Vectorf;
|
||||
}
|
|
@ -5,10 +5,13 @@
|
|||
|
||||
#include <glm/glm.hpp>
|
||||
|
||||
#include "vector.h"
|
||||
|
||||
namespace simpleengine {
|
||||
class Vertex {
|
||||
public:
|
||||
glm::vec3 position;
|
||||
//glm::vec3 position;
|
||||
simpleengine::Vectorf position;
|
||||
glm::vec3 color;
|
||||
glm::vec2 tex_coord;
|
||||
};
|
||||
|
|
|
@ -30,7 +30,10 @@ namespace simpleengine::shapes_2d {
|
|||
}
|
||||
|
||||
void Triangle::update(const float& delta_time) {
|
||||
|
||||
for (Vertex& vertex : vertices) {
|
||||
vertex.position.translate_x(0.01f);
|
||||
vertex.position.translate_y(0.01f);
|
||||
}
|
||||
}
|
||||
|
||||
void Triangle::render(std::shared_ptr<GLFWwindow> target) {
|
||||
|
|
Loading…
Reference in New Issue