#include "labm1/tema1/tema1.h" #include <vector> #include <iostream> #include…
- User
#include "lab_m1/tema1/tema1.h"
#include #include
#include "lab_m1/tema1/transform2D.h" #include "lab_m1/tema1/object2Dtema.h"
using namespace std; using namespace m1;
Tema1::Tema1() : tankX(100.0f), tankAngle(0.0f), turretAngle(glm::radians(0.0f)), moveSpeed(100.0f), rotationSpeed(100.0f) { }
Tema1::~Tema1() { }
float gen_y(float x) { x /= 50; return 1.5 * sin(0.5 * x) + 1.5 * sin(0.6 * x) + 0.4 * sin(1.5 * x); }
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);
glm::vec3 corner = glm::vec3(0, 0, 0); float squareSide = 1; // Set ground color to brown Mesh* square = object2Dtema::CreateSquare("square", corner, squareSide, glm::vec3(0.7098f, 0.7412f, 0.5373f), true); AddMeshToList(square); numSquare = 1280; // Set the desired number of squares int step = resolution.x / numSquare; for (size_t i = 0; i < numSquare + 1; ++i) { xPositions.push_back(i * step); heightMap.push_back(30 * gen_y(i * step) + 300); } InitTank();}
void Tema1::InitTank() { // Construiește baza tancului cu două trapeze tankWidth = 100.0f; Mesh* base1 = object2Dtema::CreateTrapezoid("base1", glm::vec3(0, 10, 0), 80.0f, 100.0f, 20.0f, glm::vec3(0.5f, 0.5f, 0.5f), true); Mesh* base2 = object2Dtema::CreateTrapezoid("base2", glm::vec3(20, 0, 0), 70.0f, 60.0f, 10.0f, glm::vec3(0.3f, 0.3f, 0.3f), true);
// Creează turela și tunul Mesh* turret = object2Dtema::CreateCircle("turret", glm::vec3(50, 30, 0), 17.5f, glm::vec3(0.5f, 0.5f, 0.5f), true); Mesh* barrel = object2Dtema::CreateTrapezoid("barrel", glm::vec3(0, 0, 0), 40, 40, 5, glm::vec3(0.3f, 0.3f, 0.3f), true); // Adăugare în lista de mesh-uri AddMeshToList(base1); AddMeshToList(base2); AddMeshToList(turret); AddMeshToList(barrel); Mesh* linieTraiectorie = object2Dtema::CreateTrapezoid("line", glm::vec3(0, 0, 0), 1, 1, 1, glm::vec3(0.0f, 1.0f, 1.0f), true); AddMeshToList(linieTraiectorie); // Creează un cerc pentru proiectil Mesh* projectile = object2Dtema::CreateCircle("projectile", glm::vec3(0, 0, 0), 5.0f, glm::vec3(1.0f, 0.0f, 0.0f), true); AddMeshToList(projectile);}
void Tema1::FrameStart() { // Set the background color to blue for the sky glClearColor(0.529f, 0.808f, 0.922f, 1.0f); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glm::ivec2 resolution = window->GetResolution(); // Sets the screen area where to draw glViewport(0, 0, resolution.x, resolution.y);}
float Tema1::CalculateTankY(float tankX) { // Căutăm punctele A și B din heightMap care încadrează x-ul tancului for (size_t i = 0; i < numSquare; ++i) { float x1 = xPositions[i]; float y1 = heightMap[i]; float x2 = xPositions[i + 1]; float y2 = heightMap[i + 1];
- Assistant
- User
make the whole more circular
- Assistant
To make the crater created by the projectile impact more circular, you can modify the deformation calculation to create a smoother and deeper central depression. This is often achieved by using a circular function such as a quadratic or sine function that results in a more prominent "bowl" shape. Here's an example using a quadratic drop-off to achieve a more circular crater:
void Tema1::DeformTerrain(glm::vec2 impactPoint, float radius) { for (size_t i = 0; i < numSquare + 1; ++i) { float dist = abs(xPositions[i] - impactPoint.x); if (dist < radius) { // Calculate normalized distance from impact point float normalizedDist = dist / radius; // Use a quadratic function for a smoother, circular distribution float deformation = (1 - normalizedDist * normalizedDist) * (radius / 2.0f); // Lower the terrain by the deformation amount, ensuring it does not go below zero heightMap[i] = max(heightMap[i] - deformation, 0.0f); } } }