Skip to content

Commit 5e701e7

Browse files
committed
Fix memory leak and add Scale property to Models
1 parent 75bbc00 commit 5e701e7

File tree

9 files changed

+771
-948
lines changed

9 files changed

+771
-948
lines changed

include/engine.hpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,7 @@ struct RenderUIArrows {
142142
// VkImageView diffTextureImageView;
143143
// VkSampler diffTextureSampler;
144144

145-
/* 3*2, 3 arrows, 2 objects per arrow. */
146-
std::array<RenderModel, 3*2> arrowRenderModels;
145+
std::array<RenderModel, 3> arrowRenderModels;
147146

148147
std::array<std::pair<std::pair<MatricesUBO, UIArrowsUBO>, std::pair<BufferAndMemory, BufferAndMemory>>, 3> arrowBuffers;
149148
};
@@ -219,6 +218,8 @@ class Engine {
219218
VkFramebuffer CreateFramebuffer(VkRenderPass renderPass, VkImageView imageView, VkExtent2D resolution, VkImageView depthImageView = nullptr);
220219
bool QuitEventCheck(SDL_Event &event);
221220

221+
void UnloadRenderModel(RenderModel &renderModel);
222+
222223
SwapChainSupportDetails QuerySwapChainSupport(VkPhysicalDevice physicalDevice, VkSurfaceKHR surface);
223224
VkShaderModule CreateShaderModule(VkDevice device, const std::vector<char> &code);
224225
Uint32 FindMemoryType(Uint32 typeFilter, VkMemoryPropertyFlags properties);

include/model.hpp

+5-1
Original file line numberDiff line numberDiff line change
@@ -132,13 +132,16 @@ class Model
132132

133133
Model() = default;
134134

135-
Model(const string_view path, glm::vec3 position = glm::vec3(0, 0, 0), glm::vec3 rotation = glm::vec3(0, 0, 0));
135+
Model(const string_view path, glm::vec3 position = glm::vec3(0, 0, 0), glm::vec3 rotation = glm::vec3(0, 0, 0), glm::vec3 scale = glm::vec3(1, 1, 1));
136136

137137
constexpr void SetPosition(glm::vec3 pos) { m_Position = pos; m_NeedsUpdate = true; };
138138
constexpr void SetRotation(glm::vec3 rot) { m_Rotation = rot; m_NeedsUpdate = true; };
139+
constexpr void SetScale(glm::vec3 scale) { boundingBox[0] *= (1.0f / m_Scale) * scale; boundingBox[1] *= (1.0f / m_Scale) * scale; m_Scale = scale; m_NeedsUpdate = true; };
139140

140141
constexpr glm::vec3 GetPosition() { return m_Position; };
141142
constexpr glm::vec3 GetRotation() { return m_Rotation; };
143+
constexpr glm::vec3 GetScale() { return m_Scale; };
144+
142145
glm::mat4 GetModelMatrix();
143146
private:
144147
// model data
@@ -147,6 +150,7 @@ class Model
147150

148151
glm::vec3 m_Position;
149152
glm::vec3 m_Rotation;
153+
glm::vec3 m_Scale;
150154

151155
glm::mat4 m_ModelMatrix;
152156
bool m_NeedsUpdate = false; // flag, set to true when Position and Rotation are updated, set to false when GetModelMatrix is called.

models/arrows.mtl

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,32 @@
1-
# Blender 4.2.0 MTL File: 'None'
1+
# Blender 4.2.1 LTS MTL File: 'None'
22
# www.blender.org
33

4-
newmtl Material
4+
newmtl Material.001
55
Ns 250.000000
66
Ka 1.000000 1.000000 1.000000
7-
Kd 1.000000 0.000000 0.002615
7+
Kd 0.000000 1.000000 0.000000
88
Ks 0.500000 0.500000 0.500000
99
Ke 0.000000 0.000000 0.000000
10-
Ni 1.450000
10+
Ni 1.500000
1111
d 1.000000
1212
illum 2
1313

14-
newmtl Material.001
14+
newmtl Material.002
1515
Ns 250.000000
1616
Ka 1.000000 1.000000 1.000000
17-
Kd 0.000000 1.000000 0.000000
17+
Kd 0.000000 0.000000 1.000000
1818
Ks 0.500000 0.500000 0.500000
1919
Ke 0.000000 0.000000 0.000000
2020
Ni 1.500000
2121
d 1.000000
2222
illum 2
2323

24-
newmtl Material.002
24+
newmtl Material.003
2525
Ns 250.000000
2626
Ka 1.000000 1.000000 1.000000
27-
Kd 0.000000 0.000000 1.000000
27+
Kd 1.000000 0.000000 0.002615
2828
Ks 0.500000 0.500000 0.500000
2929
Ke 0.000000 0.000000 0.000000
30-
Ni 1.500000
30+
Ni 1.450000
3131
d 1.000000
3232
illum 2

0 commit comments

Comments
 (0)