traces working and nice (on simple renderer)

This commit is contained in:
Andreas Ortmann 2016-09-27 20:23:33 +02:00
parent fd8d56bf95
commit 2b85397674
5 changed files with 26 additions and 12 deletions

View file

@ -32,7 +32,7 @@ bool Game::cycle(float dt)
acc -= spawnInterval;
float a = 2.0 * M_PI * util::randf_0_1();
float speed = 0.002;
float speed = 0.005;
m_state->players[0]->addCommand(new game::ShootCommand(a, speed));
}

View file

@ -5,6 +5,7 @@
#include "game.hpp"
#include "state/trace.hpp"
#include "state/object.hpp"
#include "state/missile.hpp"
#include "state/player.hpp"
@ -41,6 +42,10 @@ protected:
drawPlanet(planet->position, planet->radius);
}
for (const game::Trace *trace : m_game.state()->traces) {
drawTrace(trace);
}
for (const game::Ship *ship : m_game.state()->ships) {
drawShip(ship->position);
}
@ -73,9 +78,18 @@ protected:
}
void drawMissile(const glm::vec2 &pos)
{
glm::vec3 color = glm::vec3(1.0, 1.0, 0.3);
m_renderer.drawCircle(pos.x, pos.y, 0.005, color.x, color.y, color.z, 5);
m_renderer.drawCircle(pos.x, pos.y, 0.01, color.x, color.y, color.z, 6);
}
void drawTrace(const game::Trace *trace)
{
for (const game::Trace::TracePoint &p : trace->points) {
glm::vec3 color = glm::vec3(0.1, 0.3, 1.0) / (1.0f + 500.0f*p.speed);
m_renderer.drawCircle(p.position.x, p.position.y, 0.005, color.x, color.y, color.z, 3);
}
}
public:

View file

@ -130,7 +130,7 @@ void endofthejedi::GLWindow::loop() {
prev = current;
if(delta > 0.0) {
m_fps = (1000000000.0/delta);
std::cout << m_fps << "\n";
//std::cout << m_fps << "\n";
}
}
}

View file

@ -6,13 +6,13 @@ endofthejedi::Renderer::Renderer() {
endofthejedi::Renderer::~Renderer() {}
void endofthejedi::Renderer::drawCircle(float x, float y, float radius, float r,
float g, float b, int numSides) {
glBegin(GL_TRIANGLE_FAN);
glVertex2f(x, y); // center of circle
for (int i = 0; i <= numSides; i++) {
void endofthejedi::Renderer::drawCircle(float x, float y, float radius, float r, float g, float b, int numSides)
{
glBegin(GL_TRIANGLE_FAN);
glColor3f(r,g,b);
glVertex2f(x + (radius * cos(i * 2 * M_PI / numSides)), y + (radius * sin(i * 2 * M_PI / numSides)));
}
glEnd();
glVertex2f(x, y); // center of circle
for (int i = 0; i <= numSides; i++) {
glVertex2f(x + (radius * cos(i * 2 * M_PI / numSides)), y + (radius * sin(i * 2 * M_PI / numSides)));
}
glEnd();
}

View file

@ -19,7 +19,7 @@ namespace game {
void Trace::addPointFromMissile(bool forceAdd)
{
fidelityCounter++;
if (forceAdd || fidelityCounter >= 20) {
if (forceAdd || fidelityCounter >= 10) {
fidelityCounter = 0;
points.push_back(TracePoint(missile));
}