Khaotic Engine Reborn
Loading...
Searching...
No Matches
object.h
1#pragma once
2#include "model_class.h"
3#include <WICTextureLoader.h>
4#include <SimpleMath.h>
5
6#include "d_3d_class.h"
7
8enum class ObjectType
9{
10 Sphere,
11 Cube,
12 Unknown
13};
14
15enum class ShaderType
16{
17 CEL_SHADING,
18 LIGHTING,
19 NORMAL_MAPPING,
20 SPECULAR_MAPPING,
21 REFLECTION,
22 REFRACTION,
23 TEXTURE,
24 SKYBOX,
25 SUNLIGHT,
26 ALPHA_MAPPING
27};
28
29class object
30{
31public:
33 object();
34 ~object();
35
36 object(const object&) = delete;
37 object& operator=(const object&) = delete;
38
39 bool Initialize(
40 ID3D11Device* device,
41 ID3D11DeviceContext* deviceContext,
42 char* modelFilename,
43 TextureContainer& texturesContainer
44 );
45
46 void SetScaleMatrix(XMMATRIX scaleMatrix);
47 void SetRotateMatrix(XMMATRIX rotateMatrix);
48 void SetTranslateMatrix(XMMATRIX translateMatrix);
49 void SetSRMatrix(XMMATRIX srMatrix);
50 void SetWorldMatrix(XMMATRIX worldMatrix);
51
52 void SetPosition(XMVECTOR position);
53 void SetRotation(XMVECTOR rotation);
54 void SetScale(XMVECTOR scale);
55
56 XMMATRIX GetScaleMatrix() const;
57 XMMATRIX GetRotateMatrix() const;
58 XMMATRIX GetTranslateMatrix() const;
59 XMMATRIX GetSRMatrix() const;
60 XMMATRIX GetWorldMatrix() const;
61
62 XMVECTOR GetPosition();
63 XMVECTOR GetRotation();
64 XMVECTOR GetScale();
65
66 void SetVelocity(XMVECTOR);
67 void AddVelocity(float deltaTime);
68 XMVECTOR GetVelocity() const;
69 void SetAcceleration(XMVECTOR);
70 XMVECTOR GetAcceleration() const;
71 void SetMass(float);
72 float GetMass() const;
73 void SetGrounded(bool);
74 bool IsGrounded() const;
75 bool IsPhysicsEnabled() const;
76 void SetPhysicsEnabled(bool state);
77 void SetVisible (bool state) { m_isVisible = state; }
78 bool IsVisible() const { return m_isVisible; }
79
80 void UpdateWorldMatrix();
81 void UpdateSRMatrix();
82 void UpdateScaleMatrix();
83 void UpdateRotateMatrix();
84 void UpdateTranslateMatrix();
85
86 void UpdatePosition(float deltaTime);
87
88 void Update();
89
90 std::string GetName();
91 void SetName(std::string name);
92 int SetId(int id);
93 int GetId() const;
94 void SetType(ObjectType type);
95 ObjectType GetType() const { return m_type; };
96
97 ShaderType GetActiveShader() const { return m_activeShader; };
98 void SetActiveShader(ShaderType activeShader) { m_activeShader = activeShader; };
99
100 float GetBoundingRadius() const;
101 void SetBoundingRadius(float radius) { m_boundingRadius = radius; }
102
103 void SetModelPath(std::wstring& path) { m_modelPath = path; }
104 std::wstring& GetModelPath() { return m_modelPath; }
105
106 ShaderType StringToShaderType(const std::string& shaderType);
107 std::string ShaderTypeToString(ShaderType shaderType);
108
109 ObjectType StringToObjectType(const std::string& objectType);
110 std::string ObjectTypeToString(ObjectType objectType);
111
112 void LaunchObject();
113 bool LoadTexturesFromPath(std::vector<std::wstring>& texturePaths, TextureContainer& texturesContainer,d_3d_class* m_Direct3D);
114 bool SetupInstancing(ID3D11Device* device, const std::vector<XMMATRIX>& instanceTransforms);
115 void EnableInstancing(bool enabled);
116 void SetInstanceCount(int count);
117 bool IsInstancingEnabled() const;
118 int GetInstanceCount() const;
119 ID3D11Buffer* GetInstanceBuffer() const;
120 void SetAlpha(float alpha) { m_alpha = alpha; }
121 float GetAlpha() const { return m_alpha; }
122 void SetInitialStretch(float initialStretch) { m_initialStretch = initialStretch; }
123 float GetInitialStretch() const { return m_initialStretch; }
124 void SetSpringConstant(float springConstant) { m_springConstant = springConstant; }
125 float GetSpringConstant() const { return m_springConstant; }
126
127 bool IsGravityEnabled() const { return m_gravityEnabled; }
128 void SetGravityEnabled(bool state) { m_gravityEnabled = state; }
129
130 std::shared_ptr<model_class> get_model() const { return m_model_; }
131 void SetModel(std::shared_ptr<model_class> model) { m_model_ = model; }
132
133public :
134 bool m_demoSpinning = false;
135 XMVECTOR m_previousPosition;
136 XMVECTOR m_velocity;
137 int m_id;
138 bool m_gravityEnabled = true;
139
140private:
141
142 application_class& m_Application;
143
144 XMMATRIX m_scaleMatrix;
145 XMMATRIX m_rotateMatrix;
146 XMMATRIX m_translateMatrix;
147 XMMATRIX m_srMatrix;
148 XMMATRIX m_worldMatrix;
149
150 XMVECTOR m_acceleration;
151 float m_mass;
152 bool m_isGrounded;
153 bool m_isPhysicsEnabled;
154 bool m_isVisible;
155
156 std::string m_name;
157 ObjectType m_type = ObjectType::Unknown;
158 ShaderType m_activeShader = ShaderType::LIGHTING;
159
160 float m_boundingRadius;
161 std::wstring m_modelPath;
162 TextureContainer m_texturesContainer;
163 float m_alpha = 0.0f;
164 float m_initialStretch = 0.0f;
165 float m_springConstant = 10.0f;
166
167 std::shared_ptr<model_class> m_model_;
168
169};