Photon Engine 2.0.0-beta
A physically based renderer.
Loading...
Searching...
No Matches
PhysicalActor.h
Go to the documentation of this file.
1#pragma once
2
3#include "Actor/Actor.h"
6#include "Math/TVector3.h"
7#include "Math/TQuaternion.h"
8#include "SDL/sdl_interface.h"
9
10#include <Common/primitive_type.h>
11
12#include <optional>
13
14namespace ph
15{
16
17class PhysicalActor : public Actor
18{
19public:
20 TransientVisualElement cook(const CookingContext& ctx, const PreCookReport& report) const override = 0;
21
22 void translate(const real amountX, const real amountY, const real amountZ);
23 void translate(const math::Vector3R& amount);
24 void rotate(const math::Vector3R& axis, const real additionanDegrees);
25 void rotate(const math::QuaternionR& additionalRotation);
26 void scale(const real uniformAmount);
27 void scale(const real amountX, const real amountY, const real amountZ);
28 void scale(const math::Vector3R& amount);
29
30 void setBaseTransform(const math::TDecomposedTransform<real>& baseLocalToWorld);
31
32protected:
34
35public:
37 {
39
40 inline void operator () (PhysicalActor& actor) const
41 {
42 actor.translate(amount);
43 }
44
46 {
47 FunctionType func("translate");
48 func.description("Moves the actor away from the original location with a specified amount.");
49
50 TSdlVector3<OwnerType> amount("amount", &OwnerType::amount);
51 amount.description("The amount to move on each axis.");
52 amount.defaultTo({0, 0, 0});
53 func.addParam(amount);
54
55 return func;
56 }
57 };
58
59 struct SdlRotate
60 {
61 std::optional<math::Vector3R> axis;
62 std::optional<real> degrees;
63 std::optional<math::QuaternionR> rotation;
64
65 inline void operator () (PhysicalActor& actor) const
66 {
67 if(rotation)
68 {
69 actor.rotate((*rotation).normalize());
70 }
71 else if(axis && degrees)
72 {
73 actor.rotate((*axis).normalize(), *degrees);
74 }
75 else
76 {
77 throw SdlLoadError(
78 "possible input formats are: "
79 "1. A vector3 axis and real degrees; "
80 "2. Specify rotation directly with a quaternion.");
81 }
82 }
83
85 {
86 FunctionType func("rotate");
87 func.description("Rotates the actor along an axis with a specified amount.");
88
89 TSdlOptionalVector3<OwnerType> axis("axis", &OwnerType::axis);
90 axis.description("The axis for rotation.");
91 func.addParam(axis);
92
93 TSdlOptionalReal<OwnerType> degrees("degrees", &OwnerType::degrees);
94 degrees.description("The amount of the rotation, in degrees.");
95 func.addParam(degrees);
96
97 TSdlOptionalQuaternion<OwnerType> rotation("rotation", &OwnerType::rotation);
98 rotation.description("Specify the rotation with a quaternion directly.");
99 func.addParam(rotation);
100
101 return func;
102 }
103 };
104
105 struct SdlScale
106 {
108
109 inline void operator () (PhysicalActor& actor) const
110 {
111 actor.scale(amount);
112 }
113
115 {
116 FunctionType func("scale");
117 func.description("Enlarges or shrinks the actor with some specified amount.");
118
119 TSdlVector3<OwnerType> amount("amount", &OwnerType::amount);
120 amount.description("The amount to scale on each axis.");
121 amount.defaultTo({1, 1, 1});
122 func.addParam(amount);
123
124 return func;
125 }
126 };
127
129 {
130 ClassType clazz("physical");
131 clazz.docName("Physical Actor");
132 clazz.description("An actor that is visible and can be transformed.");
133 clazz.baseOn<Actor>();
134
135 clazz.addStruct(&OwnerType::m_localToWorld);
136
137 clazz.addFunction<SdlTranslate>();
138 clazz.addFunction<SdlRotate>();
139 clazz.addFunction<SdlScale>();
140
141 return clazz;
142 }
143};
144
145}// end namespace ph
Definition Actor.h:22
Information about the world being cooked.
Definition CookingContext.h:24
Definition PhysicalActor.h:18
TransformInfo m_localToWorld
Definition PhysicalActor.h:33
void setBaseTransform(const math::TDecomposedTransform< real > &baseLocalToWorld)
Definition PhysicalActor.cpp:41
void translate(const real amountX, const real amountY, const real amountZ)
Definition PhysicalActor.cpp:6
void scale(const real uniformAmount)
Definition PhysicalActor.cpp:26
PH_DEFINE_SDL_CLASS(TSdlOwnerClass< PhysicalActor >)
Definition PhysicalActor.h:128
TransientVisualElement cook(const CookingContext &ctx, const PreCookReport &report) const override=0
void rotate(const math::Vector3R &axis, const real additionanDegrees)
Definition PhysicalActor.cpp:16
Definition PreCookReport.h:13
Error on the SDL input process.
Definition sdl_exceptions.h:22
SDL binding type for a canonical SDL method.
Definition TSdlMethod.h:26
SDL binding type for a canonical SDL resource class.
Definition TSdlOwnerClass.h:23
Definition TSdlQuaternion.h:19
A field class that binds a floating point member variable.
Definition TSdlReal.h:21
Definition TSdlVector3.h:19
Definition TransformInfo.h:17
A group of cooked data that represent the visible part of the scene at a specific time....
Definition TransientVisualElement.h:19
Perform affine transformations in decomposed form.
Definition TDecomposedTransform.h:24
The root for all renderer implementations.
Definition EEngineProject.h:6
Definition PhysicalActor.h:60
std::optional< real > degrees
Definition PhysicalActor.h:62
std::optional< math::Vector3R > axis
Definition PhysicalActor.h:61
void operator()(PhysicalActor &actor) const
Definition PhysicalActor.h:65
std::optional< math::QuaternionR > rotation
Definition PhysicalActor.h:63
PH_DEFINE_SDL_FUNCTION(TSdlMethod< SdlRotate, PhysicalActor >)
Definition PhysicalActor.h:84
Definition PhysicalActor.h:106
math::Vector3R amount
Definition PhysicalActor.h:107
void operator()(PhysicalActor &actor) const
Definition PhysicalActor.h:109
PH_DEFINE_SDL_FUNCTION(TSdlMethod< SdlScale, PhysicalActor >)
Definition PhysicalActor.h:114
Definition PhysicalActor.h:37
math::Vector3R amount
Definition PhysicalActor.h:38
void operator()(PhysicalActor &actor) const
Definition PhysicalActor.h:40
PH_DEFINE_SDL_FUNCTION(TSdlMethod< SdlTranslate, PhysicalActor >)
Definition PhysicalActor.h:45