добавлено дерево, вокруг него теперь крутятся снеговики.

This commit is contained in:
vlad 2023-03-23 22:24:04 +03:00
parent 37e003ff11
commit 70b6634fc4
5 changed files with 2073 additions and 7 deletions

Binary file not shown.

View File

@ -0,0 +1,52 @@
# Blender MTL File: 'christmas-tree.blend'
# Material Count: 5
newmtl Balls-1
Ns 250.000000
Ka 1.000000 1.000000 1.000000
Kd 0.800000 0.048409 0.471644
Ks 0.500000 0.500000 0.500000
Ke 0.000000 0.000000 0.000000
Ni 1.450000
d 1.000000
illum 2
newmtl Balls-2
Ns 250.000000
Ka 1.000000 1.000000 1.000000
Kd 0.000000 0.032897 0.800000
Ks 0.500000 0.500000 0.500000
Ke 0.000000 0.000000 0.000000
Ni 1.450000
d 1.000000
illum 2
newmtl Green
Ns 250.000000
Ka 1.000000 1.000000 1.000000
Kd 0.055518 0.308912 0.004670
Ks 0.500000 0.500000 0.500000
Ke 0.000000 0.000000 0.000000
Ni 1.450000
d 1.000000
illum 2
newmtl TopFigure
Ns 250.000000
Ka 1.000000 1.000000 1.000000
Kd 1.000000 0.859637 0.000000
Ks 0.500000 0.500000 0.500000
Ke 0.000000 0.000000 0.000000
Ni 1.450000
d 1.000000
illum 2
newmtl Trunc
Ns 250.000000
Ka 1.000000 1.000000 1.000000
Kd 0.206980 0.078561 0.032670
Ks 0.500000 0.500000 0.500000
Ke 0.000000 0.000000 0.000000
Ni 1.450000
d 1.000000
illum 2

1974
lab2/res/christmas-tree.obj Normal file

File diff suppressed because it is too large Load Diff

View File

@ -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;

View File

@ -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;
}