-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #60 from nightingazer/little_something
make a little demo of what possible with the engine so far
- Loading branch information
Showing
19 changed files
with
297 additions
and
95 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
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
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
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,10 @@ | ||
// | ||
// Created by alex on 1/26/23. | ||
// | ||
|
||
#include "Random.h" | ||
|
||
namespace AGE { | ||
thread_local std::mt19937 Random::s_RandomEngine{std::random_device()()}; | ||
thread_local std::uniform_int_distribution<std::mt19937::result_type> Random::s_Distribution{}; | ||
} // AGE |
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,58 @@ | ||
// | ||
// Created by alex on 1/26/23. | ||
// | ||
|
||
#ifndef AGE_RANDOM_H | ||
#define AGE_RANDOM_H | ||
|
||
#include <random> | ||
#include <cinttypes> | ||
|
||
#include <glm/glm.hpp> | ||
|
||
namespace AGE { | ||
|
||
class Random { | ||
public: | ||
|
||
static float Float() | ||
{ | ||
return (float)s_Distribution(s_RandomEngine) / (float)std::numeric_limits<uint_fast32_t>::max(); | ||
} | ||
static float Float(float min, float max) { | ||
return Float() * (max - min) + min; | ||
} | ||
|
||
static uint32_t UInt() { | ||
return s_Distribution(s_RandomEngine); | ||
} | ||
static uint32_t UInt(uint32_t min, uint32_t max) { | ||
return min + (s_Distribution(s_RandomEngine) % (max - min + 1)); | ||
} | ||
|
||
static glm::vec3 Vec3() { | ||
return {Float(), Float(), Float()}; | ||
} | ||
static glm::vec3 Vec3(float min, float max) { | ||
return {Float(min, max), Float(min, max), Float(min, max)}; | ||
} | ||
|
||
static glm::vec2 Vec2() { | ||
return {Float(), Float()}; | ||
} | ||
static glm::vec2 Vec2(float min, float max) { | ||
return {Float(min, max), Float(min, max)}; | ||
} | ||
|
||
static glm::vec3 InUnitSphere() { | ||
return glm::normalize(Vec3(-1.0f, 1.0f)); | ||
} | ||
|
||
private: | ||
static thread_local std::mt19937 s_RandomEngine; | ||
static thread_local std::uniform_int_distribution<std::mt19937::result_type> s_Distribution; | ||
}; | ||
|
||
} // AGE | ||
|
||
#endif //AGE_RANDOM_H |
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
Submodule GLFW
updated
40 files
+0 −4 | CONTRIBUTORS.md | |
+156 −382 | docs/Doxyfile.in | |
+1 −2 | docs/window.dox | |
+13 −14 | include/GLFW/glfw3.h | |
+0 −5 | src/cocoa_init.m | |
+2 −0 | src/cocoa_joystick.h | |
+0 −4 | src/cocoa_joystick.m | |
+0 −4 | src/cocoa_monitor.m | |
+0 −4 | src/cocoa_time.c | |
+0 −4 | src/cocoa_window.m | |
+30 −55 | src/egl_context.c | |
+0 −4 | src/glx_context.c | |
+7 −0 | src/internal.h | |
+0 −4 | src/linux_joystick.c | |
+2 −0 | src/linux_joystick.h | |
+6 −6 | src/mappings.h | |
+6 −6 | src/mappings.h.in | |
+0 −4 | src/nsgl_context.m | |
+1 −7 | src/platform.c | |
+3 −43 | src/platform.h | |
+0 −4 | src/posix_module.c | |
+0 −4 | src/posix_poll.c | |
+0 −4 | src/posix_thread.c | |
+0 −4 | src/posix_time.c | |
+0 −4 | src/wgl_context.c | |
+0 −4 | src/win32_init.c | |
+0 −4 | src/win32_joystick.c | |
+2 −0 | src/win32_joystick.h | |
+0 −4 | src/win32_module.c | |
+0 −4 | src/win32_monitor.c | |
+0 −4 | src/win32_thread.c | |
+0 −3 | src/win32_time.c | |
+53 −45 | src/win32_window.c | |
+1 −5 | src/wl_init.c | |
+0 −4 | src/wl_monitor.c | |
+1 −6 | src/wl_window.c | |
+1 −5 | src/x11_init.c | |
+0 −4 | src/x11_monitor.c | |
+2 −6 | src/x11_window.c | |
+0 −3 | src/xkb_unicode.c |
Submodule glm
updated
59 files
Submodule imgui
updated
79 files
Submodule spdlog
updated
53 files
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,70 @@ | ||
// | ||
// Created by alex on 1/25/23. | ||
// | ||
|
||
#include "Particle.h" | ||
|
||
void ParticleSystem::OnUpdate(AGE::Timestep ts) { | ||
for (auto& particle: m_Particles) { | ||
if (!particle.Active) | ||
continue; | ||
|
||
if (particle.LifeRemaining <= 0.0f) { | ||
particle.Active = false; | ||
continue; | ||
} | ||
|
||
particle.LifeRemaining -= ts; | ||
particle.Position += particle.Velocity * ts.Seconds(); | ||
particle.RotationDeg += particle.RotationSpeedDeg * ts.Seconds(); | ||
} | ||
} | ||
|
||
void ParticleSystem::Render() { | ||
for (auto& particle: m_Particles) { | ||
if(!particle.Active) | ||
continue; | ||
|
||
float life = particle.LifeRemaining / particle.LifeTime; | ||
glm::vec4 color = particle.ColorBegin * (1.0f - life) + particle.ColorEnd * (life); | ||
float size = particle.SizeBegin * (1.0f + life) + particle.SizeEnd * (life); | ||
|
||
AGE::Renderer2D::DrawRotatedQuad(particle.Position, glm::vec2{size}, particle.RotationDeg, color); | ||
} | ||
} | ||
|
||
void ParticleSystem::Emit(const ParticleProps& props) { | ||
if (m_NextPoolInsert == m_Particles.end()) | ||
m_NextPoolInsert = m_Particles.begin(); | ||
|
||
glm::vec2 velocity = {props.Velocity.x + props.VelocityVariations * AGE::Random::Float(-1.0f, 1.0f), | ||
props.Velocity.y + props.VelocityVariations * AGE::Random::Float(-1.0f, 1.0f)}; | ||
float rotationSpeed = props.RotationSpeedDeg + props.RotationSpeedVariationDeg * AGE::Random::Float(-1.0f, 1.0f); | ||
|
||
float sizeBegin = props.SizeBegin + props.SizeVariations * AGE::Random::Float(-1.0f, 1.0f); | ||
float sizeEnd = props.SizeEnd + props.SizeVariations * AGE::Random::Float(-1.0f, 1.0f); | ||
|
||
glm::vec4 colorBegin = {props.ColorBegin.r + props.ColorVariations * AGE::Random::Float(-1.0f, 1.0f), | ||
props.ColorBegin.g + props.ColorVariations * AGE::Random::Float(-1.0f, 1.0f), | ||
props.ColorBegin.b + props.ColorVariations * AGE::Random::Float(-1.0f, 1.0f), | ||
props.ColorBegin.a + props.ColorVariations * AGE::Random::Float(-1.0f, 1.0f)}; | ||
glm::vec4 colorEnd = {props.ColorEnd.r + props.ColorVariations * AGE::Random::Float(-1.0f, 1.0f), | ||
props.ColorEnd.g + props.ColorVariations * AGE::Random::Float(-1.0f, 1.0f), | ||
props.ColorEnd.b + props.ColorVariations * AGE::Random::Float(-1.0f, 1.0f), | ||
props.ColorEnd.a + props.ColorVariations * AGE::Random::Float(-1.0f, 1.0f)}; | ||
|
||
m_NextPoolInsert->Active = true; | ||
m_NextPoolInsert->LifeRemaining = m_NextPoolInsert->LifeTime = props.LifeTime; | ||
|
||
m_NextPoolInsert->ColorEnd = colorBegin; | ||
m_NextPoolInsert->ColorBegin = colorEnd; | ||
|
||
m_NextPoolInsert->RotationSpeedDeg = rotationSpeed; | ||
m_NextPoolInsert->RotationDeg = 0; | ||
m_NextPoolInsert->Position = props.Position; | ||
m_NextPoolInsert->SizeBegin = sizeBegin; | ||
m_NextPoolInsert->SizeEnd = sizeEnd; | ||
m_NextPoolInsert->Velocity = velocity; | ||
|
||
m_NextPoolInsert++; | ||
} |
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,59 @@ | ||
// | ||
// Created by alex on 1/25/23. | ||
// | ||
|
||
#ifndef AGE_PARTICLE_H | ||
#define AGE_PARTICLE_H | ||
|
||
#include <vector> | ||
|
||
#include "glm/glm.hpp" | ||
|
||
#include "Age/Age.h" | ||
|
||
struct ParticleProps { | ||
glm::vec2 Position; | ||
glm::vec2 Velocity; | ||
float VelocityVariations; | ||
float RotationSpeedDeg; | ||
float RotationSpeedVariationDeg; | ||
|
||
glm::vec4 ColorBegin, ColorEnd; | ||
float ColorVariations; | ||
|
||
float SizeBegin, SizeEnd; | ||
float SizeVariations; | ||
|
||
float LifeTime{1.0f}; | ||
float Rotation; | ||
}; | ||
|
||
class ParticleSystem { | ||
public: | ||
ParticleSystem(uint32_t poolSize) : m_Particles(poolSize), m_NextPoolInsert(m_Particles.begin()) {} | ||
|
||
void OnUpdate(AGE::Timestep ts); | ||
void Render(); | ||
void Emit(const ParticleProps& props); | ||
|
||
private: | ||
struct Particle { | ||
glm::vec2 Position; | ||
float RotationDeg; | ||
float RotationSpeedDeg; | ||
glm::vec2 Velocity; | ||
glm::vec4 ColorBegin, ColorEnd; | ||
float SizeBegin, SizeEnd; | ||
|
||
float LifeTime{1.0f}; | ||
float LifeRemaining{0.0f}; | ||
|
||
bool Active{false}; | ||
}; | ||
|
||
std::vector<Particle> m_Particles; | ||
std::vector<Particle>::iterator m_NextPoolInsert; | ||
}; | ||
|
||
|
||
#endif //AGE_PARTICLE_H |
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
Oops, something went wrong.