Simulant  21.12-1303
A portable game engine for Windows, OSX, Linux, Dreamcast, and PSP
skybox.h
1 #pragma once
2 
3 #include "../../asset_manager.h"
4 #include "../../generic/identifiable.h"
5 #include "../../path.h"
6 #include "../stage_node.h"
7 #include "simulant/nodes/builtins.h"
8 #include "simulant/utils/params.h"
9 #include <stdexcept>
10 
11 namespace smlt {
12 
13 enum SkyboxFace {
14  SKYBOX_FACE_TOP,
15  SKYBOX_FACE_BOTTOM,
16  SKYBOX_FACE_LEFT,
17  SKYBOX_FACE_RIGHT,
18  SKYBOX_FACE_FRONT,
19  SKYBOX_FACE_BACK,
20  SKYBOX_FACE_MAX
21 };
22 
23 class SkyboxImageNotFoundError: public std::runtime_error {
24 public:
25  SkyboxImageNotFoundError(const std::string& what) :
26  std::runtime_error(what) {}
27 };
28 
29 class SkyboxImageDuplicateError: public std::runtime_error {
30 public:
31  SkyboxImageDuplicateError(const std::string& what) :
32  std::runtime_error(what) {}
33 };
34 
35 class Skybox: public ContainerNode, public ChainNameable<Skybox> {
36 
37 public:
38  S_DEFINE_STAGE_NODE_META(STAGE_NODE_TYPE_SKYBOX, "skybox");
39  S_DEFINE_STAGE_NODE_PARAM(Skybox, "source_directory", std::string, no_value,
40  "The directory containing the skybox images");
41  S_DEFINE_STAGE_NODE_PARAM(Skybox, "flags", TextureFlags, TextureFlags(),
42  "The flags to apply to the skybox textures");
43 
44  constexpr static float DEFAULT_SIZE = 128.0f;
45 
46  Skybox(Scene* owner);
47 
48  void set_size(float size) {
49  width_ = size;
50  }
51  float size() const {
52  return width_;
53  }
54 
55  void generate(const Path& up, const Path& down, const Path& left,
56  const Path& right, const Path& front, const Path& back,
57  const TextureFlags& flags);
58 
59  const AABB& aabb() const override;
60 
61 private:
62  friend class SkyManager;
63 
64  bool on_create(Params params) override;
65 
66  StageNodeID follow_camera_;
67 
68  ActorPtr actor_ = nullptr;
69  MeshPtr mesh_;
70  MaterialPtr materials_[SKYBOX_FACE_MAX];
71 
72  float width_;
73 };
74 
75 } // namespace smlt
smlt::Actor
Definition: actor.h:53
smlt::TextureFlags
Definition: texture_flags.h:28
smlt::SkyboxImageDuplicateError
Definition: skybox.h:29
smlt::Params
Definition: params.h:45
smlt
Definition: animation.cpp:25
smlt::Scene
Definition: scene.h:94
smlt::ContainerNode
Definition: stage_node.h:1056
smlt::Path
Definition: path.h:7
smlt::ChainNameable
Definition: nameable.h:34
smlt::AABB
Definition: aabb.h:22
smlt::Skybox
Definition: skybox.h:35
smlt::SkyboxImageNotFoundError
Definition: skybox.h:23