Browse Source

in theorie constant camera tour speed

Kajetan Johannes Hammerle 3 years ago
parent
commit
11f8004442
2 changed files with 29 additions and 20 deletions
  1. 28 20
      client/Game.cpp
  2. 1 0
      client/Game.h

+ 28 - 20
client/Game.cpp

@@ -9,11 +9,11 @@
 
 Game::Game(const Control& control, const Clock& fps, const Clock& tps, RenderSettings& renderSettings) :
 control(control), fps(fps), tps(tps), renderSettings(renderSettings), world(blockRegistry), worldRenderer(world),
-pointIndex(0), moveSpeed(0.25f), movedLength(0.0f), mode(Mode::AUTO) {
+pointIndex(0), moveSpeed(0.125f), movedLength(0.0f), mode(Mode::AUTO) {
     Random r(0);
     float h = World::WORLD_SIZE * 0.6f;
     float mid = World::WORLD_SIZE * 0.5f;
-    float randLength = World::WORLD_SIZE * 0.125f * 0.5f;
+    float randLength = World::WORLD_SIZE * 0.125f * 0.25f;
     pos.set(0, h, 0);
     lastPos.set(pos);
 
@@ -31,16 +31,8 @@ pointIndex(0), moveSpeed(0.25f), movedLength(0.0f), mode(Mode::AUTO) {
         cameraPoints.add({v, q, 0.0f});
     }
     for(uint i = 0; i < cameraPoints.getLength(); i++) {
-        cameraPoints[i].distance = distance(i, 20);
-    }
-    
-    Quaternion testQ = Quaternion(0, 0, 0, 1);
-    Quaternion rotTest = Quaternion(Vector(1, 0, 0), 5.0f);
-    
-    testQ.mul(rotTest);
-    
-    std::cout << "TEST: " << testQ.xyz.getX() << " " << testQ.xyz.getY() << " " << testQ.xyz.getZ() << " " << testQ.w << "\n";
-    
+        cameraPoints[i].distance = distance(i, 10000);
+    }   
 }
 
 void Game::tick() {
@@ -117,14 +109,7 @@ void Game::renderWorld(float lag, Renderer& renderer) const {
             index = (index + 1) % cameraPoints.getLength();
         }
         float t = leftLength / cameraPoints[index].distance;
-
-        Vector a;
-        Vector b;
-        Vector tanA;
-        Vector tanB;
-        getPointsAndTangents(index, a, b, tanA, tanB);
-
-        Vector interpolatedPos = interpolate(a, b, tanA, tanB, t);
+        Vector interpolatedPos = pointUntilDistance(leftLength, index, 10000);
         renderer.update(interpolatedPos, cameraPoints[index].q.slerp(t, cameraPoints[(index + 1) % cameraPoints.getLength()].q));
         pos = interpolatedPos;
     } else if(mode == Mode::PLAYER) {
@@ -193,6 +178,29 @@ float Game::distance(uint index, uint splits) const {
     return sum;
 }
 
+Vector Game::pointUntilDistance(float leftDistance, uint index, uint splits) const {
+    Vector a;
+    Vector b;
+    Vector tanA;
+    Vector tanB;
+    getPointsAndTangents(index, a, b, tanA, tanB);
+
+    Vector currentPos;
+    Vector currentNext = interpolate(a, b, tanA, tanB, 0.0f);
+
+    float sum = 0.0f;
+    uint i = 0;
+    while(leftDistance > sum) {
+        currentPos = currentNext;
+        float t = (i + 1.0f) / (splits + 1.0f);
+        currentNext = interpolate(a, b, tanA, tanB, t);
+        float l = currentPos.sub(currentNext).length();
+        sum += l;
+        i++;
+    }
+    return currentNext;
+}
+
 void Game::getPointsAndTangents(uint index, Vector& a, Vector& b, Vector& tanA, Vector& tanB) const {
     uint prev = index == 0 ? cameraPoints.getLength() - 1 : index - 1;
     uint currentA = (prev + 1) % cameraPoints.getLength();

+ 1 - 0
client/Game.h

@@ -25,6 +25,7 @@ public:
     Vector splineTangent(const Vector& prev, const Vector& current, const Vector& next) const;
     Vector interpolate(const Vector& a, const Vector& b, const Vector& tanA, const Vector& tanB, float t) const;
     float distance(uint index, uint splits) const;
+    Vector pointUntilDistance(float leftDistance, uint index, uint splits) const;
     void getPointsAndTangents(uint index, Vector& a, Vector& b, Vector& tanA, Vector& tanB) const;
 
 private: