grafika_komputerowa/grk/project/Sun.h
2024-02-05 22:22:25 +01:00

56 lines
1.5 KiB
C++

#include "glm.hpp"
#include "ext.hpp"
#include "./Spaceship.h"
#include "./GameObject.h"
#pragma once
class Sun : public GameObject
{
public:
glm::vec3 sunPos;
glm::vec3 sunDir;
glm::vec3 sunColor;
double scale;
GLuint program;
Core::RenderContext sphereContext;
glm::mat4 positionMatrix;
GLuint textureID;
Sun(GLuint program, Core::RenderContext sphereContext, glm::vec3 pos, glm::vec3 dir, GLuint textureID, glm::vec3 color, double scale) {
this->program = program;
this->sphereContext = sphereContext;
this->sunPos = pos;
this->sunDir = dir;
this->sunColor = color;
this->scale = scale;
this->textureID = textureID;
}
Sun(){}
void draw() {
glUseProgram(program);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, textureID);
glUniform1i(glGetUniformLocation(program, "sunTexture"), 0);
glm::mat4 viewProjectionMatrix = Core::createPerspectiveMatrix() * Spaceship::getInstance()->createCameraMatrix();
positionMatrix = glm::translate(sunPos);
glm::mat4 transformation = viewProjectionMatrix * positionMatrix * glm::scale(glm::vec3(scale));
glUniformMatrix4fv(glGetUniformLocation(program, "transformation"), 1, GL_FALSE, (float*)&transformation);
glUniform3f(glGetUniformLocation(program, "color"), sunColor.x / 2, sunColor.y / 2, sunColor.z / 2);
glUniform1f(glGetUniformLocation(program, "exposition"), 1.f);
Core::DrawContext(sphereContext);
}
glm::vec3 getPosition() {
return sunPos;
}
glm::vec3 getColor() {
return sunColor;
}
glm::mat4 getPositionMatrix() override {
return positionMatrix;
}
};