75 lines
No EOL
2.9 KiB
C++
75 lines
No EOL
2.9 KiB
C++
#include "example.hpp"
|
|
|
|
#include "platform.hpp"
|
|
#include "file.hpp"
|
|
#include "engine.hpp"
|
|
#include "scene.hpp"
|
|
#include "asset.hpp"
|
|
#include "path.hpp"
|
|
|
|
void app_main(prism::engine*) {
|
|
prism::set_domain_path(prism::domain::app, "{resource_dir}/data");
|
|
prism::set_domain_path(prism::domain::internal, "{resource_dir}/shaders");
|
|
|
|
platform::open_window("Example", {-1, -1, 1280, 720}, WindowFlags::Resizable);
|
|
}
|
|
|
|
void ExampleApp::initialize_render() {
|
|
engine->create_empty_scene();
|
|
auto scene = engine->get_scene();
|
|
|
|
camera_obj = scene->add_object();
|
|
auto& camera = scene->add<Camera>(camera_obj);
|
|
camera.near = 0.1f;
|
|
|
|
auto sun_obj = scene->add_object();
|
|
auto& sun = scene->add<Light>(sun_obj);
|
|
sun.type = Light::Type::Point;
|
|
sun.use_dynamic_shadows = true;
|
|
sun.size = 25.0f;
|
|
auto& sun_trans = scene->get<Transform>(sun_obj);
|
|
sun_trans.position = {-2, 5, 1};
|
|
|
|
auto second_sun_obj = scene->add_object();
|
|
auto& second_sun = scene->add<Light>(second_sun_obj);
|
|
second_sun.type = Light::Type::Point;
|
|
second_sun.color = {1, 0, 0};
|
|
second_sun.use_dynamic_shadows = true;
|
|
second_sun.size = 25.0f;
|
|
scene->get<Transform>(second_sun_obj).position = {-14, 1, -1};
|
|
|
|
auto third_sun_obj = scene->add_object();
|
|
auto& third_sun = scene->add<Light>(third_sun_obj);
|
|
third_sun.type = Light::Type::Point;
|
|
third_sun.color = {0, 0, 1};
|
|
third_sun.use_dynamic_shadows = true;
|
|
third_sun.size = 25.0f;
|
|
scene->get<Transform>(third_sun_obj).position = {3, 1, -1};
|
|
|
|
main_object = scene->add_object();
|
|
auto& sphere_render = scene->add<Renderable>(main_object);
|
|
sphere_render.mesh = assetm->get<Mesh>(prism::path(prism::app_domain / "models/bunny.model"));
|
|
sphere_render.materials = { assetm->get<Material>(prism::path(prism::app_domain / "materials/Material.material")) };
|
|
|
|
auto sibenik_obj = scene->add_object();
|
|
auto& sibenik_render = scene->add<Renderable>(sibenik_obj);
|
|
sibenik_render.mesh = assetm->get<Mesh>(prism::path(prism::app_domain / "models/sibenik.model"));
|
|
scene->get<Transform>(sibenik_obj).position.y = 13.5;
|
|
|
|
for(auto& part : sibenik_render.mesh->parts) {
|
|
sibenik_render.materials.push_back(assetm->get<Material>(prism::path(prism::app_domain / "materials" / (part.material_hint + ".material"))));
|
|
}
|
|
|
|
auto probe_obj = scene->add_object();
|
|
scene->add<EnvironmentProbe>(probe_obj).size = {80, 30, 25};
|
|
}
|
|
|
|
void ExampleApp::update(const float delta_time) {
|
|
main_object_spin += delta_time * 5.0f;
|
|
main_object_movement += delta_time * 0.5f;
|
|
|
|
engine->get_scene()->get<Transform>(main_object).position.x = sin(main_object_movement) * 8.0f;
|
|
engine->get_scene()->get<Transform>(main_object).rotation = euler_to_quat({0, radians(main_object_spin), 0});
|
|
|
|
camera_look_at(*engine->get_scene(), camera_obj, prism::float3{2, 2, -2} + engine->get_scene()->get<Transform>(main_object).position, engine->get_scene()->get<Transform>(main_object).position);
|
|
} |