79 lines
2.1 KiB
C++
79 lines
2.1 KiB
C++
#include "PartitionedCube.h"
|
|
|
|
#include "Cube.h"
|
|
|
|
#include <glm.hpp>
|
|
#include <ext.hpp>
|
|
|
|
PartitionedCube::PartitionedCube(const glm::vec3& position, Color* sideColors) : _faces {
|
|
sideColors[0],
|
|
sideColors[1],
|
|
sideColors[2],
|
|
sideColors[3],
|
|
sideColors[4],
|
|
sideColors[5],
|
|
}
|
|
{
|
|
this->_transform = glm::translate(glm::mat4(1.0f), position);
|
|
_animationTime = 0.0f;
|
|
_animationTimeExtend = 0.0f;
|
|
_animationTransformInvoke = _transform;
|
|
_animationTransform = glm::quat(1.0f, 0.0f, 0.0f, 0.0f);
|
|
_animationFinished = true;
|
|
|
|
for(int axis=0;axis<3;axis++) {
|
|
float factor = 1.0f * -1;
|
|
|
|
for(int reverse=0;reverse<2;reverse++) {
|
|
glm::vec3 x, y, z, v;
|
|
|
|
x = glm::vec3(0.0f);
|
|
y = glm::vec3(0.0f);
|
|
z = glm::vec3(0.0f);
|
|
|
|
z[axis] = factor;
|
|
x[(axis+1)%3] = 1.0f;
|
|
y[(axis+2)%3] = 1.0f;
|
|
|
|
glm::vec3 v0 = x * 0.5f + y * 0.5f + 0.5f * z;
|
|
glm::vec3 v1 = x * -0.5f + y * 0.5f + 0.5f * z;
|
|
glm::vec3 v2 = x * 0.5f + y * -0.5f + 0.5f * z;
|
|
glm::vec3 v3 = x * -0.5f + y * -0.5f + 0.5f * z;
|
|
|
|
int s = 2 * axis + reverse; // (-x, +x, -y, +y, -z, +z)
|
|
|
|
_meshData.addFace(v0, v1, v2, v3, sideColors[s]);
|
|
|
|
factor = -factor;
|
|
}
|
|
}
|
|
}
|
|
|
|
void PartitionedCube::Update(double deltaTime) {
|
|
this->_animationTime -= deltaTime;
|
|
|
|
if (!_animationFinished && _animationTime <= 0.0f) {
|
|
_animationFinished = true;
|
|
|
|
_transform = glm::mat4_cast(_animationTransform) * _animationTransformInvoke;
|
|
}
|
|
}
|
|
|
|
void PartitionedCube::Transform(glm::mat4 transformation)
|
|
{
|
|
this->_transform = transformation * this->_transform;
|
|
_animationTransformInvoke = transformation * _animationTransformInvoke;
|
|
_animationTransform = glm::quat_cast(transformation * glm::mat4_cast(_animationTransform));
|
|
}
|
|
|
|
void PartitionedCube::TransformAnimation(const glm::mat4& transform, float duration) {
|
|
if (!_animationFinished)
|
|
_transform = glm::mat4_cast(_animationTransform) * _animationTransformInvoke;
|
|
|
|
this->_animationTransformInvoke = this->_transform;
|
|
this->_animationTransform = glm::quat_cast(transform);
|
|
this->_animationTime = duration;
|
|
this->_animationTimeExtend = duration;
|
|
_animationFinished = false;
|
|
}
|