добавлено дерево, вокруг него теперь крутятся снеговики.
This commit is contained in:
@@ -24,6 +24,10 @@ struct Material {
|
||||
|
||||
static void loadMaterials(std::vector<Material>& materials, const std::string &filename) {
|
||||
std::ifstream file(filename, std::ios::in);
|
||||
if (!file.is_open()) {
|
||||
std::cout << "[MeshLoader] Warming: failed to open material file \"" << filename << "\"" << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
std::string line;
|
||||
std::string mtl_name;
|
||||
@@ -56,6 +60,11 @@ Mesh *MeshLoader::loadMesh(const std::string &filename) {
|
||||
|
||||
std::ifstream file(filename + ".obj", std::ios::in);
|
||||
|
||||
if (!file.is_open()) {
|
||||
std::cout << "[MeshLoader] Error: failed to open model file \"" << filename << ".obj\"" << std::endl;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
int line_number = 1;
|
||||
glm::vec3 color(0.5f, 0.0f, 1.0f); // дефолтный цвет
|
||||
std::string source;
|
||||
|
@@ -10,23 +10,44 @@
|
||||
|
||||
static Mesh* mesh_xyz;
|
||||
static Mesh* mesh_snowman;
|
||||
static Mesh* mesh_three;
|
||||
|
||||
static Shader* shader;
|
||||
|
||||
|
||||
static void drawSnowman() {
|
||||
static void drawStaticSnowman() {
|
||||
auto model_scale = glm::scale(glm::mat4(1.0f), glm::vec3(0.5f, 0.5f, 0.5f));
|
||||
|
||||
static float angle = 0.0f;
|
||||
|
||||
auto model_translate = glm::translate(glm::mat4(1.0f), glm::vec3(3, 2, 5));
|
||||
auto model_rotate = glm::rotate(glm::mat4(1.0f), angle, glm::vec3(0, 1, 0));
|
||||
angle += 0.0002f;
|
||||
auto model_rotate = glm::rotate(glm::mat4(1.0f), glm::radians(45.0f), glm::vec3(1, 1, 1));
|
||||
|
||||
shader->uniformMatrix("model", model_scale * model_translate * model_rotate);
|
||||
mesh_snowman->draw();
|
||||
}
|
||||
|
||||
static void drawThree() {
|
||||
// "базовая" матрица
|
||||
auto tree_translate = glm::translate(glm::mat4(1.0f), glm::vec3(5, 0, -5));
|
||||
shader->uniformMatrix("model", tree_translate);
|
||||
|
||||
mesh_three->draw();
|
||||
|
||||
// рисуем снеговиков вокруг дерева
|
||||
static float rotation_angle = 0.0f;
|
||||
|
||||
auto showman_translate = glm::translate(glm::mat4(1.0f), glm::vec3(0, 0, -3));
|
||||
|
||||
for (int i = 0; i < 6; i++) {
|
||||
float offset_angle = glm::radians(60.0f * (float)i);
|
||||
auto showman_rotate = glm::rotate(glm::mat4(1.0f), rotation_angle + offset_angle, glm::vec3(0, 1, 0));
|
||||
|
||||
shader->uniformMatrix("model", tree_translate * showman_rotate * showman_translate);
|
||||
|
||||
mesh_snowman->draw();
|
||||
}
|
||||
|
||||
rotation_angle += 0.0002f;
|
||||
}
|
||||
|
||||
|
||||
void renderScene(Camera& cam) {
|
||||
auto projview = cam.getProjection() * cam.getView();
|
||||
@@ -37,17 +58,26 @@ void renderScene(Camera& cam) {
|
||||
shader->uniformMatrix("model", glm::mat4(1.0f));
|
||||
mesh_xyz->draw();
|
||||
|
||||
drawSnowman();
|
||||
drawStaticSnowman();
|
||||
drawThree();
|
||||
}
|
||||
|
||||
int loadResources() {
|
||||
mesh_xyz = MeshLoader::loadMesh("res/xyz");
|
||||
if (mesh_xyz == nullptr) {
|
||||
std::cerr << "Failed to load 'xyz' mesh!" << std::endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
mesh_snowman = MeshLoader::loadMesh("res/snowman");
|
||||
if (mesh_snowman == nullptr) {
|
||||
std::cerr << "Failed to load 'snowman' mesh!" << std::endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
mesh_three = MeshLoader::loadMesh("res/christmas-tree");
|
||||
if (mesh_three == nullptr) {
|
||||
std::cerr << "Failed to load 'christmas-tree' mesh!" << std::endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -62,5 +92,6 @@ int loadResources() {
|
||||
void unloadResources() {
|
||||
delete mesh_xyz;
|
||||
delete mesh_snowman;
|
||||
delete mesh_three;
|
||||
delete shader;
|
||||
}
|
Reference in New Issue
Block a user