made PlatExplorer work in a first version with editor, but currently there are still a lot of crash probalities
This commit is contained in:
4
.vscode/c_cpp_properties.json
vendored
4
.vscode/c_cpp_properties.json
vendored
@@ -3,8 +3,8 @@
|
|||||||
{
|
{
|
||||||
"name": "Linux",
|
"name": "Linux",
|
||||||
"includePath": [
|
"includePath": [
|
||||||
"${workspaceFolder}/DemoProject/include",
|
"${workspaceFolder}/PlanetExplorerGameDemo/include",
|
||||||
"${workspaceFolder}/DemoProject/src",
|
"${workspaceFolder}/PlanetExplorerGameDemo/src",
|
||||||
"${workspaceFolder}/TSE/TSE_Base/include",
|
"${workspaceFolder}/TSE/TSE_Base/include",
|
||||||
"${workspaceFolder}/TSE/TSE_Base/src",
|
"${workspaceFolder}/TSE/TSE_Base/src",
|
||||||
"${workspaceFolder}/TSE/TSE_Core/include",
|
"${workspaceFolder}/TSE/TSE_Core/include",
|
||||||
|
|||||||
848
PlanetExplorerGameDemo/Resources/shaders/planetShader.frag
Normal file
848
PlanetExplorerGameDemo/Resources/shaders/planetShader.frag
Normal file
@@ -0,0 +1,848 @@
|
|||||||
|
#version 330 core
|
||||||
|
|
||||||
|
layout (location = 0) out vec4 color;
|
||||||
|
|
||||||
|
uniform vec2 light_origin;
|
||||||
|
uniform float timeSpeed;
|
||||||
|
uniform float ditherSize;
|
||||||
|
uniform float light_border_1;
|
||||||
|
uniform float light_border_2;
|
||||||
|
uniform float size;
|
||||||
|
uniform int octaves;
|
||||||
|
uniform float time;
|
||||||
|
uniform int should_dither;
|
||||||
|
|
||||||
|
in DATA
|
||||||
|
{
|
||||||
|
vec4 color1;
|
||||||
|
vec4 color2;
|
||||||
|
vec4 color3;
|
||||||
|
vec2 uv;
|
||||||
|
float seed;
|
||||||
|
float pixels;
|
||||||
|
float rotation;
|
||||||
|
float layer;
|
||||||
|
vec4 userValues1;
|
||||||
|
vec4 userValues2;
|
||||||
|
vec4 userValues3;
|
||||||
|
} data;
|
||||||
|
|
||||||
|
float rand(vec2 coord) {
|
||||||
|
// land has to be tiled
|
||||||
|
// tiling only works for integer values, thus the rounding
|
||||||
|
// it would probably be better to only allow integer sizes
|
||||||
|
// multiply by vec2(2,1) to simulate planet having another side
|
||||||
|
coord = mod(coord, vec2(2.0,1.0)*round(size));
|
||||||
|
return fract(sin(dot(coord.xy ,vec2(12.9898,78.233))) * 15.5453 * data.seed);
|
||||||
|
}
|
||||||
|
float rand2(vec2 coord) {
|
||||||
|
coord = mod(coord, vec2(1.0,1.0)*round(size));
|
||||||
|
return fract(sin(dot(coord.xy ,vec2(12.9898,78.233))) * 15.5453 * data.seed);
|
||||||
|
}
|
||||||
|
float rand3(vec2 coord) {
|
||||||
|
return fract(sin(dot(coord.xy ,vec2(12.9898,78.233))) * 15.5453 * data.seed);
|
||||||
|
}
|
||||||
|
|
||||||
|
float noise(vec2 coord){
|
||||||
|
vec2 i = floor(coord);
|
||||||
|
vec2 f = fract(coord);
|
||||||
|
|
||||||
|
float a = rand(i);
|
||||||
|
float b = rand(i + vec2(1.0, 0.0));
|
||||||
|
float c = rand(i + vec2(0.0, 1.0));
|
||||||
|
float d = rand(i + vec2(1.0, 1.0));
|
||||||
|
|
||||||
|
vec2 cubic = f * f * (3.0 - 2.0 * f);
|
||||||
|
|
||||||
|
return mix(a, b, cubic.x) + (c - a) * cubic.y * (1.0 - cubic.x) + (d - b) * cubic.x * cubic.y;
|
||||||
|
}
|
||||||
|
float noise2(vec2 coord){
|
||||||
|
vec2 i = floor(coord);
|
||||||
|
vec2 f = fract(coord);
|
||||||
|
|
||||||
|
float a = rand2(i);
|
||||||
|
float b = rand2(i + vec2(1.0, 0.0));
|
||||||
|
float c = rand2(i + vec2(0.0, 1.0));
|
||||||
|
float d = rand2(i + vec2(1.0, 1.0));
|
||||||
|
|
||||||
|
vec2 cubic = f * f * (3.0 - 2.0 * f);
|
||||||
|
|
||||||
|
return mix(a, b, cubic.x) + (c - a) * cubic.y * (1.0 - cubic.x) + (d - b) * cubic.x * cubic.y;
|
||||||
|
}
|
||||||
|
float noise3(vec2 coord){
|
||||||
|
vec2 i = floor(coord);
|
||||||
|
vec2 f = fract(coord);
|
||||||
|
|
||||||
|
float a = rand3(i);
|
||||||
|
float b = rand3(i + vec2(1.0, 0.0));
|
||||||
|
float c = rand3(i + vec2(0.0, 1.0));
|
||||||
|
float d = rand3(i + vec2(1.0, 1.0));
|
||||||
|
|
||||||
|
vec2 cubic = f * f * (3.0 - 2.0 * f);
|
||||||
|
|
||||||
|
return mix(a, b, cubic.x) + (c - a) * cubic.y * (1.0 - cubic.x) + (d - b) * cubic.x * cubic.y;
|
||||||
|
}
|
||||||
|
|
||||||
|
float fbm(vec2 coord){
|
||||||
|
float value = 0.0;
|
||||||
|
float scale = 0.5;
|
||||||
|
|
||||||
|
for(int i = 0; i < octaves ; i++){
|
||||||
|
value += noise(coord) * scale;
|
||||||
|
coord *= 2.0;
|
||||||
|
scale *= 0.5;
|
||||||
|
}
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
float fbm2(vec2 coord){
|
||||||
|
float value = 0.0;
|
||||||
|
float scale = 0.5;
|
||||||
|
|
||||||
|
for(int i = 0; i < octaves ; i++){
|
||||||
|
value += noise2(coord) * scale;
|
||||||
|
coord *= 2.0;
|
||||||
|
scale *= 0.5;
|
||||||
|
}
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
float fbm3(vec2 coord){
|
||||||
|
float value = 0.0;
|
||||||
|
float scale = 0.5;
|
||||||
|
|
||||||
|
for(int i = 0; i < octaves ; i++){
|
||||||
|
value += noise3(coord) * scale;
|
||||||
|
coord *= 2.0;
|
||||||
|
scale *= 0.5;
|
||||||
|
}
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
vec2 Hash2(vec2 p) {
|
||||||
|
float r = 523.0*sin(dot(p, vec2(53.3158, 43.6143)));
|
||||||
|
return vec2(fract(15.32354 * r), fract(17.25865 * r));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
bool dither(vec2 uv1, vec2 uv2) {
|
||||||
|
return mod(uv1.x+uv2.y,2.0/data.pixels) <= 1.0 / data.pixels;
|
||||||
|
}
|
||||||
|
|
||||||
|
vec2 rotate(vec2 coord, float angle){
|
||||||
|
coord -= 0.5;
|
||||||
|
coord *= mat2(vec2(cos(angle),-sin(angle)),vec2(sin(angle),cos(angle)));
|
||||||
|
return coord + 0.5;
|
||||||
|
}
|
||||||
|
|
||||||
|
vec2 spherify(vec2 uv) {
|
||||||
|
vec2 centered= uv *2.0-1.0;
|
||||||
|
float z = sqrt(1.0 - dot(centered.xy, centered.xy));
|
||||||
|
vec2 sphere = centered/(z + 1.0);
|
||||||
|
return sphere * 0.5+0.5;
|
||||||
|
}
|
||||||
|
|
||||||
|
float circleNoise(vec2 uv) {
|
||||||
|
float uv_y = floor(uv.y);
|
||||||
|
uv.x += uv_y*.31;
|
||||||
|
vec2 f = fract(uv);
|
||||||
|
float h = rand2(vec2(floor(uv.x),floor(uv_y)));
|
||||||
|
float m = (length(f-0.25-(h*0.5)));
|
||||||
|
float r = h*0.25;
|
||||||
|
return smoothstep(0.0, r, m*0.75);
|
||||||
|
}
|
||||||
|
float circleNoise2(vec2 uv) {
|
||||||
|
float uv_y = floor(uv.y);
|
||||||
|
uv.x += uv_y*.31;
|
||||||
|
vec2 f = fract(uv);
|
||||||
|
float h = rand3(vec2(floor(uv.x),floor(uv_y)));
|
||||||
|
float m = (length(f-0.25-(h*0.5)));
|
||||||
|
float r = h*0.25;
|
||||||
|
return smoothstep(r-.10*r,r,m);
|
||||||
|
}
|
||||||
|
float circleNoise3(vec2 uv) {
|
||||||
|
float uv_y = floor(uv.y);
|
||||||
|
uv.x += uv_y*.31;
|
||||||
|
vec2 f = fract(uv);
|
||||||
|
float h = rand2(vec2(floor(uv.x),floor(uv_y)));
|
||||||
|
float m = (length(f-0.25-(h*0.5)));
|
||||||
|
float r = h*0.25;
|
||||||
|
return smoothstep(r-.10*r,r,m);
|
||||||
|
}
|
||||||
|
|
||||||
|
float Cells(in vec2 p, in float numCells) {
|
||||||
|
p *= numCells;
|
||||||
|
float d = 1.0e10;
|
||||||
|
for (int xo = -1; xo <= 1; xo++)
|
||||||
|
{
|
||||||
|
for (int yo = -1; yo <= 1; yo++)
|
||||||
|
{
|
||||||
|
vec2 tp = floor(p) + vec2(float(xo), float(yo));
|
||||||
|
tp = p - tp - Hash2(mod(tp, numCells / octaves));
|
||||||
|
d = min(d, dot(tp, tp));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return sqrt(d);
|
||||||
|
}
|
||||||
|
|
||||||
|
float cloud_alpha(vec2 uv) {
|
||||||
|
float c_noise = 0.0;
|
||||||
|
|
||||||
|
// more iterations for more turbulence
|
||||||
|
for (int i = 0; i < 9; i++) {
|
||||||
|
c_noise += circleNoise((uv * size * 0.3) + (float(i+1)+10.) + (vec2(time*timeSpeed, 0.0)));
|
||||||
|
}
|
||||||
|
float fbm = fbm2(uv*size+c_noise + vec2(time*timeSpeed, 0.0));
|
||||||
|
|
||||||
|
return fbm;//step(a_cutoff, fbm);
|
||||||
|
}
|
||||||
|
|
||||||
|
float crater(vec2 uv) {
|
||||||
|
float c = 1.0;
|
||||||
|
for (int i = 0; i < 2; i++) {
|
||||||
|
c *= circleNoise2((uv * size) + (float(i+1)+10.));
|
||||||
|
}
|
||||||
|
return 1.0 - c;
|
||||||
|
}
|
||||||
|
float crater2(vec2 uv)
|
||||||
|
{
|
||||||
|
float c = 1.0;
|
||||||
|
for (int i = 0; i < 2; i++) {
|
||||||
|
c *= circleNoise3((uv * size) + (float(i+1)+10.) + vec2(time*timeSpeed,0.0));
|
||||||
|
}
|
||||||
|
return 1.0 - c;
|
||||||
|
}
|
||||||
|
|
||||||
|
float circle(vec2 uv) {
|
||||||
|
float invert = 1.0 / data.userValues1.x;
|
||||||
|
|
||||||
|
if (mod(uv.y, invert*2.0) < invert) {
|
||||||
|
uv.x += invert*0.5;
|
||||||
|
}
|
||||||
|
vec2 rand_co = floor(uv*data.userValues1.x)/data.userValues1.x;
|
||||||
|
uv = mod(uv, invert)*data.userValues1.x;
|
||||||
|
|
||||||
|
float r = rand2(rand_co);
|
||||||
|
r = clamp(r, invert, 1.0 - invert);
|
||||||
|
float circle = distance(uv, vec2(r));
|
||||||
|
return smoothstep(circle, circle+0.5, invert * data.userValues1.y * rand2(rand_co*1.5));
|
||||||
|
}
|
||||||
|
|
||||||
|
void Asteroid()
|
||||||
|
{
|
||||||
|
vec2 uv = floor(data.uv * data.pixels) / data.pixels;
|
||||||
|
|
||||||
|
bool dith = dither(uv, data.uv);
|
||||||
|
float d = distance(uv, vec2(0.5));
|
||||||
|
|
||||||
|
uv = rotate(uv, data.rotation);
|
||||||
|
|
||||||
|
float n = fbm3(uv * size);
|
||||||
|
float n2 = fbm3(uv * size + (rotate(light_origin, data.rotation)-0.5) * 0.5);
|
||||||
|
|
||||||
|
float n_step = step(0.2, n - d);
|
||||||
|
float n2_step = step(0.2, n2 - d);
|
||||||
|
|
||||||
|
float noise_rel = (n2_step + n2) - (n_step + n);
|
||||||
|
|
||||||
|
float c1 = crater(uv );
|
||||||
|
float c2 = crater(uv + (light_origin-0.5)*0.03);
|
||||||
|
|
||||||
|
vec4 col = data.color2;
|
||||||
|
|
||||||
|
bool do_dither = should_dither == 1;
|
||||||
|
|
||||||
|
if (noise_rel < -0.06 || (noise_rel < -0.04 && (dith || !do_dither))) {
|
||||||
|
col = data.color1;
|
||||||
|
}
|
||||||
|
if (noise_rel > 0.05 || (noise_rel > 0.03 && (dith || !do_dither))) {
|
||||||
|
col = data.color3;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (c1 > 0.4) {
|
||||||
|
col = data.color2;
|
||||||
|
}
|
||||||
|
if (c2<c1) {
|
||||||
|
col = data.color3;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(n_step < 0.1)
|
||||||
|
{
|
||||||
|
discard;
|
||||||
|
}
|
||||||
|
color = vec4(col.rgb, n_step * col.a);
|
||||||
|
}
|
||||||
|
void LandMassesPlanetUnder()
|
||||||
|
{
|
||||||
|
vec2 uv = floor(data.uv * data.pixels) / data.pixels;
|
||||||
|
|
||||||
|
bool dith = dither(uv, data.uv);
|
||||||
|
|
||||||
|
float d_light = distance(uv, vec2(light_origin));
|
||||||
|
float d_circle = distance(uv, vec2(0.5));
|
||||||
|
float a = step(d_circle, 0.49999);
|
||||||
|
|
||||||
|
uv = spherify(uv);
|
||||||
|
uv = rotate(uv, data.rotation);
|
||||||
|
|
||||||
|
d_light += fbm(uv*size+vec2(time*timeSpeed, 0.0))*0.3;
|
||||||
|
|
||||||
|
float dither_border = (1.0/data.pixels)*ditherSize;
|
||||||
|
|
||||||
|
bool do_dither = should_dither == 1;
|
||||||
|
|
||||||
|
vec4 col = data.color1;
|
||||||
|
if (d_light > light_border_1) {
|
||||||
|
col = data.color2;
|
||||||
|
if (d_light < light_border_1 + dither_border && (dith || !do_dither)) {
|
||||||
|
col = data.color1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (d_light > light_border_2) {
|
||||||
|
col = data.color3;
|
||||||
|
if (d_light < light_border_2 + dither_border && (dith || !do_dither)) {
|
||||||
|
col = data.color2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(a < 0.1)
|
||||||
|
{
|
||||||
|
discard;
|
||||||
|
}
|
||||||
|
color = vec4(col.rgb, a * col.a);
|
||||||
|
//color = vec4(1,0,0,1);
|
||||||
|
}
|
||||||
|
void LandMassesPlanetLandMasses()
|
||||||
|
{
|
||||||
|
float land_cutoff = data.userValues1.x;
|
||||||
|
vec4 color4 = data.userValues2;
|
||||||
|
|
||||||
|
vec2 uv = floor(data.uv * data.pixels) / data.pixels;
|
||||||
|
float d_light = distance(uv , light_origin);
|
||||||
|
float d_circle = distance(uv, vec2(0.5));
|
||||||
|
float a = step(d_circle, 0.49999);
|
||||||
|
|
||||||
|
uv = rotate(uv, data.rotation);
|
||||||
|
uv = spherify(uv);
|
||||||
|
|
||||||
|
vec2 base_fbm_uv = (uv)*size+vec2(time*timeSpeed,0.0);
|
||||||
|
float fbm1 = fbm(base_fbm_uv);
|
||||||
|
float fbm2 = fbm(base_fbm_uv - light_origin*fbm1);
|
||||||
|
float fbm3 = fbm(base_fbm_uv - light_origin*1.5*fbm1);
|
||||||
|
float fbm4 = fbm(base_fbm_uv - light_origin*2.0*fbm1);
|
||||||
|
|
||||||
|
if (d_light < light_border_1) {
|
||||||
|
fbm4 *= 0.9;
|
||||||
|
}
|
||||||
|
if (d_light > light_border_1) {
|
||||||
|
fbm2 *= 1.05;
|
||||||
|
fbm3 *= 1.05;
|
||||||
|
fbm4 *= 1.05;
|
||||||
|
}
|
||||||
|
if (d_light > light_border_2) {
|
||||||
|
fbm2 *= 1.3;
|
||||||
|
fbm3 *= 1.4;
|
||||||
|
fbm4 *= 1.8;
|
||||||
|
}
|
||||||
|
d_light = pow(d_light, 2.0)*0.1;
|
||||||
|
|
||||||
|
vec4 col = color4;
|
||||||
|
|
||||||
|
if (fbm4 + d_light < fbm1) {
|
||||||
|
col = data.color3;
|
||||||
|
}
|
||||||
|
if (fbm3 + d_light < fbm1) {
|
||||||
|
col = data.color2;
|
||||||
|
}
|
||||||
|
if (fbm2 + d_light < fbm1) {
|
||||||
|
col = data.color1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(step(land_cutoff, fbm1) * a < 0.1)
|
||||||
|
{
|
||||||
|
discard;
|
||||||
|
}
|
||||||
|
color = vec4(col.rgb, step(land_cutoff, fbm1) * a * col.a);
|
||||||
|
}
|
||||||
|
void LandMassesClouds()
|
||||||
|
{
|
||||||
|
float cloud_cover = data.userValues1.x;
|
||||||
|
float stretch = data.userValues1.y;
|
||||||
|
float cloud_curve = data.userValues1.z;
|
||||||
|
vec4 color4 = data.userValues2;
|
||||||
|
|
||||||
|
vec2 uv = floor(data.uv * data.pixels) / data.pixels;
|
||||||
|
float d_light = distance(uv , light_origin);
|
||||||
|
float d_to_center = distance(uv, vec2(0.5));
|
||||||
|
float a = step(length(uv-vec2(0.5)), 0.49999);
|
||||||
|
|
||||||
|
uv = rotate(uv, data.rotation);
|
||||||
|
uv = spherify(uv);
|
||||||
|
|
||||||
|
uv.y += smoothstep(0.0, cloud_curve, abs(uv.x-0.4));
|
||||||
|
|
||||||
|
float c = cloud_alpha(uv*vec2(1.0, stretch));
|
||||||
|
vec4 col = data.color1;
|
||||||
|
if (c < cloud_cover + 0.03) {
|
||||||
|
col = data.color2;
|
||||||
|
}
|
||||||
|
if (d_light + c*0.2 > light_border_1) {
|
||||||
|
col = data.color3;
|
||||||
|
|
||||||
|
}
|
||||||
|
if (d_light + c*0.2 > light_border_2) {
|
||||||
|
col = color4;
|
||||||
|
}
|
||||||
|
c *= step(d_to_center, 0.5);
|
||||||
|
if(step(cloud_cover, c) * a < 0.1)
|
||||||
|
{
|
||||||
|
discard;
|
||||||
|
}
|
||||||
|
color = vec4(col.rgb, step(cloud_cover, c) * a * col.a);
|
||||||
|
}
|
||||||
|
void BlackHole()
|
||||||
|
{
|
||||||
|
float radius = data.userValues1.x;
|
||||||
|
float light_width = data.userValues1.y;
|
||||||
|
|
||||||
|
vec2 uv = floor(data.uv * data.pixels) / data.pixels;
|
||||||
|
|
||||||
|
float d_to_center = distance(uv, vec2(0.5));
|
||||||
|
|
||||||
|
vec4 col = data.color1;
|
||||||
|
if (d_to_center > radius - light_width) {
|
||||||
|
col = data.color2;
|
||||||
|
}
|
||||||
|
if (d_to_center > radius - light_width * 0.5) {
|
||||||
|
col = data.color3;
|
||||||
|
}
|
||||||
|
|
||||||
|
float a = step(d_to_center, radius);
|
||||||
|
if(a < 0.1)
|
||||||
|
{
|
||||||
|
discard;
|
||||||
|
}
|
||||||
|
color = vec4(col.rgb, a * col.a);
|
||||||
|
}
|
||||||
|
void BlackHoleRing()
|
||||||
|
{
|
||||||
|
vec4 color4 = data.userValues2;
|
||||||
|
vec4 color5 = data.userValues3;
|
||||||
|
float disk_width = data.userValues1.x;
|
||||||
|
float ring_perspective = data.userValues1.y;
|
||||||
|
|
||||||
|
vec2 uv = floor(data.uv * data.pixels) / data.pixels;
|
||||||
|
|
||||||
|
bool dith = dither(data.uv, uv);
|
||||||
|
|
||||||
|
uv = rotate(uv, data.rotation);
|
||||||
|
|
||||||
|
vec2 uv2 = uv;
|
||||||
|
|
||||||
|
uv.x -= 0.5;
|
||||||
|
uv.x *= 1.3;
|
||||||
|
uv.x += 0.5;
|
||||||
|
|
||||||
|
uv = rotate(uv, sin(time * timeSpeed * 2.0) * 0.01);
|
||||||
|
vec2 l_origin = vec2(0.5);
|
||||||
|
float d_width = disk_width;
|
||||||
|
if (uv.y < 0.5) {
|
||||||
|
// if we are in the top half of the image, then add to the uv.y based on how close we are to the center
|
||||||
|
uv.y += smoothstep(distance(vec2(0.5), uv), 0.5, 0.2);
|
||||||
|
// and also the ring width has to be adjusted or it will look to stretched out
|
||||||
|
d_width += smoothstep(distance(vec2(0.5), uv), 0.5, 0.3);
|
||||||
|
|
||||||
|
// another optional thing that changes the color distribution, I like it, but can be disabled.
|
||||||
|
l_origin.y -= smoothstep(distance(vec2(0.5), uv), 0.5, 0.2);
|
||||||
|
}
|
||||||
|
else if (uv.y > 0.53) {
|
||||||
|
|
||||||
|
// same steps as before, but uv.y and light is stretched the other way, the disk width is slightly smaller here for visual effect.
|
||||||
|
uv.y -= smoothstep(distance(vec2(0.5), uv), 0.4, 0.17);
|
||||||
|
d_width += smoothstep(distance(vec2(0.5), uv), 0.5, 0.2);
|
||||||
|
l_origin.y += smoothstep(distance(vec2(0.5), uv), 0.5, 0.2);
|
||||||
|
}
|
||||||
|
float light_d = distance(uv2 * vec2(1.0, ring_perspective), l_origin * vec2(1.0, ring_perspective)) * 0.3;
|
||||||
|
|
||||||
|
vec2 uv_center = uv - vec2(0.0, 0.5);
|
||||||
|
|
||||||
|
uv_center *= vec2(1.0, ring_perspective);
|
||||||
|
float center_d = distance(uv_center,vec2(0.5, 0.0));
|
||||||
|
|
||||||
|
float disk = smoothstep(0.1-d_width*2.0, 0.5-d_width, center_d);
|
||||||
|
disk *= smoothstep(center_d-d_width, center_d, 0.4);
|
||||||
|
|
||||||
|
uv_center = rotate(uv_center+vec2(0, 0.5), time*timeSpeed*3.0);
|
||||||
|
|
||||||
|
disk *= pow(fbm(uv_center*size), 0.5);
|
||||||
|
|
||||||
|
bool do_dither = should_dither == 1;
|
||||||
|
|
||||||
|
if (dith || !do_dither) {
|
||||||
|
disk *= 1.2;
|
||||||
|
}
|
||||||
|
|
||||||
|
float n_posterized = float(5 - 1);
|
||||||
|
float posterized = floor((disk+light_d)*n_posterized);
|
||||||
|
posterized = min(posterized, n_posterized);
|
||||||
|
vec4 col = data.color1;
|
||||||
|
int indexColor = int(posterized);
|
||||||
|
switch(indexColor)
|
||||||
|
{
|
||||||
|
case 1:
|
||||||
|
col = data.color2;
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
col = data.color3;
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
col = color4;
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
col = color5;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
float disk_a = step(0.15, disk);
|
||||||
|
if(disk_a < 0.1)
|
||||||
|
{
|
||||||
|
discard;
|
||||||
|
}
|
||||||
|
color = vec4(col.rgb, disk_a * col.a);
|
||||||
|
}
|
||||||
|
void Galaxy()
|
||||||
|
{
|
||||||
|
vec4 color4 = data.userValues2;
|
||||||
|
vec4 color5 = data.userValues3;
|
||||||
|
float tilt = data.userValues1.x;
|
||||||
|
float n_layers = 4.0;
|
||||||
|
float layer_height = data.userValues1.y;
|
||||||
|
float zoom = data.userValues1.z;
|
||||||
|
float swirl = data.userValues1.w;
|
||||||
|
|
||||||
|
vec2 uv = floor(data.uv * data.pixels) / data.pixels;
|
||||||
|
|
||||||
|
bool dith = dither(data.uv, uv);
|
||||||
|
|
||||||
|
uv *= zoom;
|
||||||
|
uv -= (zoom - 1.0) / 2.0;
|
||||||
|
|
||||||
|
uv = rotate(uv, data.rotation);
|
||||||
|
vec2 uv2 = uv;
|
||||||
|
uv.y *= tilt;
|
||||||
|
uv.y -= (tilt - 1.0) / 2.0;
|
||||||
|
|
||||||
|
float d_to_center = distance(uv, vec2(0.5, 0.5));
|
||||||
|
|
||||||
|
float rot = swirl * pow(d_to_center, 0.4);
|
||||||
|
vec2 rotated_uv = rotate(uv, rot + time * timeSpeed);
|
||||||
|
|
||||||
|
float f1 = fbm3(rotated_uv * size);
|
||||||
|
f1 = floor(f1 * n_layers) / n_layers;
|
||||||
|
|
||||||
|
uv2.y *= tilt;
|
||||||
|
uv2.y -= (tilt - 1.0) / 2.0 + f1 * layer_height;
|
||||||
|
|
||||||
|
float d_to_center2 = distance(uv2, vec2(0.5, 0.5));
|
||||||
|
float rot2 = swirl * pow(d_to_center2, 0.4);
|
||||||
|
vec2 rotated_uv2 = rotate(uv2, rot2 + time * timeSpeed);
|
||||||
|
|
||||||
|
float f2 = fbm3(rotated_uv2 * size + vec2(f1) * 10.0);
|
||||||
|
float a = step(f2 + d_to_center2, 0.7);
|
||||||
|
|
||||||
|
f2 *= 2.3;
|
||||||
|
|
||||||
|
bool do_dither = should_dither == 1;
|
||||||
|
|
||||||
|
if(do_dither && dith) {
|
||||||
|
f2 *= 0.94;
|
||||||
|
}
|
||||||
|
|
||||||
|
f2 = floor(f2 * (float(5)));
|
||||||
|
f2 = min(f2, float(5));
|
||||||
|
int colorIndex = int(f2);
|
||||||
|
vec4 col = data.color1;
|
||||||
|
switch(colorIndex)
|
||||||
|
{
|
||||||
|
case 1:
|
||||||
|
col = data.color2;
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
col = data.color3;
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
col = color4;
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
col = color5;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(a < 0.1)
|
||||||
|
{
|
||||||
|
discard;
|
||||||
|
}
|
||||||
|
color = vec4(col.rgb, a * col.a);
|
||||||
|
}
|
||||||
|
void StarBase()
|
||||||
|
{
|
||||||
|
vec4 color4 = data.userValues2;
|
||||||
|
|
||||||
|
vec2 uv = floor(data.uv * data.pixels) / data.pixels;
|
||||||
|
float a = step(distance(uv, vec2(0.5)), .49999);
|
||||||
|
bool dith = dither(data.uv, uv);
|
||||||
|
|
||||||
|
uv = rotate(uv, data.rotation);
|
||||||
|
uv = spherify(uv);
|
||||||
|
|
||||||
|
float slowTime = timeSpeed * 0.2f;
|
||||||
|
|
||||||
|
float n = Cells(uv - vec2(time * slowTime * 2.0, 0), 10);
|
||||||
|
n *= Cells(uv - vec2(time * slowTime * 1.0, 0), 20);
|
||||||
|
|
||||||
|
n*= 2.;
|
||||||
|
n = clamp(n, 0.0, 1.0);
|
||||||
|
|
||||||
|
bool do_dither = should_dither == 1;
|
||||||
|
|
||||||
|
if (dith || !do_dither) {
|
||||||
|
n *= 1.3;
|
||||||
|
}
|
||||||
|
float interpolate = floor(n * float(4 - 1)) / float(4 - 1);
|
||||||
|
int index = int(interpolate * float(4-1));
|
||||||
|
|
||||||
|
vec4 col = data.color1;
|
||||||
|
switch(index)
|
||||||
|
{
|
||||||
|
case 1:
|
||||||
|
col = data.color2;
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
col = data.color3;
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
col = color4;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(a < 0.1)
|
||||||
|
{
|
||||||
|
discard;
|
||||||
|
}
|
||||||
|
color = vec4(col.rgb, a * col.a);
|
||||||
|
}
|
||||||
|
void StarBlobs()
|
||||||
|
{
|
||||||
|
vec2 pixelized = floor(data.uv * data.pixels) / data.pixels;
|
||||||
|
vec2 uv = rotate(pixelized, data.rotation);
|
||||||
|
|
||||||
|
float angle = atan(uv.x - 0.5, uv.y - 0.5);
|
||||||
|
float d = distance(pixelized, vec2(0.5));
|
||||||
|
|
||||||
|
|
||||||
|
//float slowTime = timeSpeed * 0.5f;
|
||||||
|
|
||||||
|
float scaledSize = size * 0.2f;
|
||||||
|
|
||||||
|
float c = 0.0;
|
||||||
|
for(int i = 0; i < 15; i++) {
|
||||||
|
float r = rand2(vec2(float(i)));
|
||||||
|
vec2 circleUV = vec2(d, angle);
|
||||||
|
c += circle(circleUV*scaledSize -time * timeSpeed - (1.0/d) * 0.1 + r);
|
||||||
|
}
|
||||||
|
|
||||||
|
c *= 0.37 - d;
|
||||||
|
c = step(0.07, c - d);
|
||||||
|
|
||||||
|
if(c < 0.1)
|
||||||
|
{
|
||||||
|
discard;
|
||||||
|
}
|
||||||
|
color = vec4(data.color1.rgb, c * data.color1.a);
|
||||||
|
}
|
||||||
|
void StarFlairs()
|
||||||
|
{
|
||||||
|
float storm_width = data.userValues1.w;
|
||||||
|
float storm_dither_width = data.userValues2.x;
|
||||||
|
float scale = data.userValues1.z;
|
||||||
|
|
||||||
|
vec2 pixelized = floor(data.uv * data.pixels) / data.pixels;
|
||||||
|
bool dith = dither(data.uv, pixelized);
|
||||||
|
pixelized = rotate(pixelized, data.rotation);
|
||||||
|
|
||||||
|
vec2 uv = pixelized;
|
||||||
|
float angle = atan(uv.x - 0.5, uv.y - 0.5) * 0.4;
|
||||||
|
float d = distance(pixelized, vec2(0.5));
|
||||||
|
|
||||||
|
vec2 circleUV = vec2(d, angle);
|
||||||
|
|
||||||
|
float n = fbm2(circleUV*size -time * timeSpeed);
|
||||||
|
float nc = circle(circleUV*scale -time * timeSpeed + n);
|
||||||
|
|
||||||
|
nc *= 1.5;
|
||||||
|
float n2 = fbm2(circleUV*size -time + vec2(100, 100));
|
||||||
|
nc -= n2 * 0.1;
|
||||||
|
|
||||||
|
float a = 0.0;
|
||||||
|
bool do_dither = should_dither == 1;
|
||||||
|
if (1.0 - d > nc) {
|
||||||
|
// now we generate very thin strips of positive alpha if our noise has certain values and is close enough to center
|
||||||
|
if (nc > storm_width - storm_dither_width + d && (dith || !do_dither)) {
|
||||||
|
a = 1.0;
|
||||||
|
} else if (nc > storm_width + d) { // could use an or statement instead, but this looks more clear to me
|
||||||
|
a = 1.0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
int interpolate = int(floor(n2 + nc));
|
||||||
|
vec4 col = data.color1;
|
||||||
|
if(interpolate == 1)
|
||||||
|
col = data.color2;
|
||||||
|
|
||||||
|
a *= step(n2 * 0.25, d);
|
||||||
|
if(a < 0.1)
|
||||||
|
{
|
||||||
|
discard;
|
||||||
|
}
|
||||||
|
color = vec4(col.rgb, a * col.a);
|
||||||
|
}
|
||||||
|
void Moon()
|
||||||
|
{
|
||||||
|
vec2 uv = floor(data.uv * data.pixels) / data.pixels;
|
||||||
|
|
||||||
|
bool dith = dither(uv, data.uv);
|
||||||
|
|
||||||
|
float d_light = distance(uv, vec2(light_origin));
|
||||||
|
float d_circle = distance(uv, vec2(0.5));
|
||||||
|
float a = step(d_circle, 0.49999);
|
||||||
|
|
||||||
|
uv = rotate(uv, data.rotation);
|
||||||
|
|
||||||
|
float fbm1 = fbm2(uv);
|
||||||
|
d_light += fbm2(uv*size+fbm1+vec2(time*timeSpeed, 0.0))*0.3;
|
||||||
|
float dither_border = (1.0/data.pixels)*ditherSize;
|
||||||
|
|
||||||
|
vec4 col = data.color1;
|
||||||
|
bool do_dither = should_dither == 1;
|
||||||
|
if (d_light > light_border_1) {
|
||||||
|
col = data.color2;
|
||||||
|
if (d_light < light_border_1 + dither_border && (dith || !do_dither)) {
|
||||||
|
col = data.color1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (d_light > light_border_2) {
|
||||||
|
col = data.color3;
|
||||||
|
if (d_light < light_border_2 + dither_border && (dith || !do_dither)) {
|
||||||
|
col = data.color2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(a < 0.1)
|
||||||
|
{
|
||||||
|
discard;
|
||||||
|
}
|
||||||
|
color = vec4(col.rgb, a * col.a);
|
||||||
|
}
|
||||||
|
void Craters()
|
||||||
|
{
|
||||||
|
vec2 uv = floor(data.uv * data.pixels) / data.pixels;
|
||||||
|
|
||||||
|
float d_light = distance(uv, vec2(light_origin));
|
||||||
|
float d_circle = distance(uv, vec2(0.5));
|
||||||
|
float a = step(d_circle, 0.49999);
|
||||||
|
|
||||||
|
uv = rotate(uv, data.rotation);
|
||||||
|
uv = spherify(uv);
|
||||||
|
|
||||||
|
float c1 = crater2(uv );
|
||||||
|
float c2 = crater2(uv +(light_origin-0.5)*0.03);
|
||||||
|
vec4 col = data.color1;
|
||||||
|
|
||||||
|
a *= step(0.5, c1);
|
||||||
|
if (c2<c1-(0.5-d_light)*2.0) {
|
||||||
|
col = data.color2;
|
||||||
|
}
|
||||||
|
if (d_light > light_border_1) {
|
||||||
|
col = data.color2;
|
||||||
|
}
|
||||||
|
|
||||||
|
// cut out a circle
|
||||||
|
a*= step(d_circle, 0.5);
|
||||||
|
if(a < 0.1)
|
||||||
|
{
|
||||||
|
discard;
|
||||||
|
}
|
||||||
|
color = vec4(col.rgb, a * col.a);
|
||||||
|
}
|
||||||
|
void lineTest()
|
||||||
|
{
|
||||||
|
//vec2 uv = floor(data.uv * data.pixels) / data.pixels;
|
||||||
|
float d_circle = distance(data.uv, vec2(0.5));
|
||||||
|
float a = step(d_circle, 0.5);
|
||||||
|
float b = step(d_circle, 0.5 - 1.0 / data.pixels);
|
||||||
|
b *= -1.0;
|
||||||
|
b += 1.0;
|
||||||
|
|
||||||
|
vec4 col = data.color1;
|
||||||
|
|
||||||
|
if(a < 0.1 || b < 0.1)
|
||||||
|
{
|
||||||
|
discard;
|
||||||
|
}
|
||||||
|
color = vec4(col.rgb, a * b * col.a);
|
||||||
|
}
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
if (data.layer == 0.0)
|
||||||
|
{
|
||||||
|
Asteroid();
|
||||||
|
}
|
||||||
|
else if(data.layer == 10.0)
|
||||||
|
{
|
||||||
|
LandMassesPlanetUnder();
|
||||||
|
}
|
||||||
|
else if(data.layer == 11.0)
|
||||||
|
{
|
||||||
|
LandMassesPlanetLandMasses();
|
||||||
|
}
|
||||||
|
else if(data.layer == 12.0)
|
||||||
|
{
|
||||||
|
LandMassesClouds();
|
||||||
|
}
|
||||||
|
else if(data.layer == 20.0)
|
||||||
|
{
|
||||||
|
BlackHole();
|
||||||
|
}
|
||||||
|
else if(data.layer == 21.0)
|
||||||
|
{
|
||||||
|
BlackHoleRing();
|
||||||
|
}
|
||||||
|
else if(data.layer == 30.0)
|
||||||
|
{
|
||||||
|
Galaxy();
|
||||||
|
}
|
||||||
|
else if(data.layer == 40.0)
|
||||||
|
{
|
||||||
|
StarBase();
|
||||||
|
}
|
||||||
|
else if(data.layer == 41.0)
|
||||||
|
{
|
||||||
|
StarBlobs();
|
||||||
|
}
|
||||||
|
else if(data.layer == 42.0)
|
||||||
|
{
|
||||||
|
StarFlairs();
|
||||||
|
}
|
||||||
|
else if(data.layer == 50.0)
|
||||||
|
{
|
||||||
|
Moon();
|
||||||
|
}
|
||||||
|
else if(data.layer == 51.0)
|
||||||
|
{
|
||||||
|
Craters();
|
||||||
|
}
|
||||||
|
else if(data.layer == 60.0)
|
||||||
|
{
|
||||||
|
lineTest();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
color = vec4(1,0,0,1);
|
||||||
|
}
|
||||||
|
}
|
||||||
50
PlanetExplorerGameDemo/Resources/shaders/planetShader.vert
Normal file
50
PlanetExplorerGameDemo/Resources/shaders/planetShader.vert
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
#version 330 core
|
||||||
|
|
||||||
|
layout (location = 0) in vec3 position;
|
||||||
|
layout (location = 1) in vec4 color1;
|
||||||
|
layout (location = 2) in vec4 color2;
|
||||||
|
layout (location = 3) in vec4 color3;
|
||||||
|
layout (location = 4) in vec2 uv;
|
||||||
|
layout (location = 5) in float seed;
|
||||||
|
layout (location = 6) in float pixels;
|
||||||
|
layout (location = 7) in float rotation;
|
||||||
|
layout (location = 8) in float layer;
|
||||||
|
layout (location = 9) in vec4 userValues1;
|
||||||
|
layout (location = 10) in vec4 userValues2;
|
||||||
|
layout (location = 11) in vec4 userValues3;
|
||||||
|
|
||||||
|
|
||||||
|
uniform mat4 prMatrix;
|
||||||
|
uniform mat4 camMatrix;
|
||||||
|
|
||||||
|
out DATA
|
||||||
|
{
|
||||||
|
vec4 color1;
|
||||||
|
vec4 color2;
|
||||||
|
vec4 color3;
|
||||||
|
vec2 uv;
|
||||||
|
float seed;
|
||||||
|
float pixels;
|
||||||
|
float rotation;
|
||||||
|
float layer;
|
||||||
|
vec4 userValues1;
|
||||||
|
vec4 userValues2;
|
||||||
|
vec4 userValues3;
|
||||||
|
} data;
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
gl_Position = prMatrix * camMatrix * vec4(position.x, position.y, position.z, 1.0);
|
||||||
|
|
||||||
|
data.color1 = color1;
|
||||||
|
data.color2 = color2;
|
||||||
|
data.color3 = color3;
|
||||||
|
data.uv = uv;
|
||||||
|
data.seed = seed;
|
||||||
|
data.pixels = pixels;
|
||||||
|
data.rotation = rotation;
|
||||||
|
data.layer = layer;
|
||||||
|
data.userValues1 = userValues1;
|
||||||
|
data.userValues2 = userValues2;
|
||||||
|
data.userValues3 = userValues3;
|
||||||
|
}
|
||||||
Binary file not shown.
|
Before Width: | Height: | Size: 608 B |
BIN
PlanetExplorerGameDemo/Resources/textures/mainSprites.png
Normal file
BIN
PlanetExplorerGameDemo/Resources/textures/mainSprites.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 950 B |
@@ -0,0 +1,88 @@
|
|||||||
|
#include "GravityHolder.hpp"
|
||||||
|
#include "elements/ShaderRegistry.hpp"
|
||||||
|
#include "Color.hpp"
|
||||||
|
#include "BehaviourScripts/Renderable.hpp"
|
||||||
|
#include "BehaviourScripts/MeshContainer.hpp"
|
||||||
|
#include "BehaviourScripts/Camera.hpp"
|
||||||
|
#include "PlanetRotater.hpp"
|
||||||
|
|
||||||
|
void GravityHolder::GenerateRing()
|
||||||
|
{
|
||||||
|
planetMapRing = new Transformable();
|
||||||
|
mat = new Material("ringMaterial", ShaderRegistry::GetShader("Planet Shader"));
|
||||||
|
const float pixelsNormal = gravityDistance * 4 * 32;
|
||||||
|
|
||||||
|
mat->SetValue("planetColor1", Color(0.6176f, 0.6686f, 0.1509f));
|
||||||
|
mat->SetValue("pixels", pixelsNormal);
|
||||||
|
mat->SetValue("layer", 60.0f);
|
||||||
|
|
||||||
|
mesh = new Mesh(Mesh::GetQuadMesh());;
|
||||||
|
|
||||||
|
for (auto &point : mesh->vertecies)
|
||||||
|
{
|
||||||
|
point = point * gravityDistance * 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
planetMapRing->AddBehaviourScript(new Renderable(mat));
|
||||||
|
planetMapRing->AddBehaviourScript(new MeshContainer(mesh));
|
||||||
|
|
||||||
|
planetMapRing->SetParent(baseObject);
|
||||||
|
}
|
||||||
|
|
||||||
|
GravityHolder::GravityHolder(float gravityWell)
|
||||||
|
{
|
||||||
|
gravityDistance = gravityWell;
|
||||||
|
}
|
||||||
|
|
||||||
|
GravityHolder::~GravityHolder()
|
||||||
|
{
|
||||||
|
Transformable::HardDelete(planetMapRing, true);
|
||||||
|
delete mat;
|
||||||
|
delete mesh;
|
||||||
|
}
|
||||||
|
|
||||||
|
void GravityHolder::OnUpdate()
|
||||||
|
{
|
||||||
|
if(player == nullptr) return;
|
||||||
|
Vector3 globalPos = baseObject->GetGlobalPosition();
|
||||||
|
Vector3 playerGlobalPos = player->GetGlobalPosition();
|
||||||
|
|
||||||
|
Vector3 relativPos = playerGlobalPos - globalPos;
|
||||||
|
relativPos.z = 0;
|
||||||
|
|
||||||
|
float len = relativPos.Length();
|
||||||
|
bool insideTmp1 = len < gravityDistance;
|
||||||
|
bool insideTmp2 = len < gravityDistance + 0.05f;
|
||||||
|
if(inside != insideTmp2)
|
||||||
|
{
|
||||||
|
if(insideTmp2 && onEnter != nullptr)
|
||||||
|
{
|
||||||
|
onEnter(thisSpace);
|
||||||
|
}
|
||||||
|
else if(onExit != nullptr)
|
||||||
|
{
|
||||||
|
onExit(thisSpace);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
inside = insideTmp2;
|
||||||
|
|
||||||
|
if(insideTmp1)
|
||||||
|
{
|
||||||
|
if(!baseObject->HasBehaviourScript(PLANETROTATER)) return;
|
||||||
|
PlanetRotater* rotater = (PlanetRotater*)baseObject->GetBehaviourScript(PLANETROTATER);
|
||||||
|
Vector3 change = rotater->GetPosChange();
|
||||||
|
change.z = 0;
|
||||||
|
player->position = player->position + change;
|
||||||
|
Camera* cam = Camera::mainCamera;
|
||||||
|
if(cam != nullptr)
|
||||||
|
{
|
||||||
|
cam->baseObject->position = cam->baseObject->position + change;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void GravityHolder::Start()
|
||||||
|
{
|
||||||
|
player = Transformable::Find("Player");
|
||||||
|
GenerateRing();
|
||||||
|
}
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#define GRAVITYHOLDER typeid(GravityHolder).name()
|
||||||
|
|
||||||
|
#include "Elements/ISpace.hpp"
|
||||||
|
#include "elements/BehaviourScript.hpp"
|
||||||
|
#include "elements/Transformable.hpp"
|
||||||
|
#include "elements/Material.hpp"
|
||||||
|
#include "Mesh.hpp"
|
||||||
|
|
||||||
|
using namespace TSE;
|
||||||
|
|
||||||
|
class GravityHolder : public BehaviourScript
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
Transformable* planetMapRing = nullptr;
|
||||||
|
Material* mat = nullptr;
|
||||||
|
Mesh* mesh = nullptr;
|
||||||
|
bool inside = true;
|
||||||
|
|
||||||
|
public:
|
||||||
|
ISpace* thisSpace;
|
||||||
|
Transformable* player = nullptr;
|
||||||
|
float gravityDistance = 3.0f;
|
||||||
|
void (*onEnter)(ISpace* space);
|
||||||
|
void (*onExit)(ISpace* space);
|
||||||
|
|
||||||
|
private:
|
||||||
|
void GenerateRing();
|
||||||
|
|
||||||
|
public:
|
||||||
|
GravityHolder(float gravityWell);
|
||||||
|
~GravityHolder();
|
||||||
|
void OnUpdate() override;
|
||||||
|
void Start() override;
|
||||||
|
inline const char* GetName() override
|
||||||
|
{
|
||||||
|
return "Gravity Holder";
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -0,0 +1,68 @@
|
|||||||
|
#include "PlanetRotater.hpp"
|
||||||
|
#include "MathF.hpp"
|
||||||
|
#include "utils/Time.hpp"
|
||||||
|
#include "Utilities/MathFunctions.hpp"
|
||||||
|
#include "elements/ShaderRegistry.hpp"
|
||||||
|
#include "Color.hpp"
|
||||||
|
#include "BehaviourScripts/Renderable.hpp"
|
||||||
|
#include "BehaviourScripts/MeshContainer.hpp"
|
||||||
|
|
||||||
|
PlanetRotater::PlanetRotater(float distance)
|
||||||
|
{
|
||||||
|
distanceToKeep = distance;
|
||||||
|
}
|
||||||
|
|
||||||
|
PlanetRotater::~PlanetRotater()
|
||||||
|
{
|
||||||
|
Transformable::HardDelete(planetMapRing, true);
|
||||||
|
delete mat;
|
||||||
|
delete mesh;
|
||||||
|
}
|
||||||
|
|
||||||
|
void PlanetRotater::OnUpdate()
|
||||||
|
{
|
||||||
|
float circumference = 2 * TSE_PI * distanceToKeep;
|
||||||
|
float angle = (Time::deltaTime() / circumference) * speed;
|
||||||
|
Vector2 pointToMove = {baseObject->position.x, baseObject->position.y};
|
||||||
|
|
||||||
|
Vector2 newpos = rotateKeepDistance(Vector2::zero, pointToMove, angle, distanceToKeep);
|
||||||
|
Vector3 oldglobal = baseObject->GetGlobalPosition();
|
||||||
|
baseObject->position.x = newpos.x;
|
||||||
|
baseObject->position.y = newpos.y;
|
||||||
|
Vector3 newglobal = baseObject->GetGlobalPosition();
|
||||||
|
change = newglobal - oldglobal;
|
||||||
|
}
|
||||||
|
|
||||||
|
void PlanetRotater::Start()
|
||||||
|
{
|
||||||
|
GenerateRing();
|
||||||
|
}
|
||||||
|
|
||||||
|
Vector3 PlanetRotater::GetPosChange()
|
||||||
|
{
|
||||||
|
return change;
|
||||||
|
}
|
||||||
|
|
||||||
|
void PlanetRotater::GenerateRing()
|
||||||
|
{
|
||||||
|
planetMapRing = new Transformable();
|
||||||
|
mat = new Material("ringMaterial", ShaderRegistry::GetShader("Planet Shader"));
|
||||||
|
const float pixelsNormal = distanceToKeep * 2 * 32;
|
||||||
|
|
||||||
|
mat->SetValue("planetColor1", Color(0.1176f, 0.1686f, 0.2509f));
|
||||||
|
mat->SetValue("pixels", pixelsNormal);
|
||||||
|
mat->SetValue("layer", 60.0f);
|
||||||
|
|
||||||
|
mesh = new Mesh(Mesh::GetQuadMesh());;
|
||||||
|
|
||||||
|
for (auto &point : mesh->vertecies)
|
||||||
|
{
|
||||||
|
point = point * distanceToKeep * 2;
|
||||||
|
}
|
||||||
|
//planetMapRing->scale = {distanceToKeep * 2,distanceToKeep * 2,1};
|
||||||
|
|
||||||
|
planetMapRing->AddBehaviourScript(new Renderable(mat));
|
||||||
|
planetMapRing->AddBehaviourScript(new MeshContainer(mesh));
|
||||||
|
|
||||||
|
planetMapRing->SetParent(baseObject->GetParent());
|
||||||
|
}
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#define PLANETROTATER typeid(PlanetRotater).name()
|
||||||
|
|
||||||
|
#include "elements/BehaviourScript.hpp"
|
||||||
|
#include "elements/Transformable.hpp"
|
||||||
|
#include "elements/Material.hpp"
|
||||||
|
#include "Mesh.hpp"
|
||||||
|
|
||||||
|
using namespace TSE;
|
||||||
|
|
||||||
|
class PlanetRotater : public BehaviourScript
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
Transformable* planetMapRing = nullptr;
|
||||||
|
Material* mat = nullptr;
|
||||||
|
Mesh* mesh = nullptr;
|
||||||
|
Vector3 change;
|
||||||
|
|
||||||
|
public:
|
||||||
|
float distanceToKeep = 0;
|
||||||
|
const float speed = 3;
|
||||||
|
public:
|
||||||
|
PlanetRotater(float distance);
|
||||||
|
~PlanetRotater();
|
||||||
|
void OnUpdate() override;
|
||||||
|
void Start() override;
|
||||||
|
inline const char* GetName() override
|
||||||
|
{
|
||||||
|
return "Planet Rotater";
|
||||||
|
}
|
||||||
|
Vector3 GetPosChange();
|
||||||
|
|
||||||
|
private:
|
||||||
|
void GenerateRing();
|
||||||
|
};
|
||||||
128
PlanetExplorerGameDemo/src/BehaviourScripts/SpaceController.cpp
Normal file
128
PlanetExplorerGameDemo/src/BehaviourScripts/SpaceController.cpp
Normal file
@@ -0,0 +1,128 @@
|
|||||||
|
#include "SpaceController.hpp"
|
||||||
|
#include "Rendering/PlanetShader.hpp"
|
||||||
|
#include "utils/Time.hpp"
|
||||||
|
#include "BehaviourScripts/Camera.hpp"
|
||||||
|
|
||||||
|
SpaceController::SpaceController()
|
||||||
|
{
|
||||||
|
instance = this;
|
||||||
|
}
|
||||||
|
|
||||||
|
SpaceController::SpaceController(CharacterController * cc)
|
||||||
|
{
|
||||||
|
instance = this;
|
||||||
|
character = cc;
|
||||||
|
}
|
||||||
|
|
||||||
|
SpaceController::~SpaceController()
|
||||||
|
{
|
||||||
|
if(instance == this)
|
||||||
|
{
|
||||||
|
instance = nullptr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void SpaceController::OnUpdate()
|
||||||
|
{
|
||||||
|
PlanetShader* planetShader = PlanetShader::Instance();
|
||||||
|
planetShader->time += Time::deltaTime();
|
||||||
|
|
||||||
|
if(onExit)
|
||||||
|
{
|
||||||
|
exitCountDown += Time::deltaTime();
|
||||||
|
if(exitCountDown >= 3.0f)
|
||||||
|
{
|
||||||
|
GoToTargetSpace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
exitCountDown = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void SpaceController::Start()
|
||||||
|
{
|
||||||
|
IKeyInputHandler::Enable();
|
||||||
|
}
|
||||||
|
|
||||||
|
void SpaceController::LoadSpace(ISpace *spaceToLoad)
|
||||||
|
{
|
||||||
|
if(spaceToLoad == nullptr) return;
|
||||||
|
if(currentSpace != nullptr)
|
||||||
|
currentSpace->UnloadSpace();
|
||||||
|
currentRoot = spaceToLoad->LoadSpace();
|
||||||
|
currentRoot->SetParent(baseObject);
|
||||||
|
currentSpace = spaceToLoad;
|
||||||
|
//change space animation
|
||||||
|
}
|
||||||
|
|
||||||
|
void SpaceController::GoToTargetSpace()
|
||||||
|
{
|
||||||
|
if(targetSpace == nullptr || currentSpace == nullptr) return;
|
||||||
|
uuids::uuid exitId = currentRoot->id;
|
||||||
|
if(targetSpace == currentSpace)
|
||||||
|
{
|
||||||
|
LoadSpace(targetSpace->parentSpace);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
LoadSpace(targetSpace);
|
||||||
|
}
|
||||||
|
|
||||||
|
Transformable* player = Transformable::Find("Player");
|
||||||
|
|
||||||
|
if(repositionPlayer)
|
||||||
|
{
|
||||||
|
Vector3 pos = Transformable::Find(exitId)->GetGlobalPosition();
|
||||||
|
|
||||||
|
player->position = {pos.x,pos.y,0};
|
||||||
|
Camera::mainCamera->baseObject->position = {pos.x,pos.y,0};
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
player->position = {0,0,0};
|
||||||
|
Camera::mainCamera->baseObject->position = {0,0,0};
|
||||||
|
}
|
||||||
|
|
||||||
|
targetSpace = nullptr;
|
||||||
|
onExit = false;
|
||||||
|
repositionPlayer = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void SpaceController::OnKeyUp(const Key &key, const Modifier &mods)
|
||||||
|
{
|
||||||
|
switch (key)
|
||||||
|
{
|
||||||
|
case Key::E:
|
||||||
|
GoToTargetSpace();
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void OnSpaceHover(ISpace *space)
|
||||||
|
{
|
||||||
|
SpaceController::instance->targetSpace = space;
|
||||||
|
}
|
||||||
|
|
||||||
|
void OnSpaceNoHover(ISpace *space)
|
||||||
|
{
|
||||||
|
SpaceController::instance->targetSpace = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
void OnSpaceExit(ISpace *space)
|
||||||
|
{
|
||||||
|
SpaceController::instance->repositionPlayer = true;
|
||||||
|
SpaceController::instance->onExit = true;
|
||||||
|
SpaceController::instance->targetSpace = space;
|
||||||
|
}
|
||||||
|
|
||||||
|
void OnSpaceNoExit(ISpace *space)
|
||||||
|
{
|
||||||
|
SpaceController::instance->repositionPlayer = false;
|
||||||
|
SpaceController::instance->onExit = false;
|
||||||
|
SpaceController::instance->targetSpace = nullptr;
|
||||||
|
}
|
||||||
@@ -0,0 +1,49 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#define SPACECONTROLLER typeid(SpaceController).name()
|
||||||
|
|
||||||
|
#include "Elements/ISpace.hpp"
|
||||||
|
#include "elements/BehaviourScript.hpp"
|
||||||
|
#include "elements/Transformable.hpp"
|
||||||
|
#include "elements/Material.hpp"
|
||||||
|
#include "interfaces/IKeyInputHandler.hpp"
|
||||||
|
#include "characterController/CharacterController.hpp"
|
||||||
|
#include "Mesh.hpp"
|
||||||
|
|
||||||
|
using namespace TSE;
|
||||||
|
|
||||||
|
class SpaceController : public BehaviourScript , public IKeyInputHandler
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
float exitCountDown = 0;
|
||||||
|
|
||||||
|
public:
|
||||||
|
bool onExit = false;
|
||||||
|
bool repositionPlayer = false;
|
||||||
|
static inline SpaceController* instance = nullptr;
|
||||||
|
CharacterController* character = nullptr;
|
||||||
|
ISpace* currentSpace = nullptr;
|
||||||
|
ISpace* targetSpace = nullptr;
|
||||||
|
Transformable* currentRoot = nullptr;
|
||||||
|
|
||||||
|
public:
|
||||||
|
SpaceController();
|
||||||
|
SpaceController(CharacterController*);
|
||||||
|
~SpaceController();
|
||||||
|
void OnUpdate() override;
|
||||||
|
void Start() override;
|
||||||
|
inline const char* GetName() override
|
||||||
|
{
|
||||||
|
return "Space Coltroller";
|
||||||
|
}
|
||||||
|
|
||||||
|
void LoadSpace(ISpace* spaceToLoad);
|
||||||
|
void GoToTargetSpace();
|
||||||
|
|
||||||
|
void OnKeyUp(const Key& key, const Modifier& mods) override;
|
||||||
|
};
|
||||||
|
|
||||||
|
void OnSpaceHover(ISpace* space);
|
||||||
|
void OnSpaceNoHover(ISpace* space);
|
||||||
|
void OnSpaceExit(ISpace* space);
|
||||||
|
void OnSpaceNoExit(ISpace* space);
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
#include "CameraLerp.hpp"
|
||||||
|
#include "utils/Time.hpp"
|
||||||
|
|
||||||
|
CameraLerp::CameraLerp(Transformable *t)
|
||||||
|
{
|
||||||
|
target = t;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CameraLerp::OnUpdate()
|
||||||
|
{
|
||||||
|
if (target != nullptr)
|
||||||
|
{
|
||||||
|
Vector3 targetPos = target->GetGlobalPosition();
|
||||||
|
Vector3 currentPos = baseObject->GetGlobalPosition();
|
||||||
|
if(Vector3::DistanceSqr(targetPos, currentPos) > (distanceCutoff * distanceCutoff))
|
||||||
|
{
|
||||||
|
Vector3 newPos = Vector3::Lerp(currentPos, targetPos, lerpSpeed);
|
||||||
|
Vector3 delta = baseObject->GlobalToLocalPosition(newPos) * Time::deltaTime() * speed;
|
||||||
|
baseObject->position = baseObject->position + delta;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#define CAMERALERP typeid(CameraLerp).name()
|
||||||
|
|
||||||
|
#include "elements/BehaviourScript.hpp"
|
||||||
|
#include "elements/Transformable.hpp"
|
||||||
|
|
||||||
|
using namespace TSE;
|
||||||
|
|
||||||
|
class CameraLerp : public BehaviourScript
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
Transformable* target = nullptr;
|
||||||
|
float lerpSpeed = 0.8f;
|
||||||
|
float speed = 3;
|
||||||
|
float distanceCutoff = 0.2f;
|
||||||
|
|
||||||
|
CameraLerp(Transformable* target);
|
||||||
|
|
||||||
|
void OnUpdate() override;
|
||||||
|
inline const char* GetName() override
|
||||||
|
{
|
||||||
|
return "CameraLerp";
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
@@ -0,0 +1,91 @@
|
|||||||
|
#include "CharacterController.hpp"
|
||||||
|
#include "elements/Transformable.hpp"
|
||||||
|
#include "utils/Time.hpp"
|
||||||
|
|
||||||
|
void CharacterController::OnUpdate()
|
||||||
|
{
|
||||||
|
HandleMovement();
|
||||||
|
HandleRotation();
|
||||||
|
}
|
||||||
|
|
||||||
|
void CharacterController::Start()
|
||||||
|
{
|
||||||
|
IKeyInputHandler::Enable();
|
||||||
|
ICursorHandler::Enable();
|
||||||
|
instance = this;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CharacterController::OnKeyDown(const Key &key, const Modifier &mods)
|
||||||
|
{
|
||||||
|
switch (key)
|
||||||
|
{
|
||||||
|
case Key::W:
|
||||||
|
keydelta = keydelta + Vector3::up;
|
||||||
|
break;
|
||||||
|
case Key::A:
|
||||||
|
keydelta = keydelta + Vector3::left;
|
||||||
|
break;
|
||||||
|
case Key::S:
|
||||||
|
keydelta = keydelta + Vector3::down;
|
||||||
|
break;
|
||||||
|
case Key::D:
|
||||||
|
keydelta = keydelta + Vector3::right;
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void CharacterController::OnKeyUp(const Key &key, const Modifier &mods)
|
||||||
|
{
|
||||||
|
switch (key)
|
||||||
|
{
|
||||||
|
case Key::W:
|
||||||
|
keydelta = keydelta - Vector3::up;
|
||||||
|
break;
|
||||||
|
case Key::A:
|
||||||
|
keydelta = keydelta - Vector3::left;
|
||||||
|
break;
|
||||||
|
case Key::S:
|
||||||
|
keydelta = keydelta - Vector3::down;
|
||||||
|
break;
|
||||||
|
case Key::D:
|
||||||
|
keydelta = keydelta - Vector3::right;
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void CharacterController::OnMousePosition(const Vector2 &pos)
|
||||||
|
{
|
||||||
|
mousePos = Vector2(pos);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CharacterController::HandleMovement()
|
||||||
|
{
|
||||||
|
Vector3 move;
|
||||||
|
delta = delta + keydelta;
|
||||||
|
//move = baseObject->right() * delta.x;
|
||||||
|
move = baseObject->up() * delta.y;
|
||||||
|
move.z = 0;
|
||||||
|
delta = Vector3::zero;
|
||||||
|
|
||||||
|
move = move * movementMultiplier * Time::deltaTime();
|
||||||
|
|
||||||
|
baseObject->position = baseObject->position + move;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CharacterController::HandleRotation()
|
||||||
|
{
|
||||||
|
delta = delta + keydelta;
|
||||||
|
// Vector3 lookAtPos = Camera::mainCamera->SceenPositionToGamePosition(mousePos);
|
||||||
|
//baseObject->LookAt_2D(lookAtPos);
|
||||||
|
float change = delta.x * rotationMultiplier * Time::deltaTime();
|
||||||
|
Vector3 euler = baseObject->GetEuler();
|
||||||
|
euler.z -= change;
|
||||||
|
delta = Vector3::zero;
|
||||||
|
baseObject->SetEuler(euler);
|
||||||
|
}
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#define CHARACTERCONTROLLER typeid(CharacterController).name()
|
||||||
|
|
||||||
|
#include "interfaces/IKeyInputHandler.hpp"
|
||||||
|
#include "interfaces/ICursorHandler.hpp"
|
||||||
|
#include "elements/BehaviourScript.hpp"
|
||||||
|
#include "Vector2.hpp"
|
||||||
|
#include "Vector3.hpp"
|
||||||
|
|
||||||
|
using namespace TSE;
|
||||||
|
|
||||||
|
class CharacterController : public IKeyInputHandler, public ICursorHandler, public BehaviourScript
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
Vector2 mousePos = Vector2::zero;
|
||||||
|
Vector3 keydelta = Vector3::zero;
|
||||||
|
Vector3 delta = Vector3::zero;
|
||||||
|
float movementMultiplier = 4;
|
||||||
|
float rotationMultiplier = 200;
|
||||||
|
|
||||||
|
inline static CharacterController* instance = nullptr;
|
||||||
|
|
||||||
|
public:
|
||||||
|
void OnUpdate() override;
|
||||||
|
void Start() override;
|
||||||
|
inline const char* GetName() override
|
||||||
|
{
|
||||||
|
return "CharacterController";
|
||||||
|
}
|
||||||
|
|
||||||
|
void OnKeyDown(const Key& key, const Modifier& mods) override;
|
||||||
|
void OnKeyUp(const Key& key, const Modifier& mods) override;
|
||||||
|
void OnMousePosition(const Vector2& pos) override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
void HandleMovement();
|
||||||
|
void HandleRotation();
|
||||||
|
};
|
||||||
|
|
||||||
15
PlanetExplorerGameDemo/src/Elements/ISpace.hpp
Normal file
15
PlanetExplorerGameDemo/src/Elements/ISpace.hpp
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "elements/Transformable.hpp"
|
||||||
|
|
||||||
|
class ISpace
|
||||||
|
{
|
||||||
|
protected:
|
||||||
|
|
||||||
|
TSE::Transformable* root = nullptr;
|
||||||
|
|
||||||
|
public:
|
||||||
|
ISpace* parentSpace = nullptr;
|
||||||
|
virtual TSE::Transformable* LoadSpace() = 0;
|
||||||
|
virtual void UnloadSpace() = 0;
|
||||||
|
};
|
||||||
55
PlanetExplorerGameDemo/src/Elements/SpaceNameRegistry.hpp
Normal file
55
PlanetExplorerGameDemo/src/Elements/SpaceNameRegistry.hpp
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
#include <vector>
|
||||||
|
#include "Types.hpp"
|
||||||
|
|
||||||
|
std::vector<TSE::string> galaxyNames = {
|
||||||
|
"Nivara Prime",
|
||||||
|
"Solithar Nebula",
|
||||||
|
"Xyren Cluster",
|
||||||
|
"Auralis Verge",
|
||||||
|
"Zentha-9",
|
||||||
|
"Velora Expanse",
|
||||||
|
"Typhon Spiral",
|
||||||
|
"Mareth Void",
|
||||||
|
"Arcturion Reach",
|
||||||
|
"Polaris Rift",
|
||||||
|
"Thalara Belt",
|
||||||
|
"Epsilon Vortex",
|
||||||
|
"Kirella Nova",
|
||||||
|
"Omniron Halo",
|
||||||
|
"Dathion Expanse",
|
||||||
|
"Seraphis Arm",
|
||||||
|
"Voran Spiral",
|
||||||
|
"Lucara Cluster",
|
||||||
|
"Dravon Nexus",
|
||||||
|
"Altaris Bloom",
|
||||||
|
"Orionis Field",
|
||||||
|
"Kythera Veil",
|
||||||
|
"Novara Shard",
|
||||||
|
"Zorath Continuum",
|
||||||
|
"Calypsis Core",
|
||||||
|
"Ithara Crown",
|
||||||
|
"Halion Drift",
|
||||||
|
"Vornix Reach",
|
||||||
|
"Elunara Expanse",
|
||||||
|
"Rydan Halo",
|
||||||
|
"Tenebris Veil",
|
||||||
|
"Astralis Prime",
|
||||||
|
"Eclipta Rift",
|
||||||
|
"Nysera Spiral",
|
||||||
|
"Helion Verge",
|
||||||
|
"Trivane Sector",
|
||||||
|
"Myrren’s Belt",
|
||||||
|
"Corvantis Depth",
|
||||||
|
"Sylith Arc",
|
||||||
|
"Varun Expanse",
|
||||||
|
"Orivion Core",
|
||||||
|
"Lysera Bloom",
|
||||||
|
"Naethis Halo",
|
||||||
|
"Volthara Cluster",
|
||||||
|
"Crydon Drift",
|
||||||
|
"Altherion Reach",
|
||||||
|
"Nebraxis Vortex",
|
||||||
|
"Valen Expanse",
|
||||||
|
"Serenith Spiral",
|
||||||
|
"Zephyra Prime"
|
||||||
|
};
|
||||||
15
PlanetExplorerGameDemo/src/Elements/TextureIDMap.hpp
Normal file
15
PlanetExplorerGameDemo/src/Elements/TextureIDMap.hpp
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "Vector2.hpp"
|
||||||
|
|
||||||
|
#pragma region Ship+Upgrades
|
||||||
|
|
||||||
|
#define BASE_SHIP Vector2(0,7)
|
||||||
|
#define BASE_SHIP_BOOSTER1 Vector2(1,7)
|
||||||
|
#define BASE_SHIP_EMP Vector2(2,7)
|
||||||
|
#define BASE_SHIP_ROCKET_LAUNCHER Vector2(3,7)
|
||||||
|
#define BASE_SHIP_BOOSTER2 Vector2(4,7)
|
||||||
|
#define BASE_SHIP_LASER Vector2(5,7)
|
||||||
|
#define BASE_SHIP_ROCKET_LEFT Vector2(6,7)
|
||||||
|
#define BASE_SHIP_ROCKET_RIGHT Vector2(7,7)
|
||||||
|
|
||||||
|
#pragma endregion
|
||||||
130
PlanetExplorerGameDemo/src/Elements/spaceElements/Asteroid.cpp
Normal file
130
PlanetExplorerGameDemo/src/Elements/spaceElements/Asteroid.cpp
Normal file
@@ -0,0 +1,130 @@
|
|||||||
|
#include "Asteroid.hpp"
|
||||||
|
|
||||||
|
Transformable *Asteroid::LoadSpace()
|
||||||
|
{
|
||||||
|
root = new Transformable(name);
|
||||||
|
|
||||||
|
Transformable* planet = create();
|
||||||
|
|
||||||
|
planet->SetParent(root);
|
||||||
|
|
||||||
|
return root;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Asteroid::UnloadSpace()
|
||||||
|
{
|
||||||
|
DeleteResources();
|
||||||
|
root->SetParent(nullptr);
|
||||||
|
Transformable::HardDelete(root, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
Transformable *Asteroid::create()
|
||||||
|
{
|
||||||
|
const float pixelsNormal = scale * 32;
|
||||||
|
|
||||||
|
Transformable* planetBase = new Transformable(name + "Base");
|
||||||
|
resources.push_back(planetBase);
|
||||||
|
|
||||||
|
Material* planetBaseMat = new Material("asteroidBaseMat", ShaderRegistry::GetShader("Planet Shader"));
|
||||||
|
resources.push_back(planetBaseMat);
|
||||||
|
|
||||||
|
planetBaseMat->SetValue("planetColor1", Color1);
|
||||||
|
planetBaseMat->SetValue("planetColor2", Color2);
|
||||||
|
planetBaseMat->SetValue("planetColor3", Color3);
|
||||||
|
planetBaseMat->SetValue("seed", seed);
|
||||||
|
planetBaseMat->SetValue("pixels", pixelsNormal);
|
||||||
|
planetBaseMat->SetValue("rotation", rotation);
|
||||||
|
planetBaseMat->SetValue("layer", 00.0f);
|
||||||
|
|
||||||
|
planetBase->scale = {scale,scale,1};
|
||||||
|
|
||||||
|
Mesh* planetMesh = new Mesh(Mesh::GetQuadMesh());
|
||||||
|
resources.push_back(planetMesh);
|
||||||
|
|
||||||
|
planetBase->AddBehaviourScript(new Renderable(planetBaseMat));
|
||||||
|
planetBase->AddBehaviourScript(new MeshContainer(planetMesh));
|
||||||
|
|
||||||
|
return planetBase;
|
||||||
|
}
|
||||||
|
|
||||||
|
Transformable *Asteroid::createSmall()
|
||||||
|
{
|
||||||
|
const float pixelsNormal = smallScale * 32;
|
||||||
|
|
||||||
|
Transformable* planetBase = new Transformable(name + "Base");
|
||||||
|
resources.push_back(planetBase);
|
||||||
|
|
||||||
|
Material* planetBaseMat = new Material("asteroidBaseMat", ShaderRegistry::GetShader("Planet Shader"));
|
||||||
|
resources.push_back(planetBaseMat);
|
||||||
|
|
||||||
|
planetBaseMat->SetValue("planetColor1", Color1);
|
||||||
|
planetBaseMat->SetValue("planetColor2", Color2);
|
||||||
|
planetBaseMat->SetValue("planetColor3", Color3);
|
||||||
|
planetBaseMat->SetValue("seed", seed);
|
||||||
|
planetBaseMat->SetValue("pixels", pixelsNormal);
|
||||||
|
planetBaseMat->SetValue("rotation", rotation);
|
||||||
|
planetBaseMat->SetValue("layer", 00.0f);
|
||||||
|
|
||||||
|
planetBase->scale = {smallScale,smallScale,1};
|
||||||
|
|
||||||
|
Mesh* planetMesh = new Mesh(Mesh::GetQuadMesh());
|
||||||
|
resources.push_back(planetMesh);
|
||||||
|
|
||||||
|
planetBase->AddBehaviourScript(new Renderable(planetBaseMat));
|
||||||
|
planetBase->AddBehaviourScript(new MeshContainer(planetMesh));
|
||||||
|
|
||||||
|
return planetBase;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Asteroid::DeleteResources()
|
||||||
|
{
|
||||||
|
if(resources.size() == 0) return;
|
||||||
|
|
||||||
|
Transformable* planetBase = (Transformable*)resources[0];
|
||||||
|
Material* planetMat = (Material*)resources[1];
|
||||||
|
Mesh* planetMesh = (Mesh*)resources[2];
|
||||||
|
|
||||||
|
delete planetMesh;
|
||||||
|
delete planetMat;
|
||||||
|
planetBase->SetParent(nullptr);
|
||||||
|
Transformable::HardDelete(planetBase, true);
|
||||||
|
|
||||||
|
resources.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
Asteroid *Asteroid::Load(nlohmann::json json)
|
||||||
|
{
|
||||||
|
Asteroid* asteroid = new Asteroid();
|
||||||
|
|
||||||
|
asteroid->name = json["name"];
|
||||||
|
asteroid->id = uuids::uuid::from_string(to_string(json["id"])).value_or(GenerateRandomUUID());
|
||||||
|
asteroid->seed = json["seed"];
|
||||||
|
asteroid->scale = json["scale"];
|
||||||
|
asteroid->smallScale = json["smallScale"];
|
||||||
|
asteroid->rotation = json["rotation"];
|
||||||
|
asteroid->position = ImportVector2(json["position"]);
|
||||||
|
asteroid->Color1 = ImportColor(json["Color1"]);
|
||||||
|
asteroid->Color2 = ImportColor(json["Color2"]);
|
||||||
|
asteroid->Color3 = ImportColor(json["Color3"]);
|
||||||
|
}
|
||||||
|
|
||||||
|
nlohmann::json Asteroid::Export()
|
||||||
|
{
|
||||||
|
using json = nlohmann::json;
|
||||||
|
|
||||||
|
json exp;
|
||||||
|
exp["name"] = name;
|
||||||
|
exp["id"] = to_string(id);
|
||||||
|
exp["seed"] = seed;
|
||||||
|
exp["scale"] = scale;
|
||||||
|
exp["smallScale"] = smallScale;
|
||||||
|
exp["rotation"] = rotation;
|
||||||
|
exp["position"] = ExportVector2(position);
|
||||||
|
exp["Color1"] = ExportColor(Color1);
|
||||||
|
exp["Color2"] = ExportColor(Color2);
|
||||||
|
exp["Color3"] = ExportColor(Color3);
|
||||||
|
|
||||||
|
// outposts
|
||||||
|
|
||||||
|
return exp;
|
||||||
|
}
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "Outpost.hpp"
|
||||||
|
#include "../ISpace.hpp"
|
||||||
|
|
||||||
|
class Asteroid : public ISpace
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
std::string name = "Asteroid";
|
||||||
|
uuids::uuid id = uuids::uuid();//TSE::Base::GenerateRandomUUID();
|
||||||
|
|
||||||
|
float seed = 3.0f;
|
||||||
|
Vector2 position = {0,0};
|
||||||
|
float scale = 5;
|
||||||
|
float smallScale = 1;
|
||||||
|
float rotation = 3.14f;
|
||||||
|
|
||||||
|
Color Color1 = Color(0.7294f, 0.7294f, 0.7294f);
|
||||||
|
Color Color2 = Color(0.5882f, 0.5882f, 0.5882f);
|
||||||
|
Color Color3 = Color(0.2352f, 0.2352f, 0.2352f);
|
||||||
|
|
||||||
|
std::vector<Outpost*> outposts;
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::vector<void*> resources;
|
||||||
|
|
||||||
|
public:
|
||||||
|
Transformable* LoadSpace() override;
|
||||||
|
void UnloadSpace() override;
|
||||||
|
|
||||||
|
Transformable* create();
|
||||||
|
Transformable* createSmall();
|
||||||
|
void DeleteResources();
|
||||||
|
|
||||||
|
static Asteroid* Load(nlohmann::json json);
|
||||||
|
nlohmann::json Export();
|
||||||
|
};
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "Asteroid.hpp"
|
||||||
|
|
||||||
|
class Asteroidbelt : public ISpace
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
string name = "";
|
||||||
|
float distanceToStar = 0;
|
||||||
|
float width = 0;
|
||||||
|
std::vector<Asteroid*> asteroids;
|
||||||
|
|
||||||
|
public:
|
||||||
|
Transformable* LoadSpace() override;
|
||||||
|
void UnloadSpace() override;
|
||||||
|
};
|
||||||
128
PlanetExplorerGameDemo/src/Elements/spaceElements/BlackHole.cpp
Normal file
128
PlanetExplorerGameDemo/src/Elements/spaceElements/BlackHole.cpp
Normal file
@@ -0,0 +1,128 @@
|
|||||||
|
#include "BlackHole.hpp"
|
||||||
|
|
||||||
|
Transformable *BlackHole::createSmall()
|
||||||
|
{
|
||||||
|
const float pixelsNormal = scale * 32;
|
||||||
|
|
||||||
|
Transformable* planetBase = new Transformable(name + "Base");
|
||||||
|
resources.push_back(planetBase);
|
||||||
|
Transformable* planetLand = new Transformable(name + "Rings");
|
||||||
|
resources.push_back(planetLand);
|
||||||
|
|
||||||
|
Material* planetBaseMat = new Material("planetBaseMat", ShaderRegistry::GetShader("Planet Shader"));
|
||||||
|
resources.push_back(planetBaseMat);
|
||||||
|
Material* planetLandMat = new Material("planetRingMat", ShaderRegistry::GetShader("Planet Shader"));
|
||||||
|
resources.push_back(planetLandMat);
|
||||||
|
|
||||||
|
//Base:
|
||||||
|
planetBaseMat->SetValue("planetColor1", holeColor1);
|
||||||
|
planetBaseMat->SetValue("planetColor2", holeColor2);
|
||||||
|
planetBaseMat->SetValue("planetColor3", holeColor3);
|
||||||
|
planetBaseMat->SetValue("pixels", pixelsNormal);
|
||||||
|
planetBaseMat->SetValue("layer", 20.0f);
|
||||||
|
planetBaseMat->SetValue("userValues1", Vector4(radius, lightWidth,0,0));
|
||||||
|
//Ring:
|
||||||
|
const float scaleUp = 6;
|
||||||
|
planetLandMat->SetValue("planetColor1", ringColor1);
|
||||||
|
planetLandMat->SetValue("planetColor2", ringColor2);
|
||||||
|
planetLandMat->SetValue("planetColor3", ringColor3);
|
||||||
|
planetLandMat->SetValue("userValues2", ringColor4.ToVector4());
|
||||||
|
planetLandMat->SetValue("userValues3", ringColor5.ToVector4());
|
||||||
|
planetLandMat->SetValue("userValues1", Vector4(diskWidth, ringPerspective,0,0));
|
||||||
|
planetLandMat->SetValue("seed", seed);
|
||||||
|
planetLandMat->SetValue("pixels", pixelsNormal * scaleUp);
|
||||||
|
planetLandMat->SetValue("rotation", rotation);
|
||||||
|
planetLandMat->SetValue("layer", 21.0f);
|
||||||
|
|
||||||
|
planetLand->scale = Vector3(scaleUp, scaleUp,1);
|
||||||
|
planetLand->SetParent(planetBase);
|
||||||
|
planetBase->scale = {scale,scale,1};
|
||||||
|
|
||||||
|
Mesh* planetMesh = new Mesh(Mesh::GetQuadMesh());
|
||||||
|
resources.push_back(planetMesh);
|
||||||
|
|
||||||
|
planetBase->AddBehaviourScript(new Renderable(planetBaseMat));
|
||||||
|
planetBase->AddBehaviourScript(new MeshContainer(planetMesh));
|
||||||
|
|
||||||
|
planetLand->AddBehaviourScript(new Renderable(planetLandMat));
|
||||||
|
planetLand->AddBehaviourScript(new MeshContainer(planetMesh));
|
||||||
|
|
||||||
|
return planetBase;
|
||||||
|
}
|
||||||
|
|
||||||
|
void BlackHole::DeleteResources()
|
||||||
|
{
|
||||||
|
if(resources.size() == 0) return;
|
||||||
|
|
||||||
|
Transformable* planetBase = (Transformable*)resources[0];
|
||||||
|
Transformable* planetLand = (Transformable*)resources[1];
|
||||||
|
Material* planetMat = (Material*)resources[2];
|
||||||
|
Material* landMat = (Material*)resources[3];
|
||||||
|
Mesh* planetMesh = (Mesh*)resources[4];
|
||||||
|
|
||||||
|
delete planetMesh;
|
||||||
|
delete landMat;
|
||||||
|
delete planetMat;
|
||||||
|
Transformable::HardDelete(planetLand, true);
|
||||||
|
planetBase->SetParent(nullptr);
|
||||||
|
Transformable::HardDelete(planetBase, true);
|
||||||
|
|
||||||
|
resources.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
BlackHole *BlackHole::Load(nlohmann::json json)
|
||||||
|
{
|
||||||
|
BlackHole* hole = new BlackHole();
|
||||||
|
|
||||||
|
hole->name = json["name"];
|
||||||
|
hole->position = ImportVector2(json["position"]);
|
||||||
|
hole->id = uuids::uuid::from_string(to_string(json["id"])).value_or(GenerateRandomUUID());
|
||||||
|
hole->seed = json["seed"];
|
||||||
|
hole->scale = json["scale"];
|
||||||
|
hole->rotation = json["rotation"];
|
||||||
|
hole->radius = json["radius"];
|
||||||
|
hole->lightWidth = json["lightWidth"];
|
||||||
|
hole->diskWidth = json["diskWidth"];
|
||||||
|
hole->ringPerspective = json["ringPerspective"];
|
||||||
|
|
||||||
|
hole->holeColor1 = ImportColor(json["holeColor1"]);
|
||||||
|
hole->holeColor2 = ImportColor(json["holeColor2"]);
|
||||||
|
hole->holeColor3 = ImportColor(json["holeColor3"]);
|
||||||
|
|
||||||
|
hole->ringColor1 = ImportColor(json["ringColor1"]);
|
||||||
|
hole->ringColor2 = ImportColor(json["ringColor2"]);
|
||||||
|
hole->ringColor3 = ImportColor(json["ringColor3"]);
|
||||||
|
hole->ringColor4 = ImportColor(json["ringColor4"]);
|
||||||
|
hole->ringColor5 = ImportColor(json["ringColor5"]);
|
||||||
|
|
||||||
|
return hole;
|
||||||
|
}
|
||||||
|
|
||||||
|
nlohmann::json BlackHole::Export()
|
||||||
|
{
|
||||||
|
using json = nlohmann::json;
|
||||||
|
|
||||||
|
json exp;
|
||||||
|
exp["name"] = name;
|
||||||
|
exp["position"] = ExportVector2(position);
|
||||||
|
exp["id"] = to_string(id);
|
||||||
|
exp["seed"] = seed;
|
||||||
|
exp["scale"] = scale;
|
||||||
|
exp["rotation"] = rotation;
|
||||||
|
exp["radius"] = radius;
|
||||||
|
exp["lightWidth"] = lightWidth;
|
||||||
|
exp["diskWidth"] = diskWidth;
|
||||||
|
exp["ringPerspective"] = ringPerspective;
|
||||||
|
|
||||||
|
exp["holeColor1"] = ExportColor(holeColor1);
|
||||||
|
exp["holeColor2"] = ExportColor(holeColor2);
|
||||||
|
exp["holeColor3"] = ExportColor(holeColor3);
|
||||||
|
|
||||||
|
exp["ringColor1"] = ExportColor(ringColor1);
|
||||||
|
exp["ringColor2"] = ExportColor(ringColor2);
|
||||||
|
exp["ringColor3"] = ExportColor(ringColor3);
|
||||||
|
exp["ringColor4"] = ExportColor(ringColor4);
|
||||||
|
exp["ringColor5"] = ExportColor(ringColor5);
|
||||||
|
|
||||||
|
return exp;
|
||||||
|
}
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "Planet.hpp"
|
||||||
|
|
||||||
|
class BlackHole
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
string name = "BlackHole";
|
||||||
|
uuids::uuid id = uuids::uuid();//TSE::Base::GenerateRandomUUID();
|
||||||
|
|
||||||
|
float seed = 3.0f;
|
||||||
|
float scale = 2;
|
||||||
|
float rotation = 2.64f;
|
||||||
|
Vector2 position = {0,0};
|
||||||
|
|
||||||
|
float radius = 0.5f;
|
||||||
|
float lightWidth = 0.03f;
|
||||||
|
|
||||||
|
float diskWidth = 0.15f;
|
||||||
|
float ringPerspective = 13;
|
||||||
|
|
||||||
|
Color holeColor1 = Color::black;
|
||||||
|
Color holeColor2 = Color::yellow;
|
||||||
|
Color holeColor3 = Color::orange;
|
||||||
|
|
||||||
|
Color ringColor1 = Color::yellow;
|
||||||
|
Color ringColor2 = Color::Lerp(Color::yellow, Color::orange, 0.25f);
|
||||||
|
Color ringColor3 = Color::Lerp(Color::yellow, Color::orange, 0.5f);
|
||||||
|
Color ringColor4 = Color::Lerp(Color::yellow, Color::orange, 0.75f);
|
||||||
|
Color ringColor5 = Color::orange;
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::vector<void*> resources;
|
||||||
|
|
||||||
|
public:
|
||||||
|
Transformable* createSmall();
|
||||||
|
void DeleteResources();
|
||||||
|
|
||||||
|
static BlackHole* Load(nlohmann::json json);
|
||||||
|
nlohmann::json Export();
|
||||||
|
};
|
||||||
207
PlanetExplorerGameDemo/src/Elements/spaceElements/Galaxy.cpp
Normal file
207
PlanetExplorerGameDemo/src/Elements/spaceElements/Galaxy.cpp
Normal file
@@ -0,0 +1,207 @@
|
|||||||
|
#include "Galaxy.hpp"
|
||||||
|
#include "BehaviourScripts/PlanetRotater.hpp"
|
||||||
|
#include "Utilities/MathFunctions.hpp"
|
||||||
|
#include "Utilities/Random.hpp"
|
||||||
|
#include "BehaviourScripts/GravityHolder.hpp"
|
||||||
|
#include "BehaviourScripts/SpaceController.hpp"
|
||||||
|
|
||||||
|
Transformable *Galaxy::LoadSpace()
|
||||||
|
{
|
||||||
|
root = new Transformable(name);
|
||||||
|
|
||||||
|
for (auto &&system : systems)
|
||||||
|
{
|
||||||
|
Transformable* systemObj = system->createSmall();
|
||||||
|
systemObj->SetParent(root);
|
||||||
|
systemObj->position = {system->position.x, system->position.y, -1};
|
||||||
|
}
|
||||||
|
for (auto &&hole : blackHoles)
|
||||||
|
{
|
||||||
|
Transformable* holeObj = hole->createSmall();
|
||||||
|
holeObj->SetParent(root);
|
||||||
|
// position;
|
||||||
|
}
|
||||||
|
|
||||||
|
root->id = id;
|
||||||
|
|
||||||
|
float grvityWell = GetMaxDistObj();
|
||||||
|
|
||||||
|
GravityHolder* holder = new GravityHolder(grvityWell + 4.0f);
|
||||||
|
holder->thisSpace = this;
|
||||||
|
holder->onEnter = &OnSpaceNoExit;
|
||||||
|
holder->onExit = &OnSpaceExit;
|
||||||
|
|
||||||
|
root->AddBehaviourScript(holder);
|
||||||
|
|
||||||
|
return root;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Galaxy::UnloadSpace()
|
||||||
|
{
|
||||||
|
DeleteResources();
|
||||||
|
root->SetParent(nullptr);
|
||||||
|
Transformable::HardDelete(root, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
Transformable *Galaxy::createSmall()
|
||||||
|
{
|
||||||
|
const float pixelsNormal = scale * 32;
|
||||||
|
|
||||||
|
Transformable* planetBase = new Transformable(name + "Base", id);
|
||||||
|
resources.push_back(planetBase);
|
||||||
|
|
||||||
|
Material* planetBaseMat = new Material("planetBaseMat", ShaderRegistry::GetShader("Planet Shader"));
|
||||||
|
resources.push_back(planetBaseMat);
|
||||||
|
|
||||||
|
//Base:
|
||||||
|
planetBaseMat->SetValue("planetColor1", galaxyColor1);
|
||||||
|
planetBaseMat->SetValue("planetColor2", galaxyColor2);
|
||||||
|
planetBaseMat->SetValue("planetColor3", galaxyColor3);
|
||||||
|
planetBaseMat->SetValue("userValues2", galaxyColor4.ToVector4());
|
||||||
|
planetBaseMat->SetValue("userValues3", galaxyColor5.ToVector4());
|
||||||
|
planetBaseMat->SetValue("userValues1", Vector4(tilt, layerHeight, zoom, swirl));
|
||||||
|
planetBaseMat->SetValue("seed", seed);
|
||||||
|
planetBaseMat->SetValue("pixels", pixelsNormal);
|
||||||
|
planetBaseMat->SetValue("rotation", rotation);
|
||||||
|
planetBaseMat->SetValue("layer", 30.0f);
|
||||||
|
|
||||||
|
Mesh* planetMesh = new Mesh(Mesh::GetQuadMesh());
|
||||||
|
resources.push_back(planetMesh);
|
||||||
|
|
||||||
|
for (auto &point : planetMesh->vertecies)
|
||||||
|
{
|
||||||
|
point = point * scale;
|
||||||
|
}
|
||||||
|
|
||||||
|
planetBase->AddBehaviourScript(new Renderable(planetBaseMat));
|
||||||
|
planetBase->AddBehaviourScript(new MeshContainer(planetMesh));
|
||||||
|
|
||||||
|
GravityHolder* holder = new GravityHolder(scale * 1.25f);
|
||||||
|
|
||||||
|
holder->onEnter = &OnSpaceHover;
|
||||||
|
holder->onExit = &OnSpaceNoHover;
|
||||||
|
holder->thisSpace = this;
|
||||||
|
|
||||||
|
planetBase->AddBehaviourScript(holder);
|
||||||
|
|
||||||
|
return planetBase;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Galaxy::DeleteResources()
|
||||||
|
{
|
||||||
|
for (auto &&hole : blackHoles)
|
||||||
|
{
|
||||||
|
hole->DeleteResources();
|
||||||
|
}
|
||||||
|
for (auto &&system : systems)
|
||||||
|
{
|
||||||
|
system->DeleteResources();
|
||||||
|
}
|
||||||
|
if(resources.size() == 0) return;
|
||||||
|
|
||||||
|
Transformable* planetBase = (Transformable*)resources[0];
|
||||||
|
Material* planetMat = (Material*)resources[1];
|
||||||
|
Mesh* planetMesh = (Mesh*)resources[2];
|
||||||
|
|
||||||
|
delete planetMesh;
|
||||||
|
delete planetMat;
|
||||||
|
planetBase->SetParent(nullptr);
|
||||||
|
Transformable::HardDelete(planetBase, true);
|
||||||
|
|
||||||
|
resources.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
Galaxy *Galaxy::Load(nlohmann::json json)
|
||||||
|
{
|
||||||
|
Galaxy* galaxy = new Galaxy();
|
||||||
|
|
||||||
|
galaxy->name = json["name"];
|
||||||
|
galaxy->id = uuids::uuid::from_string(to_string(json["id"])).value_or(GenerateRandomUUID());
|
||||||
|
galaxy->seed = json["seed"];
|
||||||
|
galaxy->scale = json["scale"];
|
||||||
|
galaxy->rotation = json["rotation"];
|
||||||
|
galaxy->tilt = json["tilt"];
|
||||||
|
galaxy->layerHeight = json["layerHeight"];
|
||||||
|
galaxy->zoom = json["zoom"];
|
||||||
|
galaxy->swirl = json["swirl"];
|
||||||
|
|
||||||
|
galaxy->position = ImportVector2(json["position"]);
|
||||||
|
|
||||||
|
galaxy->galaxyColor1 = ImportColor(json["galaxyColor1"]);
|
||||||
|
galaxy->galaxyColor2 = ImportColor(json["galaxyColor2"]);
|
||||||
|
galaxy->galaxyColor3 = ImportColor(json["galaxyColor3"]);
|
||||||
|
galaxy->galaxyColor4 = ImportColor(json["galaxyColor4"]);
|
||||||
|
galaxy->galaxyColor5 = ImportColor(json["galaxyColor5"]);
|
||||||
|
|
||||||
|
int holeCount = json["holeCount"];
|
||||||
|
for (int i = 0; i < holeCount; i++)
|
||||||
|
{
|
||||||
|
galaxy->blackHoles.push_back(BlackHole::Load(json["holes"][i]));
|
||||||
|
}
|
||||||
|
int systemCount = json["systemCount"];
|
||||||
|
for (int i = 0; i < systemCount; i++)
|
||||||
|
{
|
||||||
|
galaxy->systems.push_back(PlanetarySystem::Load(json["systems"][i]));
|
||||||
|
}
|
||||||
|
|
||||||
|
//Planetary system
|
||||||
|
|
||||||
|
return galaxy;
|
||||||
|
}
|
||||||
|
|
||||||
|
nlohmann::json Galaxy::Export()
|
||||||
|
{
|
||||||
|
using json = nlohmann::json;
|
||||||
|
|
||||||
|
json exp;
|
||||||
|
exp["name"] = name;
|
||||||
|
exp["id"] = to_string(id);
|
||||||
|
exp["seed"] = seed;
|
||||||
|
exp["scale"] = scale;
|
||||||
|
exp["rotation"] = rotation;
|
||||||
|
exp["tilt"] = tilt;
|
||||||
|
exp["layerHeight"] = layerHeight;
|
||||||
|
exp["zoom"] = zoom;
|
||||||
|
exp["swirl"] = swirl;
|
||||||
|
|
||||||
|
exp["position"] = ExportVector2(position);
|
||||||
|
|
||||||
|
exp["galaxyColor1"] = ExportColor(galaxyColor1);
|
||||||
|
exp["galaxyColor2"] = ExportColor(galaxyColor2);
|
||||||
|
exp["galaxyColor3"] = ExportColor(galaxyColor3);
|
||||||
|
exp["galaxyColor4"] = ExportColor(galaxyColor4);
|
||||||
|
exp["galaxyColor5"] = ExportColor(galaxyColor5);
|
||||||
|
|
||||||
|
//PlanetarySystems
|
||||||
|
|
||||||
|
exp["holeCount"] = blackHoles.size();
|
||||||
|
int i = 0;
|
||||||
|
for (auto &&hole : blackHoles)
|
||||||
|
{
|
||||||
|
exp["holes"][i++] = hole->Export();
|
||||||
|
}
|
||||||
|
exp["systemCount"] = systems.size();
|
||||||
|
i = 0;
|
||||||
|
// for (auto &&system : systems)
|
||||||
|
// {
|
||||||
|
// exp["systems"][i++] = system->Export();
|
||||||
|
// }
|
||||||
|
|
||||||
|
return exp;
|
||||||
|
}
|
||||||
|
|
||||||
|
float Galaxy::GetMaxDistObj()
|
||||||
|
{
|
||||||
|
float dist = 0;
|
||||||
|
|
||||||
|
for (auto &&system : systems)
|
||||||
|
{
|
||||||
|
dist = std::max(dist, system->position.Length());
|
||||||
|
}
|
||||||
|
for (auto &&hole : blackHoles)
|
||||||
|
{
|
||||||
|
dist = std::max(dist, hole->position.Length());
|
||||||
|
}
|
||||||
|
|
||||||
|
return dist;
|
||||||
|
}
|
||||||
46
PlanetExplorerGameDemo/src/Elements/spaceElements/Galaxy.hpp
Normal file
46
PlanetExplorerGameDemo/src/Elements/spaceElements/Galaxy.hpp
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "PlanetarySystem.hpp"
|
||||||
|
#include "BlackHole.hpp"
|
||||||
|
|
||||||
|
class Galaxy : public ISpace
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
string name = "";
|
||||||
|
uuids::uuid id = uuids::uuid();//TSE::Base::GenerateRandomUUID();
|
||||||
|
|
||||||
|
Vector2 position;
|
||||||
|
float seed = 3.0f;
|
||||||
|
float scale = 2;
|
||||||
|
float rotation = 2.64f;
|
||||||
|
|
||||||
|
float tilt = 4;
|
||||||
|
float layerHeight = 0.4f;
|
||||||
|
float zoom = 2;
|
||||||
|
float swirl = -9;
|
||||||
|
|
||||||
|
Color galaxyColor1 = Color::yellow;
|
||||||
|
Color galaxyColor2 = Color::Lerp(Color::yellow, Color::orange, 0.25f);
|
||||||
|
Color galaxyColor3 = Color::Lerp(Color::yellow, Color::orange, 0.5f);
|
||||||
|
Color galaxyColor4 = Color::Lerp(Color::yellow, Color::orange, 0.75f);
|
||||||
|
Color galaxyColor5 = Color::orange;
|
||||||
|
|
||||||
|
std::vector<PlanetarySystem*> systems;
|
||||||
|
std::vector<BlackHole*> blackHoles;
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::vector<void*> resources;
|
||||||
|
|
||||||
|
public:
|
||||||
|
Transformable* LoadSpace() override;
|
||||||
|
void UnloadSpace() override;
|
||||||
|
|
||||||
|
Transformable* createSmall();
|
||||||
|
void DeleteResources();
|
||||||
|
|
||||||
|
static Galaxy* Load(nlohmann::json json);
|
||||||
|
nlohmann::json Export();
|
||||||
|
private:
|
||||||
|
float GetMaxDistObj();
|
||||||
|
|
||||||
|
};
|
||||||
@@ -0,0 +1,44 @@
|
|||||||
|
#include "LocalCluster.hpp"
|
||||||
|
|
||||||
|
Transformable *LocalCluster::LoadSpace()
|
||||||
|
{
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
void LocalCluster::UnloadSpace()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
LocalCluster *LocalCluster::Load(nlohmann::json json)
|
||||||
|
{
|
||||||
|
LocalCluster* cluster = new LocalCluster();
|
||||||
|
|
||||||
|
cluster->name = json["name"];
|
||||||
|
cluster->id = uuids::uuid::from_string(to_string(json["id"])).value_or(GenerateRandomUUID());
|
||||||
|
|
||||||
|
int galaxyCount = json["galaxyCount"];
|
||||||
|
for (int i = 0; i < galaxyCount; i++)
|
||||||
|
{
|
||||||
|
cluster->galaxies.push_back(Galaxy::Load(json["galaxies"][i]));
|
||||||
|
}
|
||||||
|
|
||||||
|
return cluster;
|
||||||
|
}
|
||||||
|
|
||||||
|
nlohmann::json LocalCluster::Export()
|
||||||
|
{
|
||||||
|
using json = nlohmann::json;
|
||||||
|
|
||||||
|
json exp;
|
||||||
|
exp["name"] = name;
|
||||||
|
exp["id"] = to_string(id);
|
||||||
|
|
||||||
|
exp["galaxyCount"] = galaxies.size();
|
||||||
|
int i = 0;
|
||||||
|
for (auto &&galaxy : galaxies)
|
||||||
|
{
|
||||||
|
exp["galaxies"][i++] = galaxy->Export();
|
||||||
|
}
|
||||||
|
|
||||||
|
return exp;
|
||||||
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "Galaxy.hpp"
|
||||||
|
|
||||||
|
class LocalCluster : public ISpace
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
string name = "";
|
||||||
|
uuids::uuid id = uuids::uuid();//TSE::Base::GenerateRandomUUID();
|
||||||
|
|
||||||
|
std::vector<Galaxy*> galaxies;
|
||||||
|
|
||||||
|
public:
|
||||||
|
Transformable* LoadSpace() override;
|
||||||
|
void UnloadSpace() override;
|
||||||
|
|
||||||
|
static LocalCluster* Load(nlohmann::json json);
|
||||||
|
nlohmann::json Export();
|
||||||
|
};
|
||||||
208
PlanetExplorerGameDemo/src/Elements/spaceElements/Moon.cpp
Normal file
208
PlanetExplorerGameDemo/src/Elements/spaceElements/Moon.cpp
Normal file
@@ -0,0 +1,208 @@
|
|||||||
|
#include "Moon.hpp"
|
||||||
|
#include "BehaviourScripts/GravityHolder.hpp"
|
||||||
|
#include "BehaviourScripts/SpaceController.hpp"
|
||||||
|
|
||||||
|
Transformable *Moon::LoadSpace()
|
||||||
|
{
|
||||||
|
root = new Transformable(name);
|
||||||
|
|
||||||
|
Transformable* planet = create();
|
||||||
|
|
||||||
|
planet->SetParent(root);
|
||||||
|
|
||||||
|
root->id = id;
|
||||||
|
|
||||||
|
return root;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Moon::UnloadSpace()
|
||||||
|
{
|
||||||
|
DeleteResources();
|
||||||
|
root->SetParent(nullptr);
|
||||||
|
Transformable::HardDelete(root, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
Transformable *Moon::create()
|
||||||
|
{
|
||||||
|
const float pixelsNormal = scale * 32;
|
||||||
|
|
||||||
|
Transformable* planetBase = new Transformable(name + "Base");
|
||||||
|
resources.push_back(planetBase);
|
||||||
|
Transformable* planetLand = new Transformable(name + "Craters");
|
||||||
|
resources.push_back(planetLand);
|
||||||
|
|
||||||
|
Material* planetBaseMat = new Material("planetBaseMat", ShaderRegistry::GetShader("Planet Shader"));
|
||||||
|
resources.push_back(planetBaseMat);
|
||||||
|
Material* planetLandMat = new Material("planetCraterMat", ShaderRegistry::GetShader("Planet Shader"));
|
||||||
|
resources.push_back(planetLandMat);
|
||||||
|
|
||||||
|
//Base:
|
||||||
|
planetBaseMat->SetValue("planetColor1", baseColor1);
|
||||||
|
planetBaseMat->SetValue("planetColor2", baseColor2);
|
||||||
|
planetBaseMat->SetValue("planetColor3", baseColor3);
|
||||||
|
planetBaseMat->SetValue("seed", seed);
|
||||||
|
planetBaseMat->SetValue("pixels", pixelsNormal);
|
||||||
|
planetBaseMat->SetValue("rotation", rotation);
|
||||||
|
planetBaseMat->SetValue("layer", 50.0f);
|
||||||
|
//Craters:
|
||||||
|
planetLandMat->SetValue("planetColor1", craterColor1);
|
||||||
|
planetLandMat->SetValue("planetColor2", craterColor2);
|
||||||
|
planetLandMat->SetValue("seed", seed);
|
||||||
|
planetLandMat->SetValue("pixels", pixelsNormal);
|
||||||
|
planetLandMat->SetValue("rotation", rotation);
|
||||||
|
planetLandMat->SetValue("layer", 51.0f);
|
||||||
|
|
||||||
|
planetLand->SetParent(planetBase);
|
||||||
|
|
||||||
|
Mesh* planetMesh = new Mesh(Mesh::GetQuadMesh());
|
||||||
|
resources.push_back(planetMesh);
|
||||||
|
|
||||||
|
for (auto &point : planetMesh->vertecies)
|
||||||
|
{
|
||||||
|
point = point * scale;
|
||||||
|
}
|
||||||
|
|
||||||
|
planetBase->AddBehaviourScript(new Renderable(planetBaseMat));
|
||||||
|
planetBase->AddBehaviourScript(new MeshContainer(planetMesh));
|
||||||
|
|
||||||
|
planetLand->AddBehaviourScript(new Renderable(planetLandMat));
|
||||||
|
planetLand->AddBehaviourScript(new MeshContainer(planetMesh));
|
||||||
|
|
||||||
|
GravityHolder* holder = new GravityHolder(scale * 1.25f);
|
||||||
|
holder->thisSpace = this;
|
||||||
|
holder->onEnter = &OnSpaceNoExit;
|
||||||
|
holder->onExit = &OnSpaceExit;
|
||||||
|
|
||||||
|
planetBase->AddBehaviourScript(holder);
|
||||||
|
|
||||||
|
return planetBase;
|
||||||
|
}
|
||||||
|
|
||||||
|
Transformable *Moon::createSmall()
|
||||||
|
{
|
||||||
|
const float pixelsNormal = smallScale * 32;
|
||||||
|
|
||||||
|
Transformable* planetBase = new Transformable(name + "Base", id);
|
||||||
|
resources.push_back(planetBase);
|
||||||
|
Transformable* planetLand = new Transformable(name + "Craters");
|
||||||
|
resources.push_back(planetLand);
|
||||||
|
|
||||||
|
Material* planetBaseMat = new Material("planetBaseMat", ShaderRegistry::GetShader("Planet Shader"));
|
||||||
|
resources.push_back(planetBaseMat);
|
||||||
|
Material* planetLandMat = new Material("planetCraterMat", ShaderRegistry::GetShader("Planet Shader"));
|
||||||
|
resources.push_back(planetLandMat);
|
||||||
|
|
||||||
|
//Base:
|
||||||
|
planetBaseMat->SetValue("planetColor1", baseColor1);
|
||||||
|
planetBaseMat->SetValue("planetColor2", baseColor2);
|
||||||
|
planetBaseMat->SetValue("planetColor3", baseColor3);
|
||||||
|
planetBaseMat->SetValue("seed", seed);
|
||||||
|
planetBaseMat->SetValue("pixels", pixelsNormal);
|
||||||
|
planetBaseMat->SetValue("rotation", rotation);
|
||||||
|
planetBaseMat->SetValue("layer", 50.0f);
|
||||||
|
//Craters:
|
||||||
|
planetLandMat->SetValue("planetColor1", craterColor1);
|
||||||
|
planetLandMat->SetValue("planetColor2", craterColor2);
|
||||||
|
planetLandMat->SetValue("seed", seed);
|
||||||
|
planetLandMat->SetValue("pixels", pixelsNormal);
|
||||||
|
planetLandMat->SetValue("rotation", rotation);
|
||||||
|
planetLandMat->SetValue("layer", 51.0f);
|
||||||
|
|
||||||
|
planetLand->SetParent(planetBase);
|
||||||
|
|
||||||
|
Mesh* planetMesh = new Mesh(Mesh::GetQuadMesh());
|
||||||
|
resources.push_back(planetMesh);
|
||||||
|
|
||||||
|
for (auto &point : planetMesh->vertecies)
|
||||||
|
{
|
||||||
|
point = point * smallScale;
|
||||||
|
}
|
||||||
|
|
||||||
|
planetBase->AddBehaviourScript(new Renderable(planetBaseMat));
|
||||||
|
planetBase->AddBehaviourScript(new MeshContainer(planetMesh));
|
||||||
|
|
||||||
|
planetLand->AddBehaviourScript(new Renderable(planetLandMat));
|
||||||
|
planetLand->AddBehaviourScript(new MeshContainer(planetMesh));
|
||||||
|
|
||||||
|
GravityHolder* holder = new GravityHolder(smallScale * 1.25f);
|
||||||
|
|
||||||
|
holder->onEnter = &OnSpaceHover;
|
||||||
|
holder->onExit = &OnSpaceNoHover;
|
||||||
|
holder->thisSpace = this;
|
||||||
|
|
||||||
|
planetBase->AddBehaviourScript(holder);
|
||||||
|
|
||||||
|
return planetBase;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Moon::DeleteResources()
|
||||||
|
{
|
||||||
|
if(resources.size() == 0) return;
|
||||||
|
|
||||||
|
Transformable* planetBase = (Transformable*)resources[0];
|
||||||
|
Transformable* planetLand = (Transformable*)resources[1];
|
||||||
|
Material* planetMat = (Material*)resources[2];
|
||||||
|
Material* landMat = (Material*)resources[3];
|
||||||
|
Mesh* planetMesh = (Mesh*)resources[4];
|
||||||
|
|
||||||
|
delete planetMesh;
|
||||||
|
delete landMat;
|
||||||
|
delete planetMat;
|
||||||
|
Transformable::HardDelete(planetLand, true);
|
||||||
|
planetBase->SetParent(nullptr);
|
||||||
|
Transformable::HardDelete(planetBase, true);
|
||||||
|
|
||||||
|
resources.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
Moon *Moon::Load(nlohmann::json json)
|
||||||
|
{
|
||||||
|
Moon* moon = new Moon();
|
||||||
|
moon->name = json["name"];
|
||||||
|
moon->id = uuids::uuid::from_string(to_string(json["id"])).value_or(GenerateRandomUUID());
|
||||||
|
moon->seed = json["seed"];
|
||||||
|
moon->distanceToPlanet = json["distanceToPlanet"];
|
||||||
|
moon->scale = json["scale"];
|
||||||
|
moon->smallScale = json["smallScale"];
|
||||||
|
moon->rotation = json["rotation"];
|
||||||
|
|
||||||
|
moon->baseColor1 = ImportColor(json["baseColor1"]);
|
||||||
|
moon->baseColor2 = ImportColor(json["baseColor2"]);
|
||||||
|
moon->baseColor3 = ImportColor(json["baseColor3"]);
|
||||||
|
|
||||||
|
moon->craterColor1 = ImportColor(json["craterColor1"]);
|
||||||
|
moon->craterColor2 = ImportColor(json["craterColor2"]);
|
||||||
|
|
||||||
|
//outposts
|
||||||
|
|
||||||
|
//satelites
|
||||||
|
|
||||||
|
return moon;
|
||||||
|
}
|
||||||
|
|
||||||
|
nlohmann::json Moon::Export()
|
||||||
|
{
|
||||||
|
using json = nlohmann::json;
|
||||||
|
|
||||||
|
json exp;
|
||||||
|
exp["name"] = name;
|
||||||
|
exp["id"] = to_string(id);
|
||||||
|
exp["seed"] = seed;
|
||||||
|
exp["distanceToPlanet"] = distanceToPlanet;
|
||||||
|
exp["scale"] = scale;
|
||||||
|
exp["smallScale"] = smallScale;
|
||||||
|
exp["rotation"] = rotation;
|
||||||
|
|
||||||
|
exp["baseColor1"] = ExportColor(baseColor1);
|
||||||
|
exp["baseColor2"] = ExportColor(baseColor2);
|
||||||
|
exp["baseColor3"] = ExportColor(baseColor3);
|
||||||
|
|
||||||
|
exp["craterColor1"] = ExportColor(craterColor1);
|
||||||
|
exp["craterColor2"] = ExportColor(craterColor2);
|
||||||
|
|
||||||
|
//outposts
|
||||||
|
|
||||||
|
//satelites
|
||||||
|
|
||||||
|
return exp;
|
||||||
|
}
|
||||||
43
PlanetExplorerGameDemo/src/Elements/spaceElements/Moon.hpp
Normal file
43
PlanetExplorerGameDemo/src/Elements/spaceElements/Moon.hpp
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "Satelite.hpp"
|
||||||
|
#include "Outpost.hpp"
|
||||||
|
#include "../ISpace.hpp"
|
||||||
|
|
||||||
|
class Moon : public ISpace
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
std::string name = "Moon";
|
||||||
|
uuids::uuid id = uuids::uuid();//TSE::Base::GenerateRandomUUID();
|
||||||
|
|
||||||
|
float seed = 3.0f;
|
||||||
|
float distanceToPlanet = 10;
|
||||||
|
float scale = 3;
|
||||||
|
float smallScale = 1;
|
||||||
|
float rotation = 3.14f;
|
||||||
|
|
||||||
|
Color baseColor1 = {0.8901f, 0.8549f, 0.8117f};
|
||||||
|
Color baseColor2 = {0.6039f, 0.5803f, 0.5176f};
|
||||||
|
Color baseColor3 = {0.1568f, 0.1450f, 0.1568f};
|
||||||
|
|
||||||
|
Color craterColor1 = {0.6235f, 0.6078f, 0.5411f};
|
||||||
|
Color craterColor2 = {0.1686f, 0.1803f, 0.1333f};
|
||||||
|
|
||||||
|
std::vector<Outpost*> outposts;
|
||||||
|
std::vector<Satelite*> satelites;
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::vector<void*> resources;
|
||||||
|
|
||||||
|
public:
|
||||||
|
Transformable* LoadSpace() override;
|
||||||
|
void UnloadSpace() override;
|
||||||
|
|
||||||
|
|
||||||
|
Transformable* create();
|
||||||
|
Transformable* createSmall();
|
||||||
|
void DeleteResources();
|
||||||
|
|
||||||
|
static Moon* Load(nlohmann::json json);
|
||||||
|
nlohmann::json Export();
|
||||||
|
};
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "Types.hpp"
|
||||||
|
#include "json.hpp"
|
||||||
|
#include "Vector2.hpp"
|
||||||
|
#include "Color.hpp"
|
||||||
|
#include "Mesh.hpp"
|
||||||
|
#include "elements/Material.hpp"
|
||||||
|
#include "BehaviourScripts/Renderable.hpp"
|
||||||
|
#include "BehaviourScripts/MeshContainer.hpp"
|
||||||
|
#include "utils/JsonExports.hpp"
|
||||||
|
#include "IdGenerator.hpp"
|
||||||
|
#include "elements/ShaderRegistry.hpp"
|
||||||
|
|
||||||
|
using namespace TSE;
|
||||||
|
|
||||||
|
class Outpost
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
string name = "";
|
||||||
|
};
|
||||||
321
PlanetExplorerGameDemo/src/Elements/spaceElements/Planet.cpp
Normal file
321
PlanetExplorerGameDemo/src/Elements/spaceElements/Planet.cpp
Normal file
@@ -0,0 +1,321 @@
|
|||||||
|
#include "Planet.hpp"
|
||||||
|
#include "BehaviourScripts/PlanetRotater.hpp"
|
||||||
|
#include "Utilities/MathFunctions.hpp"
|
||||||
|
#include "Utilities/Random.hpp"
|
||||||
|
#include "BehaviourScripts/GravityHolder.hpp"
|
||||||
|
#include "BehaviourScripts/SpaceController.hpp"
|
||||||
|
|
||||||
|
Transformable *Planet::LoadSpace()
|
||||||
|
{
|
||||||
|
root = new Transformable(name);
|
||||||
|
|
||||||
|
Transformable* planet = create();
|
||||||
|
|
||||||
|
planet->SetParent(root);
|
||||||
|
|
||||||
|
auto rng = std::uniform_real_distribution<float> ();
|
||||||
|
|
||||||
|
for (auto &&moon : moons)
|
||||||
|
{
|
||||||
|
Transformable* moonObj = moon->createSmall();
|
||||||
|
moonObj->SetParent(root);
|
||||||
|
moonObj->AddBehaviourScript(new PlanetRotater(moon->distanceToPlanet));
|
||||||
|
Vector2 pos = rotateKeepDistance(Vector2::zero, {0, moon->distanceToPlanet}, GetRandomFloat(0, 360), moon->distanceToPlanet);
|
||||||
|
moonObj->position = {pos.x, pos.y, -1};
|
||||||
|
}
|
||||||
|
|
||||||
|
root->id = id;
|
||||||
|
|
||||||
|
return root;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Planet::UnloadSpace()
|
||||||
|
{
|
||||||
|
DeleteResources();
|
||||||
|
root->SetParent(nullptr);
|
||||||
|
Transformable::HardDelete(root, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
Transformable *Planet::create()
|
||||||
|
{
|
||||||
|
const float pixelsNormal = scale * 32;
|
||||||
|
|
||||||
|
Transformable* planetBase = new Transformable(name + "Base");
|
||||||
|
resources.push_back(planetBase);
|
||||||
|
Transformable* planetLand = new Transformable(name + "Land");
|
||||||
|
resources.push_back(planetLand);
|
||||||
|
Transformable* planetCloud = new Transformable(name + "Cloud");
|
||||||
|
resources.push_back(planetCloud);
|
||||||
|
|
||||||
|
Material* planetBaseMat = new Material("planetBaseMat", ShaderRegistry::GetShader("Planet Shader"));
|
||||||
|
resources.push_back(planetBaseMat);
|
||||||
|
Material* planetLandMat = new Material("planetLandMat", ShaderRegistry::GetShader("Planet Shader"));
|
||||||
|
resources.push_back(planetLandMat);
|
||||||
|
Material* planetCloudMat = new Material("planetCloudMat", ShaderRegistry::GetShader("Planet Shader"));
|
||||||
|
resources.push_back(planetCloudMat);
|
||||||
|
|
||||||
|
//Base:
|
||||||
|
planetBaseMat->SetValue("planetColor1", waterColor1);
|
||||||
|
planetBaseMat->SetValue("planetColor2", waterColor2);
|
||||||
|
planetBaseMat->SetValue("planetColor3", waterColor3);
|
||||||
|
planetBaseMat->SetValue("seed", seed);
|
||||||
|
planetBaseMat->SetValue("pixels", pixelsNormal);
|
||||||
|
planetBaseMat->SetValue("rotation", rotation);
|
||||||
|
planetBaseMat->SetValue("layer", 10.0f);
|
||||||
|
//Land masses:
|
||||||
|
planetLandMat->SetValue("planetColor1", landColor1);
|
||||||
|
planetLandMat->SetValue("planetColor2", landColor2);
|
||||||
|
planetLandMat->SetValue("planetColor3", landColor3);
|
||||||
|
planetLandMat->SetValue("userValues2", landColor4.ToVector4());
|
||||||
|
planetLandMat->SetValue("userValues1", Vector4(landCutoff,0,0,0));
|
||||||
|
planetLandMat->SetValue("seed", seed);
|
||||||
|
planetLandMat->SetValue("pixels", pixelsNormal);
|
||||||
|
planetLandMat->SetValue("rotation", rotation);
|
||||||
|
planetLandMat->SetValue("layer", 11.0f);
|
||||||
|
//Clouds:
|
||||||
|
planetCloudMat->SetValue("planetColor1", cloudColor1);
|
||||||
|
planetCloudMat->SetValue("planetColor2", cloudColor2);
|
||||||
|
planetCloudMat->SetValue("planetColor3", cloudColor3);
|
||||||
|
planetCloudMat->SetValue("userValues2", cloudColor4.ToVector4());
|
||||||
|
planetCloudMat->SetValue("userValues1", Vector4(cloudCover,stretch,cloudCurve,0));
|
||||||
|
planetCloudMat->SetValue("seed", seed);
|
||||||
|
planetCloudMat->SetValue("pixels", pixelsNormal);
|
||||||
|
planetCloudMat->SetValue("rotation", rotation);
|
||||||
|
planetCloudMat->SetValue("layer", 12.0f);
|
||||||
|
|
||||||
|
planetLand->SetParent(planetBase);
|
||||||
|
planetCloud->SetParent(planetBase);
|
||||||
|
|
||||||
|
Mesh* planetMesh = new Mesh(Mesh::GetQuadMesh());
|
||||||
|
resources.push_back(planetMesh);
|
||||||
|
|
||||||
|
for (auto &point : planetMesh->vertecies)
|
||||||
|
{
|
||||||
|
point = point * scale;
|
||||||
|
}
|
||||||
|
|
||||||
|
planetBase->AddBehaviourScript(new Renderable(planetBaseMat));
|
||||||
|
planetBase->AddBehaviourScript(new MeshContainer(planetMesh));
|
||||||
|
|
||||||
|
planetLand->AddBehaviourScript(new Renderable(planetLandMat));
|
||||||
|
planetLand->AddBehaviourScript(new MeshContainer(planetMesh));
|
||||||
|
|
||||||
|
planetCloud->AddBehaviourScript(new Renderable(planetCloudMat));
|
||||||
|
planetCloud->AddBehaviourScript(new MeshContainer(planetMesh));
|
||||||
|
|
||||||
|
float grvityWell = GetMaxMoonDistance();
|
||||||
|
|
||||||
|
GravityHolder* holder = new GravityHolder(grvityWell + 4.0f);
|
||||||
|
holder->thisSpace = this;
|
||||||
|
holder->onEnter = &OnSpaceNoExit;
|
||||||
|
holder->onExit = &OnSpaceExit;
|
||||||
|
|
||||||
|
planetBase->AddBehaviourScript(holder);
|
||||||
|
|
||||||
|
return planetBase;
|
||||||
|
}
|
||||||
|
|
||||||
|
Transformable *Planet::createSmall()
|
||||||
|
{
|
||||||
|
const float pixelsNormal = smallScale * 32;
|
||||||
|
|
||||||
|
Transformable* planetBase = new Transformable(name + "Base", id);
|
||||||
|
resources.push_back(planetBase);
|
||||||
|
Transformable* planetLand = new Transformable(name + "Land");
|
||||||
|
resources.push_back(planetLand);
|
||||||
|
Transformable* planetCloud = new Transformable(name + "Cloud");
|
||||||
|
resources.push_back(planetCloud);
|
||||||
|
|
||||||
|
Material* planetBaseMat = new Material("planetBaseMat", ShaderRegistry::GetShader("Planet Shader"));
|
||||||
|
resources.push_back(planetBaseMat);
|
||||||
|
Material* planetLandMat = new Material("planetLandMat", ShaderRegistry::GetShader("Planet Shader"));
|
||||||
|
resources.push_back(planetLandMat);
|
||||||
|
Material* planetCloudMat = new Material("planetCloudMat", ShaderRegistry::GetShader("Planet Shader"));
|
||||||
|
resources.push_back(planetCloudMat);
|
||||||
|
|
||||||
|
//Base:
|
||||||
|
planetBaseMat->SetValue("planetColor1", waterColor1);
|
||||||
|
planetBaseMat->SetValue("planetColor2", waterColor2);
|
||||||
|
planetBaseMat->SetValue("planetColor3", waterColor3);
|
||||||
|
planetBaseMat->SetValue("seed", seed);
|
||||||
|
planetBaseMat->SetValue("pixels", pixelsNormal);
|
||||||
|
planetBaseMat->SetValue("rotation", rotation);
|
||||||
|
planetBaseMat->SetValue("layer", 10.0f);
|
||||||
|
// //Land masses:
|
||||||
|
planetLandMat->SetValue("planetColor1", landColor1);
|
||||||
|
planetLandMat->SetValue("planetColor2", landColor2);
|
||||||
|
planetLandMat->SetValue("planetColor3", landColor3);
|
||||||
|
planetLandMat->SetValue("userValues2", landColor4.ToVector4());
|
||||||
|
planetLandMat->SetValue("userValues1", Vector4(landCutoff,0,0,0));
|
||||||
|
planetLandMat->SetValue("seed", seed);
|
||||||
|
planetLandMat->SetValue("pixels", pixelsNormal);
|
||||||
|
planetLandMat->SetValue("rotation", rotation);
|
||||||
|
planetLandMat->SetValue("layer", 11.0f);
|
||||||
|
//Clouds:
|
||||||
|
planetCloudMat->SetValue("planetColor1", cloudColor1);
|
||||||
|
planetCloudMat->SetValue("planetColor2", cloudColor2);
|
||||||
|
planetCloudMat->SetValue("planetColor3", cloudColor3);
|
||||||
|
planetCloudMat->SetValue("userValues2", cloudColor4.ToVector4());
|
||||||
|
planetCloudMat->SetValue("userValues1", Vector4(cloudCover,stretch,cloudCurve,0));
|
||||||
|
planetCloudMat->SetValue("seed", seed);
|
||||||
|
planetCloudMat->SetValue("pixels", pixelsNormal);
|
||||||
|
planetCloudMat->SetValue("rotation", rotation);
|
||||||
|
planetCloudMat->SetValue("layer", 12.0f);
|
||||||
|
|
||||||
|
planetLand->SetParent(planetBase);
|
||||||
|
planetCloud->SetParent(planetBase);
|
||||||
|
|
||||||
|
Mesh* planetMesh = new Mesh(Mesh::GetQuadMesh());
|
||||||
|
resources.push_back(planetMesh);
|
||||||
|
|
||||||
|
for (auto &point : planetMesh->vertecies)
|
||||||
|
{
|
||||||
|
point = point * smallScale;
|
||||||
|
}
|
||||||
|
|
||||||
|
planetBase->AddBehaviourScript(new Renderable(planetBaseMat));
|
||||||
|
planetBase->AddBehaviourScript(new MeshContainer(planetMesh));
|
||||||
|
|
||||||
|
planetLand->AddBehaviourScript(new Renderable(planetLandMat));
|
||||||
|
planetLand->AddBehaviourScript(new MeshContainer(planetMesh));
|
||||||
|
|
||||||
|
planetCloud->AddBehaviourScript(new Renderable(planetCloudMat));
|
||||||
|
planetCloud->AddBehaviourScript(new MeshContainer(planetMesh));
|
||||||
|
|
||||||
|
GravityHolder* holder = new GravityHolder(smallScale * 1.25f);
|
||||||
|
|
||||||
|
holder->onEnter = &OnSpaceHover;
|
||||||
|
holder->onExit = &OnSpaceNoHover;
|
||||||
|
holder->thisSpace = this;
|
||||||
|
|
||||||
|
planetBase->AddBehaviourScript(holder);
|
||||||
|
|
||||||
|
return planetBase;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Planet::DeleteResources()
|
||||||
|
{
|
||||||
|
for (auto &&moon : moons)
|
||||||
|
{
|
||||||
|
moon->DeleteResources();
|
||||||
|
}
|
||||||
|
if(resources.size() == 0) return;
|
||||||
|
|
||||||
|
Transformable* planetBase = (Transformable*)resources[0];
|
||||||
|
Transformable* planetLand = (Transformable*)resources[1];
|
||||||
|
Transformable* planetClouds = (Transformable*)resources[2];
|
||||||
|
Material* planetMat = (Material*)resources[3];
|
||||||
|
Material* landMat = (Material*)resources[4];
|
||||||
|
Material* cloudMat = (Material*)resources[5];
|
||||||
|
Mesh* planetMesh = (Mesh*)resources[6];
|
||||||
|
|
||||||
|
delete planetMesh;
|
||||||
|
delete cloudMat;
|
||||||
|
delete landMat;
|
||||||
|
delete planetMat;
|
||||||
|
Transformable::HardDelete(planetClouds, true);
|
||||||
|
Transformable::HardDelete(planetLand, true);
|
||||||
|
planetBase->SetParent(nullptr);
|
||||||
|
Transformable::HardDelete(planetBase, true);
|
||||||
|
|
||||||
|
resources.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
Planet *Planet::Load(nlohmann::json json)
|
||||||
|
{
|
||||||
|
Planet* planet = new Planet();
|
||||||
|
planet->name = json["name"];
|
||||||
|
planet->id = uuids::uuid::from_string(to_string(json["id"])).value_or(GenerateRandomUUID());
|
||||||
|
planet->seed = json["seed"];
|
||||||
|
planet->distanceToStar = json["distanceToStar"];
|
||||||
|
planet->scale = json["scale"];
|
||||||
|
planet->smallScale = json["smallScale"];
|
||||||
|
planet->rotation = json["rotation"];
|
||||||
|
planet->landCutoff = json["landCutoff"];
|
||||||
|
planet->cloudCover = json["cloudCover"];
|
||||||
|
planet->stretch = json["stretch"];
|
||||||
|
planet->cloudCurve = json["cloudCurve"];
|
||||||
|
//waterColors
|
||||||
|
planet->waterColor1 = ImportColor(json["waterColor1"]);
|
||||||
|
planet->waterColor2 = ImportColor(json["waterColor2"]);
|
||||||
|
planet->waterColor3 = ImportColor(json["waterColor3"]);
|
||||||
|
//landColors
|
||||||
|
planet->landColor1 = ImportColor(json["landColor1"]);
|
||||||
|
planet->landColor2 = ImportColor(json["landColor2"]);
|
||||||
|
planet->landColor3 = ImportColor(json["landColor3"]);
|
||||||
|
planet->landColor4 = ImportColor(json["landColor4"]);
|
||||||
|
//cloudColors
|
||||||
|
planet->cloudColor1 = ImportColor(json["cloudColor1"]);
|
||||||
|
planet->cloudColor2 = ImportColor(json["cloudColor2"]);
|
||||||
|
planet->cloudColor3 = ImportColor(json["cloudColor3"]);
|
||||||
|
planet->cloudColor4 = ImportColor(json["cloudColor4"]);
|
||||||
|
|
||||||
|
int moonCount = json["moonCount"];
|
||||||
|
for (int i = 0; i < moonCount; i++)
|
||||||
|
{
|
||||||
|
planet->moons.push_back(Moon::Load(json["moons"][i]));
|
||||||
|
}
|
||||||
|
|
||||||
|
//outposts
|
||||||
|
|
||||||
|
//satelites
|
||||||
|
|
||||||
|
return planet;
|
||||||
|
}
|
||||||
|
|
||||||
|
nlohmann::json Planet::Export()
|
||||||
|
{
|
||||||
|
using json = nlohmann::json;
|
||||||
|
|
||||||
|
json exp;
|
||||||
|
exp["name"] = name;
|
||||||
|
exp["id"] = to_string(id);
|
||||||
|
exp["seed"] = seed;
|
||||||
|
exp["distanceToStar"] = distanceToStar;
|
||||||
|
exp["scale"] = scale;
|
||||||
|
exp["smallScale"] = smallScale;
|
||||||
|
exp["rotation"] = rotation;
|
||||||
|
exp["landCutoff"] = landCutoff;
|
||||||
|
exp["cloudCover"] = cloudCover;
|
||||||
|
exp["stretch"] = stretch;
|
||||||
|
exp["cloudCurve"] = cloudCurve;
|
||||||
|
//waterColors
|
||||||
|
exp["waterColor1"] = ExportColor(waterColor1);
|
||||||
|
exp["waterColor2"] = ExportColor(waterColor2);
|
||||||
|
exp["waterColor3"] = ExportColor(waterColor3);
|
||||||
|
//landColors
|
||||||
|
exp["landColor1"] = ExportColor(landColor1);
|
||||||
|
exp["landColor2"] = ExportColor(landColor2);
|
||||||
|
exp["landColor3"] = ExportColor(landColor3);
|
||||||
|
exp["landColor4"] = ExportColor(landColor4);
|
||||||
|
//cloudColors
|
||||||
|
exp["cloudColor1"] = ExportColor(cloudColor1);
|
||||||
|
exp["cloudColor2"] = ExportColor(cloudColor2);
|
||||||
|
exp["cloudColor3"] = ExportColor(cloudColor3);
|
||||||
|
exp["cloudColor4"] = ExportColor(cloudColor4);
|
||||||
|
|
||||||
|
exp["moonCount"] = moons.size();
|
||||||
|
int i = 0;
|
||||||
|
for (auto &&moon : moons)
|
||||||
|
{
|
||||||
|
exp["moons"][i++] = moon->Export();
|
||||||
|
}
|
||||||
|
|
||||||
|
//outposts
|
||||||
|
|
||||||
|
//satelites
|
||||||
|
|
||||||
|
return exp;
|
||||||
|
}
|
||||||
|
|
||||||
|
float Planet::GetMaxMoonDistance()
|
||||||
|
{
|
||||||
|
float dist = 0;
|
||||||
|
|
||||||
|
for (auto &&moon : moons)
|
||||||
|
{
|
||||||
|
dist = std::max(dist, moon->distanceToPlanet);
|
||||||
|
}
|
||||||
|
|
||||||
|
return dist;
|
||||||
|
}
|
||||||
56
PlanetExplorerGameDemo/src/Elements/spaceElements/Planet.hpp
Normal file
56
PlanetExplorerGameDemo/src/Elements/spaceElements/Planet.hpp
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "Moon.hpp"
|
||||||
|
|
||||||
|
class Planet : public ISpace
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
string name = "Earth";
|
||||||
|
uuids::uuid id = uuids::uuid();//TSE::Base::GenerateRandomUUID();
|
||||||
|
|
||||||
|
float seed = 3.0f;
|
||||||
|
float distanceToStar = 10;
|
||||||
|
float scale = 5;
|
||||||
|
float smallScale = 1;
|
||||||
|
float rotation = 3.14f;
|
||||||
|
|
||||||
|
Color waterColor1 = Color::aqua;
|
||||||
|
Color waterColor2 = Color::Lerp(Color::aqua, Color::blue, 0.5f);
|
||||||
|
Color waterColor3 = Color::blue;
|
||||||
|
|
||||||
|
Color landColor1 = Color::green;
|
||||||
|
Color landColor2 = Color::Lerp(Color::green, {0,0.39f,0}, 0.33f);
|
||||||
|
Color landColor3 = Color::Lerp(Color::green, {0,0.39f,0}, 0.66f);
|
||||||
|
Color landColor4 = {0,0.39f,0};
|
||||||
|
float landCutoff = 0.25f;
|
||||||
|
|
||||||
|
Color cloudColor1 = Color::white;
|
||||||
|
Color cloudColor2 = Color::Lerp(Color::white, Color::gray, 0.33f);
|
||||||
|
Color cloudColor3 = Color::Lerp(Color::white, Color::gray, 0.66f);
|
||||||
|
Color cloudColor4 = Color::gray;
|
||||||
|
float cloudCover = 0.25f;
|
||||||
|
float stretch = 2;
|
||||||
|
float cloudCurve = 1.3f;
|
||||||
|
|
||||||
|
std::vector<Moon*> moons;
|
||||||
|
std::vector<Outpost*> outposts;
|
||||||
|
std::vector<Satelite*> satelites;
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::vector<void*> resources;
|
||||||
|
|
||||||
|
public:
|
||||||
|
Transformable* LoadSpace() override;
|
||||||
|
void UnloadSpace() override;
|
||||||
|
|
||||||
|
|
||||||
|
Transformable* create();
|
||||||
|
Transformable* createSmall();
|
||||||
|
void DeleteResources();
|
||||||
|
|
||||||
|
static Planet* Load(nlohmann::json json);
|
||||||
|
nlohmann::json Export();
|
||||||
|
|
||||||
|
private:
|
||||||
|
float GetMaxMoonDistance();
|
||||||
|
};
|
||||||
@@ -0,0 +1,140 @@
|
|||||||
|
#include "PlanetarySystem.hpp"
|
||||||
|
#include "BehaviourScripts/PlanetRotater.hpp"
|
||||||
|
#include "Utilities/MathFunctions.hpp"
|
||||||
|
#include "Utilities/Random.hpp"
|
||||||
|
#include "BehaviourScripts/GravityHolder.hpp"
|
||||||
|
#include "BehaviourScripts/SpaceController.hpp"
|
||||||
|
|
||||||
|
void PlanetarySystem::DeleteResources()
|
||||||
|
{
|
||||||
|
for (auto &&star : stars)
|
||||||
|
{
|
||||||
|
star->DeleteResources();
|
||||||
|
}
|
||||||
|
for (auto &&planet : planets)
|
||||||
|
{
|
||||||
|
planet->DeleteResources();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Transformable *PlanetarySystem::LoadSpace()
|
||||||
|
{
|
||||||
|
root = new Transformable(name);
|
||||||
|
|
||||||
|
if(stars.size() == 1)
|
||||||
|
{
|
||||||
|
Transformable* starObj = stars[0]->create();
|
||||||
|
starObj->SetParent(root);
|
||||||
|
starObj->position.z = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (auto &&planet : planets)
|
||||||
|
{
|
||||||
|
Transformable* planetObj = planet->createSmall();
|
||||||
|
planetObj->SetParent(root);
|
||||||
|
planetObj->position.x += planet->distanceToStar;
|
||||||
|
planetObj->AddBehaviourScript(new PlanetRotater(planet->distanceToStar));
|
||||||
|
Vector2 pos = rotateKeepDistance(Vector2::zero, {0, planet->distanceToStar}, GetRandomFloat(0, 360), planet->distanceToStar);
|
||||||
|
planetObj->position = {pos.x, pos.y, -1};
|
||||||
|
}
|
||||||
|
|
||||||
|
root->id = id;
|
||||||
|
|
||||||
|
float grvityWell = GetMaxPlanetDistance();
|
||||||
|
|
||||||
|
GravityHolder* holder = new GravityHolder(grvityWell + 4.0f);
|
||||||
|
holder->thisSpace = this;
|
||||||
|
holder->onEnter = &OnSpaceNoExit;
|
||||||
|
holder->onExit = &OnSpaceExit;
|
||||||
|
|
||||||
|
root->AddBehaviourScript(holder);
|
||||||
|
|
||||||
|
return root;
|
||||||
|
}
|
||||||
|
|
||||||
|
void PlanetarySystem::UnloadSpace()
|
||||||
|
{
|
||||||
|
DeleteResources();
|
||||||
|
root->SetParent(nullptr);
|
||||||
|
Transformable::HardDelete(root, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
PlanetarySystem *PlanetarySystem::Load(nlohmann::json json)
|
||||||
|
{
|
||||||
|
PlanetarySystem* system = new PlanetarySystem();
|
||||||
|
|
||||||
|
system->name = json["name"];
|
||||||
|
system->id = uuids::uuid::from_string(to_string(json["id"])).value_or(GenerateRandomUUID());
|
||||||
|
|
||||||
|
system->position = ImportVector2(json["position"]);
|
||||||
|
|
||||||
|
int starCount = json["starCount"];
|
||||||
|
for (int i = 0; i < starCount; i++)
|
||||||
|
{
|
||||||
|
system->stars.push_back(Star::Load(json["stars"][i]));
|
||||||
|
}
|
||||||
|
int planetCount = json["planetCount"];
|
||||||
|
for (int i = 0; i < planetCount; i++)
|
||||||
|
{
|
||||||
|
system->planets.push_back(Planet::Load(json["planets"][i]));
|
||||||
|
}
|
||||||
|
|
||||||
|
return system;
|
||||||
|
}
|
||||||
|
|
||||||
|
nlohmann::json PlanetarySystem::Export()
|
||||||
|
{
|
||||||
|
using json = nlohmann::json;
|
||||||
|
|
||||||
|
json exp;
|
||||||
|
exp["name"] = name;
|
||||||
|
exp["id"] = to_string(id);
|
||||||
|
exp["position"] = ExportVector2(position);
|
||||||
|
|
||||||
|
exp["starCount"] = stars.size();
|
||||||
|
int i = 0;
|
||||||
|
for (auto &&star : stars)
|
||||||
|
{
|
||||||
|
exp["stars"][i++] = star->Export();
|
||||||
|
}
|
||||||
|
exp["planetCount"] = planets.size();
|
||||||
|
i = 0;
|
||||||
|
for (auto &&planet : planets)
|
||||||
|
{
|
||||||
|
exp["planets"][i++] = planet->Export();
|
||||||
|
}
|
||||||
|
|
||||||
|
return exp;
|
||||||
|
}
|
||||||
|
|
||||||
|
Transformable *PlanetarySystem::createSmall()
|
||||||
|
{
|
||||||
|
if(stars.size() == 1)
|
||||||
|
{
|
||||||
|
Transformable* starObj = stars[0]->createSmall();
|
||||||
|
starObj->position.z = -1;
|
||||||
|
starObj->id = id;
|
||||||
|
|
||||||
|
GravityHolder* holder = new GravityHolder(stars[0]->smallScale);
|
||||||
|
|
||||||
|
holder->onEnter = &OnSpaceHover;
|
||||||
|
holder->onExit = &OnSpaceNoHover;
|
||||||
|
holder->thisSpace = this;
|
||||||
|
|
||||||
|
starObj->AddBehaviourScript(holder);
|
||||||
|
|
||||||
|
return starObj;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
float PlanetarySystem::GetMaxPlanetDistance()
|
||||||
|
{
|
||||||
|
float dist = 0;
|
||||||
|
|
||||||
|
for (auto &&planet : planets)
|
||||||
|
{
|
||||||
|
dist = std::max(dist, planet->distanceToStar);
|
||||||
|
}
|
||||||
|
|
||||||
|
return dist;
|
||||||
|
}
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "Planet.hpp"
|
||||||
|
#include "Asteroidbelt.hpp"
|
||||||
|
#include "Star.hpp"
|
||||||
|
|
||||||
|
class PlanetarySystem : public ISpace
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
string name = "";
|
||||||
|
uuids::uuid id = uuids::uuid();//TSE::Base::GenerateRandomUUID();
|
||||||
|
|
||||||
|
Vector2 position;
|
||||||
|
|
||||||
|
std::vector<Star*> stars;
|
||||||
|
std::vector<Planet*> planets;
|
||||||
|
|
||||||
|
public:
|
||||||
|
void DeleteResources();
|
||||||
|
|
||||||
|
Transformable* LoadSpace() override;
|
||||||
|
void UnloadSpace() override;
|
||||||
|
|
||||||
|
static PlanetarySystem* Load(nlohmann::json json);
|
||||||
|
nlohmann::json Export();
|
||||||
|
|
||||||
|
Transformable* createSmall();
|
||||||
|
|
||||||
|
private:
|
||||||
|
float GetMaxPlanetDistance();
|
||||||
|
};
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "Types.hpp"
|
||||||
|
#include "json.hpp"
|
||||||
|
|
||||||
|
class Satelite
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
TSE::string name = "";
|
||||||
|
float distanceToPlanet = 0;
|
||||||
|
};
|
||||||
219
PlanetExplorerGameDemo/src/Elements/spaceElements/Star.cpp
Normal file
219
PlanetExplorerGameDemo/src/Elements/spaceElements/Star.cpp
Normal file
@@ -0,0 +1,219 @@
|
|||||||
|
#include "Star.hpp"
|
||||||
|
|
||||||
|
Transformable *Star::create()
|
||||||
|
{
|
||||||
|
const float pixelsNormal = scale * 32;
|
||||||
|
|
||||||
|
Transformable* planetBase = new Transformable(name + "Blobs");
|
||||||
|
resources.push_back(planetBase);
|
||||||
|
Transformable* planetLand = new Transformable(name + "Base");
|
||||||
|
resources.push_back(planetLand);
|
||||||
|
Transformable* planetCloud = new Transformable(name + "Flairs");
|
||||||
|
resources.push_back(planetCloud);
|
||||||
|
|
||||||
|
Material* planetBaseMat = new Material("planetBlobsMat", ShaderRegistry::GetShader("Planet Shader"));
|
||||||
|
resources.push_back(planetBaseMat);
|
||||||
|
Material* planetLandMat = new Material("planetBaseMat", ShaderRegistry::GetShader("Planet Shader"));
|
||||||
|
resources.push_back(planetLandMat);
|
||||||
|
Material* planetCloudMat = new Material("planetFlairsMat", ShaderRegistry::GetShader("Planet Shader"));
|
||||||
|
resources.push_back(planetCloudMat);
|
||||||
|
|
||||||
|
//base:
|
||||||
|
planetLandMat->SetValue("planetColor1", baseColor1);
|
||||||
|
planetLandMat->SetValue("planetColor2", baseColor2);
|
||||||
|
planetLandMat->SetValue("planetColor3", baseColor3);
|
||||||
|
planetLandMat->SetValue("userValues2", baseColor4.ToVector4());
|
||||||
|
planetLandMat->SetValue("seed", seed);
|
||||||
|
planetLandMat->SetValue("pixels", pixelsNormal);
|
||||||
|
planetLandMat->SetValue("rotation", rotation);
|
||||||
|
planetLandMat->SetValue("layer", 40.0f);
|
||||||
|
//blobs:
|
||||||
|
const float scaleUp = 2.5f;
|
||||||
|
planetBaseMat->SetValue("planetColor1", blobColor);
|
||||||
|
planetBaseMat->SetValue("userValues1", Vector4(circleAmount, circleSize,0,0));
|
||||||
|
planetBaseMat->SetValue("seed", seed);
|
||||||
|
planetBaseMat->SetValue("pixels", pixelsNormal * scaleUp);
|
||||||
|
planetBaseMat->SetValue("rotation", rotation);
|
||||||
|
planetBaseMat->SetValue("layer", 41.0f);
|
||||||
|
|
||||||
|
planetLand->scale = Vector3(1 / scaleUp, 1 / scaleUp,1);
|
||||||
|
//Flairs:
|
||||||
|
planetCloudMat->SetValue("planetColor1", flairColor1);
|
||||||
|
planetCloudMat->SetValue("planetColor2", flairColor2);
|
||||||
|
planetCloudMat->SetValue("userValues1", Vector4(circleAmount, circleSize, scale, stormWidth));
|
||||||
|
planetCloudMat->SetValue("userValues2", Vector4(stormDitherWidth,0,0,0));
|
||||||
|
planetCloudMat->SetValue("seed", seed);
|
||||||
|
planetCloudMat->SetValue("pixels", pixelsNormal * scaleUp);
|
||||||
|
planetCloudMat->SetValue("rotation", rotation);
|
||||||
|
planetCloudMat->SetValue("layer", 42.0f);
|
||||||
|
|
||||||
|
planetLand->SetParent(planetBase);
|
||||||
|
planetCloud->SetParent(planetBase);
|
||||||
|
planetBase->scale = {scale * scaleUp,scale * scaleUp,1};
|
||||||
|
|
||||||
|
Mesh* planetMesh = new Mesh(Mesh::GetQuadMesh());
|
||||||
|
resources.push_back(planetMesh);
|
||||||
|
|
||||||
|
planetBase->AddBehaviourScript(new Renderable(planetBaseMat));
|
||||||
|
planetBase->AddBehaviourScript(new MeshContainer(planetMesh));
|
||||||
|
|
||||||
|
planetLand->AddBehaviourScript(new Renderable(planetLandMat));
|
||||||
|
planetLand->AddBehaviourScript(new MeshContainer(planetMesh));
|
||||||
|
|
||||||
|
planetCloud->AddBehaviourScript(new Renderable(planetCloudMat));
|
||||||
|
planetCloud->AddBehaviourScript(new MeshContainer(planetMesh));
|
||||||
|
|
||||||
|
return planetBase;
|
||||||
|
}
|
||||||
|
|
||||||
|
Transformable *Star::createSmall()
|
||||||
|
{
|
||||||
|
const float pixelsNormal = smallScale * 32;
|
||||||
|
|
||||||
|
Transformable* planetBase = new Transformable(name + "Blobs");
|
||||||
|
resources.push_back(planetBase);
|
||||||
|
Transformable* planetLand = new Transformable(name + "Base");
|
||||||
|
resources.push_back(planetLand);
|
||||||
|
Transformable* planetCloud = new Transformable(name + "Flairs");
|
||||||
|
resources.push_back(planetCloud);
|
||||||
|
|
||||||
|
Material* planetBaseMat = new Material("planetBlobsMat", ShaderRegistry::GetShader("Planet Shader"));
|
||||||
|
resources.push_back(planetBaseMat);
|
||||||
|
Material* planetLandMat = new Material("planetBaseMat", ShaderRegistry::GetShader("Planet Shader"));
|
||||||
|
resources.push_back(planetLandMat);
|
||||||
|
Material* planetCloudMat = new Material("planetFlairsMat", ShaderRegistry::GetShader("Planet Shader"));
|
||||||
|
resources.push_back(planetCloudMat);
|
||||||
|
|
||||||
|
//base:
|
||||||
|
planetBaseMat->SetValue("planetColor1", baseColor1);
|
||||||
|
planetBaseMat->SetValue("planetColor2", baseColor2);
|
||||||
|
planetBaseMat->SetValue("planetColor3", baseColor3);
|
||||||
|
planetBaseMat->SetValue("userValues2", baseColor4.ToVector4());
|
||||||
|
planetBaseMat->SetValue("seed", seed);
|
||||||
|
planetBaseMat->SetValue("pixels", pixelsNormal);
|
||||||
|
planetBaseMat->SetValue("rotation", rotation);
|
||||||
|
planetBaseMat->SetValue("layer", 40.0f);
|
||||||
|
//blobs:
|
||||||
|
// const float scaleUp = 2.5f;
|
||||||
|
// planetBaseMat->SetValue("planetColor1", blobColor);
|
||||||
|
// planetBaseMat->SetValue("userValues1", Vector4(circleAmount, circleSize,0,0));
|
||||||
|
// planetBaseMat->SetValue("seed", seed);
|
||||||
|
// planetBaseMat->SetValue("pixels", pixelsNormal * scaleUp);
|
||||||
|
// planetBaseMat->SetValue("rotation", rotation);
|
||||||
|
// planetBaseMat->SetValue("layer", 41.0f);
|
||||||
|
|
||||||
|
// planetLand->scale = Vector3(1 / scaleUp, 1 / scaleUp,1);
|
||||||
|
// //Flairs:
|
||||||
|
// planetCloudMat->SetValue("planetColor1", flairColor1);
|
||||||
|
// planetCloudMat->SetValue("planetColor2", flairColor2);
|
||||||
|
// planetCloudMat->SetValue("userValues1", Vector4(circleAmount, circleSize, scaleS, stormWidth));
|
||||||
|
// planetCloudMat->SetValue("userValues2", Vector4(stormDitherWidth,0,0,0));
|
||||||
|
// planetCloudMat->SetValue("seed", seed);
|
||||||
|
// planetCloudMat->SetValue("pixels", pixelsNormal * scaleUp);
|
||||||
|
// planetCloudMat->SetValue("rotation", rotation);
|
||||||
|
// planetCloudMat->SetValue("layer", 42.0f);
|
||||||
|
|
||||||
|
// planetLand->SetParent(planetBase);
|
||||||
|
// planetCloud->SetParent(planetBase);
|
||||||
|
|
||||||
|
Mesh* planetMesh = new Mesh(Mesh::GetQuadMesh());
|
||||||
|
resources.push_back(planetMesh);
|
||||||
|
|
||||||
|
for (auto &point : planetMesh->vertecies)
|
||||||
|
{
|
||||||
|
point = point * smallScale;
|
||||||
|
}
|
||||||
|
|
||||||
|
planetBase->AddBehaviourScript(new Renderable(planetBaseMat));
|
||||||
|
planetBase->AddBehaviourScript(new MeshContainer(planetMesh));
|
||||||
|
|
||||||
|
// planetLand->AddBehaviourScript(new Renderable(planetLandMat));
|
||||||
|
// planetLand->AddBehaviourScript(new MeshContainer(planetMesh));
|
||||||
|
|
||||||
|
// planetCloud->AddBehaviourScript(new Renderable(planetCloudMat));
|
||||||
|
// planetCloud->AddBehaviourScript(new MeshContainer(planetMesh));
|
||||||
|
|
||||||
|
return planetBase;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Star::DeleteResources()
|
||||||
|
{
|
||||||
|
|
||||||
|
Transformable* planetBase = (Transformable*)resources[0];
|
||||||
|
Transformable* planetLand = (Transformable*)resources[1];
|
||||||
|
Transformable* planetClouds = (Transformable*)resources[2];
|
||||||
|
Material* planetMat = (Material*)resources[3];
|
||||||
|
Material* landMat = (Material*)resources[4];
|
||||||
|
Material* cloudMat = (Material*)resources[5];
|
||||||
|
Mesh* planetMesh = (Mesh*)resources[6];
|
||||||
|
|
||||||
|
delete planetMesh;
|
||||||
|
delete cloudMat;
|
||||||
|
delete landMat;
|
||||||
|
delete planetMat;
|
||||||
|
Transformable::HardDelete(planetClouds, true);
|
||||||
|
Transformable::HardDelete(planetLand, true);
|
||||||
|
planetBase->SetParent(nullptr);
|
||||||
|
Transformable::HardDelete(planetBase, true);
|
||||||
|
|
||||||
|
resources.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
Star *Star::Load(nlohmann::json json)
|
||||||
|
{
|
||||||
|
Star* star;
|
||||||
|
|
||||||
|
star->name = json["name"];
|
||||||
|
star->id = uuids::uuid::from_string(to_string(json["id"])).value_or(GenerateRandomUUID());
|
||||||
|
star->seed = json["seed"];
|
||||||
|
star->scale = json["scale"];
|
||||||
|
star->smallScale = json["smallScale"];
|
||||||
|
star->rotation = json["rotation"];
|
||||||
|
star->circleAmount = json["circleAmount"];
|
||||||
|
star->circleSize = json["circleSize"];
|
||||||
|
star->stormWidth = json["stormWidth"];
|
||||||
|
star->stormDitherWidth = json["stormDitherWidth"];
|
||||||
|
star->scaleS = json["scaleS"];
|
||||||
|
|
||||||
|
star->baseColor1 = ImportColor(json["baseColor1"]);
|
||||||
|
star->baseColor2 = ImportColor(json["baseColor2"]);
|
||||||
|
star->baseColor3 = ImportColor(json["baseColor3"]);
|
||||||
|
star->baseColor4 = ImportColor(json["baseColor4"]);
|
||||||
|
|
||||||
|
star->blobColor = ImportColor(json["blobColor"]);
|
||||||
|
|
||||||
|
star->flairColor1 = ImportColor(json["flairColor1"]);
|
||||||
|
star->flairColor2 = ImportColor(json["flairColor2"]);
|
||||||
|
|
||||||
|
return star;
|
||||||
|
}
|
||||||
|
|
||||||
|
nlohmann::json Star::Export()
|
||||||
|
{
|
||||||
|
using json = nlohmann::json;
|
||||||
|
|
||||||
|
json exp;
|
||||||
|
exp["name"] = name;
|
||||||
|
exp["id"] = to_string(id);
|
||||||
|
exp["seed"] = seed;
|
||||||
|
exp["scale"] = scale;
|
||||||
|
exp["smallScale"] = smallScale;
|
||||||
|
exp["rotation"] = rotation;
|
||||||
|
exp["circleAmount"] = circleAmount;
|
||||||
|
exp["circleSize"] = circleSize;
|
||||||
|
exp["stormWidth"] = stormWidth;
|
||||||
|
exp["stormDitherWidth"] = stormDitherWidth;
|
||||||
|
exp["scaleS"] = scaleS;
|
||||||
|
|
||||||
|
exp["baseColor1"] = ExportColor(baseColor1);
|
||||||
|
exp["baseColor2"] = ExportColor(baseColor2);
|
||||||
|
exp["baseColor3"] = ExportColor(baseColor3);
|
||||||
|
exp["baseColor4"] = ExportColor(baseColor4);
|
||||||
|
|
||||||
|
exp["blobColor"] = ExportColor(blobColor);
|
||||||
|
|
||||||
|
exp["flairColor1"] = ExportColor(flairColor1);
|
||||||
|
exp["flairColor2"] = ExportColor(flairColor2);
|
||||||
|
|
||||||
|
return exp;
|
||||||
|
}
|
||||||
43
PlanetExplorerGameDemo/src/Elements/spaceElements/Star.hpp
Normal file
43
PlanetExplorerGameDemo/src/Elements/spaceElements/Star.hpp
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "Planet.hpp"
|
||||||
|
|
||||||
|
class Star
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
string name = "";
|
||||||
|
uuids::uuid id = uuids::uuid();//TSE::Base::GenerateRandomUUID();
|
||||||
|
|
||||||
|
float seed = 3.0f;
|
||||||
|
float scale = 4;
|
||||||
|
float smallScale = 1;
|
||||||
|
float rotation = 3.14f;
|
||||||
|
|
||||||
|
float circleAmount = 5;
|
||||||
|
float circleSize = 2;
|
||||||
|
|
||||||
|
float stormWidth = 0.3f;
|
||||||
|
float stormDitherWidth = 0.07f;
|
||||||
|
float scaleS = 1;
|
||||||
|
|
||||||
|
Color baseColor1 = Color::yellow;
|
||||||
|
Color baseColor2 = Color::Lerp(Color::yellow, Color::orange, 0.33f);
|
||||||
|
Color baseColor3 = Color::Lerp(Color::yellow, Color::orange, 0.66f);
|
||||||
|
Color baseColor4 = Color::orange;
|
||||||
|
|
||||||
|
Color blobColor = Color::Lerp(Color::yellow, Color::orange, 0.5f);
|
||||||
|
|
||||||
|
Color flairColor1 = Color::Lerp(Color::yellow, Color::orange, 0.3f);
|
||||||
|
Color flairColor2 = Color::Lerp(Color::yellow, Color::orange, 0.7f);
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::vector<void*> resources;
|
||||||
|
|
||||||
|
public:
|
||||||
|
Transformable* create();
|
||||||
|
Transformable* createSmall();
|
||||||
|
void DeleteResources();
|
||||||
|
|
||||||
|
static Star* Load(nlohmann::json json);
|
||||||
|
nlohmann::json Export();
|
||||||
|
};
|
||||||
195
PlanetExplorerGameDemo/src/Rendering/PlanetShader.cpp
Normal file
195
PlanetExplorerGameDemo/src/Rendering/PlanetShader.cpp
Normal file
@@ -0,0 +1,195 @@
|
|||||||
|
#include "PlanetShader.hpp"
|
||||||
|
#include "GL/gl3w.h"
|
||||||
|
#include "BehaviourScripts/Renderable.hpp"
|
||||||
|
#include "Color.hpp"
|
||||||
|
|
||||||
|
#define SHADER_VERTEX_INDEX 0
|
||||||
|
#define SHADER_COLOR_PLANET1_INDEX 1
|
||||||
|
#define SHADER_COLOR_PLANET2_INDEX 2
|
||||||
|
#define SHADER_COLOR_PLANET3_INDEX 3
|
||||||
|
#define SHADER_UV_INDEX 4
|
||||||
|
#define SHADER_SEED_INDEX 5
|
||||||
|
#define SHADER_PIXELS_INDEX 6
|
||||||
|
#define SHADER_ROTATION_INDEX 7
|
||||||
|
#define SHADER_LAYER_INDEX 8
|
||||||
|
#define SHADER_USER_VALUES1_INDEX 9
|
||||||
|
#define SHADER_USER_VALUES2_INDEX 10
|
||||||
|
#define SHADER_USER_VALUES3_INDEX 11
|
||||||
|
|
||||||
|
#define SHADER_PACKAGE_SIZE (sizeof(float) * (3 + 4 + 4 + 4 + 2 + 1 + 1 + 1 + 1 + 4 + 4 + 4))
|
||||||
|
|
||||||
|
PlanetShader* PlanetShader::instance = nullptr;
|
||||||
|
|
||||||
|
PlanetShader *PlanetShader::Instance()
|
||||||
|
{
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
void PlanetShader::Destroy()
|
||||||
|
{
|
||||||
|
if(instance != nullptr)
|
||||||
|
delete instance;
|
||||||
|
instance = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
void PlanetShader::Init(float width, float height)
|
||||||
|
{
|
||||||
|
using namespace TSE::GLFW;
|
||||||
|
std::vector<std::unique_ptr<ShaderPart>> parts;
|
||||||
|
parts.push_back(ShaderPart::LoadFromPath("./shaders/planetShader.vert", GL_VERTEX_SHADER));
|
||||||
|
parts.push_back(ShaderPart::LoadFromPath("./shaders/planetShader.frag", GL_FRAGMENT_SHADER));
|
||||||
|
instance = new PlanetShader(std::move(parts));
|
||||||
|
}
|
||||||
|
|
||||||
|
PlanetShader::PlanetShader(std::vector<std::unique_ptr<ShaderPart>> &&parts) : Shader(parts)
|
||||||
|
{
|
||||||
|
PackageSize = SHADER_PACKAGE_SIZE;
|
||||||
|
}
|
||||||
|
|
||||||
|
void PlanetShader::OnEnable() const
|
||||||
|
{
|
||||||
|
glEnableVertexAttribArray(SHADER_VERTEX_INDEX);
|
||||||
|
glVertexAttribPointer(SHADER_VERTEX_INDEX, 3, GL_FLOAT, false, SHADER_PACKAGE_SIZE, (void*)0);
|
||||||
|
glEnableVertexAttribArray(SHADER_COLOR_PLANET1_INDEX);
|
||||||
|
glVertexAttribPointer(SHADER_COLOR_PLANET1_INDEX, 4, GL_FLOAT, false, SHADER_PACKAGE_SIZE, (void*)(sizeof(float) * 3));
|
||||||
|
glEnableVertexAttribArray(SHADER_COLOR_PLANET2_INDEX);
|
||||||
|
glVertexAttribPointer(SHADER_COLOR_PLANET2_INDEX, 4, GL_FLOAT, false, SHADER_PACKAGE_SIZE, (void*)(sizeof(float) * 7));
|
||||||
|
glEnableVertexAttribArray(SHADER_COLOR_PLANET3_INDEX);
|
||||||
|
glVertexAttribPointer(SHADER_COLOR_PLANET3_INDEX, 4, GL_FLOAT, false, SHADER_PACKAGE_SIZE, (void*)(sizeof(float) * 11));
|
||||||
|
glEnableVertexAttribArray(SHADER_UV_INDEX);
|
||||||
|
glVertexAttribPointer(SHADER_UV_INDEX, 2, GL_FLOAT, false, SHADER_PACKAGE_SIZE, (void*)(sizeof(float) * 15));
|
||||||
|
glEnableVertexAttribArray(SHADER_SEED_INDEX);
|
||||||
|
glVertexAttribPointer(SHADER_SEED_INDEX, 1, GL_FLOAT, false, SHADER_PACKAGE_SIZE, (void*)(sizeof(float) * 17));
|
||||||
|
glEnableVertexAttribArray(SHADER_PIXELS_INDEX);
|
||||||
|
glVertexAttribPointer(SHADER_PIXELS_INDEX, 1, GL_FLOAT, false, SHADER_PACKAGE_SIZE, (void*)(sizeof(float) * 18));
|
||||||
|
glEnableVertexAttribArray(SHADER_ROTATION_INDEX);
|
||||||
|
glVertexAttribPointer(SHADER_ROTATION_INDEX, 1, GL_FLOAT, false, SHADER_PACKAGE_SIZE, (void*)(sizeof(float) * 19));
|
||||||
|
glEnableVertexAttribArray(SHADER_LAYER_INDEX);
|
||||||
|
glVertexAttribPointer(SHADER_LAYER_INDEX, 1, GL_FLOAT, false, SHADER_PACKAGE_SIZE, (void*)(sizeof(float) * 20));
|
||||||
|
glEnableVertexAttribArray(SHADER_USER_VALUES1_INDEX);
|
||||||
|
glVertexAttribPointer(SHADER_USER_VALUES1_INDEX, 4, GL_FLOAT, false, SHADER_PACKAGE_SIZE, (void*)(sizeof(float) * 21));
|
||||||
|
glEnableVertexAttribArray(SHADER_USER_VALUES2_INDEX);
|
||||||
|
glVertexAttribPointer(SHADER_USER_VALUES2_INDEX, 4, GL_FLOAT, false, SHADER_PACKAGE_SIZE, (void*)(sizeof(float) * 25));
|
||||||
|
glEnableVertexAttribArray(SHADER_USER_VALUES3_INDEX);
|
||||||
|
glVertexAttribPointer(SHADER_USER_VALUES3_INDEX, 4, GL_FLOAT, false, SHADER_PACKAGE_SIZE, (void*)(sizeof(float) * 29));
|
||||||
|
}
|
||||||
|
|
||||||
|
void PlanetShader::OnDisable() const
|
||||||
|
{
|
||||||
|
glDisableVertexAttribArray(SHADER_VERTEX_INDEX);
|
||||||
|
glDisableVertexAttribArray(SHADER_COLOR_PLANET1_INDEX);
|
||||||
|
glDisableVertexAttribArray(SHADER_COLOR_PLANET2_INDEX);
|
||||||
|
glDisableVertexAttribArray(SHADER_COLOR_PLANET3_INDEX);
|
||||||
|
glDisableVertexAttribArray(SHADER_UV_INDEX);
|
||||||
|
glDisableVertexAttribArray(SHADER_SEED_INDEX);
|
||||||
|
glDisableVertexAttribArray(SHADER_PIXELS_INDEX);
|
||||||
|
glDisableVertexAttribArray(SHADER_ROTATION_INDEX);
|
||||||
|
glDisableVertexAttribArray(SHADER_LAYER_INDEX);
|
||||||
|
glDisableVertexAttribArray(SHADER_USER_VALUES1_INDEX);
|
||||||
|
glDisableVertexAttribArray(SHADER_USER_VALUES2_INDEX);
|
||||||
|
glDisableVertexAttribArray(SHADER_USER_VALUES3_INDEX);
|
||||||
|
}
|
||||||
|
|
||||||
|
void PlanetShader::OnFlush()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void PlanetShader::OnDrawCall(int indexCount)
|
||||||
|
{
|
||||||
|
SetUniform("light_origin", &light_origion);
|
||||||
|
SetUniform("timeSpeed", timeSpeed);
|
||||||
|
SetUniform("ditherSize", ditherSize);
|
||||||
|
SetUniform("light_border_1", light_border_1);
|
||||||
|
SetUniform("light_border_2", light_border_2);
|
||||||
|
SetUniform("size", size);
|
||||||
|
SetUniform("octaves", octaves);
|
||||||
|
SetUniform("time", time);
|
||||||
|
SetUniform("should_dither", (should_dither ? 1 : 0));
|
||||||
|
|
||||||
|
glDrawElements(GL_TRIANGLES, indexCount, GL_UNSIGNED_SHORT, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
void PlanetShader::OnSubmit(const Transformable &t, float *&target, TransformationStack &stack, void (*restartDrawcall)(IRenderer &), IRenderer &rnd)
|
||||||
|
{
|
||||||
|
auto* r = dynamic_cast<Renderable*>(t.GetBehaviourScript(RENDERABLE));
|
||||||
|
if (!r) return;
|
||||||
|
|
||||||
|
const Vector3* verts = r->GetVertices();
|
||||||
|
const Vector2* uvs = r->GetUVs();
|
||||||
|
ushort vCount = r->GetVertexCount();
|
||||||
|
Color c1 = Color::white;
|
||||||
|
if(r->GetMaterial()->HasValue("planetColor1"))
|
||||||
|
c1 = r->GetMaterial()->GetValue<Color>("planetColor1");
|
||||||
|
Color c2 = Color::white;
|
||||||
|
if(r->GetMaterial()->HasValue("planetColor2"))
|
||||||
|
c2 = r->GetMaterial()->GetValue<Color>("planetColor2");
|
||||||
|
Color c3 = Color::white;
|
||||||
|
if(r->GetMaterial()->HasValue("planetColor3"))
|
||||||
|
c3 = r->GetMaterial()->GetValue<Color>("planetColor3");
|
||||||
|
float seed = 0;
|
||||||
|
if(r->GetMaterial()->HasValue("seed"))
|
||||||
|
seed = r->GetMaterial()->GetValue<float>("seed");
|
||||||
|
float pixels = 0;
|
||||||
|
if(r->GetMaterial()->HasValue("pixels"))
|
||||||
|
pixels = r->GetMaterial()->GetValue<float>("pixels");
|
||||||
|
float rotation = 0;
|
||||||
|
if(r->GetMaterial()->HasValue("rotation"))
|
||||||
|
rotation = r->GetMaterial()->GetValue<float>("rotation");
|
||||||
|
const float layer = r->GetMaterial()->GetValue<float>("layer");
|
||||||
|
Vector4 userVal1 = Vector4::zero;
|
||||||
|
if(r->GetMaterial()->HasValue("userValues1"))
|
||||||
|
userVal1 = r->GetMaterial()->GetValue<Vector4>("userValues1");
|
||||||
|
Vector4 userVal2 = Vector4::zero;
|
||||||
|
if(r->GetMaterial()->HasValue("userValues2"))
|
||||||
|
userVal2 = r->GetMaterial()->GetValue<Vector4>("userValues2");
|
||||||
|
Vector4 userVal3 = Vector4::zero;
|
||||||
|
if(r->GetMaterial()->HasValue("userValues3"))
|
||||||
|
userVal3 = r->GetMaterial()->GetValue<Vector4>("userValues3");
|
||||||
|
Matrix4x4 matr = t.GetLocalMatrix();
|
||||||
|
|
||||||
|
stack.Push(matr);
|
||||||
|
const Matrix4x4& top = stack.Top();
|
||||||
|
|
||||||
|
//Todo transformable.lastmatrix hier ergänzen
|
||||||
|
|
||||||
|
for (ushort i = 0; i < vCount; i++) {
|
||||||
|
Vector3 p = top * verts[i];
|
||||||
|
Vector2 uv = uvs[i];
|
||||||
|
*target++ = p.x;
|
||||||
|
*target++ = p.y;
|
||||||
|
*target++ = p.z;
|
||||||
|
*target++ = c1.r;
|
||||||
|
*target++ = c1.g;
|
||||||
|
*target++ = c1.b;
|
||||||
|
*target++ = c1.a;
|
||||||
|
*target++ = c2.r;
|
||||||
|
*target++ = c2.g;
|
||||||
|
*target++ = c2.b;
|
||||||
|
*target++ = c2.a;
|
||||||
|
*target++ = c3.r;
|
||||||
|
*target++ = c3.g;
|
||||||
|
*target++ = c3.b;
|
||||||
|
*target++ = c3.a;
|
||||||
|
*target++ = uv.x;
|
||||||
|
*target++ = uv.y;
|
||||||
|
*target++ = seed;
|
||||||
|
*target++ = pixels;
|
||||||
|
*target++ = rotation;
|
||||||
|
*target++ = layer;
|
||||||
|
*target++ = userVal1.x;
|
||||||
|
*target++ = userVal1.y;
|
||||||
|
*target++ = userVal1.z;
|
||||||
|
*target++ = userVal1.w;
|
||||||
|
*target++ = userVal2.x;
|
||||||
|
*target++ = userVal2.y;
|
||||||
|
*target++ = userVal2.z;
|
||||||
|
*target++ = userVal2.w;
|
||||||
|
*target++ = userVal3.x;
|
||||||
|
*target++ = userVal3.y;
|
||||||
|
*target++ = userVal3.z;
|
||||||
|
*target++ = userVal3.w;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
stack.Pop();
|
||||||
|
}
|
||||||
36
PlanetExplorerGameDemo/src/Rendering/PlanetShader.hpp
Normal file
36
PlanetExplorerGameDemo/src/Rendering/PlanetShader.hpp
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "shader/Shader.hpp"
|
||||||
|
|
||||||
|
using namespace TSE;
|
||||||
|
using namespace TSE::GLFW;
|
||||||
|
|
||||||
|
class PlanetShader : public Shader
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
static PlanetShader* instance;
|
||||||
|
|
||||||
|
public:
|
||||||
|
Vector2 light_origion = {0.39f, 0.61f};
|
||||||
|
float timeSpeed = 0.1f; //range(0.0f, 1.0f);
|
||||||
|
float ditherSize = 2.0f; //range(0.0f, 10.0f);
|
||||||
|
float light_border_1 = 0.4f; //range(0.0f, 1.0f);
|
||||||
|
float light_border_2 = 0.6f; //range(0.0f, 1.0f);
|
||||||
|
float size = 10;
|
||||||
|
int octaves = 1; //range(0, 20);
|
||||||
|
float time = 0.0f;
|
||||||
|
bool should_dither = true;
|
||||||
|
|
||||||
|
public:
|
||||||
|
static PlanetShader* Instance();
|
||||||
|
static void Destroy();
|
||||||
|
static void Init(float width, float height);
|
||||||
|
PlanetShader(std::vector<std::unique_ptr<ShaderPart>>&& parts);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void OnEnable() const override;
|
||||||
|
void OnDisable() const override;
|
||||||
|
void OnFlush() override;
|
||||||
|
void OnDrawCall(int indexCount) override;
|
||||||
|
void OnSubmit(const Transformable& t, float*& target, TransformationStack& stack, void (*restartDrawcall)(IRenderer&), IRenderer& rnd) override;
|
||||||
|
};
|
||||||
95
PlanetExplorerGameDemo/src/Utilities/CharacterCreator.cpp
Normal file
95
PlanetExplorerGameDemo/src/Utilities/CharacterCreator.cpp
Normal file
@@ -0,0 +1,95 @@
|
|||||||
|
#include "CharacterCreator.hpp"
|
||||||
|
#include "BehaviourScripts/Camera.hpp"
|
||||||
|
#include "elements/Material.hpp"
|
||||||
|
#include "BehaviourScripts/Renderable.hpp"
|
||||||
|
#include "BehaviourScripts/Image.hpp"
|
||||||
|
#include "BehaviourScripts/MeshContainer.hpp"
|
||||||
|
#include "Color.hpp"
|
||||||
|
#include "Elements/TextureIDMap.hpp"
|
||||||
|
#include "elements/ShaderRegistry.hpp"
|
||||||
|
#include "BehaviourScripts/characterController/CameraLerp.hpp"
|
||||||
|
#include "TextureHandler.hpp"
|
||||||
|
|
||||||
|
using namespace TSE;
|
||||||
|
|
||||||
|
void MakeCamera(Scene *scene, IWindow *wnd)
|
||||||
|
{
|
||||||
|
Transformable* testobjekt = new Transformable("MainCamera");
|
||||||
|
|
||||||
|
Camera* cam = new Camera();
|
||||||
|
cam->SetRenderScale(256);
|
||||||
|
cam->SetRenderTarget(wnd);
|
||||||
|
testobjekt->AddBehaviourScript(cam);
|
||||||
|
|
||||||
|
Layer* camLayer = new Layer("cam");
|
||||||
|
|
||||||
|
camLayer->AddTransformable(testobjekt);
|
||||||
|
|
||||||
|
scene->AddLayer(camLayer);
|
||||||
|
cam->OnResize(wnd->GetSize().x, wnd->GetSize().y, wnd);
|
||||||
|
}
|
||||||
|
|
||||||
|
Transformable* MakeTile(Vector2 tile_pos, Vector2& position, Material* mat, std::string name = "")
|
||||||
|
{
|
||||||
|
Transformable* tile = nullptr;
|
||||||
|
if(name.empty())
|
||||||
|
{
|
||||||
|
tile = new Transformable("tile(" + std::to_string(position.x) + "|" + std::to_string(position.y) + ")");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
tile = new Transformable(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
tile->SetPosition(position);
|
||||||
|
|
||||||
|
Renderable* renderable = new Renderable(mat);
|
||||||
|
tile->AddBehaviourScript(renderable);
|
||||||
|
|
||||||
|
Mesh* mesh = new Mesh(Mesh::GetQuadMesh());
|
||||||
|
MeshContainer* container = new MeshContainer(mesh);
|
||||||
|
tile->AddBehaviourScript(container);
|
||||||
|
|
||||||
|
Image* img = new Image();
|
||||||
|
tile->AddBehaviourScript(img);
|
||||||
|
Sprite* spr = new Sprite();
|
||||||
|
TextureHandler::mainSet->GetSpriteAt(tile_pos, *spr);
|
||||||
|
img->SetSprite(*spr);
|
||||||
|
|
||||||
|
return tile;
|
||||||
|
}
|
||||||
|
|
||||||
|
CharacterController *MakePlayer(Scene *scene)
|
||||||
|
{
|
||||||
|
Transformable* player = new Transformable("Player");
|
||||||
|
CharacterController* cc = (CharacterController*)player->AddBehaviourScript(new CharacterController());
|
||||||
|
|
||||||
|
Material* mat = new Material("DungenMat", ShaderRegistry::GetShader("Basic Unlit Texture Shader"));
|
||||||
|
mat->SetValue<Color>("mainColor", Color::white);
|
||||||
|
|
||||||
|
Vector2 zero;
|
||||||
|
Transformable* playerUI = MakeTile(BASE_SHIP, zero, mat, "BaseShip");
|
||||||
|
Transformable* playerUIExrta1 = MakeTile(BASE_SHIP_BOOSTER1, zero, mat, "BASE_SHIP_BOOSTER1");
|
||||||
|
Transformable* playerUIExrta2 = MakeTile(BASE_SHIP_EMP, zero, mat, "BASE_SHIP_EMP");
|
||||||
|
Transformable* playerUIExrta3 = MakeTile(BASE_SHIP_ROCKET_LAUNCHER, zero, mat, "BASE_SHIP_ROCKET_LAUNCHER");
|
||||||
|
Transformable* playerUIExrta4 = MakeTile(BASE_SHIP_BOOSTER2, zero, mat, "BASE_SHIP_BOOSTER2");
|
||||||
|
Transformable* playerUIExrta5 = MakeTile(BASE_SHIP_LASER, zero, mat, "BASE_SHIP_LASER");
|
||||||
|
Transformable* playerUIExrta6 = MakeTile(BASE_SHIP_ROCKET_LEFT, zero, mat, "BASE_SHIP_ROCKET_LEFT");
|
||||||
|
Transformable* playerUIExrta7 = MakeTile(BASE_SHIP_ROCKET_RIGHT, zero, mat, "BASE_SHIP_ROCKET_RIGHT");
|
||||||
|
playerUI->SetParent(player);
|
||||||
|
playerUIExrta1->SetParent(player);
|
||||||
|
playerUIExrta2->SetParent(player);
|
||||||
|
playerUIExrta3->SetParent(player);
|
||||||
|
playerUIExrta4->SetParent(player);
|
||||||
|
playerUIExrta5->SetParent(player);
|
||||||
|
playerUIExrta6->SetParent(player);
|
||||||
|
playerUIExrta7->SetParent(player);
|
||||||
|
|
||||||
|
Camera::mainCamera->baseObject->AddBehaviourScript(new CameraLerp(player));
|
||||||
|
|
||||||
|
|
||||||
|
Layer* playerLayer = new Layer("Player");
|
||||||
|
playerLayer->AddTransformable(player);
|
||||||
|
scene->AddLayer(playerLayer);
|
||||||
|
return cc;
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "BehaviourScripts/characterController/CharacterController.hpp"
|
||||||
|
#include "elements/Scene.hpp"
|
||||||
|
|
||||||
|
void MakeCamera(TSE::Scene* scene, TSE::IWindow* wnd);
|
||||||
|
CharacterController* MakePlayer(TSE::Scene* scene);
|
||||||
332
PlanetExplorerGameDemo/src/Utilities/GalaxyGenerator.cpp
Normal file
332
PlanetExplorerGameDemo/src/Utilities/GalaxyGenerator.cpp
Normal file
@@ -0,0 +1,332 @@
|
|||||||
|
#include "GalaxyGenerator.hpp"
|
||||||
|
#include "Elements/SpaceNameRegistry.hpp"
|
||||||
|
#include "MathF.hpp"
|
||||||
|
|
||||||
|
Color HSVtoRGB(float h, float s, float v)
|
||||||
|
{
|
||||||
|
float c = v * s;
|
||||||
|
float x = c * (1 - std::fabs(fmod(h / 60.0f, 2) - 1));
|
||||||
|
float m = v - c;
|
||||||
|
float r, g, b;
|
||||||
|
if (h < 60) { r = c; g = x; b = 0; }
|
||||||
|
else if (h < 120) { r = x; g = c; b = 0; }
|
||||||
|
else if (h < 180) { r = 0; g = c; b = x; }
|
||||||
|
else if (h < 240) { r = 0; g = x; b = c; }
|
||||||
|
else if (h < 300) { r = x; g = 0; b = c; }
|
||||||
|
else { r = c; g = 0; b = x; }
|
||||||
|
Color res = {(r + m), (g + m), (b + m), 1};
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
Color HSVtoRGB(Color col)
|
||||||
|
{
|
||||||
|
float c = col.b * col.g;
|
||||||
|
float x = c * (1 - std::fabs(fmod(col.r / 60.0f, 2) - 1));
|
||||||
|
float m = col.b - c;
|
||||||
|
float r, g, b;
|
||||||
|
if (col.r < 60) { r = c; g = x; b = 0; }
|
||||||
|
else if (col.r < 120) { r = x; g = c; b = 0; }
|
||||||
|
else if (col.r < 180) { r = 0; g = c; b = x; }
|
||||||
|
else if (col.r < 240) { r = 0; g = x; b = c; }
|
||||||
|
else if (col.r < 300) { r = x; g = 0; b = c; }
|
||||||
|
else { r = c; g = 0; b = x; }
|
||||||
|
Color res = {(r + m), (g + m), (b + m), col.a};
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
LocalCluster *GalaxyGenerator::GenerateCluster(int seed)
|
||||||
|
{
|
||||||
|
InitRandom(seed);
|
||||||
|
|
||||||
|
LocalCluster* cluster = new LocalCluster();
|
||||||
|
|
||||||
|
int galaxyCount = GetRandomInt(2, 4);
|
||||||
|
for (int g = 0; g < galaxyCount; g++)
|
||||||
|
{
|
||||||
|
Galaxy* gal = GenerateGalaxy();
|
||||||
|
cluster->galaxies.push_back(gal);
|
||||||
|
}
|
||||||
|
|
||||||
|
return cluster;
|
||||||
|
}
|
||||||
|
|
||||||
|
Color GalaxyGenerator::GetRandomBrightColor()
|
||||||
|
{
|
||||||
|
float h = GetRandomFloat(0.0f, 360.0f);
|
||||||
|
float s = GetRandomFloat(0.8f, 1.0f);
|
||||||
|
float v = GetRandomFloat(0.6f, 0.8f);
|
||||||
|
|
||||||
|
return Color(h,s,v,1);
|
||||||
|
}
|
||||||
|
|
||||||
|
Color GalaxyGenerator::AddLightShifts(Color &c)
|
||||||
|
{
|
||||||
|
float hp = GetRandomFloat(-2.5f, 2.5f);
|
||||||
|
float sp = GetRandomFloat(-0.15f, 0.15f);
|
||||||
|
float vp = GetRandomFloat(-0.15f, 0.15f);
|
||||||
|
|
||||||
|
Color res = {c.r + hp, c.g + sp, c.b + vp, c.a};
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
Star *GalaxyGenerator::GenerateStar()
|
||||||
|
{
|
||||||
|
Star* star = new Star();
|
||||||
|
|
||||||
|
//name
|
||||||
|
star->id = GetRandomUuid();
|
||||||
|
star->seed = GetRandomFloat(1.0f, 10.0f);
|
||||||
|
star->scale = GetRandomFloat(4.0f, 5.0f);
|
||||||
|
star->smallScale = star->scale / 10.0f;
|
||||||
|
star->rotation = GetRandomFloat(0, 2 * TSE_PI);
|
||||||
|
|
||||||
|
Color baseColor = Color(GetRandomFloat(20.0f, 55.0f), GetRandomFloat(0.7f, 0.85f), GetRandomFloat(0.8f, 1.0f), 1);
|
||||||
|
|
||||||
|
star->baseColor1 = HSVtoRGB(AddLightShifts(baseColor));
|
||||||
|
star->baseColor2 = HSVtoRGB(AddLightShifts(baseColor));
|
||||||
|
star->baseColor3 = HSVtoRGB(AddLightShifts(baseColor));
|
||||||
|
star->baseColor4 = HSVtoRGB(AddLightShifts(baseColor));
|
||||||
|
|
||||||
|
star->blobColor = HSVtoRGB(AddLightShifts(baseColor));
|
||||||
|
|
||||||
|
star->flairColor1 = HSVtoRGB(AddLightShifts(baseColor));
|
||||||
|
star->flairColor2 = HSVtoRGB(AddLightShifts(baseColor));
|
||||||
|
|
||||||
|
return star;
|
||||||
|
}
|
||||||
|
|
||||||
|
float perceivedBrightnessHSV(const Color& c) {
|
||||||
|
// dunkle, satte Farben wirken dunkler
|
||||||
|
return c.b * (1.0f - 0.5f * c.g);
|
||||||
|
}
|
||||||
|
|
||||||
|
void sortByPerceivedBrightness(std::vector<Color>& colors) {
|
||||||
|
std::sort(colors.begin(), colors.end(), [](const Color& a, const Color& b) {
|
||||||
|
return perceivedBrightnessHSV(a) < perceivedBrightnessHSV(b);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
Planet *GalaxyGenerator::GeneratePlanet(float distanceToStar)
|
||||||
|
{
|
||||||
|
Planet* planet = new Planet();
|
||||||
|
|
||||||
|
//name
|
||||||
|
planet->id = GetRandomUuid();
|
||||||
|
planet->seed = GetRandomFloat(1.0f, 10.0f);
|
||||||
|
planet->distanceToStar = distanceToStar;
|
||||||
|
planet->scale = GetRandomFloat(4.5f, 5.5f);
|
||||||
|
planet->smallScale = planet->scale / 5.0f;
|
||||||
|
planet->rotation = GetRandomFloat(3.0f, 3.28f);
|
||||||
|
planet->landCutoff = GetRandomFloat(0.2f, 0.4f);
|
||||||
|
|
||||||
|
Color BaseColor = {GetRandomFloat(190.0f, 270.0f), GetRandomFloat(0.55f, 1.0f), GetRandomFloat(0.55f, 1.0f), 1};
|
||||||
|
|
||||||
|
std::vector<Color> colorVector;
|
||||||
|
colorVector.push_back(AddLightShifts(BaseColor));
|
||||||
|
colorVector.push_back(AddLightShifts(BaseColor));
|
||||||
|
colorVector.push_back(AddLightShifts(BaseColor));
|
||||||
|
sortByPerceivedBrightness(colorVector);
|
||||||
|
|
||||||
|
planet->waterColor1 = HSVtoRGB(colorVector[2]);
|
||||||
|
planet->waterColor2 = HSVtoRGB(colorVector[1]);
|
||||||
|
planet->waterColor3 = HSVtoRGB(colorVector[0]);
|
||||||
|
|
||||||
|
BaseColor = {GetRandomFloat(90.0f, 140.0f), GetRandomFloat(0.75f, 1.0f), GetRandomFloat(0.2f, 0.8f), 1};
|
||||||
|
|
||||||
|
colorVector.clear();
|
||||||
|
colorVector.push_back(AddLightShifts(BaseColor));
|
||||||
|
colorVector.push_back(AddLightShifts(BaseColor));
|
||||||
|
colorVector.push_back(AddLightShifts(BaseColor));
|
||||||
|
colorVector.push_back(AddLightShifts(BaseColor));
|
||||||
|
sortByPerceivedBrightness(colorVector);
|
||||||
|
|
||||||
|
planet->landColor1 = HSVtoRGB(colorVector[3]);
|
||||||
|
planet->landColor2 = HSVtoRGB(colorVector[2]);
|
||||||
|
planet->landColor3 = HSVtoRGB(colorVector[1]);
|
||||||
|
planet->landColor4 = HSVtoRGB(colorVector[0]);
|
||||||
|
|
||||||
|
BaseColor = {GetRandomFloat(0.0f, 360.0f), GetRandomFloat(0.0f, 0.20f), GetRandomFloat(0.9f, 1.0f), 1};
|
||||||
|
|
||||||
|
colorVector.clear();
|
||||||
|
colorVector.push_back(AddLightShifts(BaseColor));
|
||||||
|
colorVector.push_back(AddLightShifts(BaseColor));
|
||||||
|
colorVector.push_back(AddLightShifts(BaseColor));
|
||||||
|
colorVector.push_back(AddLightShifts(BaseColor));
|
||||||
|
sortByPerceivedBrightness(colorVector);
|
||||||
|
|
||||||
|
planet->cloudColor1 = HSVtoRGB(colorVector[3]);
|
||||||
|
planet->cloudColor2 = HSVtoRGB(colorVector[2]);
|
||||||
|
planet->cloudColor3 = HSVtoRGB(colorVector[1]);
|
||||||
|
planet->cloudColor4 = HSVtoRGB(colorVector[0]);
|
||||||
|
|
||||||
|
int moonCount = GetRandomInt(0,2);
|
||||||
|
float distanceToPlanet = 4;
|
||||||
|
for (int p = 0; p < moonCount; p++)
|
||||||
|
{
|
||||||
|
distanceToPlanet += GetRandomFloat(2.0f, 4.0f);
|
||||||
|
Moon* moon = GenerateMoon(distanceToPlanet);
|
||||||
|
moon->parentSpace = planet;
|
||||||
|
planet->moons.push_back(moon);
|
||||||
|
}
|
||||||
|
|
||||||
|
return planet;
|
||||||
|
}
|
||||||
|
|
||||||
|
Moon *GalaxyGenerator::GenerateMoon(float distanceToPlanet)
|
||||||
|
{
|
||||||
|
Moon* moon = new Moon();
|
||||||
|
|
||||||
|
//name
|
||||||
|
moon->id = GetRandomUuid();
|
||||||
|
moon->seed = GetRandomFloat(1.0f, 10.0f);
|
||||||
|
moon->distanceToPlanet = distanceToPlanet;
|
||||||
|
moon->scale = GetRandomFloat(2.5f, 3.5f);
|
||||||
|
moon->smallScale = moon->scale / 5.0f;
|
||||||
|
moon->rotation = GetRandomFloat(3.0f, 3.28f);
|
||||||
|
|
||||||
|
Color BaseColor = {GetRandomFloat(0.0f, 360.0f), GetRandomFloat(0.25f, 0.35f), GetRandomFloat(0.35f, 0.8f), 1};
|
||||||
|
|
||||||
|
std::vector<Color> colorVector;
|
||||||
|
colorVector.push_back(AddLightShifts(BaseColor));
|
||||||
|
colorVector.push_back(AddLightShifts(BaseColor));
|
||||||
|
colorVector.push_back(AddLightShifts(BaseColor));
|
||||||
|
sortByPerceivedBrightness(colorVector);
|
||||||
|
|
||||||
|
moon->baseColor1 = HSVtoRGB(colorVector[2]);
|
||||||
|
moon->baseColor2 = HSVtoRGB(colorVector[1]);
|
||||||
|
moon->baseColor3 = HSVtoRGB(colorVector[0]);
|
||||||
|
|
||||||
|
colorVector.clear();
|
||||||
|
colorVector.push_back(AddLightShifts(BaseColor));
|
||||||
|
colorVector.push_back(AddLightShifts(BaseColor));
|
||||||
|
sortByPerceivedBrightness(colorVector);
|
||||||
|
|
||||||
|
moon->craterColor1 = HSVtoRGB(colorVector[1]);
|
||||||
|
moon->craterColor2 = HSVtoRGB(colorVector[0]);
|
||||||
|
|
||||||
|
return moon;
|
||||||
|
}
|
||||||
|
|
||||||
|
Galaxy *GalaxyGenerator::GenerateGalaxy()
|
||||||
|
{
|
||||||
|
Galaxy* gal = new Galaxy();
|
||||||
|
|
||||||
|
gal->name = galaxyNames[GetRandomInt(0, galaxyNames.size() - 1)];
|
||||||
|
gal->id = GetRandomUuid();
|
||||||
|
//position
|
||||||
|
gal->seed = GetRandomFloat(1.0f, 10.0f);
|
||||||
|
gal->scale = GetRandomFloat(2.0f, 4.0f);
|
||||||
|
gal->rotation += GetRandomFloat(-0.5f, 0.5f);
|
||||||
|
|
||||||
|
gal->tilt += GetRandomFloat(-0.5f, 0.5f);
|
||||||
|
gal->layerHeight += GetRandomFloat(-0.1f, 0.1f);
|
||||||
|
gal->zoom += GetRandomFloat(-0.3f, 0.3f);
|
||||||
|
gal->swirl += GetRandomFloat(-2.0f, 2.0f);
|
||||||
|
|
||||||
|
Color BaseColor = GetRandomBrightColor();
|
||||||
|
|
||||||
|
gal->galaxyColor1 = HSVtoRGB(AddLightShifts(BaseColor));
|
||||||
|
gal->galaxyColor2 = HSVtoRGB(AddLightShifts(BaseColor));
|
||||||
|
gal->galaxyColor3 = HSVtoRGB(AddLightShifts(BaseColor));
|
||||||
|
gal->galaxyColor4 = HSVtoRGB(AddLightShifts(BaseColor));
|
||||||
|
gal->galaxyColor5 = HSVtoRGB(AddLightShifts(BaseColor));
|
||||||
|
|
||||||
|
const int numArms = 5;
|
||||||
|
const float armSeparationDistance = 2 * TSE_PI / numArms;
|
||||||
|
const float armOffsetMax = 0.5f;
|
||||||
|
const float rotationFactor = 5;
|
||||||
|
const float randomOffsetXY = 0.02f;
|
||||||
|
|
||||||
|
|
||||||
|
int systemCount = GetRandomInt(5000, 10000);
|
||||||
|
for (int s = 0; s < systemCount; s++)
|
||||||
|
{
|
||||||
|
float distance = GetRandomFloat(2, 10);
|
||||||
|
distance = pow(distance, 2);
|
||||||
|
|
||||||
|
float angle = GetRandomFloat(0, 1) * 2 * TSE_PI;
|
||||||
|
float armOffset = GetRandomFloat(0, 1) * armOffsetMax;
|
||||||
|
armOffset = armOffset - armOffsetMax / 2;
|
||||||
|
armOffset = armOffset * (1 / distance);
|
||||||
|
|
||||||
|
float squaredArmOffset = pow(armOffset, 2);
|
||||||
|
if(armOffset < 0)
|
||||||
|
squaredArmOffset = squaredArmOffset * -1;
|
||||||
|
armOffset = squaredArmOffset;
|
||||||
|
|
||||||
|
float rotation = distance * rotationFactor;
|
||||||
|
|
||||||
|
angle = (int)(angle / armSeparationDistance) * armSeparationDistance + armOffset + rotation;
|
||||||
|
|
||||||
|
float starX = cos(angle) * distance;
|
||||||
|
float starY = sin(angle) * distance;
|
||||||
|
|
||||||
|
float randomOffsetX = GetRandomFloat(0, 1) * randomOffsetXY;
|
||||||
|
float randomOffsetY = GetRandomFloat(0, 1) * randomOffsetXY;
|
||||||
|
|
||||||
|
starX += randomOffsetX;
|
||||||
|
starY += randomOffsetY;
|
||||||
|
|
||||||
|
PlanetarySystem* system = GenerateSystem();
|
||||||
|
system->position = {starX, starY};
|
||||||
|
system->parentSpace = gal;
|
||||||
|
gal->systems.push_back(system);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//black Holes
|
||||||
|
|
||||||
|
return gal;
|
||||||
|
}
|
||||||
|
|
||||||
|
PlanetarySystem *GalaxyGenerator::GenerateSystem()
|
||||||
|
{
|
||||||
|
PlanetarySystem* ps = new PlanetarySystem();
|
||||||
|
|
||||||
|
//name
|
||||||
|
ps->id = GetRandomUuid();
|
||||||
|
//position
|
||||||
|
|
||||||
|
//---stars---
|
||||||
|
|
||||||
|
int starCount = GetRandomInt(1,3);
|
||||||
|
|
||||||
|
Star* star = GenerateStar();
|
||||||
|
ps->stars.push_back(star);
|
||||||
|
|
||||||
|
//---Planets---
|
||||||
|
|
||||||
|
int planetCount = GetRandomInt(0,6);
|
||||||
|
float distanceToStar = 4;
|
||||||
|
for (int p = 0; p < planetCount; p++)
|
||||||
|
{
|
||||||
|
distanceToStar += GetRandomFloat(2.0f, 4.0f);
|
||||||
|
Planet* planet = GeneratePlanet(distanceToStar);
|
||||||
|
planet->parentSpace = ps;
|
||||||
|
ps->planets.push_back(planet);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ps;
|
||||||
|
}
|
||||||
|
|
||||||
|
void GalaxyGenerator::InitRandom(int seed)
|
||||||
|
{
|
||||||
|
rng = std::mt19937(seed);
|
||||||
|
uuidRnd = uuids::uuid_random_generator(rng);
|
||||||
|
}
|
||||||
|
|
||||||
|
float GalaxyGenerator::GetRandomFloat(float from, float to)
|
||||||
|
{
|
||||||
|
std::uniform_real_distribution<float> dist(from, to);
|
||||||
|
return dist(rng);
|
||||||
|
}
|
||||||
|
|
||||||
|
int GalaxyGenerator::GetRandomInt(int from, int to)
|
||||||
|
{
|
||||||
|
std::uniform_int_distribution<> dist(from, to);
|
||||||
|
return dist(rng);
|
||||||
|
}
|
||||||
|
|
||||||
|
uuids::uuid GalaxyGenerator::GetRandomUuid()
|
||||||
|
{
|
||||||
|
return uuidRnd();
|
||||||
|
}
|
||||||
30
PlanetExplorerGameDemo/src/Utilities/GalaxyGenerator.hpp
Normal file
30
PlanetExplorerGameDemo/src/Utilities/GalaxyGenerator.hpp
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <random>
|
||||||
|
#include "Color.hpp"
|
||||||
|
#include "uuid.h"
|
||||||
|
#include "Elements/spaceElements/LocalCluster.hpp"
|
||||||
|
|
||||||
|
class GalaxyGenerator
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
inline static std::mt19937 rng = std::mt19937();
|
||||||
|
inline static uuids::uuid_random_generator uuidRnd = uuids::uuid_random_generator(rng);
|
||||||
|
|
||||||
|
public:
|
||||||
|
static LocalCluster* GenerateCluster(int seed);
|
||||||
|
|
||||||
|
private:
|
||||||
|
static Color GetRandomBrightColor();
|
||||||
|
static Color AddLightShifts(Color& c);
|
||||||
|
static Star* GenerateStar();
|
||||||
|
static Planet* GeneratePlanet(float distanceToStar);
|
||||||
|
static Moon* GenerateMoon(float distanceToPlanet);
|
||||||
|
static Galaxy* GenerateGalaxy();
|
||||||
|
static PlanetarySystem* GenerateSystem();
|
||||||
|
static void InitRandom(int seed);
|
||||||
|
static float GetRandomFloat(float from, float to);
|
||||||
|
static int GetRandomInt(int from, int to);
|
||||||
|
static uuids::uuid GetRandomUuid();
|
||||||
|
|
||||||
|
};
|
||||||
33
PlanetExplorerGameDemo/src/Utilities/MathFunctions.cpp
Normal file
33
PlanetExplorerGameDemo/src/Utilities/MathFunctions.cpp
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
#include "MathFunctions.hpp"
|
||||||
|
#include "MathF.hpp"
|
||||||
|
#include <cmath>
|
||||||
|
|
||||||
|
TSE::Vector2 rotateKeepDistance(const TSE::Vector2 &p1, const TSE::Vector2 &p2, float angle, float distance)
|
||||||
|
{
|
||||||
|
using namespace TSE;
|
||||||
|
|
||||||
|
Vector2 relativVector = p2 - p1;
|
||||||
|
|
||||||
|
float len = relativVector.Length();
|
||||||
|
|
||||||
|
Vector2 relativNormal;
|
||||||
|
if(len > TSE_EPSILON)
|
||||||
|
{
|
||||||
|
relativNormal = Vector2::Normalize(relativVector);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
relativNormal = Vector2::right;
|
||||||
|
}
|
||||||
|
|
||||||
|
float c = std::cos(angle);
|
||||||
|
float s = std::sin(angle);
|
||||||
|
|
||||||
|
Vector2 rotation = Vector2(relativNormal.x * c - relativNormal.y * s, relativNormal.x * s + relativNormal.y * c);
|
||||||
|
|
||||||
|
Vector2 rightDistance = rotation * distance;
|
||||||
|
|
||||||
|
Vector2 res = p1 + rightDistance;
|
||||||
|
|
||||||
|
return res;
|
||||||
|
}
|
||||||
5
PlanetExplorerGameDemo/src/Utilities/MathFunctions.hpp
Normal file
5
PlanetExplorerGameDemo/src/Utilities/MathFunctions.hpp
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "Vector2.hpp"
|
||||||
|
|
||||||
|
TSE::Vector2 rotateKeepDistance(const TSE::Vector2& p1, const TSE::Vector2& p2, float angle, float distance);
|
||||||
15
PlanetExplorerGameDemo/src/Utilities/Random.cpp
Normal file
15
PlanetExplorerGameDemo/src/Utilities/Random.cpp
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
#include "Random.hpp"
|
||||||
|
|
||||||
|
std::mt19937 rng = std::mt19937();
|
||||||
|
|
||||||
|
float GetRandomFloat(float min, float max)
|
||||||
|
{
|
||||||
|
std::uniform_real_distribution<float> dist(min, max);
|
||||||
|
return dist(rng);
|
||||||
|
}
|
||||||
|
|
||||||
|
uuids::uuid GetRandomUuid()
|
||||||
|
{
|
||||||
|
auto gen = uuids::uuid_random_generator(rng);
|
||||||
|
return gen();
|
||||||
|
}
|
||||||
5
PlanetExplorerGameDemo/src/Utilities/Random.hpp
Normal file
5
PlanetExplorerGameDemo/src/Utilities/Random.hpp
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "uuid.h"
|
||||||
|
|
||||||
|
float GetRandomFloat(float min, float max);
|
||||||
|
uuids::uuid GetRandomUuid();
|
||||||
13
PlanetExplorerGameDemo/src/Utilities/TextureHandler.cpp
Normal file
13
PlanetExplorerGameDemo/src/Utilities/TextureHandler.cpp
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
#include "TextureHandler.hpp"
|
||||||
|
|
||||||
|
void TextureHandler::LoadTextures()
|
||||||
|
{
|
||||||
|
mainTextures = new Texture(".textures/mainSprites.png");
|
||||||
|
mainSet = new TileSet(mainTextures, 8, 8);
|
||||||
|
}
|
||||||
|
|
||||||
|
void TextureHandler::UnLoadTextures()
|
||||||
|
{
|
||||||
|
delete mainSet;
|
||||||
|
delete mainTextures;
|
||||||
|
}
|
||||||
15
PlanetExplorerGameDemo/src/Utilities/TextureHandler.hpp
Normal file
15
PlanetExplorerGameDemo/src/Utilities/TextureHandler.hpp
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "elements/TileSet.hpp"
|
||||||
|
|
||||||
|
using namespace TSE;
|
||||||
|
|
||||||
|
class TextureHandler
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
inline static Texture* mainTextures = nullptr;
|
||||||
|
inline static TileSet* mainSet = nullptr;
|
||||||
|
|
||||||
|
static void LoadTextures();
|
||||||
|
static void UnLoadTextures();
|
||||||
|
};
|
||||||
@@ -14,67 +14,110 @@
|
|||||||
#include "elements/Layer.hpp"
|
#include "elements/Layer.hpp"
|
||||||
#include "elements/Scene.hpp"
|
#include "elements/Scene.hpp"
|
||||||
#include "EditorSubsystem.hpp"
|
#include "EditorSubsystem.hpp"
|
||||||
|
#include "BehaviourScripts/characterController/CharacterController.hpp"
|
||||||
|
#include "Elements/spaceElements/LocalCluster.hpp"
|
||||||
|
#include "Rendering/PlanetShader.hpp"
|
||||||
|
#include "elements/ShaderRegistry.hpp"
|
||||||
|
#include "Utilities/TextureHandler.hpp"
|
||||||
|
#include "Utilities/CharacterCreator.hpp"
|
||||||
|
#include "Utilities/GalaxyGenerator.hpp"
|
||||||
|
#include "BehaviourScripts/SpaceController.hpp"
|
||||||
|
|
||||||
|
#define USE_EDITOR
|
||||||
|
|
||||||
using namespace TSE;
|
using namespace TSE;
|
||||||
using namespace TSE::GLFW;
|
using namespace TSE::GLFW;
|
||||||
using namespace TSE::EDITOR;
|
using namespace TSE::EDITOR;
|
||||||
|
|
||||||
int main(int argc, char** argv)
|
IWindow* wnd = nullptr;
|
||||||
|
DefaultRendererOpenGL* rend = nullptr;
|
||||||
|
Scene* currentScene = nullptr;
|
||||||
|
Layer* planeteryLayer = nullptr;
|
||||||
|
CharacterController* cc = nullptr;
|
||||||
|
LocalCluster* lc = nullptr;
|
||||||
|
EditorSubsystem* editor;
|
||||||
|
|
||||||
|
void SetupWindow()
|
||||||
{
|
{
|
||||||
IWindow* wnd = new WindowGlfw("DemoProject", 600, 400, new OpenGLRenderingBackend(Color::aqua, false, 4, true));
|
Color backColor(0.0571f, 0.0819f, 0.1043f);
|
||||||
EditorSubsystem editor;
|
#ifdef USE_EDITOR
|
||||||
LoadBasicShaders(600, 400);
|
wnd = new WindowGlfw(PROJECT_NAME, 800, 600, new OpenGLRenderingBackend(backColor, false, 8, true), WindowType::Maximized);
|
||||||
|
editor = new EditorSubsystem();
|
||||||
DefaultRendererOpenGL rnd = DefaultRendererOpenGL(*BasicShader::Instance());
|
#else
|
||||||
|
wnd = new WindowGlfw(PROJECT_NAME, 800, 600, new OpenGLRenderingBackend(backColor, false, 8, false), WindowType::Maximized);
|
||||||
|
#endif
|
||||||
|
LoadBasicShaders(wnd->GetSize().x, wnd->GetSize().y);
|
||||||
|
|
||||||
#pragma region obj1
|
PlanetShader::Init(wnd->GetSize().x, wnd->GetSize().y);
|
||||||
|
ShaderRegistry::SetShader("Planet Shader", PlanetShader::Instance());
|
||||||
Transformable* obj1 = new Transformable("testObj");
|
|
||||||
|
|
||||||
RectBase rb = RectBase();
|
|
||||||
obj1->AddBehaviourScript(&rb);
|
|
||||||
Material mat = Material("testMat", BasicShader::Instance());
|
|
||||||
mat.SetValue<Color>("mainColor", Color::black);
|
|
||||||
Renderable r = Renderable(&mat);
|
|
||||||
obj1->AddBehaviourScript(&r);
|
|
||||||
obj1->position = Vector3(0,0,0);
|
|
||||||
obj1->scale = Vector3(8,1,1);
|
|
||||||
|
|
||||||
#pragma endregion
|
rend = new DefaultRendererOpenGL(*BasicShader::Instance());
|
||||||
|
|
||||||
Layer game("game");
|
TextureHandler::LoadTextures();
|
||||||
|
|
||||||
game.AddTransformable(obj1);
|
|
||||||
|
|
||||||
Scene scene;
|
currentScene = new Scene();
|
||||||
scene.AddLayer(&game);
|
Transformable* trans = new Transformable();
|
||||||
scene.AddLayer(&editor.editorLayer);
|
planeteryLayer = new Layer("PlanetsAndStuff");
|
||||||
|
currentScene->AddLayer(planeteryLayer);
|
||||||
|
planeteryLayer->AddTransformable(trans);
|
||||||
|
|
||||||
//((Camera*)(editor.editorLayer.GetAllObjects()[0]->GetBehaviourScriptAt(0)))->SetRenderTarget(wnd);
|
MakeCamera(currentScene, wnd);
|
||||||
|
cc = MakePlayer(currentScene);
|
||||||
|
|
||||||
editor.hv.SetScene(&scene);
|
SpaceController* controller = (SpaceController*)trans->AddBehaviourScript(new SpaceController(cc));
|
||||||
|
lc = GalaxyGenerator::GenerateCluster(69);
|
||||||
|
controller->LoadSpace(lc->galaxies[0]->systems[96]);
|
||||||
|
|
||||||
|
#ifdef USE_EDITOR
|
||||||
|
currentScene->AddLayer(&editor->editorLayer);
|
||||||
|
editor->hv.SetScene(currentScene);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
void CleanUp()
|
||||||
|
{
|
||||||
|
#ifdef USE_EDITOR
|
||||||
|
delete(editor);
|
||||||
|
#endif
|
||||||
|
Transformable::DeleteAll();
|
||||||
|
PlanetShader::Destroy();
|
||||||
|
UnLoadBasicShaders();
|
||||||
|
TextureHandler::UnLoadTextures();
|
||||||
|
}
|
||||||
|
|
||||||
|
void GameLoop()
|
||||||
|
{
|
||||||
while(!wnd->ShouldClose())
|
while(!wnd->ShouldClose())
|
||||||
{
|
{
|
||||||
wnd->Clear();
|
wnd->Clear();
|
||||||
rnd.Begin();
|
rend->Begin();
|
||||||
|
|
||||||
scene.Render(rnd, *wnd);
|
if(currentScene != nullptr)
|
||||||
|
currentScene->Render(*rend, *wnd);
|
||||||
|
|
||||||
rnd.End();
|
rend->End();
|
||||||
rnd.Flush();
|
rend->Flush();
|
||||||
|
|
||||||
scene.DoneRender();
|
if(currentScene != nullptr)
|
||||||
|
currentScene->DoneRender();
|
||||||
|
|
||||||
//editor.sv.Render();
|
#ifdef USE_EDITOR
|
||||||
editor.controller.Update();
|
editor->controller.Update();
|
||||||
//ImGui::ShowDemoWindow();
|
#endif
|
||||||
wnd->Update();
|
wnd->Update();
|
||||||
scene.Update();
|
if(currentScene != nullptr)
|
||||||
|
currentScene->Update();
|
||||||
}
|
}
|
||||||
UnLoadBasicShaders();
|
}
|
||||||
Transformable::DeleteAll();
|
|
||||||
|
|
||||||
|
int main(int argc, char** argv)
|
||||||
|
{
|
||||||
|
SetupWindow();
|
||||||
|
|
||||||
|
GameLoop();
|
||||||
|
|
||||||
|
CleanUp();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user