Commit 18f71285 authored by Benjamin Castel's avatar Benjamin Castel
Browse files

doc: Lightly-commented headers (doxygen)

parent 6dac5d9e
Loading
Loading
Loading
Loading
+63 −47
Changes for include/GlApplication.hpp: 63 added lines, 47 removed lines.
Original line number Diff line number Diff line
#pragma once


#include <Application.hpp>
#include <glApi.hpp>
#include <ObjLoader.hpp>
#include <utils.hpp>


#include <GLFW/glfw3.h>
#include <glm/ext.hpp>
#include <glm/gtc/matrix_transform.hpp>
#include <stb_image.h>


#include <iostream>
#include <memory>
#include <cstdlib>
#include <ctime>


#include "GuiElement.hpp"
#include "RenderObject.hpp"
#include "model/Asteroid.hpp"
@@ -23,16 +27,69 @@
#include "model/Player.hpp"
#include "model/Spaceship.hpp"

#define WIN_NOT_WIN_YET -1
#define WIN_PLAYER_1 1
#define WIN_PLAYER_2 2
#define WIN_DRAW 3

#define SKYBOX_SIZE 400
#define WIN_NOT_WIN_YET -1 // In case no one won yet
#define WIN_PLAYER_1     1 // In case Player 1 won
#define WIN_PLAYER_2     2 // In case Player 2 won
#define WIN_DRAW         3 // In case of a draw

#define SKYBOX_SIZE 400    // Semi-scale of the skybox

class RenderObject;

class RenderObject; // Forward declaration of RenderObject class


/**
 * @brief Class used to handle the whole application
 * Glitter's-Application-derived class
 */
class GlApplication : public Application {
    private:
        /**
         * @brief Enum containing every model key
         * Enum containing every key used to retrieve models but also entities of the same type
         */
        enum ModelKeys {
            SPACESHIP_1, // Player one's spaceship
            SPACESHIP_2, // Player two's spaceship
            LASER_1,     // Laser shot by player one's spaceship 
            LASER_2,     // Laser shot by player two's spaceship
            ASTEROID,    // Asteroid
            SKYBOX,      // Skybox
            PLANKS,      // Glitter's plank
            TRON,        // Glitter's tron
            OBB          // Oriented Bounding Box
        };

        bool drawBoundingBoxes; 

        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
        std::vector<std::shared_ptr<GuiElement>> m_guiElement;                 // gui elements

        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

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

        std::shared_ptr<Spaceship> m_spaceshipPlayer1;                         // Player 1 spaceship
        std::shared_ptr<Spaceship> m_spaceshipPlayer2;                         // Player 2 spaceship

        std::shared_ptr<GuiElement> win;                                       // Screen to display to the winner
        std::shared_ptr<GuiElement> lose;                                      // Screen to display to the loser
        std::shared_ptr<GuiElement> draw;                                      // Screen to display to both players in case of draw

        std::shared_ptr<LifeGui> healthbar;                                    // Health bar GUI element

        int winner;                                                            // Winning player

        Program guiProgram;                                                    // Glitter program used to render the GUI
    
