#include "labm1/tema1/tema1.h" #include <vector> #include <cmath> #include…
- User
#include "lab_m1/tema1/tema1.h" #include #include #include "lab_m1/tema1/transform2D.h" #include "lab_m1/lab3/object2D.h"
using namespace std; using namespace m1;
Tema1::Tema1() { }
Tema1::~Tema1() { }
void Tema1::Init() { glm::ivec2 resolution = window->GetResolution(); auto camera = GetSceneCamera(); camera->SetOrthographic(0, (float)resolution.x, 0, (float)resolution.y, 0.01f, 400); camera->SetPosition(glm::vec3(0, 0, 50)); camera->SetRotation(glm::vec3(0, 0, 0)); camera->Update(); GetCameraInput()->SetActive(false);
codeheightMap.clear(); int numPoints = 128; // Number of samples along the x-axis float x = -128; while (x < 128){ // Calculate height using the composite function float y = sin(x) + 2.0f * sin(0.5f * x) + 0.5f * sin(3.0f * x); heightMap.push_back(glm::vec2(x, y)); x += 10.0f; } glm::vec3 corner = glm::vec3(0, 0, 0); float squareSide = 100; meshes["square1"] = object2D::CreateSquare("square1", corner, squareSide, glm::vec3(0.5f, 0.5f, 0.5f), true);}
void Tema1::Update(float deltaTimeSeconds) { for (size_t i = 0; i < heightMap.size() - 1; ++i) { glm::vec2 A = heightMap[i]; glm::vec2 B = heightMap[i + 1];
codeglm::mat3 modelMatrix = glm::mat3(1.0f); float scaleX = B.x - A.x; float scaleY = std::max(B.y, A.y); // Scale by width and height to fit the segment between points modelMatrix *= transform2D::Scale(scaleX, scaleY); // Calculate and apply shear factor based on slope between A and B float shearFactor = (B.y - A.y) / (B.x - A.x); modelMatrix *= transform2D::Sheer(shearFactor); // Translate the square to position A modelMatrix *= transform2D::Translate(A.x, A.y); // Render the terrain segment RenderMesh2D(meshes["square1"], shaders["VertexColor"], modelMatrix); }}
- Assistant
- User
#pragma once
#include "components/simple_scene.h" #include "utils/glm_utils.h"
namespace m1 { class Tema1 : public gfxc::SimpleScene { public: Tema1(); ~Tema1();
codevoid Init() override; private: void FrameStart() override; void Update(float deltaTimeSeconds) override; void FrameEnd() override; void OnInputUpdate(float deltaTime, int mods) override; void OnKeyPress(int key, int mods) override; void OnKeyRelease(int key, int mods) override; void OnMouseMove(int mouseX, int mouseY, int deltaX, int deltaY) override; void OnMouseBtnPress(int mouseX, int mouseY, int button, int mods) override; void OnMouseBtnRelease(int mouseX, int mouseY, int button, int mods) override; void OnMouseScroll(int mouseX, int mouseY, int offsetX, int offsetY) override; void OnWindowResize(int width, int height) override; glm::vec2 CalculateCatmullRomPoint(float t, glm::vec2 p0, glm::vec2 p1, glm::vec2 p2, glm::vec2 p3); protected: float cx, cy; glm::mat3 modelMatrix; float translateX, translateY; float scaleX, scaleY; float angularStep; float numSquares; float amplitude; float freq; std::vector<glm::vec2> heightMap; }; - Assistant