WIP interpolating scale and orientation
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
#include <unordered_map>
|
||||
#include <boost/shared_array.hpp>
|
||||
#include <glm/common.hpp>
|
||||
#include <glm/gtc/quaternion.hpp>
|
||||
|
||||
#include "Common.h"
|
||||
#include "Core/System.h"
|
||||
@@ -12,6 +13,7 @@
|
||||
|
||||
#include "Network/EInterpolate.h"
|
||||
|
||||
#define SNAPSHOTINTERVAL 0.05f
|
||||
|
||||
class InterpolationSystem : public PureSystem
|
||||
{
|
||||
@@ -19,7 +21,7 @@ class InterpolationSystem : public PureSystem
|
||||
{
|
||||
glm::vec3 Position;
|
||||
glm::vec3 Scale;
|
||||
glm::vec3 Orientation;
|
||||
glm::quat Orientation;
|
||||
double interpolationTime;
|
||||
};
|
||||
public:
|
||||
@@ -35,7 +37,14 @@ private:
|
||||
//std::unordered_map<EntityID, std::queue<Transform>> m_InterpolationPoints;
|
||||
std::unordered_map<EntityID, Transform> m_InterpolationPoints;
|
||||
|
||||
glm::vec3 vectorInterpolation(glm::vec3 prev, glm::vec3 next, double currentTime);
|
||||
//glm::vec3 vectorInterpolation(glm::vec3 prev, glm::vec3 next, double currentTime);
|
||||
template <typename T>
|
||||
T vectorInterpolation(T prev, T next, double currentTime)
|
||||
{
|
||||
T difference = next - prev;
|
||||
T vector = (difference / SNAPSHOTINTERVAL) * static_cast<float>(currentTime);
|
||||
return vector;
|
||||
}
|
||||
|
||||
EventRelay<InterpolationSystem, Events::Interpolate> m_EInterpolate;
|
||||
bool InterpolationSystem::OnInterpolate(const Events::Interpolate& e);
|
||||
|
||||
@@ -24,17 +24,27 @@ void InterpolationSystem::UpdateComponent(World * world, ComponentWrapper & tran
|
||||
{
|
||||
Transform& sTransform = m_InterpolationPoints[transform.EntityID];
|
||||
sTransform.interpolationTime += dt;
|
||||
// Position
|
||||
glm::vec3 nextPosition = sTransform.Position;
|
||||
glm::vec3 currentPosition = static_cast<glm::vec3>(transform["Position"]);
|
||||
(glm::vec3&)transform["Position"] += vectorInterpolation(currentPosition, nextPosition, sTransform.interpolationTime);
|
||||
(glm::vec3&)transform["Position"] += vectorInterpolation<glm::vec3>(currentPosition, nextPosition, sTransform.interpolationTime);
|
||||
// Orientation
|
||||
glm::quat nextOrientation = sTransform.Orientation;
|
||||
glm::quat currentOrientation = glm::quat(static_cast<glm::vec3>(transform["Orientation"]));
|
||||
(glm::vec3&)transform["Orientation"] = glm::eulerAngles(glm::slerp<float>(currentOrientation, nextOrientation, sTransform.interpolationTime / SNAPSHOTINTERVAL));
|
||||
// Scale
|
||||
glm::vec3 nextScale = sTransform.Scale;
|
||||
glm::vec3 currentScale = static_cast<glm::vec3>(transform["Scale"]);
|
||||
//glm::vec3 resize = vectorInterpolation<glm::vec3>(currentScale, nextScale, sTransform.interpolationTime);
|
||||
(glm::vec3&)transform["Scale"] += vectorInterpolation<glm::vec3>(currentScale, nextScale, sTransform.interpolationTime);
|
||||
}
|
||||
|
||||
glm::vec3 InterpolationSystem::vectorInterpolation(glm::vec3 prev, glm::vec3 next, double currentTime)
|
||||
{
|
||||
glm::vec3 difference = next - prev;
|
||||
glm::vec3 position = difference / 0.05f * static_cast<float>(currentTime);
|
||||
return position;
|
||||
}
|
||||
//glm::vec3 InterpolationSystem::vectorInterpolation(glm::vec3 prev, glm::vec3 next, double currentTime)
|
||||
//{
|
||||
// glm::vec3 difference = next - prev;
|
||||
// glm::vec3 position = difference / SNAPSHOTINTERVAL * static_cast<float>(currentTime);
|
||||
// return position;
|
||||
//}
|
||||
|
||||
bool InterpolationSystem::OnInterpolate(const Events::Interpolate & e)
|
||||
{
|
||||
@@ -43,9 +53,11 @@ bool InterpolationSystem::OnInterpolate(const Events::Interpolate & e)
|
||||
// Read the data
|
||||
memcpy(&transform.Position, e.DataArray.get() + offset, sizeof(glm::vec3));
|
||||
offset += sizeof(glm::vec3);
|
||||
memcpy(&transform.Orientation, e.DataArray.get() + offset, sizeof(glm::vec3));
|
||||
glm::vec3 tempOrientation;
|
||||
memcpy(&tempOrientation, e.DataArray.get() + offset, sizeof(glm::vec3));
|
||||
transform.Orientation = glm::quat(tempOrientation);
|
||||
offset += sizeof(glm::vec3);
|
||||
memcpy(&transform.Scale, e.DataArray.get() + offset, sizeof(glm::vec3));
|
||||
memcpy(&transform.Scale, e.DataArray.get() + offset, sizeof(glm::vec3));
|
||||
transform.interpolationTime = 0.0f;
|
||||
m_InterpolationPoints[e.Entity] = transform;
|
||||
// Check if queue already exists
|
||||
|
||||
Reference in New Issue
Block a user