mirror of
https://github.com/Linloir/SceneEditor.git
synced 2025-12-19 00:18:12 +08:00
[CORE][ADD] Add light API & function to renderable
This commit is contained in:
parent
aeaac1833f
commit
032d346151
@ -6,6 +6,13 @@ Renderable::Renderable(Model* model) : _model(model) {}
|
|||||||
|
|
||||||
Renderable::Renderable(Model* model, glm::vec3 position) : _model(model), _position(position) {}
|
Renderable::Renderable(Model* model, glm::vec3 position) : _model(model), _position(position) {}
|
||||||
|
|
||||||
|
Renderable::~Renderable() {
|
||||||
|
if (_light != nullptr) {
|
||||||
|
delete _light;
|
||||||
|
_light = nullptr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void Renderable::setModel(Model* model) {
|
void Renderable::setModel(Model* model) {
|
||||||
_model = model;
|
_model = model;
|
||||||
}
|
}
|
||||||
@ -34,6 +41,19 @@ void Renderable::setScale(float scale) {
|
|||||||
_scale = glm::vec3(scale);
|
_scale = glm::vec3(scale);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ScopedLight Renderable::transformedLight() const {
|
||||||
|
// Transform the light position to the world space
|
||||||
|
return _light->toWorldSpace(modelMatrix());
|
||||||
|
}
|
||||||
|
|
||||||
|
ScopedLight* Renderable::originalLight() const {
|
||||||
|
return _light;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Renderable::makeLight() {
|
||||||
|
_light = new ScopedLight(glm::vec3(0.0f));
|
||||||
|
}
|
||||||
|
|
||||||
void Renderable::render(ShaderProgram shader) {
|
void Renderable::render(ShaderProgram shader) {
|
||||||
// Check if initialized
|
// Check if initialized
|
||||||
if (_model == nullptr) {
|
if (_model == nullptr) {
|
||||||
@ -50,6 +70,10 @@ void Renderable::render(ShaderProgram shader) {
|
|||||||
// check here to get global boundary
|
// check here to get global boundary
|
||||||
// must check before get boundary
|
// must check before get boundary
|
||||||
void Renderable::checkBoundary() {
|
void Renderable::checkBoundary() {
|
||||||
|
if (_model == nullptr) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
std::vector<glm::vec3> temp = {_model->upperBoundVex(),_model->lowerBoundVex()};
|
std::vector<glm::vec3> temp = {_model->upperBoundVex(),_model->lowerBoundVex()};
|
||||||
|
|
||||||
_lowerBoundVex = glm::vec3(3e36, 3e36, 3e36);
|
_lowerBoundVex = glm::vec3(3e36, 3e36, 3e36);
|
||||||
|
|||||||
@ -4,6 +4,7 @@
|
|||||||
#include <GLM/ext/matrix_transform.hpp>
|
#include <GLM/ext/matrix_transform.hpp>
|
||||||
|
|
||||||
#include "model.h"
|
#include "model.h"
|
||||||
|
#include "illuminer.h"
|
||||||
#include "shader.h"
|
#include "shader.h"
|
||||||
|
|
||||||
class Renderable {
|
class Renderable {
|
||||||
@ -17,6 +18,7 @@ private:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
Model* _model = nullptr;
|
Model* _model = nullptr;
|
||||||
|
ScopedLight* _light = nullptr;
|
||||||
glm::vec3 _position = glm::vec3(0.0f);
|
glm::vec3 _position = glm::vec3(0.0f);
|
||||||
glm::mat4 _rotation = glm::mat4(1.0f);
|
glm::mat4 _rotation = glm::mat4(1.0f);
|
||||||
glm::vec3 _scale = glm::vec3(1.0f);
|
glm::vec3 _scale = glm::vec3(1.0f);
|
||||||
@ -26,6 +28,7 @@ private:
|
|||||||
public:
|
public:
|
||||||
Renderable(Model* model);
|
Renderable(Model* model);
|
||||||
Renderable(Model* model, glm::vec3 position);
|
Renderable(Model* model, glm::vec3 position);
|
||||||
|
~Renderable();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void setModel(Model* model);
|
void setModel(Model* model);
|
||||||
@ -36,6 +39,11 @@ public:
|
|||||||
void scale(float deltaScale);
|
void scale(float deltaScale);
|
||||||
void setScale(float scale);
|
void setScale(float scale);
|
||||||
|
|
||||||
|
ScopedLight transformedLight() const; // pass out the light object to scene manager to gather all light sources
|
||||||
|
ScopedLight* originalLight() const; // pass out the light object to scene manager to set light attributes
|
||||||
|
bool hasLight() const { return _light != nullptr; }
|
||||||
|
void makeLight(); // create a light source in the object
|
||||||
|
|
||||||
inline glm::mat4 modelMatrix() const;
|
inline glm::mat4 modelMatrix() const;
|
||||||
|
|
||||||
inline glm::vec3 upperBoundVex()const;
|
inline glm::vec3 upperBoundVex()const;
|
||||||
@ -43,7 +51,6 @@ public:
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
void render(ShaderProgram shader);
|
void render(ShaderProgram shader);
|
||||||
// check here to get global boundary
|
|
||||||
void checkBoundary();
|
void checkBoundary();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user