mirror of
https://github.com/bailwillharr/engine.git
synced 2024-09-21 04:51:18 +00:00
Begin collision/physics rewrite
This commit is contained in:
parent
78ed78120b
commit
2db3cf8722
6244
cpplint.py
vendored
Normal file
6244
cpplint.py
vendored
Normal file
File diff suppressed because it is too large
Load Diff
@ -12,11 +12,7 @@ struct AABB {
|
|||||||
glm::vec3 pos2;
|
glm::vec3 pos2;
|
||||||
};
|
};
|
||||||
|
|
||||||
class PhysicsSystem;
|
|
||||||
|
|
||||||
struct ColliderComponent {
|
struct ColliderComponent {
|
||||||
friend PhysicsSystem;
|
|
||||||
|
|
||||||
bool is_static = true;
|
bool is_static = true;
|
||||||
bool is_trigger =
|
bool is_trigger =
|
||||||
false; // entity receives an event on collision enter and exit
|
false; // entity receives an event on collision enter and exit
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
namespace engine {
|
namespace engine {
|
||||||
|
|
||||||
struct CustomComponent {
|
struct CustomComponent {
|
||||||
|
std::function<void(void)> onInit; // void onInit(void);
|
||||||
std::function<void(float)> onUpdate; // void onUpdate(float ts);
|
std::function<void(float)> onUpdate; // void onUpdate(float ts);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
#ifndef ENGINE_INCLUDE_COMPONENTS_TRANSFORM_H_
|
#ifndef ENGINE_INCLUDE_COMPONENTS_TRANSFORM_H_
|
||||||
#define ENGINE_INCLUDE_COMPONENTS_TRANSFORM_H_
|
#define ENGINE_INCLUDE_COMPONENTS_TRANSFORM_H_
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
#include <glm/gtc/quaternion.hpp>
|
#include <glm/gtc/quaternion.hpp>
|
||||||
#include <glm/mat4x4.hpp>
|
#include <glm/mat4x4.hpp>
|
||||||
#include <glm/vec3.hpp>
|
#include <glm/vec3.hpp>
|
||||||
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
namespace engine {
|
namespace engine {
|
||||||
|
|
||||||
struct TransformComponent {
|
struct TransformComponent {
|
||||||
|
@ -7,6 +7,8 @@
|
|||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include <typeinfo>
|
#include <typeinfo>
|
||||||
|
|
||||||
|
#include <glm/vec3.hpp>
|
||||||
|
|
||||||
#include "ecs_system.h"
|
#include "ecs_system.h"
|
||||||
#include "event_system.h"
|
#include "event_system.h"
|
||||||
|
|
||||||
@ -29,9 +31,9 @@ class Scene {
|
|||||||
|
|
||||||
/* ecs stuff */
|
/* ecs stuff */
|
||||||
|
|
||||||
uint32_t CreateEntity(const std::string& tag, uint32_t parent = 0);
|
uint32_t CreateEntity(const std::string& tag, uint32_t parent = 0, const glm::vec3& pos = {});
|
||||||
|
|
||||||
uint32_t getEntity(const std::string& tag, uint32_t parent = 0);
|
uint32_t GetEntity(const std::string& tag, uint32_t parent = 0);
|
||||||
|
|
||||||
size_t GetComponentSignaturePosition(size_t hash);
|
size_t GetComponentSignaturePosition(size_t hash);
|
||||||
|
|
||||||
|
@ -33,6 +33,7 @@ static std::filesystem::path getResourcesPath() {
|
|||||||
std::filesystem::path resourcesPath{};
|
std::filesystem::path resourcesPath{};
|
||||||
|
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
|
// get the path of the currently running process
|
||||||
CHAR exeDirBuf[MAX_PATH + 1];
|
CHAR exeDirBuf[MAX_PATH + 1];
|
||||||
GetModuleFileNameA(NULL, exeDirBuf, WIN_MAX_PATH + 1);
|
GetModuleFileNameA(NULL, exeDirBuf, WIN_MAX_PATH + 1);
|
||||||
std::filesystem::path cwd = std::filesystem::path(exeDirBuf).parent_path();
|
std::filesystem::path cwd = std::filesystem::path(exeDirBuf).parent_path();
|
||||||
|
@ -31,7 +31,8 @@ Scene::Scene(Application* app) : app_(app) {
|
|||||||
|
|
||||||
Scene::~Scene() {}
|
Scene::~Scene() {}
|
||||||
|
|
||||||
uint32_t Scene::CreateEntity(const std::string& tag, uint32_t parent) {
|
uint32_t Scene::CreateEntity(const std::string& tag, uint32_t parent,
|
||||||
|
const glm::vec3& pos) {
|
||||||
uint32_t id = next_entity_id_++;
|
uint32_t id = next_entity_id_++;
|
||||||
|
|
||||||
signatures_.emplace(id, std::bitset<kMaxComponents>{});
|
signatures_.emplace(id, std::bitset<kMaxComponents>{});
|
||||||
@ -48,7 +49,7 @@ uint32_t Scene::CreateEntity(const std::string& tag, uint32_t parent) {
|
|||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t Scene::getEntity(const std::string& tag, uint32_t parent) {
|
uint32_t Scene::GetEntity(const std::string& tag, uint32_t parent) {
|
||||||
return GetSystem<TransformSystem>()->GetChildEntity(parent, tag);
|
return GetSystem<TransformSystem>()->GetChildEntity(parent, tag);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,40 +1,38 @@
|
|||||||
#include "util/files.h"
|
#include "util/files.h"
|
||||||
|
|
||||||
#include "stb_image.h"
|
|
||||||
|
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
|
||||||
|
#include "stb_image.h"
|
||||||
|
|
||||||
namespace engine::util {
|
namespace engine::util {
|
||||||
|
|
||||||
std::unique_ptr<std::vector<char>> ReadTextFile(const std::string& path)
|
std::unique_ptr<std::vector<char>> ReadTextFile(const std::string& path) {
|
||||||
{
|
|
||||||
auto buffer = std::make_unique<std::vector<char>>();
|
|
||||||
|
|
||||||
std::ifstream file(path, std::ios::ate);
|
std::ifstream file(path, std::ios::ate);
|
||||||
|
|
||||||
if (file.is_open() == false) {
|
if (file.is_open() == false) {
|
||||||
throw std::runtime_error("Unable to open file " + path);
|
throw std::runtime_error("Unable to open file " + path);
|
||||||
}
|
}
|
||||||
|
|
||||||
// reserve enough space for the text file, but leave the size at 0
|
auto buffer = std::make_unique<std::vector<char>>(file.tellg());
|
||||||
buffer->reserve(file.tellg());
|
|
||||||
|
|
||||||
file.seekg(0);
|
file.seekg(0);
|
||||||
|
|
||||||
|
int i = 0;
|
||||||
while (!file.eof()) {
|
while (!file.eof()) {
|
||||||
char c{};
|
char c{};
|
||||||
file.read(&c, 1);
|
file.read(&c, 1); // reading 1 char at a time
|
||||||
buffer->push_back(c);
|
|
||||||
|
buffer->data()[i] = c;
|
||||||
|
|
||||||
|
++i;
|
||||||
}
|
}
|
||||||
|
|
||||||
file.close();
|
file.close();
|
||||||
|
|
||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unique_ptr<std::vector<uint8_t>> ReadBinaryFile(const std::string& path)
|
std::unique_ptr<std::vector<uint8_t>> ReadBinaryFile(const std::string& path) {
|
||||||
{
|
|
||||||
std::ifstream file(path, std::ios::ate | std::ios::binary);
|
std::ifstream file(path, std::ios::ate | std::ios::binary);
|
||||||
if (file.is_open() == false) {
|
if (file.is_open() == false) {
|
||||||
throw std::runtime_error("Unable to open file " + path);
|
throw std::runtime_error("Unable to open file " + path);
|
||||||
@ -43,18 +41,17 @@ namespace engine::util {
|
|||||||
auto buffer = std::make_unique<std::vector<uint8_t>>(file.tellg());
|
auto buffer = std::make_unique<std::vector<uint8_t>>(file.tellg());
|
||||||
|
|
||||||
file.seekg(0);
|
file.seekg(0);
|
||||||
|
|
||||||
file.read((char*)buffer->data(), buffer->size());
|
file.read((char*)buffer->data(), buffer->size());
|
||||||
|
|
||||||
file.close();
|
file.close();
|
||||||
|
|
||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unique_ptr<std::vector<uint8_t>> ReadImageFile(const std::string& path, int *width, int *height)
|
std::unique_ptr<std::vector<uint8_t>> ReadImageFile(const std::string& path,
|
||||||
{
|
int* width, int* height) {
|
||||||
int x, y, n;
|
int x, y, n;
|
||||||
unsigned char *data = stbi_load(path.c_str(), &x, &y, &n, STBI_rgb_alpha);
|
unsigned char* data =
|
||||||
|
stbi_load(path.c_str(), &x, &y, &n, STBI_rgb_alpha); // Image is 4 bpp
|
||||||
|
|
||||||
if (data == nullptr) {
|
if (data == nullptr) {
|
||||||
throw std::runtime_error("Unable to open file " + path);
|
throw std::runtime_error("Unable to open file " + path);
|
||||||
@ -71,7 +68,6 @@ namespace engine::util {
|
|||||||
stbi_image_free(data);
|
stbi_image_free(data);
|
||||||
|
|
||||||
return buffer;
|
return buffer;
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} // namespace engine::util
|
||||||
|
@ -6,7 +6,6 @@
|
|||||||
#include <glm/trigonometric.hpp>
|
#include <glm/trigonometric.hpp>
|
||||||
|
|
||||||
#include "application.h"
|
#include "application.h"
|
||||||
#include "components/collider.h"
|
|
||||||
#include "components/transform.h"
|
#include "components/transform.h"
|
||||||
#include "input_manager.h"
|
#include "input_manager.h"
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
@ -19,67 +18,23 @@ CameraControllerSystem::CameraControllerSystem(engine::Scene* scene)
|
|||||||
typeid(CameraControllerComponent).hash_code()}) {}
|
typeid(CameraControllerComponent).hash_code()}) {}
|
||||||
|
|
||||||
void CameraControllerSystem::OnUpdate(float ts) {
|
void CameraControllerSystem::OnUpdate(float ts) {
|
||||||
if (t == nullptr || c == nullptr || col == nullptr) {
|
if (t == nullptr || c == nullptr) {
|
||||||
for (uint32_t entity : entities_) {
|
for (uint32_t entity : entities_) {
|
||||||
t = scene_->GetComponent<engine::TransformComponent>(entity);
|
t = scene_->GetComponent<engine::TransformComponent>(entity);
|
||||||
col = scene_->GetComponent<engine::ColliderComponent>(entity);
|
|
||||||
c = scene_->GetComponent<CameraControllerComponent>(entity);
|
c = scene_->GetComponent<CameraControllerComponent>(entity);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (t == nullptr) return;
|
if (t == nullptr) return;
|
||||||
if (c == nullptr) return;
|
if (c == nullptr) return;
|
||||||
if (col == nullptr) return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const float dt = ts;
|
const float dt = ts;
|
||||||
|
|
||||||
constexpr float G = 9.8f;
|
constexpr float G = 9.8f;
|
||||||
const float kMaxSlopeAngle = glm::cos(glm::radians(20.0f));
|
|
||||||
constexpr float kFloorSinkLevel =
|
|
||||||
0.05f; // how far into the floor to ground the player
|
|
||||||
|
|
||||||
glm::vec3 norm = c->last_collision_normal;
|
|
||||||
|
|
||||||
glm::vec3 dir =
|
glm::vec3 dir =
|
||||||
glm::normalize(glm::rotateY(glm::vec3{1.0f, 0.0f, 0.0f}, c->yaw) +
|
glm::normalize(glm::rotateY(glm::vec3{1.0f, 0.0f, 0.0f}, c->yaw) +
|
||||||
glm::rotateY(glm::vec3{0.0f, 0.0f, 1.0f}, c->yaw));
|
glm::rotateY(glm::vec3{0.0f, 0.0f, 1.0f}, c->yaw));
|
||||||
const float slope = glm::dot(dir, norm);
|
|
||||||
|
|
||||||
bool is_sliding = false;
|
|
||||||
|
|
||||||
if (c->just_collided) {
|
|
||||||
if (slope > kMaxSlopeAngle) {
|
|
||||||
// slide across wall
|
|
||||||
is_sliding = true;
|
|
||||||
} else {
|
|
||||||
if (c->dy < 0.0f && c->is_grounded == false) {
|
|
||||||
// in the ground, push up a bit
|
|
||||||
float floorY = c->last_collision_point.y;
|
|
||||||
t->position.y = floorY + 1.5f - kFloorSinkLevel;
|
|
||||||
c->dy = 0.0f;
|
|
||||||
c->is_grounded = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (c->just_collided == false && slope <= kMaxSlopeAngle) {
|
|
||||||
// just stopped colliding with a floor collider
|
|
||||||
c->is_grounded = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (c->is_grounded == false) c->dy -= G * dt;
|
|
||||||
|
|
||||||
// jumping
|
|
||||||
constexpr float JUMPVEL =
|
|
||||||
(float)2.82231110971133017648; // std::sqrt(2 * G * JUMPHEIGHT);
|
|
||||||
if (scene_->app()->input_manager()->GetButton("jump") &&
|
|
||||||
c->is_grounded == true) {
|
|
||||||
c->dy = JUMPVEL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (scene_->app()->window()->GetButton(engine::inputs::MouseButton::M_LEFT)) {
|
|
||||||
c->dy += dt * c->kThrust;
|
|
||||||
}
|
|
||||||
|
|
||||||
// in metres per second
|
// in metres per second
|
||||||
float speed = c->kWalkSpeed;
|
float speed = c->kWalkSpeed;
|
||||||
@ -104,20 +59,16 @@ void CameraControllerSystem::OnUpdate(float ts) {
|
|||||||
|
|
||||||
// update position relative to camera direction in xz plane
|
// update position relative to camera direction in xz plane
|
||||||
const glm::vec3 d2x_rotated = glm::rotateY(glm::vec3{dx, 0.0f, 0.0f}, c->yaw);
|
const glm::vec3 d2x_rotated = glm::rotateY(glm::vec3{dx, 0.0f, 0.0f}, c->yaw);
|
||||||
const glm::vec3 d2z_rotated = glm::rotateY(glm::vec3{0.0f, 0.0f, dz}, c->yaw);
|
const glm::vec3 d2z_rotated =
|
||||||
|
glm::rotateY(glm::rotateX(glm::vec3{0.0f, 0.0f, dz}, c->pitch), c->yaw);
|
||||||
glm::vec3 h_vel = (d2x_rotated + d2z_rotated);
|
glm::vec3 h_vel = (d2x_rotated + d2z_rotated);
|
||||||
if (is_sliding) {
|
|
||||||
h_vel = glm::vec3{norm.z, 0.0f, -norm.x};
|
|
||||||
}
|
|
||||||
h_vel *= speed;
|
h_vel *= speed;
|
||||||
t->position += h_vel * dt;
|
t->position += h_vel * dt;
|
||||||
t->position.y += c->dy * dt;
|
|
||||||
|
|
||||||
constexpr float kMaxDistanceFromOrigin = 10000.0f;
|
constexpr float kMaxDistanceFromOrigin = 10000.0f;
|
||||||
|
|
||||||
if (glm::length(t->position) > kMaxDistanceFromOrigin) {
|
if (glm::length(t->position) > kMaxDistanceFromOrigin) {
|
||||||
t->position = {0.0f, 5.0f, 0.0f};
|
t->position = {0.0f, 5.0f, 0.0f};
|
||||||
c->dy = 0.0f;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ROTATION STUFF */
|
/* ROTATION STUFF */
|
||||||
@ -152,7 +103,6 @@ void CameraControllerSystem::OnUpdate(float ts) {
|
|||||||
|
|
||||||
if (scene_->app()->window()->GetKeyPress(engine::inputs::Key::K_R)) {
|
if (scene_->app()->window()->GetKeyPress(engine::inputs::Key::K_R)) {
|
||||||
t->position = {0.0f, 5.0f, 0.0f};
|
t->position = {0.0f, 5.0f, 0.0f};
|
||||||
c->dy = 0.0f;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (scene_->app()->input_manager()->GetButtonPress("fullscreen")) {
|
if (scene_->app()->input_manager()->GetButtonPress("fullscreen")) {
|
||||||
@ -162,14 +112,4 @@ void CameraControllerSystem::OnUpdate(float ts) {
|
|||||||
if (scene_->app()->input_manager()->GetButtonPress("exit")) {
|
if (scene_->app()->input_manager()->GetButtonPress("exit")) {
|
||||||
scene_->app()->window()->SetCloseFlag();
|
scene_->app()->window()->SetCloseFlag();
|
||||||
}
|
}
|
||||||
|
|
||||||
c->just_collided = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// called once per frame
|
|
||||||
void CameraControllerSystem::OnEvent(
|
|
||||||
engine::PhysicsSystem::CollisionEvent info) {
|
|
||||||
c->just_collided = info.is_collision_enter;
|
|
||||||
c->last_collision_normal = info.normal;
|
|
||||||
c->last_collision_point = info.point;
|
|
||||||
}
|
}
|
@ -5,40 +5,23 @@
|
|||||||
|
|
||||||
#include "components/transform.h"
|
#include "components/transform.h"
|
||||||
#include "ecs_system.h"
|
#include "ecs_system.h"
|
||||||
#include "event_system.h"
|
|
||||||
#include "systems/collisions.h"
|
|
||||||
|
|
||||||
struct CameraControllerComponent {
|
struct CameraControllerComponent {
|
||||||
static constexpr float kWalkSpeed = 4.0f;
|
static constexpr float kWalkSpeed = 4.0f;
|
||||||
static constexpr float kThrust = 25.0f;
|
|
||||||
static constexpr float kCameraSensitivity = 0.007f;
|
static constexpr float kCameraSensitivity = 0.007f;
|
||||||
|
|
||||||
float yaw = 0.0f;
|
float yaw = 0.0f;
|
||||||
float pitch = 0.0f;
|
float pitch = 0.0f;
|
||||||
float dy = 0.0f;
|
|
||||||
|
|
||||||
glm::vec3 last_collision_normal{};
|
|
||||||
glm::vec3 last_collision_point{};
|
|
||||||
|
|
||||||
bool just_collided = false;
|
|
||||||
bool is_grounded = false;
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class CameraControllerSystem
|
class CameraControllerSystem
|
||||||
: public engine::System,
|
: public engine::System {
|
||||||
public engine::EventHandler<engine::PhysicsSystem::CollisionEvent> {
|
|
||||||
public:
|
public:
|
||||||
CameraControllerSystem(engine::Scene* scene);
|
CameraControllerSystem(engine::Scene* scene);
|
||||||
|
|
||||||
// engine::System overrides
|
// engine::System overrides
|
||||||
void OnUpdate(float ts) override;
|
void OnUpdate(float ts) override;
|
||||||
|
|
||||||
// engine::EventHandler overrides
|
|
||||||
void OnEvent(engine::PhysicsSystem::CollisionEvent info) override;
|
|
||||||
|
|
||||||
engine::TransformComponent* t = nullptr;
|
engine::TransformComponent* t = nullptr;
|
||||||
engine::ColliderComponent* col = nullptr;
|
|
||||||
CameraControllerComponent* c = nullptr;
|
CameraControllerComponent* c = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -49,13 +49,10 @@ void PlayGame(GameSettings settings) {
|
|||||||
graphics_settings.vsync = true;
|
graphics_settings.vsync = true;
|
||||||
graphics_settings.wait_for_present = false;
|
graphics_settings.wait_for_present = false;
|
||||||
graphics_settings.msaa_level = engine::gfx::MSAALevel::kOff;
|
graphics_settings.msaa_level = engine::gfx::MSAALevel::kOff;
|
||||||
|
|
||||||
engine::Application app(PROJECT_NAME, PROJECT_VERSION, graphics_settings);
|
engine::Application app(PROJECT_NAME, PROJECT_VERSION, graphics_settings);
|
||||||
|
|
||||||
app.SetFrameLimiter(settings.enable_frame_limiter);
|
app.SetFrameLimiter(settings.enable_frame_limiter);
|
||||||
|
|
||||||
// configure window
|
|
||||||
app.window()->SetRelativeMouseMode(true);
|
app.window()->SetRelativeMouseMode(true);
|
||||||
|
|
||||||
ConfigureInputs(app.input_manager());
|
ConfigureInputs(app.input_manager());
|
||||||
|
|
||||||
auto my_scene = app.scene_manager()->CreateEmptyScene();
|
auto my_scene = app.scene_manager()->CreateEmptyScene();
|
||||||
@ -68,18 +65,13 @@ void PlayGame(GameSettings settings) {
|
|||||||
auto camera = my_scene->CreateEntity("camera");
|
auto camera = my_scene->CreateEntity("camera");
|
||||||
my_scene->GetComponent<engine::TransformComponent>(camera)->position = {
|
my_scene->GetComponent<engine::TransformComponent>(camera)->position = {
|
||||||
0.0f, 10.0f, 0.0f};
|
0.0f, 10.0f, 0.0f};
|
||||||
auto camer_collider =
|
auto camera_collider =
|
||||||
my_scene->AddComponent<engine::ColliderComponent>(camera);
|
my_scene->AddComponent<engine::ColliderComponent>(camera);
|
||||||
camer_collider->is_static = false;
|
camera_collider->is_static = false;
|
||||||
camer_collider->is_trigger = true;
|
camera_collider->is_trigger = false;
|
||||||
camer_collider->aabb = {{-0.2f, -1.5f, -0.2f},
|
camera_collider->aabb = {{-0.2f, -1.5f, -0.2f},
|
||||||
{0.2f, 0.2f, 0.2f}}; // Origin is at eye level
|
{0.2f, 0.2f, 0.2f}}; // Origin is at eye level
|
||||||
my_scene->AddComponent<CameraControllerComponent>(camera);
|
my_scene->AddComponent<CameraControllerComponent>(camera);
|
||||||
my_scene->event_system()
|
|
||||||
->SubscribeToEventType<engine::PhysicsSystem::CollisionEvent>(
|
|
||||||
engine::EventSubscriberKind::kEntity, camera,
|
|
||||||
my_scene->GetSystem<CameraControllerSystem>());
|
|
||||||
|
|
||||||
auto render_system = my_scene->GetSystem<engine::RenderSystem>();
|
auto render_system = my_scene->GetSystem<engine::RenderSystem>();
|
||||||
render_system->SetCameraEntity(camera);
|
render_system->SetCameraEntity(camera);
|
||||||
}
|
}
|
||||||
@ -93,33 +85,6 @@ void PlayGame(GameSettings settings) {
|
|||||||
&app.render_data_, app.GetResourcePath("textures/space2.png"),
|
&app.render_data_, app.GetResourcePath("textures/space2.png"),
|
||||||
engine::resources::Texture::Filtering::kAnisotropic);
|
engine::resources::Texture::Filtering::kAnisotropic);
|
||||||
|
|
||||||
#if 0
|
|
||||||
/* cube */
|
|
||||||
{
|
|
||||||
uint32_t cube = my_scene->CreateEntity("cube");
|
|
||||||
my_scene->GetComponent<engine::TransformComponent>(cube)->position =
|
|
||||||
glm::vec3{-0.5f + 5.0f, -0.5f + 5.0f, -0.5f + 5.0f};
|
|
||||||
auto cube_renderable =
|
|
||||||
my_scene->AddComponent<engine::RenderableComponent>(cube);
|
|
||||||
cube_renderable->material = std::make_shared<engine::resources::Material>(
|
|
||||||
app.GetResource<engine::resources::Shader>("builtin.standard"));
|
|
||||||
cube_renderable->material->texture_ = grass_texture;
|
|
||||||
// app.GetResource<engine::resources::Texture>("builtin.white");
|
|
||||||
cube_renderable->mesh = GenCuboidMesh(app.gfxdev(), 1.0f, 1.0f, 1.0f, 1);
|
|
||||||
auto cube_collider =
|
|
||||||
my_scene->AddComponent<engine::ColliderComponent>(cube);
|
|
||||||
cube_collider->is_static = true;
|
|
||||||
cube_collider->aabb = {{0.0f, 0.0f, 0.0f}, {1.0f, 1.0f, 1.0f}};
|
|
||||||
}
|
|
||||||
|
|
||||||
engine::util::LoadMeshFromFile(
|
|
||||||
my_scene, app.GetResourcePath("models/astronaut/astronaut.dae"));
|
|
||||||
|
|
||||||
engine::util::LoadMeshFromFile(
|
|
||||||
my_scene, app.GetResourcePath("models/plane/plane.dae"));
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* skybox */
|
/* skybox */
|
||||||
{
|
{
|
||||||
uint32_t skybox = my_scene->CreateEntity("skybox");
|
uint32_t skybox = my_scene->CreateEntity("skybox");
|
||||||
@ -165,7 +130,7 @@ void PlayGame(GameSettings settings) {
|
|||||||
{
|
{
|
||||||
int width, height;
|
int width, height;
|
||||||
auto bitmap = app.GetResource<engine::resources::Font>("builtin.mono")
|
auto bitmap = app.GetResource<engine::resources::Font>("builtin.mono")
|
||||||
->GetTextBitmap("ABCDEFGHIJKLMNOPQRSTUVWXYZ12345", 768.0f,
|
->GetTextBitmap("ABCDEFGHIJKLMNOPQRSTUVWXYZ12345", 1080.0f,
|
||||||
width, height);
|
width, height);
|
||||||
|
|
||||||
uint32_t textbox = my_scene->CreateEntity("textbox");
|
uint32_t textbox = my_scene->CreateEntity("textbox");
|
||||||
@ -177,11 +142,11 @@ void PlayGame(GameSettings settings) {
|
|||||||
textbox_renderable->material->texture_ =
|
textbox_renderable->material->texture_ =
|
||||||
std::make_unique<engine::resources::Texture>(
|
std::make_unique<engine::resources::Texture>(
|
||||||
&app.render_data_, bitmap->data(), width, height,
|
&app.render_data_, bitmap->data(), width, height,
|
||||||
engine::resources::Texture::Filtering::kBilinear);
|
engine::resources::Texture::Filtering::kAnisotropic);
|
||||||
textbox_renderable->mesh = GenSphereMesh(app.gfxdev(), 1.0f, 5);
|
textbox_renderable->mesh = GenSphereMesh(app.gfxdev(), 1.0f, 5);
|
||||||
my_scene->GetComponent<engine::TransformComponent>(textbox)->scale.y =
|
my_scene->GetComponent<engine::TransformComponent>(textbox)->scale.y =
|
||||||
(float)height / (float)width;
|
(float)height / (float)width;
|
||||||
textbox_renderable->shown = false;
|
textbox_renderable->shown = true;
|
||||||
|
|
||||||
my_scene->AddComponent<engine::CustomComponent>(textbox)->onUpdate =
|
my_scene->AddComponent<engine::CustomComponent>(textbox)->onUpdate =
|
||||||
[&](float ts) {
|
[&](float ts) {
|
||||||
|
Loading…
Reference in New Issue
Block a user