Removed junk

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

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

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

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

Loading…
Cancel
Save