grafika_komputerowa/grk/project/Planet.h
Pawel Felcyn 90e88b0dc2 xd
2024-01-24 22:49:59 +01:00

45 lines
1.3 KiB
C++

#include "./GameObject.h"
#include "glm.hpp"
#include "ext.hpp"
#include "src/Render_Utils.h"
#include <tuple>
#pragma once
class Planet : public GameObject
{
private:
GameObject* center;
float distanceFromCenter;
float rotationSpeed;
Core::RenderContext sphereContext;
float scale;
glm::vec3 position;
glm::mat4 positionMatrix;
std::tuple<GLuint, GLuint> texture;
public:
Planet(GameObject* center, float distanceFromCenter, float rotationSpeed, float scale, Core::RenderContext sphereContext, std::tuple<GLuint, GLuint> texture) {
this->center = center;
this->distanceFromCenter = distanceFromCenter;
this->rotationSpeed = rotationSpeed;
this->sphereContext = sphereContext;
this->scale = scale;
this->position = glm::vec3(0);
this->texture = texture;
}
glm::mat4 getPositionMatrix() override {
return positionMatrix;
}
void draw(float time, GLuint program) {
if (center == nullptr) {
return;
}
float rotationAngle = glm::radians(time * rotationSpeed);
positionMatrix = center->getPositionMatrix() * glm::eulerAngleY(time * rotationSpeed) * glm::translate(glm::vec3(distanceFromCenter, 0, 0));
glm::mat4 modelMatrix = positionMatrix * glm::scale(glm::vec3(scale));
Core::drawObjectPBRTexture(sphereContext, modelMatrix, std::get<0>(texture), std::get<1>(texture), 0.3, 0.0, program);
}
};