grafika_komputerowa/grk/project/Sun.h

51 lines
1.3 KiB
C
Raw Normal View History

2024-01-03 20:40:52 +01:00
#include "glm.hpp"
#include "ext.hpp"
2024-01-03 22:06:27 +01:00
#include "./Spaceship.h"
2024-01-08 16:17:25 +01:00
#include "./GameObject.h"
2024-01-03 20:40:52 +01:00
#pragma once
2024-01-08 16:17:25 +01:00
class Sun : public GameObject
2024-01-03 20:40:52 +01:00
{
public:
2024-01-04 20:51:01 +01:00
glm::vec3 sunPos;
glm::vec3 sunDir;
glm::vec3 sunColor;
double scale;
2024-01-03 22:06:27 +01:00
GLuint program;
Core::RenderContext sphereContext;
2024-01-08 16:17:25 +01:00
glm::mat4 positionMatrix;
2024-01-03 22:06:27 +01:00
2024-01-04 20:51:01 +01:00
Sun(GLuint program, Core::RenderContext sphereContext, glm::vec3 pos, glm::vec3 dir, glm::vec3 color, double scale) {
2024-01-03 22:06:27 +01:00
this->program = program;
this->sphereContext = sphereContext;
2024-01-04 20:51:01 +01:00
this->sunPos = pos;
this->sunDir = dir;
this->sunColor = color;
this->scale = scale;
2024-01-03 22:06:27 +01:00
}
Sun(){}
void draw() {
glUseProgram(program);
glm::mat4 viewProjectionMatrix = Core::createPerspectiveMatrix() * Spaceship::getInstance().createCameraMatrix();
2024-01-08 16:17:25 +01:00
positionMatrix = glm::translate(sunPos);
glm::mat4 transformation = viewProjectionMatrix * positionMatrix * glm::scale(glm::vec3(scale));
2024-01-03 22:06:27 +01:00
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);
}
2024-01-08 16:17:25 +01:00
2024-01-10 20:56:06 +01:00
glm::vec3 getPosition() {
return sunPos;
}
glm::vec3 getColor() {
return sunColor;
}
2024-01-08 16:17:25 +01:00
glm::mat4 getPositionMatrix() override {
return positionMatrix;
}
2024-01-03 20:40:52 +01:00
};