sculpto
Public Member Functions | Friends | List of all members
scl::scene Class Reference

#include <scene.h>

Public Member Functions

int GetViewportId () const
 
const vec3GetEnviromentAmbient () const
 
void SetViewportId (int ViewportId)
 
void SetEnviromentAmbient (const vec3 &EnviromentAmbient)
 
 scene ()
 
 ~scene ()
 
void Render ()
 
void Update ()
 
scene_object CreateObject (const std::string &Name="")
 
scene_object CreaetOrGetObject (const std::string &Name)
 
scene_object GetSceneObject (scene_object_handle SceneObjectHandle)
 
void RemoveObject (scene_object &Object)
 

Friends

class scene_object
 
class scene_serializer
 
class scene_hierarchy_window
 

Detailed Description

Scene class.

Definition at line 26 of file scene.h.

Constructor & Destructor Documentation

◆ scene()

scl::scene::scene ( )

Scene default constructor.

Definition at line 26 of file scene.cpp.

27{
28 event_dispatcher::AddEventListner<mouse_button_event>([&](mouse_button_event &Event) { CallUpdate(); return false; });
29 event_dispatcher::AddEventListner<mouse_wheel_event>([&](mouse_wheel_event &Event) { CallUpdate(); return false; });
30 event_dispatcher::AddEventListner<mouse_move_event>([&](mouse_move_event &Event) { CallUpdate(); return false; });
31 event_dispatcher::AddEventListner<keyboard_event>([&](keyboard_event &Event) { CallUpdate(); return false; });
32 event_dispatcher::AddEventListner<viewport_resize_event>([&](viewport_resize_event &Event)
33 {
34 if (Event.GetViewportId() == ViewportId)
35 ViewportWidth = Event.GetWidth(),
36 ViewportHeight = Event.GetHeight();
37 return false;
38 });
39}

◆ ~scene()

scl::scene::~scene ( )

Scene default destructor.

Definition at line 41 of file scene.cpp.

42{
43}

Member Function Documentation

◆ CreaetOrGetObject()

scl::scene_object scl::scene::CreaetOrGetObject ( const std::string &  Name)
  • Get first scene object with specified name (ordered by creating time) or create new, if nothing found function.
Parameters
Name- name of getting/creating object.
Returns
found/created scene object.

Definition at line 114 of file scene.cpp.

115{
116 for (auto &&[entity, name] : Registry.view<name_component>().each())
117 if (name.Name == Name) return scene_object { entity, this };
118 return this->CreateObject(Name);
119}
scene_object CreateObject(const std::string &Name="")
Definition: scene.cpp:107
friend class scene_object
Definition: scene.h:28

◆ CreateObject()

scl::scene_object scl::scene::CreateObject ( const std::string &  Name = "")
  • Create scene object function.
Parameters
Name- object name (mainly for debug purpose).
Returns
created object.

Definition at line 107 of file scene.cpp.

108{
109 scene_object created_object { this->Registry.create(), this };
110 created_object.AddComponent<name_component>(Name == "" ? "Unnamed component" : Name);
111 return created_object;
112}

◆ GetEnviromentAmbient()

const vec3 & scl::scene::GetEnviromentAmbient ( ) const
inline

Scene ambient color getter function.

Definition at line 47 of file scene.h.

47{ return EnviromentAmbient; }

◆ GetSceneObject()

scl::scene_object scl::scene::GetSceneObject ( scene_object_handle  SceneObjectHandle)
  • Get scene object by its handle function.
Parameters
SceneObjectEntity- handle of getting scene object.
Returns
scene object.

Definition at line 121 of file scene.cpp.

122{
123 return scene_object { SceneObjectHandle, this };
124}

◆ GetViewportId()

int scl::scene::GetViewportId ( ) const
inline

Scene scripts update call timer.

Scene getter/setter functions.

Scene viewport id gette function.

Definition at line 45 of file scene.h.

45{ return ViewportId; }

◆ RemoveObject()

void scl::scene::RemoveObject ( scene_object Object)

Definition at line 126 of file scene.cpp.

127{
128 Registry.destroy(Object.Entity);
129 Object.Entity = entt::null;
130 Object.Scene = nullptr;
131}

◆ Render()

void scl::scene::Render ( )
  • Perform scene rendering function.
Parameters
None.
Returns
None.

Definition at line 71 of file scene.cpp.

72{
73 // Set up scene primary camera
74 camera *primary_camera {};
75 for (auto &&[entity, camera] : Registry.view<camera_component>().each())
76 if (camera.IsPrimary) { primary_camera = &camera.Camera; break; }
77 if (primary_camera == nullptr) return;
78 if (primary_camera->GetViewportWidth() != ViewportWidth || primary_camera->GetViewportHeight() != ViewportHeight)
79 primary_camera->Resize(ViewportWidth, ViewportHeight);
80
81 renderer::StartPipeline(*primary_camera, EnviromentAmbient);
82 {
83 for (auto &&[entity, point_light, transform] : Registry.group<point_light_component>(entt::get<transform_component>).each())
84 renderer::SubmitPointLight(transform.Position, point_light.Color * point_light.Strength, point_light.Constant, point_light.Linear, point_light.Quadratic);
85
86 for (auto &&[entity, directional_light, transform] : Registry.group<directional_light_component>(entt::get<transform_component>).each())
87 {
88 vec3 direction = transform.AnglesMatr.TransformVector(vec3 { 0, -1, 0 });
89 vec3 at = transform.Position + direction;
90 renderer::SubmitDirectionalLight(direction, directional_light.Color * directional_light.Strength, directional_light.GetIsShadow(),
91 matr4::View(transform.Position, at, { 0, 1, 0 }) * directional_light.GetProjection(), directional_light.GetShadowMap());
92 }
93
94 for (auto &&[entity, spot_light, transform] : Registry.group<spot_light_component>(entt::get<transform_component>).each())
95 {
96 vec3 direction = transform.AnglesMatr.TransformVector(vec3 { 0, -1, 0 });
97 renderer::SubmitSpotLight(transform.Position, direction, spot_light.Color * spot_light.Strength,
98 spot_light.InnerCutoffCos, spot_light.OuterCutoffCos, spot_light.Epsilon);
99 }
100
101 for (auto &&[entity, mesh, transform] : Registry.group<mesh_component>(entt::get<transform_component>).each())
102 if (mesh.Mesh != nullptr) renderer::Submit(mesh, transform);
103 }
105}
static matr4 View(vec3< float > Location, vec3< float > At, vec3< float > Up)
Definition: matr4.h:391
static void StartPipeline(const camera &Camera, const vec3 &EnviromentAmbiente)
Definition: Renderer.cpp:174
static void Submit(const shared< mesh > &Mesh, const vec3 &Scale, const vec3 &Angles, const vec3 &Position)
Definition: Renderer.cpp:251
static void SubmitSpotLight(const vec3 &Position, const vec3 &Direction, const vec3 &Color, float InnerCutoffCos, float OuterCutoffCos, float Epsilon)
Definition: Renderer.cpp:238
static void SubmitPointLight(const vec3 &Position, const vec3 &Color, float Constant, float Linear, float Quadratic)
Definition: Renderer.cpp:210
static void EndPipeline()
Definition: Renderer.cpp:198
static void SubmitDirectionalLight(const vec3 &Direction, const vec3 &Color, bool IsShadows=false, const matr4 &ViewProjection={}, const shared< frame_buffer > &ShadowMap=nullptr)
Definition: Renderer.cpp:222
math::vec3< float > vec3
Definition: base.h:38

◆ SetEnviromentAmbient()

void scl::scene::SetEnviromentAmbient ( const vec3 EnviromentAmbient)
inline

Scene enviroment ambient color setter function.

Definition at line 52 of file scene.h.

52{ this->EnviromentAmbient = EnviromentAmbient; }

◆ SetViewportId()

void scl::scene::SetViewportId ( int  ViewportId)
inline

Scene viewport setter function.

Definition at line 50 of file scene.h.

50{ this->ViewportId = ViewportId; }

◆ Update()

void scl::scene::Update ( )
  • Scene update function.
Parameters
None.
Returns
None.

Definition at line 63 of file scene.cpp.

64{
65 UpdateDelay += timer::GetDeltaTime();
66 if (UpdateDelay < 0.015) return;
67 UpdateDelay = 0;
68 CallUpdate();
69}
static float GetDeltaTime()
Definition: timer.h:42

Friends And Related Function Documentation

◆ scene_hierarchy_window

friend class scene_hierarchy_window
friend

Definition at line 30 of file scene.h.

◆ scene_object

friend class scene_object
friend

Definition at line 28 of file scene.h.

◆ scene_serializer

friend class scene_serializer
friend

Definition at line 29 of file scene.h.


The documentation for this class was generated from the following files: