Removed junk

pull/3/head
E. Almqvist 2 years ago
parent 6df9a10c49
commit ddcf4c747e
  1. 16
      headers/renderer.hpp
  2. 13
      src/main.cpp
  3. 29
      src/renderer.cpp

@ -21,11 +21,14 @@
namespace Renderer { namespace Renderer {
class Object { class Object {
public: public:
const char* name = "Object";
Object(); Object();
Object(glm::vec3 pos); Object(glm::vec3 pos);
Object(glm::vec3 pos, glm::vec3 angle); Object(glm::vec3 pos, glm::vec3 angle);
glm::mat4 getModelTransform();
void transform(glm::mat4 T);
void scale(glm::vec3 vscale);
glm::mat4 getPositionTransform(); glm::mat4 getPositionTransform();
void setPosition(glm::vec3 pos); void setPosition(glm::vec3 pos);
void translate(glm::vec3 dpos); void translate(glm::vec3 dpos);
@ -33,12 +36,10 @@ namespace Renderer {
glm::mat4 getRotationTransform(); glm::mat4 getRotationTransform();
void setRotation(glm::vec3 angle); void setRotation(glm::vec3 angle);
void rotate(glm::vec3 dangle); void rotate(glm::vec3 dangle);
private:
void transform(glm::mat4 T);
void updatePositionTransform(); void updatePositionTransform();
void updateRotationTransform(); void updateRotationTransform();
private:
glm::vec3 position = glm::vec3(0.0f, 0.0f, 0.0f); glm::vec3 position = glm::vec3(0.0f, 0.0f, 0.0f);
glm::vec3 angle = glm::vec3(0.0f, 0.0f, 0.0f); glm::vec3 angle = glm::vec3(0.0f, 0.0f, 0.0f);
glm::mat4 positionTransform = glm::mat4(1.0f); glm::mat4 positionTransform = glm::mat4(1.0f);
@ -48,7 +49,6 @@ namespace Renderer {
class Camera : public Object { class Camera : public Object {
public: public:
const char* name = "Camera";
Camera(GLFWwindow* win); Camera(GLFWwindow* win);
Camera(GLFWwindow* win, glm::vec3 pos); Camera(GLFWwindow* win, glm::vec3 pos);
Camera(GLFWwindow* win, glm::vec3 pos, glm::vec3 angle); Camera(GLFWwindow* win, glm::vec3 pos, glm::vec3 angle);
@ -62,14 +62,9 @@ namespace Renderer {
class RenderObject : public Object { class RenderObject : public Object {
public: public:
const char* name = "RenderObject";
RenderObject(std::vector<float> verts, std::vector<unsigned int> indices); RenderObject(std::vector<float> verts, std::vector<unsigned int> indices);
void render(GLFWwindow* win, Camera cam); void render(GLFWwindow* win, Camera cam);
void preRenderHook(); void preRenderHook();
void transform(glm::mat4 T);
void setPosition(glm::vec3 pos);
void setRotation(glm::vec3 angle);
private: private:
Shaders::Shader shader; Shaders::Shader shader;
unsigned int EBO; unsigned int EBO;
@ -96,7 +91,6 @@ namespace Renderer {
class TexturedObject : public RenderObject { class TexturedObject : public RenderObject {
public: public:
const char* name = "TexturedObject";
using RenderObject::RenderObject; using RenderObject::RenderObject;
void setTexture(const char* t_src); void setTexture(const char* t_src);
void preRenderHook(); void preRenderHook();

@ -27,7 +27,9 @@ void processInput(GLFWwindow *win) {
void renderCallback() { void renderCallback() {
// Make background // Make background
glClearColor(0.1f, 0.1f, 0.1f, 1.0f); // glClearColor(0.1f, 0.1f, 0.1f, 1.0f);
glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
// glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
} }
@ -151,7 +153,6 @@ int main() {
Renderer::TexturedObject ro(verts, indices); Renderer::TexturedObject ro(verts, indices);
ro.setPosition(glm::vec3(0.2f, -1.0f, -8.0f)); ro.setPosition(glm::vec3(0.2f, -1.0f, -8.0f));
ro.name = "Hej";
Renderer::TexturedObject ro2(verts, indices); Renderer::TexturedObject ro2(verts, indices);
ro2.setPosition(glm::vec3(0.5f, 0.0, -8.0f)); ro2.setPosition(glm::vec3(0.5f, 0.0, -8.0f));
@ -162,7 +163,6 @@ int main() {
scene.spawnObject(ro); scene.spawnObject(ro);
// scene.spawnObject(ro2); // scene.spawnObject(ro2);
// Window width & height
while (!glfwWindowShouldClose(win)) { while (!glfwWindowShouldClose(win)) {
// Handle input // Handle input
processInput(win); processInput(win);
@ -175,15 +175,16 @@ int main() {
// Move the camera left and right // Move the camera left and right
// scene.camera.setPosition(glm::vec3(0.0f, 0.0f, 8*gVal-4.0f)); // scene.camera.setPosition(glm::vec3(0.0f, 0.0f, 8*gVal-4.0f));
scene.camera.translate(glm::vec3(0.0f, 0.0f, 0.01f)); // scene.camera.translate(glm::vec3(0.0f, 0.0f, 0.01f));
scene.camera.setRotation(glm::vec3(0.0f, 5.0f, 0.0f)); scene.camera.setRotation(glm::vec3(0.0f, 5.0f, 0.0f));
// scene.camera.rotate(glm::vec3(0.0f, -0.4f, 0.0f)); // scene.camera.rotate(glm::vec3(0.0f, -0.4f, 0.0f));
// Move the objects & stuff // Move the objects & stuff
float rotang = time; float rotang = time;
// ro.setRotation(glm::vec3(time*10, 0.0f, time)); // ro.setRotation(glm::vec3(time*10, 0.0f, time));
ro.translate(glm::vec3(0.0f, 0.0f, -0.015f)); // ro.translate(glm::vec3(0.0f, 0.0f, -0.015f));
ro.rotate(glm::vec3(20.0f, 0.0f, 0.0f)); ro.setPosition(glm::vec3(10.0f, 0.0f, 0.0f));
// ro.rotate(glm::vec3(20.0f, 0.0f, 0.0f));
// Render new frame // Render new frame
scene.render(); scene.render();

@ -22,6 +22,14 @@ namespace Renderer {
setRotation(angle); setRotation(angle);
} }
glm::mat4 Object::getModelTransform() { return modelTransform; }
void Object::scale(glm::vec3 vscale) {
glm::mat4 T = glm::mat4(1.0f);
T = glm::scale(T, vscale);
modelTransform = T;
}
void Object::transform(glm::mat4 T) { void Object::transform(glm::mat4 T) {
modelTransform = T; modelTransform = T;
} }
@ -35,7 +43,9 @@ namespace Renderer {
void Object::setPosition(glm::vec3 pos) { void Object::setPosition(glm::vec3 pos) {
position = pos; position = pos;
std::cout << "New pos: " << glm::to_string(pos) << " vs. " << glm::to_string(position) << std::endl;
updatePositionTransform(); updatePositionTransform();
std::cout << "Updated positionTransform: " << glm::to_string(positionTransform) << std::endl;
} }
void Object::translate(glm::vec3 dpos) { void Object::translate(glm::vec3 dpos) {
@ -160,13 +170,13 @@ namespace Renderer {
void RenderObject::render(GLFWwindow* win, Camera cam) { void RenderObject::render(GLFWwindow* win, Camera cam) {
shader.setMat4("modelPosition", getPositionTransform()); shader.setMat4("modelPosition", getPositionTransform());
shader.setMat4("modelRotation", getRotationTransform()); shader.setMat4("modelRotation", getRotationTransform());
shader.setMat4("model", getModelTransform());
shader.setMat4("camPos", cam.getPositionTransform()); shader.setMat4("camPos", cam.getPositionTransform());
shader.setMat4("camRot", cam.getRotationTransform()); shader.setMat4("camRot", cam.getRotationTransform());
shader.setMat4("camProjection", cam.projection); shader.setMat4("camProjection", cam.projection);
std::cout << "Name: " << name << " | "; std::cout << "Rendered positionTransform:" << glm::to_string(getPositionTransform()) << std::endl;
std::cout << glm::to_string(getPositionTransform()) << std::endl;
shader.use(); shader.use();
@ -174,21 +184,6 @@ namespace Renderer {
glDrawArrays(GL_TRIANGLES, 0, indicesVec.size()); glDrawArrays(GL_TRIANGLES, 0, indicesVec.size());
} }
void RenderObject::setPosition(glm::vec3 pos) {
Object::setPosition(pos);
shader.setMat4("modelPosition", getPositionTransform());
}
void RenderObject::setRotation(glm::vec3 angle) {
Object::setRotation(angle);
shader.setMat4("modelRotation", getRotationTransform());
}
void RenderObject::transform(glm::mat4 T) {
Object::transform(T);
shader.setMat4("model", T);
}
// TexturedObject // TexturedObject
void TexturedObject::setTexture(const char* t_src) { void TexturedObject::setTexture(const char* t_src) {
texture.texture_src = t_src; texture.texture_src = t_src;

Loading…
Cancel
Save