Restore pixel perfect camera code.
This commit is contained in:
@@ -20,6 +20,7 @@ void SceneComponent::init(const std::shared_ptr<SceneItem> item) {
|
||||
sceneComponentState,
|
||||
SCENE_COMPONENT_STATE_INIT
|
||||
);
|
||||
this->events.clear();
|
||||
this->item = item;
|
||||
this->onInit();
|
||||
}
|
||||
@@ -39,6 +40,11 @@ void SceneComponent::dispose() {
|
||||
sceneComponentState,
|
||||
SCENE_COMPONENT_STATE_DISPOSED
|
||||
);
|
||||
|
||||
for(auto &event : this->events) {
|
||||
event();
|
||||
}
|
||||
this->events.clear();
|
||||
this->onDispose();
|
||||
this->item.reset();
|
||||
}
|
||||
|
@@ -20,6 +20,8 @@ namespace Dawn {
|
||||
uint_fast8_t sceneComponentState = 0;
|
||||
|
||||
protected:
|
||||
std::vector<std::function<void()>> events;
|
||||
|
||||
/**
|
||||
* Custom component listener that is invoked when the component is meant
|
||||
* to initialize.
|
||||
|
@@ -168,6 +168,25 @@ void SceneItemTransform::lookAt(
|
||||
this->setWorldTransform(glm::lookAt(position, target, up));
|
||||
}
|
||||
|
||||
float_t SceneItemTransform::lookAtPixelPerfect(
|
||||
const glm::vec3 &position,
|
||||
const glm::vec3 &look,
|
||||
const float_t &viewportHeight,
|
||||
const float_t &fov,
|
||||
const float_t &scale
|
||||
) {
|
||||
float_t z = (
|
||||
tanf((glm::radians(180.0f) - fov) / 2.0f) *
|
||||
(viewportHeight/2.0f)
|
||||
) / scale;
|
||||
this->lookAt(
|
||||
glm::vec3(position.x, position.y, position.z + z),
|
||||
look,
|
||||
glm::vec3(0, 1, 0)
|
||||
);
|
||||
return z;
|
||||
}
|
||||
|
||||
SceneItemTransform::~SceneItemTransform() {
|
||||
std::for_each(
|
||||
this->children.begin(),
|
||||
|
@@ -164,6 +164,24 @@ namespace Dawn {
|
||||
const glm::vec3 up
|
||||
);
|
||||
|
||||
/**
|
||||
* Shorthand combined for lookAt and perspectivePixelPerfectDistance
|
||||
* to allow you to create pixel perfect lookAt camera view matricies.
|
||||
*
|
||||
* @param position Position of the camera. Z is for an offset.
|
||||
* @param look Position in world space this transform looks at.
|
||||
* @param viewportHeight Height of the viewport.
|
||||
* @param fov Field of view (in radians).
|
||||
* @return The Z distance that was calculated.
|
||||
*/
|
||||
float_t lookAtPixelPerfect(
|
||||
const glm::vec3 &position,
|
||||
const glm::vec3 &look,
|
||||
const float_t &viewportHeight,
|
||||
const float_t &fov,
|
||||
const float_t &scale = 1.0f
|
||||
);
|
||||
|
||||
virtual ~SceneItemTransform();
|
||||
};
|
||||
}
|
Reference in New Issue
Block a user