Commit 83bae3a3 authored by Justine Martin's avatar Justine Martin 💖
Browse files

feat : Systeme de gestion d'entités pour le rendu

parent a2b77743
Loading
Loading
Loading
Loading
+1 −1
Changes for CMakeLists.txt: 1 added line, 1 removed line.
Original line number Diff line number Diff line
@@ -18,5 +18,5 @@ include_directories("glitter/ext/tinyobjloader"
		${OPENGL_INCLUDE_DIR})

add_executable(GLE-test src/main.cpp src/RenderObject.cpp src/RenderObjectPart.cpp src/GlApplication.cpp
               src/model/Spaceship.cpp src/model/Renderable.cpp)
               src/model/Spaceship.cpp src/model/Entity.cpp)
target_link_libraries(GLE-test utils ${GLFW3_LIBRARIES} ${GLEW_LIBRARIES})
+17 −8
Changes for include/GlApplication.hpp: 17 added lines, 8 removed lines.
Original line number Diff line number Diff line
@@ -26,28 +26,37 @@ class GlApplication : public Application {

        void setFramebufferSize(int framebufferWidth, int framebufferHeight);

    public:
        static bool displayNormals; ///< Toggles normal display

    private:
        enum ModelKeys {
            SPACESHIP,
            PLANKS,
            TRON
        };

        void loadModels();
        void createEntities();

        void renderFrame() override;
        void update() override;
        static void resize(GLFWwindow * window, int framebufferWidth, int framebufferHeight);
        static void keyCallback(GLFWwindow * window, int key, int scancode, int action, int mods);
        void continuousKey();
        void continuousKey(float deltaTime);
        void computeView(bool reset = false);

    private:
        std::vector<std::shared_ptr<RenderObject>> m_objects; ///< render objects
        std::map<ModelKeys, std::vector<std::shared_ptr<Entity>>> m_entities;  ///< objects to render
        std::map<ModelKeys, std::unique_ptr<RenderObject>> m_models;           ///< loaded models

        glm::mat4 m_proj;                                     ///< Projection matrix
        glm::mat4 m_view;                                     ///< worldView matrix

        float m_eyePhi;                                       ///< Camera position longitude angle
        float m_eyeTheta;                                     ///< Camera position latitude angle
        float m_currentTime;                                  ///< elapsed time since first frame
        float m_deltaTime;                                    ///< elapsed time since last frame

        int m_framebufferWidth;                               ///< Window's width
        int m_framebufferHeight;                              ///< Window's height

        Spaceship m_spaceshipPlayer1;                         ///< Player 1 spaceship
        Spaceship m_spaceshipPlayer2;                         ///< Player 2 spaceship
        std::shared_ptr<Spaceship> m_spaceshipPlayer1;        ///< Player 1 spaceship
        std::shared_ptr<Spaceship> m_spaceshipPlayer2;        ///< Player 2 spaceship
};
+4 −5
Changes for include/RenderObject.hpp: 4 added lines, 5 removed lines.
Original line number Diff line number Diff line
@@ -17,7 +17,6 @@
 */
class RenderObject {
	public:
		RenderObject() = delete;
		RenderObject(const RenderObject &) = delete;

		static std::unique_ptr<RenderObject> createCheckerBoardPlaneInstance(const glm::mat4 & modelWorld);
@@ -27,7 +26,7 @@ class RenderObject {
		 * @param modelWorld the matrix transform between the object (a.k.a model) space and the world space
		 * @return the created RenderObject as a smart pointer
		 */
		static std::shared_ptr<RenderObject> createWavefrontInstance(const std::string & objname, const glm::mat4 & modelWorld);
		static std::unique_ptr<RenderObject> createWavefrontInstance(const std::string & objname);

		/**
		 * @brief Sets all uniform variables related to material and lighting
@@ -48,15 +47,15 @@ class RenderObject {
		 * @param proj the projection matrix
		 * @param view the worldView matrix
		 */
		void update(const glm::mat4 & proj, const glm::mat4 & view);
		void update(const glm::mat4 & proj, const glm::mat4 & view, const glm::mat4 &model);

	private:
		RenderObject(const glm::mat4 & modelWorld);
		RenderObject();
		void loadWavefront(const std::string & objname);

	private:
		glm::mat4 m_mw; ///< modelWorld matrix
		std::vector<RenderObjectPart> m_parts;
		
		std::unique_ptr<Sampler> m_diffusemap;
		std::unique_ptr<Sampler> m_normalmap;
		std::unique_ptr<Sampler> m_specularmap;
+1 −0
Changes for include/RenderObjectPart.hpp: 1 added line, 0 removed lines.
Original line number Diff line number Diff line
@@ -10,6 +10,7 @@ class RenderObjectPart {
                RenderObjectPart(const RenderObjectPart &) = delete;
                RenderObjectPart(RenderObjectPart &&) = default;
                RenderObjectPart(std::shared_ptr<VAO> vao, std::shared_ptr<Program> program, std::shared_ptr<Texture> texture, std::shared_ptr<Texture> ntexture, std::shared_ptr<Texture> stexture);
                
                void draw(Sampler * colormap, Sampler * normalmap, Sampler * specularmap);
                void update(const glm::mat4 & proj, const glm::mat4 & view, const glm::mat4 & mw);

+33 −0
Changes for include/model/Entity.hpp: 33 added lines, 0 removed lines.
Original line number Diff line number Diff line
#pragma once 

#include <glm/ext.hpp>
#include <glm/gtc/matrix_transform.hpp>

#include <string>
#include <memory>

#include "RenderObject.hpp"

class Entity {
    private:
        std::shared_ptr<RenderObject> renderObject;
    
    public:
        Entity();
        virtual void update(const double &time);

        glm::mat4 getModelMatrix() const;
        void move(glm::vec3 translation);
        void rotate(glm::vec3 rotation);
        void setScale(float scale);

    private:
        void computeModelMatrix(); 

        glm::mat4 m_modelMatrix;

        glm::vec3 m_position;
        glm::vec3 m_rotation;
        float m_scale;
};
Loading