Fixed scene not using updated RenderObjects

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

@ -79,13 +79,13 @@ namespace Renderer {
Camera camera;
Scene(GLFWwindow* win);
Scene(GLFWwindow* win, std::vector<RenderObject> ROs);
Scene(GLFWwindow* win, std::vector<RenderObject*> ROs);
void setCamera(Camera cam);
void spawnObject(RenderObject ro);
void spawnObject(RenderObject *ro);
void render();
private:
std::vector<RenderObject> renderObjects = std::vector<RenderObject>();
std::vector<RenderObject*> renderObjects = std::vector<RenderObject*>();
GLFWwindow* window;
};

@ -28,8 +28,8 @@ void processInput(GLFWwindow *win) {
void renderCallback() {
// Make background
// 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);
// 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);
}
@ -157,11 +157,11 @@ int main() {
Renderer::TexturedObject ro2(verts, indices);
ro2.setPosition(glm::vec3(0.5f, 0.0, -8.0f));
ro.setTexture(RUSTY_METAL_TEXTURE);
ro2.setTexture("assets/textures/meep.jpg");
ro.setTexture(RUSTY_METAL_TEXTURE);
scene.spawnObject(ro);
// scene.spawnObject(ro2);
scene.spawnObject(&ro);
scene.spawnObject(&ro2);
while (!glfwWindowShouldClose(win)) {
// Handle input
@ -174,17 +174,12 @@ int main() {
float gVal = sin(time);
// 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.setRotation(glm::vec3(0.0f, 5.0f, 0.0f));
// scene.camera.rotate(glm::vec3(0.0f, -0.4f, 0.0f));
scene.camera.translate(glm::vec3(0.0f, 0.0f, 0.02f + gVal/100.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.setPosition(glm::vec3(10.0f, 0.0f, 0.0f));
// ro.rotate(glm::vec3(20.0f, 0.0f, 0.0f));
ro.translate(glm::vec3(0.0f, 0.0f, -0.021f));
// Render new frame
scene.render();

@ -43,9 +43,7 @@ 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) {
@ -67,8 +65,6 @@ namespace Renderer {
T = glm::rotate(T, glm::radians(z_Ang), glm::vec3(0.0f, 0.0f, 1.0f));
rotationTransform = T;
// std::cout << "Name: " << name << " | ";
// std::cout << glm::to_string(T) << std::endl;
}
void Object::setRotation(glm::vec3 ang) {
@ -88,11 +84,11 @@ namespace Renderer {
camera.setFOV(DEFAULT_FOV);
}
Scene::Scene(GLFWwindow* win, std::vector<RenderObject> ROs) : Scene(win) {
Scene::Scene(GLFWwindow* win, std::vector<RenderObject*> ROs) : Scene(win) {
renderObjects = ROs;
}
void Scene::spawnObject(RenderObject ro) {
void Scene::spawnObject(RenderObject *ro) {
renderObjects.push_back(ro);
}
@ -101,8 +97,8 @@ namespace Renderer {
}
void Scene::render() {
for ( RenderObject ro: renderObjects )
ro.render(window, camera);
for ( RenderObject *ro: renderObjects )
ro->render(window, camera);
}
// Camera
@ -176,8 +172,6 @@ namespace Renderer {
shader.setMat4("camRot", cam.getRotationTransform());
shader.setMat4("camProjection", cam.projection);
std::cout << "Rendered positionTransform:" << glm::to_string(getPositionTransform()) << std::endl;
shader.use();
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, EBO);
@ -191,8 +185,6 @@ namespace Renderer {
}
void TexturedObject::preRenderHook() {
printf("TexturedObject was here!\n");
printf("Now has texture: %s", texture.texture_src);
if (texture.loaded)
texture.bind();
}

Loading…
Cancel
Save