    public:
        GlApplication(int windowWidth, int windowHeight);
        void setCallbacks() override;
@@ -43,18 +100,6 @@ class GlApplication : public Application {
        void toggleHitboxes();

    private:
        enum ModelKeys {
            SPACESHIP_1,
            SPACESHIP_2,
            LASER_1,
            LASER_2,
            ASTEROID,
            SKYBOX,
            PLANKS,
            TRON,
            OBB
        };

        void loadModels();
        void createEntities();

@@ -75,33 +120,4 @@ class GlApplication : public Application {
        void processPlayer2Input(GLFWwindow *window, float deltaTime);

        void resetGame();
    private:
        bool drawBoundingBoxes;

        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
        std::vector<std::shared_ptr<GuiElement>> m_guiElement;           ///< gui elements

        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

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

        std::shared_ptr<Spaceship> m_spaceshipPlayer1;        ///< Player 1 spaceship
        std::shared_ptr<Spaceship> m_spaceshipPlayer2;        ///< Player 2 spaceship

        std::shared_ptr<GuiElement> win;
        std::shared_ptr<GuiElement> lose;
        std::shared_ptr<GuiElement> draw;

        std::shared_ptr<LifeGui> healthbar;

        int winner;

        Program guiProgram;
};
+21 −15
Changes for include/GuiElement.hpp: 21 added lines, 15 removed lines.
Original line number Diff line number Diff line
#pragma once


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


#include <stb_image.h>


#include "glApi.hpp"
#include "utils.hpp"


/**
 * @brief Base class for every GUI element
 * Class inherited by any GUI element destined to be rendered directly on-screen
 */
class GuiElement {
	private:
		glm::vec2 position;               // (x,y) Position on the screen
		glm::vec2 dimension;              // (x,y) Scale on the screen

		glm::vec2 position;
		glm::vec2 dimension;

		Sampler textureSampler;
		std::shared_ptr<Texture> texture;
		VAO vao;

		glm::mat4 modelMatrix;

		void computeModelMatrix();

		void createElement(Program &program);
		Sampler textureSampler;           // Texture sampler linked to the GUI element
		std::shared_ptr<Texture> texture; // Smart pointer to glitter's Texture of the Element
		VAO vao;                          // VAO of the GUI Element

	protected:
		void setTexture(std::shared_ptr<Texture> &newTexture);
		glm::mat4 modelMatrix;            // Basic model matrix to render the element

	public: 

		GuiElement(Program &program, const std::string &texturePath);
		GuiElement(Program &program);

@@ -37,4 +36,11 @@ class GuiElement {

		void draw();
		void updateUniforms(Program &guiProgram);

	protected:
		void setTexture(std::shared_ptr<Texture> &newTexture);
	
	private:
			void computeModelMatrix();
			void createElement(Program &program);
};
+16 −11
Changes for include/RenderObject.hpp: 16 added lines, 11 removed lines.
Original line number Diff line number Diff line
#pragma once


#include <glApi.hpp>
#include <ObjLoader.hpp>
#include <utils.hpp>


#include <stb_image.h>


#include <memory>


#include "RenderObjectPart.hpp"


/**
 * @brief The RenderObject class
 *
 * A RenderObject is split into parts, sharing the same geometry (VBOs), but referencing different primitive subsets (IBO) and materials (textures, ...).
 */
class RenderObject {
	private:
		std::vector<RenderObjectPart> m_parts;  // Sub-parts of the object
		
		std::unique_ptr<Sampler> m_diffusemap;  // Diffuse map of the object
		std::unique_ptr<Sampler> m_normalmap;   // Normal map of the object
		std::unique_ptr<Sampler> m_specularmap; // Specular map of the object

		std::shared_ptr<Program> program;       // OpenGL program to render the object

		glm::vec3 dimensions;                   // Dimensions of the object (used to compute OBBs)

	public:
		RenderObject(const RenderObject &) = delete;

@@ -56,15 +72,4 @@ class RenderObject {
	private:
		RenderObject();
		void loadWavefront(const std::string & objname);

	private:
		std::vector<RenderObjectPart> m_parts;
		
		std::unique_ptr<Sampler> m_diffusemap;
		std::unique_ptr<Sampler> m_normalmap;
		std::unique_ptr<Sampler> m_specularmap;

		std::shared_ptr<Program> program;

		glm::vec3 dimensions;
};
+14 −7
Changes for include/RenderObjectPart.hpp: 14 added lines, 7 removed lines.
Original line number Diff line number Diff line
#pragma once


#include <glApi.hpp>


#include <memory>


/**
 * @brief Class representing a sub-part of an object
 * Class representing a sub-RenderObject
 */
class RenderObjectPart {
    private:
        std::shared_ptr<VAO>     m_vao;             // Smart pointer to corresponding RenderObject's VAO
        std::shared_ptr<Program> m_program;         // Smart pointer to corresponding RenderObject's OpenGL Program
        std::shared_ptr<Texture> m_diffuseTexture;  // Smart pointer to corresponding RenderObject's Diffuse map
        std::shared_ptr<Texture> m_normalTexture;   // Smart pointer to corresponding RenderObject's normal map
        std::shared_ptr<Texture> m_specularTexture; // Smart pointer to corresponding RenderObject's specular map
    
    public:
        RenderObjectPart() = delete;
        RenderObjectPart(const RenderObjectPart &) = delete;
@@ -15,11 +29,4 @@ class RenderObjectPart {
        void update(const glm::mat4 & proj, const glm::mat4 & view, const glm::mat4 & mw);

        glm::vec3 get_dimensions() const;

            private:
                std::shared_ptr<VAO> m_vao;
                std::shared_ptr<Program> m_program;
                std::shared_ptr<Texture> m_diffuseTexture;
                std::shared_ptr<Texture> m_normalTexture;
                std::shared_ptr<Texture> m_specularTexture;
};
+11 −3
Changes for include/model/Asteroid.hpp: 11 added lines, 3 removed lines.
Original line number Diff line number Diff line
#pragma once


#include <cstdlib>
#include <ctime>


#include <glm/ext.hpp>


#include "model/Entity.hpp"

#define ASTEROID_SPEED 0.1

#define ASTEROID_SPEED 0.1 // Speed of asteroid rotation


/**
 * @brief Class representing an Asteroid
 * Entity-derived asteroid class
 */
class Asteroid : public Entity {
    private:

        glm::vec3 rotationAngle;
        glm::vec3 rotationAngle; // Euler angles used to rotate the asteroid

    public:
        Asteroid();
Loading