adding simple dummy ship model.

This commit is contained in:
Andreas Ortmann 2016-09-28 14:41:15 +02:00
parent 1ad020dbd4
commit 4906777e9a
4 changed files with 55 additions and 7 deletions

View file

@ -1 +1 @@
sphere(1, $fn=128);
sphere(1, $fn=1024);

15
data/mesh/ship.scad Normal file
View file

@ -0,0 +1,15 @@
translate([-1,0,0]) cube([2, 0.2, 2], center=true);
translate([1,0,1-0.5]) cube([2, 0.2, 1], center=true);
translate([1,0,1-0.5]) {
cube([1, 5.0, 0.2], center=true);
for (s=[-1,1]) {
translate([1,2*s,0]) cube([4,0.5,0.5], center=true);
}
}
translate([0,0-0.25,0.5]) cube([5, 0.5, 0.3]);
for (n=[0:14]) {
translate([n*0.5-2,0,0.5]) cube([0.2, 2/(1+log(n/2)), 0.3], center=true);
}
translate([-2,0,0]) sphere(1, $fn=12);

View file

@ -15,7 +15,8 @@ namespace endofthejedi {
addModel("../data/mesh/small_atomic_bomb.stl", &m_missileModel);
//addModel("../data/mesh/planet_128.stl", &m_planetModel);
addModel("../data/mesh/planet_12.stl", &m_planetModel);
addModel("../data/mesh/planet_12.stl", &m_planetModel);
addModel("../data/mesh/ship.stl", &m_shipModel);
std::string vss_simple =
"#version 120\n"
@ -82,7 +83,12 @@ namespace endofthejedi {
{
m_shader.bind();
// TODO :Z?
renderPlanets(state);
renderShips(state);
renderMissiles(state);
//glColor3f(1.0, 0.0, 0.0);
//glBegin(GL_QUADS);
@ -111,10 +117,36 @@ namespace endofthejedi {
void RendererPolygon3d::renderMissiles(const game::State *state)
{
(void) state;
//m_missileModel->bind();
// TODO
//m_missileModel->render();
m_missileModel->bind();
for (const game::Player *player : state->players) {
for (const game::Missile *missile : player->missiles) {
glm::vec3 c = glm::vec3(1.0, 1.0, 0.3);
const auto &p = missile->position;
glUniform3f(m_shader.location("position"), p.x, p.y, 0.0);
glUniform3f(m_shader.location("color"), c.x, c.y, c.z);
glUniform1f(m_shader.location("scale"), 1.0);
m_missileModel->render();
}
}
}
void RendererPolygon3d::renderShips(const game::State *state)
{
m_shipModel->bind();
for (const game::Ship *ship : state->ships) {
glm::vec3 c = glm::vec3(0.1, 1.0, 0.2);
const auto &p = ship->position;
glUniform3f(m_shader.location("position"), p.x, p.y, 0.0);
glUniform3f(m_shader.location("color"), c.x, c.y, c.z);
glUniform1f(m_shader.location("scale"), 0.02);
m_shipModel->render();
}
}
void RendererPolygon3d::addModel(const std::string &filename, PolygonModel **dest)

View file

@ -24,7 +24,7 @@ namespace endofthejedi {
private:
void renderPlanets(const game::State *state);
void renderMissiles(const game::State *state);
//void renderShips(const game::State *state);
void renderShips(const game::State *state);
void addModel(const std::string &filename, PolygonModel **dest);
@ -35,6 +35,7 @@ namespace endofthejedi {
// and with a specific variable name here
PolygonModel *m_missileModel;
PolygonModel *m_planetModel;
PolygonModel *m_shipModel;
// for rendering everything
Shader m_shader;