Skip to content
Snippets Groups Projects
Commit 4bc5d02c authored by Joseph Walton-Rivers's avatar Joseph Walton-Rivers
Browse files

allow colours to be defined in scene files

parent 1ff0a577
No related branches found
No related tags found
No related merge requests found
......@@ -47,6 +47,11 @@ prefabs:
pipeline: phong
shape:
type: sphere
gfx::material:
ambient: [0.25, 0.25, 0.25]
diffuse: [0.4, 0.4, 0.4]
specular: [0.774597,0.774597,0.774597]
shininess: 0.6
phys::Body:
shape:
type: sphere
......@@ -58,6 +63,11 @@ prefabs:
pipeline: phong
shape:
type: box
gfx::material:
ambient: [0.0215, 0.1754, 0.0215]
diffuse: [1, 1, 1]
specular: [0.0633, 0.727811, 0.633]
shininess: 0.6
phys::Body:
type: kinematic
shape:
......
......@@ -43,22 +43,11 @@ static void setup_prefabs(fggl::ecs3::World& world, Prefabs& prefabs) {
// player (cube because my sphere function doesn't exist yet
prefabs.player = world.findPrototype("player");
world.add<fggl::phys::Dynamics>(prefabs.player);
auto* material = world.add< fggl::gfx::PhongMaterial >( prefabs.player );
material->ambient = fggl::math::vec3(0.25F, 0.25F, 0.25F);
material->diffuse = fggl::math::vec3(0.4F, 0.4F, 0.4F);
material->specular = fggl::math::vec3(0.774597F, 0.774597F, 0.774597F);
material->shininess = 0.6F;
}
{
// collectable
prefabs.collectable = world.findPrototype("collectable");
auto* material = world.add< fggl::gfx::PhongMaterial >( prefabs.collectable );
material->ambient = fggl::math::vec3(0.0215F, 0.1754F, 0.0215F);
material->diffuse = fggl::math::vec3(0.007568F, 0.61424F, 0.07568F);
material->specular = fggl::math::vec3(0.633F, 0.727811F, 0.633F);
material->shininess = 0.6F;
// we need both of these for callbacks to trigger.
world.add<fggl::phys::CollisionCallbacks>(prefabs.collectable);
......@@ -147,6 +136,7 @@ static fggl::ecs3::entity_t setup_environment(fggl::ecs3::World& world, const fg
namespace demo {
constexpr fggl::math::vec2 WORLD_SIZE{40.0F, 40.0F };
constexpr fggl::math::vec3 COLLECTABLE_ROTATION{15, 30, 45};
constexpr fggl::math::vec3 COLOUR_WHITE{1.0F, 1.0F, 1.0F};
constexpr fggl::math::vec3 COLOUR_BLUE{0.0F, 0.0F, 1.0F};
constexpr float MOVE_FORCE{3.0F};
......@@ -315,15 +305,9 @@ namespace demo {
continue;
}
auto* transform = world.get<fggl::math::Transform>(entity);
// rotate the cubes
fggl::math::vec3 angles{15, 30, 45};
transform->rotateEuler( angles * deltaTime );
//auto* renderer = world.get<fggl::data::StaticMesh>( entity );
//renderer->hintColour = fggl::math::vec3(1.0F, 1.0F, 1.0F);
auto* transform = world.get<fggl::math::Transform>(entity);
transform->rotateEuler( COLLECTABLE_ROTATION * deltaTime );
}
}
......
......@@ -25,6 +25,8 @@
#ifndef FGGL_DEBUG_LOGGING_HPP
#define FGGL_DEBUG_LOGGING_HPP
#include <string_view>
namespace fggl::debug {
using FmtType = const std::string_view;
......
......@@ -2,6 +2,7 @@
#define FGGL_ECS_COMPONENT_H
#include "utility.hpp"
#include "fggl/debug/logging.hpp"
#include <cassert>
#include <cstring>
......@@ -69,7 +70,7 @@ namespace fggl::ecs {
C* ptr = new C();
bool restored = restore_config<C>(ptr, config);
if ( !restored ) {
std::cerr << "error restoring " << name() << std::endl;
debug::warning("error restoring {}", C::name);
assert( false && "failed to restore configuration when loading type!" );
}
return ptr;
......
......@@ -184,6 +184,15 @@ namespace fggl::ecs {
return true;
}
template<>
bool restore_config(gfx::PhongMaterial* comp, const YAML::Node& node) {
comp->diffuse = node["diffuse"].as<math::vec3>( gfx::DEFAULT_DIFFUSE );
comp->ambient = node["ambient"].as<math::vec3>( gfx::DEFAULT_AMBIENT );
comp->specular = node["specular"].as<math::vec3>( gfx::DEFAULT_SPECULAR );
comp->shininess = node["shininess"].as<float>( gfx::DEFAULT_SHININESS );
return true;
}
template<>
bool restore_config(data::StaticMesh* meshComp, const YAML::Node& node) {
if ( !node["pipeline"] ) {
......
......@@ -192,7 +192,8 @@ namespace fggl::ecs3 {
}
}
std::cerr << "asked for unknown component type: " << name << std::endl;
debug::warning("asked for unknown/unregistered component type: {}", name);
assert(false && "unknown component type, are you sure it was registered?");
return 0;
}
......
......@@ -29,6 +29,11 @@
namespace fggl::gfx {
constexpr math::vec3 DEFAULT_AMBIENT { 0.05F, 0.05F, 0.05F};
constexpr math::vec3 DEFAULT_DIFFUSE { 0.5F, 0.5F, 0.5F};
constexpr math::vec3 DEFAULT_SPECULAR { 0.7F, 0.7F, 0.7F};
constexpr float DEFAULT_SHININESS = .078125F;
struct PhongMaterial {
constexpr static const char* name = "gfx::material";
math::vec3 ambient;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment