lots of changes
This commit is contained in:
1 parent
c3475ec41d
commit
41eecfa2c2
29 files changed
+35194
-33659
No files matched your search
@@ -1,6 +1,6 @@
|
||||
target_sources(MeshShadingDemo
|
||||
PUBLIC
|
||||
FlyCamSystem.h
|
||||
FlyCamSystem.cpp
|
||||
SplineCamSystem.h
|
||||
target_sources(MeshShadingDemo
|
||||
PUBLIC
|
||||
FlyCamSystem.h
|
||||
FlyCamSystem.cpp
|
||||
SplineCamSystem.h
|
||||
SplineCamSystem.cpp)
|
||||
+53
-53
@@ -1,54 +1,54 @@
|
||||
#include "FlyCamSystem.h"
|
||||
|
||||
FlyCamSystem::FlyCamSystem(PScene scene)
|
||||
: System::ComponentSystem<Component::KeyboardInput, Component::Camera, Component::Transform, Component::PointLight>(scene) {}
|
||||
|
||||
FlyCamSystem::~FlyCamSystem() {}
|
||||
|
||||
void FlyCamSystem::update(Component::KeyboardInput& input, Component::Camera& camera, Component::Transform& transform, Component::PointLight& light) {
|
||||
float cameraMove = static_cast<float>(deltaTime) * 4;
|
||||
if(input.keys[KeyCode::KEY_LEFT_SHIFT])
|
||||
{
|
||||
cameraMove *= 10;
|
||||
}
|
||||
Vector forward = transform.getForward();
|
||||
Vector side = transform.getRight();
|
||||
Vector moveVector = Vector();
|
||||
|
||||
if (input.keys[KeyCode::KEY_J])
|
||||
{
|
||||
std::cout << transform.getPosition() << std::endl;
|
||||
}
|
||||
|
||||
if(input.keys[KeyCode::KEY_W])
|
||||
{
|
||||
moveVector += forward * cameraMove;
|
||||
}
|
||||
if(input.keys[KeyCode::KEY_S])
|
||||
{
|
||||
moveVector += forward * -cameraMove;
|
||||
}
|
||||
if(input.keys[KeyCode::KEY_A])
|
||||
{
|
||||
moveVector += side * -cameraMove;
|
||||
}
|
||||
if(input.keys[KeyCode::KEY_D])
|
||||
{
|
||||
moveVector += side * cameraMove;
|
||||
}
|
||||
if(input.keys[KeyCode::KEY_E])
|
||||
{
|
||||
moveVector += Vector(0, cameraMove, 0);
|
||||
}
|
||||
if(input.keys[KeyCode::KEY_Q])
|
||||
{
|
||||
moveVector += Vector(0, -cameraMove, 0);
|
||||
}
|
||||
transform.translate(moveVector);
|
||||
if(input.mouse2)
|
||||
{
|
||||
transform.setRotation(glm::rotate(transform.getRotation(), input.deltaX / 500, Vector(0, 1, 0)));
|
||||
transform.setRotation(glm::rotate(transform.getRotation(), input.deltaY / 500, transform.getRight()));
|
||||
}
|
||||
light.attenuation += input.scrollY * 0.1;
|
||||
#include "FlyCamSystem.h"
|
||||
|
||||
FlyCamSystem::FlyCamSystem(PScene scene)
|
||||
: System::ComponentSystem<Component::KeyboardInput, Component::Camera, Component::Transform, Component::PointLight>(scene) {}
|
||||
|
||||
FlyCamSystem::~FlyCamSystem() {}
|
||||
|
||||
void FlyCamSystem::update(Component::KeyboardInput& input, Component::Camera& camera, Component::Transform& transform, Component::PointLight& light) {
|
||||
float cameraMove = static_cast<float>(deltaTime) * 4;
|
||||
if(input.keys[KeyCode::KEY_LEFT_SHIFT])
|
||||
{
|
||||
cameraMove *= 10;
|
||||
}
|
||||
Vector forward = transform.getForward();
|
||||
Vector side = transform.getRight();
|
||||
Vector moveVector = Vector();
|
||||
|
||||
if (input.keys[KeyCode::KEY_J])
|
||||
{
|
||||
std::cout << transform.getPosition() << std::endl;
|
||||
}
|
||||
|
||||
if(input.keys[KeyCode::KEY_W])
|
||||
{
|
||||
moveVector += forward * cameraMove;
|
||||
}
|
||||
if(input.keys[KeyCode::KEY_S])
|
||||
{
|
||||
moveVector += forward * -cameraMove;
|
||||
}
|
||||
if(input.keys[KeyCode::KEY_A])
|
||||
{
|
||||
moveVector += side * -cameraMove;
|
||||
}
|
||||
if(input.keys[KeyCode::KEY_D])
|
||||
{
|
||||
moveVector += side * cameraMove;
|
||||
}
|
||||
if(input.keys[KeyCode::KEY_E])
|
||||
{
|
||||
moveVector += Vector(0, cameraMove, 0);
|
||||
}
|
||||
if(input.keys[KeyCode::KEY_Q])
|
||||
{
|
||||
moveVector += Vector(0, -cameraMove, 0);
|
||||
}
|
||||
transform.translate(moveVector);
|
||||
if(input.mouse2)
|
||||
{
|
||||
transform.setRotation(glm::rotate(transform.getRotation(), input.deltaX / 500, Vector(0, 1, 0)));
|
||||
transform.setRotation(glm::rotate(transform.getRotation(), input.deltaY / 500, transform.getRight()));
|
||||
}
|
||||
light.attenuation += input.scrollY * 0.1;
|
||||
}
|
||||
+22
-22
@@ -1,23 +1,23 @@
|
||||
#pragma once
|
||||
#include "Define.h"
|
||||
#include <MinimalEngine.h>
|
||||
#include <Scene/Scene.h>
|
||||
#include <System/ComponentSystem.h>
|
||||
#include <Component/Camera.h>
|
||||
#include <Component/KeyboardInput.h>
|
||||
|
||||
class FlyCamSystem : public System::ComponentSystem<
|
||||
Component::KeyboardInput,
|
||||
Component::Camera,
|
||||
Component::Transform,
|
||||
Component::PointLight>
|
||||
{
|
||||
public:
|
||||
FlyCamSystem(PScene scene);
|
||||
virtual ~FlyCamSystem();
|
||||
virtual void update(Seele::Component::KeyboardInput& input, Seele::Component::Camera& camera, Seele::Component::Transform& transform, Seele::Component::PointLight& pointLight) override;
|
||||
private:
|
||||
float lastMouseX;
|
||||
float lastMouseY;
|
||||
};
|
||||
#pragma once
|
||||
#include "Define.h"
|
||||
#include <MinimalEngine.h>
|
||||
#include <Scene/Scene.h>
|
||||
#include <System/ComponentSystem.h>
|
||||
#include <Component/Camera.h>
|
||||
#include <Component/KeyboardInput.h>
|
||||
|
||||
class FlyCamSystem : public System::ComponentSystem<
|
||||
Component::KeyboardInput,
|
||||
Component::Camera,
|
||||
Component::Transform,
|
||||
Component::PointLight>
|
||||
{
|
||||
public:
|
||||
FlyCamSystem(PScene scene);
|
||||
virtual ~FlyCamSystem();
|
||||
virtual void update(Seele::Component::KeyboardInput& input, Seele::Component::Camera& camera, Seele::Component::Transform& transform, Seele::Component::PointLight& pointLight) override;
|
||||
private:
|
||||
float lastMouseX;
|
||||
float lastMouseY;
|
||||
};
|
||||
DEFINE_REF(FlyCamSystem)
|
||||
+141
-141
@@ -1,141 +1,141 @@
|
||||
#include "SplineCamSystem.h"
|
||||
|
||||
SplineCamSystem::SplineCamSystem(PScene scene)
|
||||
: System::ComponentSystem<Component::Camera, Component::Transform, PathFollow>(scene)
|
||||
{}
|
||||
|
||||
SplineCamSystem::~SplineCamSystem()
|
||||
{}
|
||||
|
||||
void SplineCamSystem::update(Component::Camera& cam, Component::Transform& transform, PathFollow& follow)
|
||||
{
|
||||
if (follow.path == nullptr)
|
||||
return;
|
||||
Path& path = follow.path->accessComponent<Path>();
|
||||
|
||||
//for (size_t i = 0; i < path.points.size() - 1; ++i)
|
||||
//{
|
||||
// addDebugVertex(DebugVertex{
|
||||
// .position = path.points[i],
|
||||
// .color = Vector(0, 1, 0)
|
||||
// });
|
||||
// addDebugVertex(DebugVertex{
|
||||
// .position = path.points[i + 1],
|
||||
// .color = Vector(0, 1, 0)
|
||||
// });
|
||||
//}
|
||||
|
||||
updateFollowDistance(follow, path.getPathLength());
|
||||
std::tuple<int, float> pt = findP0AndTForDistance(path, follow.distance);
|
||||
auto [p0Index, t] = pt;
|
||||
if (p0Index < 0 || (path.points.size() <= p0Index + 3 && !path.looping))
|
||||
// Not enough points to interpolate...
|
||||
return;
|
||||
|
||||
Vector p0 = path.points[p0Index];
|
||||
Vector p1 = path.points[(p0Index + 1) % path.points.size()];
|
||||
Vector p2 = path.points[(p0Index + 2) % path.points.size()];
|
||||
Vector p3 = path.points[(p0Index + 3) % path.points.size()];
|
||||
|
||||
Vector oldPos = transform.getPosition() - follow.pathOffset;
|
||||
Vector newPos = path.catmullrom(t, p0, p1, p2, p3, path.tension);
|
||||
transform.setPosition(newPos + follow.pathOffset);
|
||||
|
||||
if ((oldPos - follow.lastPos).length() > Path::LAST_POS_EPSILON)
|
||||
{
|
||||
follow.lastPos = oldPos;
|
||||
}
|
||||
Vector tangentVector = glm::normalize(follow.lastPos - newPos);
|
||||
Quaternion newRot = glm::quatLookAt(tangentVector, Vector(0.0f, 1.0f, 0.0f));
|
||||
transform.setRotation(newRot);
|
||||
}
|
||||
|
||||
std::tuple<int, float> SplineCamSystem::findP0AndTForDistance(const Path& path, float distance)
|
||||
{
|
||||
if (path.arcLengthTable.size() == 0)
|
||||
return std::tuple<int, float>(-1, 0.0f);
|
||||
|
||||
int p0 = -1;
|
||||
float t = 0.0f;
|
||||
|
||||
int pIndexToCheck = 1;//path.pointOffset + 1;
|
||||
|
||||
//if (path.looping)
|
||||
//{
|
||||
// // If looping, subtract loop distance until we are in the final "lap"
|
||||
// float lapDistance = path.arcLengthTable[path.arcLengthTable.size() - 1][path.arcLengthTable[path.arcLengthTable.size() - 1].size() - 1];
|
||||
// while (distance >= lapDistance)
|
||||
// {
|
||||
// distance -= lapDistance;
|
||||
// }
|
||||
//
|
||||
// // If we are in a new loop, the path.pointOffset might not be valid anymore
|
||||
// if (path.arcLengthTable[path.pointOffset][0] > distance)
|
||||
// {
|
||||
// pIndexToCheck = 1;
|
||||
// }
|
||||
//}
|
||||
float lapDistance = path.arcLengthTable[path.arcLengthTable.size() - 1][path.arcLengthTable[path.arcLengthTable.size() - 1].size() - 1];
|
||||
if (distance >= lapDistance)
|
||||
{
|
||||
getGlobals().running = false;
|
||||
}
|
||||
|
||||
while (pIndexToCheck < path.arcLengthTable.size()
|
||||
&& path.arcLengthTable[pIndexToCheck][0] < distance)
|
||||
{
|
||||
pIndexToCheck++;
|
||||
}
|
||||
p0 = pIndexToCheck - 1;
|
||||
|
||||
int arcTableIndex = 1;
|
||||
float additionalT = 0.0f;
|
||||
// TODO this could be improved e.g. by using binary search
|
||||
while (arcTableIndex < path.arcLengthTable[p0].size()
|
||||
&& path.arcLengthTable[p0][arcTableIndex] < distance)
|
||||
{
|
||||
arcTableIndex++;
|
||||
}
|
||||
arcTableIndex--;
|
||||
|
||||
// Interpolate between arc length table entries to find additionalT
|
||||
if (arcTableIndex + 1 < path.arcLengthTable[p0].size())
|
||||
{
|
||||
float distanceA = path.arcLengthTable[p0][arcTableIndex];
|
||||
float distanceB = path.arcLengthTable[p0][arcTableIndex + 1];
|
||||
|
||||
float abDistance = distanceB - distanceA;
|
||||
float requiredDistanceAfterA = distance - distanceA;
|
||||
additionalT = Path::ARC_LENGTH_TABLE_DISTANCE * (requiredDistanceAfterA / abDistance);
|
||||
}
|
||||
|
||||
t = (arcTableIndex * Path::ARC_LENGTH_TABLE_DISTANCE) + additionalT;
|
||||
|
||||
assert(p0 < path.points.size());
|
||||
assert(t >= 0.0f && t <= 1.0f);
|
||||
return std::tuple<int, float>(p0, t);
|
||||
}
|
||||
|
||||
void SplineCamSystem::updateFollowDistance(PathFollow& follow, float pathLength)
|
||||
{
|
||||
follow.time = follow.time + deltaTime;
|
||||
switch (follow.speedControl)
|
||||
{
|
||||
case PathFollow::SpeedControl::Linear:
|
||||
// We increase distance instead of setting it based on overall time, because Linear SpeedControl allows for traversalSpeed change
|
||||
follow.distance += (deltaTime * follow.traversalSpeed);
|
||||
break;
|
||||
case PathFollow::SpeedControl::EaseInEaseOut:
|
||||
{
|
||||
float timeNeededForPath = pathLength / follow.traversalSpeed;
|
||||
float t = follow.time / timeNeededForPath;
|
||||
int laps = (int)t;
|
||||
t = t - laps;
|
||||
float s = (glm::sin(t * glm::pi<float>() - glm::pi<float>() / 2.f) + 1) / 2.f;
|
||||
follow.distance = ((laps + s) * pathLength);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
assert(false && "Unknown SpeedControl");
|
||||
}
|
||||
}
|
||||
#include "SplineCamSystem.h"
|
||||
|
||||
SplineCamSystem::SplineCamSystem(PScene scene)
|
||||
: System::ComponentSystem<Component::Camera, Component::Transform, PathFollow>(scene)
|
||||
{}
|
||||
|
||||
SplineCamSystem::~SplineCamSystem()
|
||||
{}
|
||||
|
||||
void SplineCamSystem::update(Component::Camera& cam, Component::Transform& transform, PathFollow& follow)
|
||||
{
|
||||
if (follow.path == nullptr)
|
||||
return;
|
||||
Path& path = follow.path->accessComponent<Path>();
|
||||
|
||||
//for (size_t i = 0; i < path.points.size() - 1; ++i)
|
||||
//{
|
||||
// addDebugVertex(DebugVertex{
|
||||
// .position = path.points[i],
|
||||
// .color = Vector(0, 1, 0)
|
||||
// });
|
||||
// addDebugVertex(DebugVertex{
|
||||
// .position = path.points[i + 1],
|
||||
// .color = Vector(0, 1, 0)
|
||||
// });
|
||||
//}
|
||||
|
||||
updateFollowDistance(follow, path.getPathLength());
|
||||
std::tuple<int, float> pt = findP0AndTForDistance(path, follow.distance);
|
||||
auto [p0Index, t] = pt;
|
||||
if (p0Index < 0 || (path.points.size() <= p0Index + 3 && !path.looping))
|
||||
// Not enough points to interpolate...
|
||||
return;
|
||||
|
||||
Vector p0 = path.points[p0Index];
|
||||
Vector p1 = path.points[(p0Index + 1) % path.points.size()];
|
||||
Vector p2 = path.points[(p0Index + 2) % path.points.size()];
|
||||
Vector p3 = path.points[(p0Index + 3) % path.points.size()];
|
||||
|
||||
Vector oldPos = transform.getPosition() - follow.pathOffset;
|
||||
Vector newPos = path.catmullrom(t, p0, p1, p2, p3, path.tension);
|
||||
transform.setPosition(newPos + follow.pathOffset);
|
||||
|
||||
if ((oldPos - follow.lastPos).length() > Path::LAST_POS_EPSILON)
|
||||
{
|
||||
follow.lastPos = oldPos;
|
||||
}
|
||||
Vector tangentVector = glm::normalize(follow.lastPos - newPos);
|
||||
Quaternion newRot = glm::quatLookAt(tangentVector, Vector(0.0f, 1.0f, 0.0f));
|
||||
transform.setRotation(newRot);
|
||||
}
|
||||
|
||||
std::tuple<int, float> SplineCamSystem::findP0AndTForDistance(const Path& path, float distance)
|
||||
{
|
||||
if (path.arcLengthTable.size() == 0)
|
||||
return std::tuple<int, float>(-1, 0.0f);
|
||||
|
||||
int p0 = -1;
|
||||
float t = 0.0f;
|
||||
|
||||
int pIndexToCheck = 1;//path.pointOffset + 1;
|
||||
|
||||
//if (path.looping)
|
||||
//{
|
||||
// // If looping, subtract loop distance until we are in the final "lap"
|
||||
// float lapDistance = path.arcLengthTable[path.arcLengthTable.size() - 1][path.arcLengthTable[path.arcLengthTable.size() - 1].size() - 1];
|
||||
// while (distance >= lapDistance)
|
||||
// {
|
||||
// distance -= lapDistance;
|
||||
// }
|
||||
//
|
||||
// // If we are in a new loop, the path.pointOffset might not be valid anymore
|
||||
// if (path.arcLengthTable[path.pointOffset][0] > distance)
|
||||
// {
|
||||
// pIndexToCheck = 1;
|
||||
// }
|
||||
//}
|
||||
float lapDistance = path.arcLengthTable[path.arcLengthTable.size() - 1][path.arcLengthTable[path.arcLengthTable.size() - 1].size() - 1];
|
||||
if (distance >= lapDistance)
|
||||
{
|
||||
getGlobals().running = false;
|
||||
}
|
||||
|
||||
while (pIndexToCheck < path.arcLengthTable.size()
|
||||
&& path.arcLengthTable[pIndexToCheck][0] < distance)
|
||||
{
|
||||
pIndexToCheck++;
|
||||
}
|
||||
p0 = pIndexToCheck - 1;
|
||||
|
||||
int arcTableIndex = 1;
|
||||
float additionalT = 0.0f;
|
||||
// TODO this could be improved e.g. by using binary search
|
||||
while (arcTableIndex < path.arcLengthTable[p0].size()
|
||||
&& path.arcLengthTable[p0][arcTableIndex] < distance)
|
||||
{
|
||||
arcTableIndex++;
|
||||
}
|
||||
arcTableIndex--;
|
||||
|
||||
// Interpolate between arc length table entries to find additionalT
|
||||
if (arcTableIndex + 1 < path.arcLengthTable[p0].size())
|
||||
{
|
||||
float distanceA = path.arcLengthTable[p0][arcTableIndex];
|
||||
float distanceB = path.arcLengthTable[p0][arcTableIndex + 1];
|
||||
|
||||
float abDistance = distanceB - distanceA;
|
||||
float requiredDistanceAfterA = distance - distanceA;
|
||||
additionalT = Path::ARC_LENGTH_TABLE_DISTANCE * (requiredDistanceAfterA / abDistance);
|
||||
}
|
||||
|
||||
t = (arcTableIndex * Path::ARC_LENGTH_TABLE_DISTANCE) + additionalT;
|
||||
|
||||
assert(p0 < path.points.size());
|
||||
assert(t >= 0.0f && t <= 1.0f);
|
||||
return std::tuple<int, float>(p0, t);
|
||||
}
|
||||
|
||||
void SplineCamSystem::updateFollowDistance(PathFollow& follow, float pathLength)
|
||||
{
|
||||
follow.time = follow.time + deltaTime;
|
||||
switch (follow.speedControl)
|
||||
{
|
||||
case PathFollow::SpeedControl::Linear:
|
||||
// We increase distance instead of setting it based on overall time, because Linear SpeedControl allows for traversalSpeed change
|
||||
follow.distance += (deltaTime * follow.traversalSpeed);
|
||||
break;
|
||||
case PathFollow::SpeedControl::EaseInEaseOut:
|
||||
{
|
||||
float timeNeededForPath = pathLength / follow.traversalSpeed;
|
||||
float t = follow.time / timeNeededForPath;
|
||||
int laps = (int)t;
|
||||
t = t - laps;
|
||||
float s = (glm::sin(t * glm::pi<float>() - glm::pi<float>() / 2.f) + 1) / 2.f;
|
||||
follow.distance = ((laps + s) * pathLength);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
assert(false && "Unknown SpeedControl");
|
||||
}
|
||||
}
|
||||
@@ -1,23 +1,23 @@
|
||||
#pragma once
|
||||
#include "Define.h"
|
||||
#include <MinimalEngine.h>
|
||||
#include <Scene/Scene.h>
|
||||
#include <System/ComponentSystem.h>
|
||||
#include <Component/Camera.h>
|
||||
#include <Component/Path.h>
|
||||
#include <Component/PathFollow.h>
|
||||
|
||||
class SplineCamSystem : public System::ComponentSystem<
|
||||
Component::Camera,
|
||||
Component::Transform,
|
||||
PathFollow>
|
||||
{
|
||||
public:
|
||||
SplineCamSystem(PScene scene);
|
||||
virtual ~SplineCamSystem();
|
||||
virtual void update(Component::Camera& camera, Component::Transform& transform, PathFollow& follow);
|
||||
private:
|
||||
std::tuple<int, float> findP0AndTForDistance(const Path& path, float distance);
|
||||
void updateFollowDistance(PathFollow& follow, float pathLength);
|
||||
};
|
||||
#pragma once
|
||||
#include "Define.h"
|
||||
#include <MinimalEngine.h>
|
||||
#include <Scene/Scene.h>
|
||||
#include <System/ComponentSystem.h>
|
||||
#include <Component/Camera.h>
|
||||
#include <Component/Path.h>
|
||||
#include <Component/PathFollow.h>
|
||||
|
||||
class SplineCamSystem : public System::ComponentSystem<
|
||||
Component::Camera,
|
||||
Component::Transform,
|
||||
PathFollow>
|
||||
{
|
||||
public:
|
||||
SplineCamSystem(PScene scene);
|
||||
virtual ~SplineCamSystem();
|
||||
virtual void update(Component::Camera& camera, Component::Transform& transform, PathFollow& follow);
|
||||
private:
|
||||
std::tuple<int, float> findP0AndTForDistance(const Path& path, float distance);
|
||||
void updateFollowDistance(PathFollow& follow, float pathLength);
|
||||
};
|
||||
DEFINE_REF(SplineCamSystem)
|
||||
Reference in new issue
Block a user