-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
62 changed files
with
15,905 additions
and
5,449 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,30 @@ | ||
FetchContent_Declare ( | ||
stb | ||
GIT_REPOSITORY [[https://github.com/nothings/stb]] | ||
GIT_TAG [[b42009b3b9d4ca35bc703f5310eedc74f584be58]] | ||
) | ||
find_package (Stb QUIET) | ||
if (NOT Stb_FOUND) | ||
FetchContent_Declare ( | ||
stb | ||
GIT_REPOSITORY [[https://github.com/nothings/stb]] | ||
GIT_TAG [[c0c982601f40183e74d84a61237e968dca08380e]] | ||
) | ||
|
||
FetchContent_GetProperties (stb) | ||
if (NOT stb_POPULATED) | ||
message (STATUS "Cloning stb…") | ||
FetchContent_Populate (stb) | ||
endif () | ||
FetchContent_GetProperties (stb) | ||
if (NOT stb_POPULATED) | ||
message (STATUS "Cloning stb…") | ||
FetchContent_Populate (stb) | ||
endif () | ||
|
||
add_library( stb::stb INTERFACE IMPORTED) | ||
set_target_properties(stb::stb PROPERTIES | ||
INTERFACE_INCLUDE_DIRECTORIES "${stb_SOURCE_DIR}" | ||
INTERFACE_SOURCES "${CMAKE_SOURCE_DIR}/src/core/stb_impl.c" | ||
) | ||
add_library (stb::stb INTERFACE IMPORTED) | ||
set_target_properties (stb::stb PROPERTIES | ||
INTERFACE_INCLUDE_DIRECTORIES "${stb_SOURCE_DIR}" | ||
INTERFACE_SOURCES "${CMAKE_SOURCE_DIR}/src/core/stb_impl.c" | ||
) | ||
else () | ||
# vcpkg has its own FindStb.cmake which defines `Stb_FOUND` and | ||
# `Stb_INCLUDE_DIR`, but not library which can be readily linked | ||
# against. So wrap an interface library around those sources, similar | ||
# to when we retrieve the library sources ourselves. | ||
add_library (stb::stb INTERFACE IMPORTED) | ||
set_target_properties (stb::stb PROPERTIES | ||
INTERFACE_INCLUDE_DIRECTORIES "${Stb_INCLUDE_DIR}" | ||
INTERFACE_SOURCES "${CMAKE_SOURCE_DIR}/src/core/stb_impl.c" | ||
) | ||
endif () |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,20 @@ | ||
FetchContent_Declare ( | ||
tinyfiledialogs | ||
GIT_REPOSITORY [[https://git.code.sf.net/p/tinyfiledialogs/code]] | ||
GIT_TAG [[fb228c5bcd7d0574d08b71b4fae84676328addaf]] | ||
) | ||
find_package (tinyfiledialogs QUIET) | ||
if (NOT tinyfiledialogs_FOUND) | ||
FetchContent_Declare ( | ||
tinyfiledialogs | ||
GIT_REPOSITORY [[https://git.code.sf.net/p/tinyfiledialogs/code]] | ||
GIT_TAG [[e11f94cd7887b101d64f74892d769f0139b5e166]] | ||
) | ||
|
||
FetchContent_GetProperties (tinyfiledialogs) | ||
if (NOT tinyfiledialogs_POPULATED) | ||
message (STATUS "Cloning tinyfiledialogs…") | ||
FetchContent_Populate (tinyfiledialogs) | ||
endif () | ||
FetchContent_GetProperties (tinyfiledialogs) | ||
if (NOT tinyfiledialogs_POPULATED) | ||
message (STATUS "Cloning tinyfiledialogs…") | ||
FetchContent_Populate (tinyfiledialogs) | ||
endif () | ||
|
||
add_library( tinyfiledialogs::tinyfiledialogs INTERFACE IMPORTED) | ||
set_target_properties(tinyfiledialogs::tinyfiledialogs PROPERTIES | ||
INTERFACE_INCLUDE_DIRECTORIES "${tinyfiledialogs_SOURCE_DIR}" | ||
INTERFACE_SOURCES "${tinyfiledialogs_SOURCE_DIR}/tinyfiledialogs.c" | ||
) | ||
add_library( tinyfiledialogs::tinyfiledialogs INTERFACE IMPORTED) | ||
set_target_properties(tinyfiledialogs::tinyfiledialogs PROPERTIES | ||
INTERFACE_INCLUDE_DIRECTORIES "${tinyfiledialogs_SOURCE_DIR}" | ||
INTERFACE_SOURCES "${tinyfiledialogs_SOURCE_DIR}/tinyfiledialogs.c" | ||
) | ||
endif () |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,3 @@ void main() | |
|
||
gl_Position = vertex_world_to_clip * vertex_model_to_world * vec4(vertex, 1.0); | ||
} | ||
|
||
|
||
|
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,14 @@ | ||
#version 410 | ||
|
||
uniform bool has_opacity_texture; | ||
uniform sampler2D opacity_texture; | ||
|
||
in VS_OUT { | ||
vec2 texcoord; | ||
} fs_in; | ||
|
||
void main() | ||
{ | ||
if (has_opacity_texture && texture(opacity_texture, fs_in.texcoord).r < 1.0) | ||
discard; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#version 410 | ||
|
||
in VS_OUT { | ||
flat uint axis_index; | ||
} vs_out; | ||
|
||
out vec4 frag_color; | ||
|
||
void main() | ||
{ | ||
switch (vs_out.axis_index) | ||
{ | ||
case 0: | ||
frag_color = vec4(0.8f, 0.2f, 0.2f, 1.0f); | ||
break; | ||
case 1: | ||
frag_color = vec4(0.2f, 0.8f, 0.2f, 1.0f); | ||
break; | ||
case 2: | ||
frag_color = vec4(0.2f, 0.2f, 0.8f, 1.0f); | ||
break; | ||
default: | ||
frag_color = vec4(1.0f); | ||
break; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#version 410 | ||
|
||
layout (location = 0) in vec3 vertex; | ||
|
||
uniform mat4 vertex_model_to_world; | ||
uniform mat4 vertex_world_to_clip; | ||
uniform float thickness_scale; | ||
uniform float length_scale; | ||
|
||
out VS_OUT { | ||
flat uint axis_index; | ||
} vs_out; | ||
|
||
|
||
void main() | ||
{ | ||
vs_out.axis_index = gl_InstanceID; | ||
vec3 local_vertex = vertex; | ||
|
||
// One arrow is instanced three times, to provide all three axes. That | ||
// arrow represents a (1 0 0) vector. | ||
|
||
// Scale the arrow before it is transformed to represent an axis other | ||
// than x. | ||
local_vertex.yz *= thickness_scale; | ||
local_vertex.x *= length_scale; | ||
|
||
// The first instance is for the x axis, so no additional | ||
// transformation is needed. | ||
// | ||
// The second instance is for the y axis, so swap the x and y | ||
// components. | ||
if (vs_out.axis_index == 1) | ||
{ | ||
local_vertex.xy = local_vertex.yx; | ||
} | ||
// The third instance is for the z axis, so set x to -z, and z to x. | ||
else if (vs_out.axis_index == 2) | ||
{ | ||
float tmpX = local_vertex.x; | ||
local_vertex.x = -local_vertex.z; | ||
local_vertex.z = tmpX; | ||
} | ||
|
||
gl_Position = vertex_world_to_clip * vertex_model_to_world * vec4(local_vertex, 1.0); | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
#include "CelestialBody.hpp" | ||
|
||
#include <glm/gtc/matrix_transform.hpp> | ||
#include <glm/trigonometric.hpp> | ||
|
||
#include "core/helpers.hpp" | ||
#include "core/Log.h" | ||
|
||
CelestialBody::CelestialBody(bonobo::mesh_data const& shape, | ||
GLuint const* program, | ||
GLuint diffuse_texture_id) | ||
{ | ||
_body.node.set_geometry(shape); | ||
_body.node.add_texture("diffuse_texture", diffuse_texture_id, GL_TEXTURE_2D); | ||
_body.node.set_program(program); | ||
} | ||
|
||
glm::mat4 CelestialBody::render(std::chrono::microseconds elapsed_time, | ||
glm::mat4 const& view_projection, | ||
glm::mat4 const& parent_transform, | ||
bool show_basis) | ||
{ | ||
// Convert the duration from microseconds to seconds. | ||
auto const elapsed_time_s = std::chrono::duration<float>(elapsed_time).count(); | ||
// If a different ratio was needed, for example a duration in | ||
// milliseconds, the following would have been used: | ||
// auto const elapsed_time_ms = std::chrono::duration<float, std::milli>(elapsed_time).count(); | ||
|
||
_body.spin.rotation_angle = -glm::half_pi<float>() / 2.0f; | ||
|
||
glm::mat4 world = parent_transform; | ||
|
||
if (show_basis) | ||
{ | ||
bonobo::renderBasis(1.0f, 2.0f, view_projection, world); | ||
} | ||
|
||
// Note: The second argument of `node::render()` is supposed to be the | ||
// parent transform of the node, not the whole world matrix, as the | ||
// node internally manages its local transforms. However in our case we | ||
// manage all the local transforms ourselves, so the internal transform | ||
// of the node is just the identity matrix and we can forward the whole | ||
// world matrix. | ||
_body.node.render(view_projection, world); | ||
|
||
return parent_transform; | ||
} | ||
|
||
void CelestialBody::add_child(CelestialBody* child) | ||
{ | ||
_children.push_back(child); | ||
} | ||
|
||
std::vector<CelestialBody*> const& CelestialBody::get_children() const | ||
{ | ||
return _children; | ||
} | ||
|
||
void CelestialBody::set_orbit(OrbitConfiguration const& configuration) | ||
{ | ||
_body.orbit.radius = configuration.radius; | ||
_body.orbit.inclination = configuration.inclination; | ||
_body.orbit.speed = configuration.speed; | ||
_body.orbit.rotation_angle = 0.0f; | ||
} | ||
|
||
void CelestialBody::set_scale(glm::vec3 const& scale) | ||
{ | ||
_body.scale = scale; | ||
} | ||
|
||
void CelestialBody::set_spin(SpinConfiguration const& configuration) | ||
{ | ||
_body.spin.axial_tilt = configuration.axial_tilt; | ||
_body.spin.speed = configuration.speed; | ||
_body.spin.rotation_angle = 0.0f; | ||
} | ||
|
||
void CelestialBody::set_ring(bonobo::mesh_data const& shape, | ||
GLuint const* program, | ||
GLuint diffuse_texture_id, | ||
glm::vec2 const& scale) | ||
{ | ||
_ring.node.set_geometry(shape); | ||
_ring.node.add_texture("diffuse_texture", diffuse_texture_id, GL_TEXTURE_2D); | ||
_ring.node.set_program(program); | ||
|
||
_ring.scale = scale; | ||
} |
Oops, something went wrong.