2016-09-28 09:50:35 +00:00
|
|
|
#include "renderer.hpp"
|
|
|
|
|
2016-09-29 06:28:56 +00:00
|
|
|
#include <list>
|
|
|
|
|
2016-10-02 09:00:03 +00:00
|
|
|
#include <glm/gtc/type_ptr.hpp>
|
|
|
|
#include <glm/gtc/matrix_transform.hpp>
|
|
|
|
#include <glm/gtx/euler_angles.hpp>
|
|
|
|
#include <glm/gtc/random.hpp>
|
|
|
|
#include <glm/vec3.hpp>
|
|
|
|
#include <glm/gtc/matrix_transform.hpp>
|
|
|
|
|
2016-09-28 09:50:35 +00:00
|
|
|
#include "glclasses.hpp"
|
|
|
|
|
|
|
|
#include "game.hpp"
|
|
|
|
|
|
|
|
#include "state/trace.hpp"
|
|
|
|
#include "state/object.hpp"
|
|
|
|
#include "state/missile.hpp"
|
|
|
|
#include "state/player.hpp"
|
|
|
|
#include "state/planet.hpp"
|
|
|
|
#include "state/ship.hpp"
|
|
|
|
#include "state/explosion.hpp"
|
|
|
|
|
2016-09-28 19:26:11 +00:00
|
|
|
#include "particle_batch.hpp"
|
|
|
|
#include "polygon_model.hpp"
|
2016-09-28 14:12:25 +00:00
|
|
|
|
2016-09-28 09:50:35 +00:00
|
|
|
namespace endofthejedi {
|
|
|
|
|
2016-09-28 11:00:40 +00:00
|
|
|
class RendererPolygon3d : public Renderer {
|
2016-09-28 09:50:35 +00:00
|
|
|
public:
|
|
|
|
void setup();
|
|
|
|
void render(const game::State *state) override;
|
|
|
|
|
2016-10-02 09:00:03 +00:00
|
|
|
void setWindowSize(int px, int py);
|
|
|
|
void setCameraMatrix(const glm::mat4 &cam);
|
|
|
|
|
2016-09-28 12:19:05 +00:00
|
|
|
private:
|
2016-09-28 14:12:25 +00:00
|
|
|
void renderPlanets();
|
|
|
|
void renderMissiles();
|
|
|
|
void renderShips();
|
2016-09-28 19:26:11 +00:00
|
|
|
void renderParticles();
|
2016-09-28 12:19:05 +00:00
|
|
|
|
|
|
|
void addModel(const std::string &filename, PolygonModel **dest);
|
|
|
|
|
2016-10-02 19:06:02 +00:00
|
|
|
void addExplosionEffect(
|
|
|
|
size_t id, const glm::vec2 &pos, const glm::vec2 &missileVelocity,
|
|
|
|
bool hitPlanet,
|
|
|
|
size_t n, float duration);
|
2016-09-29 06:28:56 +00:00
|
|
|
|
|
|
|
void advanceGraphicObjects(float dt);
|
|
|
|
|
2016-09-28 14:12:25 +00:00
|
|
|
// shortcuts which use the lower versions
|
|
|
|
glm::mat4 computeModelMatrix(const game::Planet *planet);
|
|
|
|
glm::mat4 computeModelMatrix(const game::Missile *missile);
|
|
|
|
glm::mat4 computeModelMatrix(const game::Ship *ship);
|
|
|
|
|
|
|
|
// do the actual computation with these values
|
|
|
|
glm::mat4 computeModelMatrix(const glm::vec2 &pos, float scale, float angle=0.0);
|
|
|
|
|
2016-09-29 07:16:34 +00:00
|
|
|
void renderTraces();
|
|
|
|
|
2016-10-03 08:47:02 +00:00
|
|
|
void configureLightningInShader(Shader *shader) const;
|
2016-09-30 20:47:28 +00:00
|
|
|
|
2016-09-28 11:00:40 +00:00
|
|
|
private:
|
2016-09-28 11:36:22 +00:00
|
|
|
// all models are also here (for easy reloading etc.)
|
|
|
|
std::vector<PolygonModel*> m_models;
|
|
|
|
|
|
|
|
// and with a specific variable name here
|
2016-09-28 12:19:05 +00:00
|
|
|
PolygonModel *m_missileModel;
|
|
|
|
PolygonModel *m_planetModel;
|
2016-09-28 12:41:15 +00:00
|
|
|
PolygonModel *m_shipModel;
|
2016-09-28 11:16:11 +00:00
|
|
|
|
2016-09-28 11:36:22 +00:00
|
|
|
// for rendering everything
|
2016-10-02 09:00:03 +00:00
|
|
|
Shader m_shader_game_objects;
|
|
|
|
Shader m_shader_particles;
|
2016-09-28 14:12:25 +00:00
|
|
|
|
|
|
|
// for accessing
|
|
|
|
const game::State *m_state;
|
2016-09-28 19:26:11 +00:00
|
|
|
|
2016-09-29 06:28:56 +00:00
|
|
|
std::list<ParticleBatch*> m_particles;
|
|
|
|
|
|
|
|
// time value for last rendering cycle (-1 after setup/startup)
|
|
|
|
float m_lastTime;
|
2016-10-02 09:00:03 +00:00
|
|
|
|
|
|
|
float m_aspectRatio;
|
2016-10-03 11:37:49 +00:00
|
|
|
|
|
|
|
// TODO: put representation specialized for rendering in here
|
|
|
|
std::list<const game::Missile*> m_missiles;
|
|
|
|
std::list<const game::Ship*> m_ships;
|
2016-09-28 11:00:40 +00:00
|
|
|
};
|
2016-09-28 09:50:35 +00:00
|
|
|
}
|