Conquer Space 0.0.0
A space themed grand strategy game set in the near future, with realistic orbital mechanics, and an emphasis on economics and politics.
model.h
Go to the documentation of this file.
1/* Conquer Space
2 * Copyright (C) 2021-2023 Conquer Space
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <https://www.gnu.org/licenses/>.
16 */
17#pragma once
18
19#include <map>
20#include <memory>
21#include <string>
22#include <vector>
23
24#include <glm/vec2.hpp>
25#include <glm/vec3.hpp>
26
27#include "engine/asset/asset.h"
30
31namespace cqsp::asset {
37};
38
39struct Material {
40 std::vector<asset::Texture*> diffuse;
41 std::vector<asset::Texture*> specular;
42 std::vector<asset::Texture*> ambient;
43 std::vector<asset::Texture*> height;
44 glm::vec3 base_diffuse;
45 glm::vec3 base_specular;
46 glm::vec3 base_ambient;
47 glm::vec3 base_emissive;
49
50 Material() = default;
52 for (auto& texture : diffuse) {
53 delete texture;
54 }
55 for (auto& texture : specular) {
56 delete texture;
57 }
58 for (auto& texture : ambient) {
59 delete texture;
60 }
61 for (auto& texture : height) {
62 delete texture;
63 }
64 }
65};
66
67struct ModelMesh : public engine::Mesh {
69};
70
71typedef std::shared_ptr<ModelMesh> ModelMesh_t;
72
73struct Model : public Asset {
74 std::vector<ModelMesh_t> meshes;
75 std::map<int, Material> materials;
76
78
79 void Draw(ShaderProgram* shader) {
80 for (auto& model_mesh : meshes) {
81 // Set the texture of the model mesh
82 // Set the material
83 // ISS just has a base diffuse color
84 auto& material = materials[model_mesh->material];
85
86 shader->setVec3("diffuse", material.base_diffuse);
87 model_mesh->Draw();
88 }
89 }
90};
91
92struct Vertex {
93 public:
94 static const int MAX_BONE_INFLUENCE = 4;
95 // position
96 glm::vec3 position = glm::vec3(0.f, 0.f, 0.f);
97 // normal
98 glm::vec3 normal = glm::vec3(0.f, 0.f, 0.f);
99 // texCoords
100 glm::vec2 texCoords = glm::vec2(0.f, 0.f);
101 // tangent
102 glm::vec3 tangent = glm::vec3(0.f, 0.f, 0.f);
103 // bitangent
104 glm::vec3 bitangent = glm::vec3(0.f, 0.f, 0.f);
105 //bone indexes which will influence this vertex
107 //weights from each bone
109};
110} // namespace cqsp::asset
The base class for assets.
Definition: asset.h:157
A shader program.
Definition: shader.h:68
void setVec3(const std::string &name, const glm::vec3 &value)
Definition: shader.cpp:95
Definition: texture.h:33
Definition: mesh.h:25
Definition: asset.h:30
AssetType
Definition: asset.h:31
@ MODEL
Model prototype.
Definition: assetprototype.h:30
std::shared_ptr< ModelMesh > ModelMesh_t
Definition: model.h:71
Definition: model.h:39
glm::vec3 base_specular
Definition: model.h:45
std::vector< asset::Texture * > ambient
Definition: model.h:42
std::vector< asset::Texture * > specular
Definition: model.h:41
~Material()
Definition: model.h:51
glm::vec3 base_ambient
Definition: model.h:46
glm::vec3 base_transparent
Definition: model.h:48
std::vector< asset::Texture * > height
Definition: model.h:43
glm::vec3 base_diffuse
Definition: model.h:44
std::vector< asset::Texture * > diffuse
Definition: model.h:40
glm::vec3 base_emissive
Definition: model.h:47
Definition: model.h:32
asset::Texture * ambient
Definition: model.h:35
asset::Texture * specular
Definition: model.h:34
asset::Texture * diffuse
Definition: model.h:33
asset::Texture * height
Definition: model.h:36
Definition: model.h:73
AssetType GetAssetType() override
Definition: model.h:77
std::map< int, Material > materials
Definition: model.h:75
std::vector< ModelMesh_t > meshes
Definition: model.h:74
void Draw(ShaderProgram *shader)
Definition: model.h:79
Definition: model.h:67
int material
Definition: model.h:68
Definition: model.h:92
glm::vec2 texCoords
Definition: model.h:100
glm::vec3 normal
Definition: model.h:98
glm::vec3 position
Definition: model.h:96
glm::vec3 bitangent
Definition: model.h:104
static const int MAX_BONE_INFLUENCE
Definition: model.h:94
int m_BoneIDs[MAX_BONE_INFLUENCE]
Definition: model.h:106
float m_Weights[MAX_BONE_INFLUENCE]
Definition: model.h:108
glm::vec3 tangent
Definition: model.h:102