planet distribution is nice now and one sun is always placed with bigger radius and space nearby.
This commit is contained in:
parent
f2bdadd49f
commit
0b71aad1f7
5 changed files with 86 additions and 45 deletions
|
@ -6,8 +6,9 @@ varying vec3 lightDirection;
|
||||||
|
|
||||||
uniform vec3 lightColor;
|
uniform vec3 lightColor;
|
||||||
uniform vec3 lightPosition;
|
uniform vec3 lightPosition;
|
||||||
uniform float materialKind;
|
|
||||||
uniform vec3 materialColor;
|
uniform vec3 materialColor;
|
||||||
|
uniform int materialKind;
|
||||||
|
uniform int materialSeed;
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
|
@ -23,27 +24,15 @@ void main()
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: add noise texture
|
// TODO: add noise texture
|
||||||
vec3 IDiffuse = vec3(materialColor) * lightColor * max(dot(normal, lightDirection), 0.0);
|
vec3 color = materialColor;
|
||||||
|
color = max(vec3(0.0), min(vec3(1.0), color));
|
||||||
|
|
||||||
|
vec3 IDiffuse = vec3(color) * lightColor * max(dot(normal, lightDirection), 0.0);
|
||||||
|
|
||||||
// TODO make instensity/exponent as parameter
|
// TODO make instensity/exponent as parameter
|
||||||
//vec3 ISpecular = lightColor * 5.0 * pow(max(dot(Reflected, Eye), 0.0), 2.0);
|
//vec3 ISpecular = lightColor * 5.0 * pow(max(dot(Reflected, Eye), 0.0), 2.0);
|
||||||
vec3 ISpecular = lightColor * pow(max(dot(Reflected, Eye), 0.0), 2.0);
|
//vec3 ISpecular = lightColor * pow(max(dot(Reflected, Eye), 0.0), 2.0);
|
||||||
|
|
||||||
if (dot(lightDirection, normal) <= 0.0) {
|
//gl_FragColor = vec4((IAmbient + IDiffuse) + ISpecular, 1.0);
|
||||||
ISpecular = vec3(0.0, 0.0, 0.0);
|
gl_FragColor = vec4((IAmbient + IDiffuse), 1.0);
|
||||||
}
|
|
||||||
|
|
||||||
// p: point of the fragment on the surface
|
|
||||||
//vec3 v_eye = normalize(pos_eye - pos_space); // point from p to eye
|
|
||||||
//vec3 v_sun = normalize(sun_light_dir); // points from p to the sun
|
|
||||||
|
|
||||||
//float specular = spec_int * pow(
|
|
||||||
// clamp(dot((v_eye + v_sun)/2.0, normal), 0.0, 1.0),
|
|
||||||
// 2.0*specular_exponent);
|
|
||||||
|
|
||||||
//ISpecular = vec3(1.0, 0.0, 0.0) * specular;
|
|
||||||
|
|
||||||
//gl_FragColor = vec4(ISpecular, 1.0);
|
|
||||||
gl_FragColor = vec4((IAmbient + IDiffuse) + ISpecular, 1.0);
|
|
||||||
//gl_FragColor = vec4(0.5+0.5*normal, 1.0);
|
|
||||||
}
|
}
|
|
@ -10,6 +10,8 @@
|
||||||
#include "network/server.hpp"
|
#include "network/server.hpp"
|
||||||
#include "options.hpp"
|
#include "options.hpp"
|
||||||
|
|
||||||
|
#include <sys/time.h>
|
||||||
|
|
||||||
uint64_t optionsFlags;
|
uint64_t optionsFlags;
|
||||||
|
|
||||||
using asio::ip::tcp;
|
using asio::ip::tcp;
|
||||||
|
@ -71,6 +73,8 @@ int main(int argc, char *argv[])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
srand(time(NULL));
|
||||||
|
|
||||||
Game game;
|
Game game;
|
||||||
game.state()->setDeveloperMode(devMode);
|
game.state()->setDeveloperMode(devMode);
|
||||||
|
|
||||||
|
@ -78,7 +82,7 @@ int main(int argc, char *argv[])
|
||||||
Server s(io_service, game.state(), atoi(port) );
|
Server s(io_service, game.state(), atoi(port) );
|
||||||
|
|
||||||
//GameWindow window(500, 500, &game);
|
//GameWindow window(500, 500, &game);
|
||||||
GameWindow window(750, 750, &game);
|
GameWindow window(500, 500, &game);
|
||||||
window.set_maxfps(60.0);
|
window.set_maxfps(60.0);
|
||||||
window.open();
|
window.open();
|
||||||
|
|
||||||
|
|
|
@ -171,7 +171,8 @@ namespace endofthejedi {
|
||||||
|
|
||||||
glm::vec3 c = planet->getColor();
|
glm::vec3 c = planet->getColor();
|
||||||
glUniform3f(m_shader.location("materialColor"), c.x, c.y, c.z);
|
glUniform3f(m_shader.location("materialColor"), c.x, c.y, c.z);
|
||||||
glUniform1f(m_shader.location("materialKind"), (float) planet->material);
|
glUniform1i(m_shader.location("materialSeed"), planet->seed);
|
||||||
|
glUniform1i(m_shader.location("materialKind"), (int) planet->material);
|
||||||
|
|
||||||
m_planetModel->render();
|
m_planetModel->render();
|
||||||
}
|
}
|
||||||
|
@ -294,16 +295,22 @@ namespace endofthejedi {
|
||||||
|
|
||||||
void RendererPolygon3d::configureLightningInShader()
|
void RendererPolygon3d::configureLightningInShader()
|
||||||
{
|
{
|
||||||
glm::vec3 c = glm::vec3(1.0, 1.0, 0.8);
|
// TODO: add a few small lights for explosions so they lit the
|
||||||
glUniform3f(m_shader.location("lightColor"), c.x, c.y, c.z);
|
// surroundsings
|
||||||
|
|
||||||
|
// TODO: use the sun planet color for this!
|
||||||
|
glm::vec3 c = glm::vec3(1.0, 1.0, 0.8);
|
||||||
glm::vec3 p = glm::vec3(0.3f, 0.4f, 0.0f);
|
glm::vec3 p = glm::vec3(0.3f, 0.4f, 0.0f);
|
||||||
|
|
||||||
for (const game::Planet *planet : m_state->planets) {
|
for (const game::Planet *planet : m_state->planets) {
|
||||||
if (planet->material == game::Planet::Material::Sun) {
|
if (planet->material == game::Planet::Material::Sun) {
|
||||||
p = glm::vec3(planet->position, 0.0);
|
p = glm::vec3(planet->position, 0.0);
|
||||||
|
c = planet->getColor();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
glUniform3f(m_shader.location("lightPosition"), p.x, p.y, p.z);
|
glUniform3f(m_shader.location("lightPosition"), p.x, p.y, p.z);
|
||||||
|
glUniform3f(m_shader.location("lightColor"), c.x, c.y, c.z);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,7 +19,7 @@
|
||||||
#include "util.hpp"
|
#include "util.hpp"
|
||||||
|
|
||||||
namespace game {
|
namespace game {
|
||||||
void State::init(bool devMode)
|
void State::init(int numPlanets, bool devMode)
|
||||||
{
|
{
|
||||||
m_nextId = 0;
|
m_nextId = 0;
|
||||||
m_time = 0.0;
|
m_time = 0.0;
|
||||||
|
@ -30,31 +30,72 @@ namespace game {
|
||||||
m_maxNumTraces = 10;
|
m_maxNumTraces = 10;
|
||||||
m_developerMode = devMode;
|
m_developerMode = devMode;
|
||||||
|
|
||||||
bool planetsOnCircle = false;
|
|
||||||
|
|
||||||
int numPlanets = 10;
|
|
||||||
for (int i=0; i<numPlanets; i++) {
|
|
||||||
float t = i / static_cast<float>(numPlanets);
|
|
||||||
t *= 2.0*M_PI;
|
|
||||||
|
|
||||||
// distribute but not in the center
|
|
||||||
int tries = 0;
|
|
||||||
glm::vec2 pos;
|
|
||||||
do {
|
|
||||||
float cr = 0.7;
|
|
||||||
if (planetsOnCircle) {
|
|
||||||
pos = cr * glm::vec2(std::sin(t), std::cos(t));
|
|
||||||
} else {
|
|
||||||
pos = cr * util::randv2_m1_1();
|
|
||||||
}
|
|
||||||
} while(glm::length(pos) < 0.2 && tries++ < 1000);
|
|
||||||
|
|
||||||
Planet::Material mat = Planet::Material::Rock;
|
Planet::Material mat = Planet::Material::Rock;
|
||||||
if (i == 0) {
|
|
||||||
|
for (int i=0; i<numPlanets; i++) {
|
||||||
|
switch(i) {
|
||||||
|
case 0:
|
||||||
mat = Planet::Material::Sun;
|
mat = Planet::Material::Sun;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 1:
|
||||||
|
case 2:
|
||||||
|
mat = Planet::Material::Water;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 3:
|
||||||
|
case 4:
|
||||||
|
mat = Planet::Material::Sand;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 5:
|
||||||
|
mat = Planet::Material::Metal;
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
mat = Planet::Material::Rock;
|
||||||
}
|
}
|
||||||
|
|
||||||
planets.push_back(new Planet(pos, i, 0.03 + 0.07*util::randf_0_1(), mat));
|
glm::vec2 pos;
|
||||||
|
float radius = 0.03 + 0.07*util::randf_0_1();
|
||||||
|
if (i == 0) {
|
||||||
|
// sun is bigger but not too big
|
||||||
|
radius += 0.05;
|
||||||
|
if (radius > 0.9) {
|
||||||
|
radius = 0.9;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
bool tooNearToCenter = true;
|
||||||
|
bool collidesWithOtherPlanet = true;
|
||||||
|
|
||||||
|
// distribute but not in the center and not next to other planets
|
||||||
|
int tries = 0;
|
||||||
|
do {
|
||||||
|
pos = util::randv2_m1_1();
|
||||||
|
|
||||||
|
collidesWithOtherPlanet = false;
|
||||||
|
tooNearToCenter = glm::length(pos) < 0.1;
|
||||||
|
|
||||||
|
if (!tooNearToCenter) {
|
||||||
|
for (const Planet *other : planets) {
|
||||||
|
float d = glm::distance(other->position, pos);
|
||||||
|
|
||||||
|
float extraDist = (other->material == Planet::Material::Sun)
|
||||||
|
? 4.0
|
||||||
|
: 1.0;
|
||||||
|
|
||||||
|
if (d < extraDist*other->radius + radius) {
|
||||||
|
collidesWithOtherPlanet = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} while((collidesWithOtherPlanet || tooNearToCenter) && tries++ < 1000);
|
||||||
|
|
||||||
|
planets.push_back(new Planet(pos, i, radius, mat));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -40,7 +40,7 @@ namespace game {
|
||||||
|
|
||||||
// called to setup the state (randomize planets, kill
|
// called to setup the state (randomize planets, kill
|
||||||
// traces/missiles/ships etc.)
|
// traces/missiles/ships etc.)
|
||||||
void init(bool devMode=false);
|
void init(int numPlanets=15, bool devMode=false);
|
||||||
|
|
||||||
// main method to advance the simulation by the given timestamp in
|
// main method to advance the simulation by the given timestamp in
|
||||||
// seconds.
|
// seconds.
|
||||||
|
|
Loading…
Reference in a new issue