--- /dev/null
+/playground
+/playground.*
--- /dev/null
+package "playground"
+{
+ require "mspcore";
+ require "mspdatafile";
+ require "mspmath";
+ require "mspgui";
+ require "mspgl";
+ require "mspvr";
+ require "mspgame";
+ require "sigc++-2.0";
+
+ program "playground"
+ {
+ source "source";
+ };
+};
--- /dev/null
+shape
+{
+ sphere
+ {
+ radius 0.1;
+ };
+ technique_name "checker_blue.tech";
+};
--- /dev/null
+import pbr_material;
+
+#pragma MSP stage(fragment)
+vec4 get_base_color() override
+{
+ ivec3 ipos = ivec3(floor(vertex.xyz*1.73205));
+ float intensity = 1.0;
+ if(((ipos.x^ipos.y^ipos.z)&2)!=0)
+ intensity -= 0.5f;
+ if(((ipos.x^ipos.y^ipos.z)&1)==0)
+ intensity -= 0.1f;
+ return intensity*pbr_material.base_color*pbr_material.tint;
+}
--- /dev/null
+module "checker.glsl"
+{
+ specialize "use_shadow_map" true;
+};
--- /dev/null
+method ""
+{
+ material
+ {
+ type pbr;
+ base_color 0.8 0.8 0.8;
+ roughness 0.9;
+ };
+ shader "checker.shader";
+ receive_shadows true;
+};
+method "shadow"
+{
+ shader "occluder.glsl.shader";
+};
--- /dev/null
+method ""
+{
+ material
+ {
+ type pbr;
+ base_color 0.0 0.3 1.0;
+ roughness 0.3;
+ };
+ shader "checker.shader";
+ receive_shadows true;
+};
+method "shadow"
+{
+ shader "occluder.glsl.shader";
+};
--- /dev/null
+method ""
+{
+ material
+ {
+ type pbr;
+ base_color 0.5 0.3 0.1;
+ roughness 0.9;
+ };
+ shader "checker.shader";
+ receive_shadows true;
+};
+method "shadow"
+{
+ shader "occluder.glsl.shader";
+};
--- /dev/null
+method ""
+{
+ material
+ {
+ type pbr;
+ base_color 0.8 0.0 0.0;
+ roughness 0.3;
+ };
+ shader "checker.shader";
+ receive_shadows true;
+};
+method "shadow"
+{
+ shader "occluder.glsl.shader";
+};
--- /dev/null
+shape
+{
+ box
+ {
+ extent 0.1 1.5 0.3;
+ };
+ technique_name "checker_brown.tech";
+};
--- /dev/null
+shape
+{
+ box
+ {
+ extent 10.0 10.0 1.0;
+ };
+ technique_name "checker.tech";
+};
--- /dev/null
+near_clip 0.05;
+far_clip 20.0;
--- /dev/null
+fixture "ground.fixt.setup"
+{
+ transform
+ {
+ position 0.0 0.0 -0.5;
+ };
+};
+fixture "edge.fixt.setup"
+{
+ transform
+ {
+ position 0.7 0.0 0.14;
+ euler 0.0 15.0 0.0;
+ };
+};
+fixture "edge.fixt.setup"
+{
+ transform
+ {
+ position 0.0 0.7 0.14;
+ euler 0.0 15.0 90.0;
+ };
+};
+fixture "edge.fixt.setup"
+{
+ transform
+ {
+ position -0.7 0.0 0.14;
+ euler 0.0 15.0 180.0;
+ };
+};
+fixture "edge.fixt.setup"
+{
+ transform
+ {
+ position 0.0 -0.7 0.14;
+ euler 0.0 15.0 270.0;
+ };
+};
--- /dev/null
+shape
+{
+ sphere
+ {
+ radius 0.06;
+ };
+ technique_name "checker_red.tech";
+};
--- /dev/null
+type DIRECTIONAL;
+intensity 2.0;
+cast_shadows true;
--- /dev/null
+#include "fixture.h"
+
+using namespace Msp;
+
+Fixture::Fixture(Game::Handle<Game::Entity> p, const Setup &s, const Game::TransformValues &t):
+ Entity(p, t),
+ setup(s),
+ rigid_body(this),
+ shape(this, setup.shape)
+{ }
--- /dev/null
+#ifndef FIXTURE_H_
+#define FIXTURE_H_
+
+#include <msp/game/entity.h>
+#include <msp/game/rigidbody.h>
+#include <msp/game/shape.h>
+#include "playground/setups.h"
+
+class Fixture: public Msp::Game::Entity
+{
+public:
+ using Setup = FixtureSetup;
+
+private:
+ const Setup &setup;
+ Msp::Game::Owned<Msp::Game::RigidBody> rigid_body;
+ Msp::Game::Owned<Msp::Game::Shape> shape;
+
+public:
+ Fixture(Msp::Game::Handle<Msp::Game::Entity>, const Setup &, const Msp::Game::TransformValues &);
+};
+
+#endif
--- /dev/null
+#include "playground.h"
+#include <random>
+#include <msp/game/physicssystem.h>
+#include <msp/game/root.h>
+#include <msp/game/stageplan.h>
+#include "fixture.h"
+#include "playground/setups.h"
+#include "toy.h"
+
+using namespace std;
+using namespace Msp;
+
+Playground::Playground(int, char **):
+ stage(director.create_stage("playground")),
+ cam_entity(stage.get_root(), Game::TransformValues({ 0.0f, -1.5f, 1.5f }, Geometry::make_quat(45.0f*Geometry::degrees, { 1.0f, 0.0f, 0.0f }))),
+ camera(cam_entity, resources.get<Game::CameraSetup>("playground.camera.setup")),
+ shadow_setup{ 15.0f },
+ shadow_target(cam_entity, shadow_setup),
+ sun_entity(stage.get_root(), Game::TransformValues({}, Geometry::make_quat(30.0f*Geometry::degrees, { 1.0f, -0.5f, 0.0f }))),
+ sun(sun_entity, resources.get<Game::LightSetup>("sun.light.setup"))
+{
+ Game::StagePlan::register_entity_type<Fixture>("fixture");
+
+ stage.add_system<Game::PhysicsSystem>();
+ stage.apply_plan(resources.get<Game::StagePlan>("playground.stage"));
+
+ vector<ToySetup *> toy_setups = resources.get_all<ToySetup>();
+ std::mt19937 random;
+ std::uniform_int_distribution<unsigned> type_dist(0, toy_setups.size()-1);
+ std::uniform_real_distribution<float> hdist(-0.65f, 0.65f);
+ std::uniform_real_distribution<float> vdist(0.3f, 0.6f);
+ for(unsigned i=0; i<15; ++i)
+ {
+ const ToySetup &setup = *toy_setups[type_dist(random)];
+ LinAl::Vector<float, 3> pos(hdist(random), hdist(random), vdist(random));
+ toys.emplace_back(stage.get_root(), setup, Game::TransformValues(pos, Geometry::Quaternion<float>::one()));
+ }
+
+ director.activate_stage(stage);
+}
+
+
+PlaygroundResources::PlaygroundResources()
+{
+ add_type<FixtureSetup>().suffix(".fixt.setup");
+ add_type<ToySetup>().suffix(".toy.setup");
+}
--- /dev/null
+#ifndef PLAYGROUND_H_
+#define PLAYGROUND_H_
+
+#include <msp/game/camera.h>
+#include <msp/game/light.h>
+#include <msp/game/owned.h>
+#include <msp/game/resources.h>
+#include <msp/game/shadowtarget.h>
+#include <msp/game/stage.h>
+#include <msp/gameview/application.h>
+#include <msp/gameview/resources.h>
+
+class Toy;
+
+class PlaygroundResources: public Msp::Game::ApplicationResources, public Msp::GameView::Resources
+{
+public:
+ PlaygroundResources();
+};
+
+class Playground: public Msp::GameView::Application<Playground, PlaygroundResources>
+{
+private:
+ Msp::Game::Stage &stage;
+ Msp::Game::Owned<Msp::Game::Entity> cam_entity;
+ Msp::Game::Owned<Msp::Game::Camera> camera;
+ Msp::Game::ShadowTargetSetup shadow_setup;
+ Msp::Game::Owned<Msp::Game::ShadowTarget> shadow_target;
+ Msp::Game::Owned<Msp::Game::Entity> sun_entity;
+ Msp::Game::Owned<Msp::Game::Light> sun;
+ std::vector<Msp::Game::Owned<Toy>> toys;
+
+public:
+ Playground(int, char **);
+};
+
+#endif
--- /dev/null
+import "msp/game/setups";
+
+entity Fixture
+{
+ field shape Shape;
+};
+
+entity Toy
+{
+ field shape Shape;
+};
--- /dev/null
+#include "toy.h"
+
+using namespace Msp;
+
+Toy::Toy(Game::Handle<Game::Entity> p, const Setup &s, const Game::TransformValues &t):
+ Entity(p, t),
+ setup(s),
+ rigid_body(this),
+ shape(this, setup.shape),
+ motion(this)
+{ }
--- /dev/null
+#ifndef TOY_H_
+#define TOY_H_
+
+#include <msp/game/entity.h>
+#include <msp/game/motion.h>
+#include <msp/game/rigidbody.h>
+#include <msp/game/shape.h>
+#include "playground/setups.h"
+
+class Toy: public Msp::Game::Entity
+{
+public:
+ using Setup = ToySetup;
+
+private:
+ const Setup &setup;
+ Msp::Game::Owned<Msp::Game::RigidBody> rigid_body;
+ Msp::Game::Owned<Msp::Game::Shape> shape;
+ Msp::Game::Owned<Msp::Game::Motion> motion;
+
+public:
+ Toy(Msp::Game::Handle<Msp::Game::Entity>, const Setup &, const Msp::Game::TransformValues &);
+};
+
+#endif