|
@@ -1,3 +1,5 @@
|
|
|
|
+#include <cmath>
|
|
|
|
+
|
|
#include "client/Game.h"
|
|
#include "client/Game.h"
|
|
#include "client/utils/Utils.h"
|
|
#include "client/utils/Utils.h"
|
|
#include "rendering/Renderer.h"
|
|
#include "rendering/Renderer.h"
|
|
@@ -11,9 +13,12 @@ pointIndex(0), moveSpeed(0.25f), movedLength(0.0f), mode(Mode::AUTO) {
|
|
Random r(0);
|
|
Random r(0);
|
|
float h = World::WORLD_SIZE * 0.75f;
|
|
float h = World::WORLD_SIZE * 0.75f;
|
|
float mid = World::WORLD_SIZE * 0.5f;
|
|
float mid = World::WORLD_SIZE * 0.5f;
|
|
- float randLength = World::WORLD_SIZE * 0.125f;
|
|
|
|
|
|
+ float randLength = World::WORLD_SIZE * 0.125f * 0.5f;
|
|
pos.set(0, h, 0);
|
|
pos.set(0, h, 0);
|
|
lastPos.set(pos);
|
|
lastPos.set(pos);
|
|
|
|
+
|
|
|
|
+ rotation = Quaternion(Vector(1, 0, 0), -80);
|
|
|
|
+ lastRotation = rotation;
|
|
|
|
|
|
for(uint i = 0; i < cameraPoints.getCapacity(); i++) {
|
|
for(uint i = 0; i < cameraPoints.getCapacity(); i++) {
|
|
Vector offset(mid, h, mid);
|
|
Vector offset(mid, h, mid);
|
|
@@ -28,11 +33,17 @@ pointIndex(0), moveSpeed(0.25f), movedLength(0.0f), mode(Mode::AUTO) {
|
|
}
|
|
}
|
|
|
|
|
|
void Game::tick() {
|
|
void Game::tick() {
|
|
|
|
+ lastRotation = rotation;
|
|
lastPos = pos;
|
|
lastPos = pos;
|
|
if(mode == Mode::PLAYER) {
|
|
if(mode == Mode::PLAYER) {
|
|
Vector right(1.0f, 0.0f, 0.0f);
|
|
Vector right(1.0f, 0.0f, 0.0f);
|
|
Vector up(0.0f, 1.0f, 0.0f);
|
|
Vector up(0.0f, 1.0f, 0.0f);
|
|
Vector back(0.0f, 0.0f, -1.0f);
|
|
Vector back(0.0f, 0.0f, -1.0f);
|
|
|
|
+
|
|
|
|
+ Matrix m = rotation.toMatrix();
|
|
|
|
+ right.mul(m);
|
|
|
|
+ up.mul(m);
|
|
|
|
+ back.mul(m);
|
|
|
|
|
|
const float speed = 1.0f;
|
|
const float speed = 1.0f;
|
|
if(control.keys.down.isDown()) {
|
|
if(control.keys.down.isDown()) {
|
|
@@ -53,31 +64,31 @@ void Game::tick() {
|
|
if(control.keys.sneak.isDown()) {
|
|
if(control.keys.sneak.isDown()) {
|
|
pos.addMul(up, -speed);
|
|
pos.addMul(up, -speed);
|
|
}
|
|
}
|
|
-
|
|
|
|
- /*const float rotation = 5.0f;
|
|
|
|
|
|
+
|
|
|
|
+ const float rotationSpeed = 5.0f;
|
|
if(control.keys.camLeft.isDown()) {
|
|
if(control.keys.camLeft.isDown()) {
|
|
- lengthAngle += rotation;
|
|
|
|
|
|
+ rotation.mul(Quaternion(up, rotationSpeed));
|
|
}
|
|
}
|
|
if(control.keys.camRight.isDown()) {
|
|
if(control.keys.camRight.isDown()) {
|
|
- lengthAngle -= rotation;
|
|
|
|
|
|
+ rotation.mul(Quaternion(up, -rotationSpeed));
|
|
}
|
|
}
|
|
- if(control.keys.camUp.isDown() && widthAngle - rotation > -90.0f) {
|
|
|
|
- widthAngle -= rotation;
|
|
|
|
|
|
+ if(control.keys.camUp.isDown()) {
|
|
|
|
+ rotation.mul(Quaternion(right, rotationSpeed));
|
|
|
|
+ }
|
|
|
|
+ if(control.keys.camDown.isDown()) {
|
|
|
|
+ rotation.mul(Quaternion(right, -rotationSpeed));
|
|
}
|
|
}
|
|
- if(control.keys.camDown.isDown() && widthAngle + rotation < 90.0f) {
|
|
|
|
- widthAngle += rotation;
|
|
|
|
- }*/
|
|
|
|
} else if(mode == Mode::AUTO) {
|
|
} else if(mode == Mode::AUTO) {
|
|
movedLength += moveSpeed;
|
|
movedLength += moveSpeed;
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
if(control.keys.test.isDown()) {
|
|
if(control.keys.test.isDown()) {
|
|
mode = Mode::PLAYER;
|
|
mode = Mode::PLAYER;
|
|
}
|
|
}
|
|
if(control.keys.test2.isDown()) {
|
|
if(control.keys.test2.isDown()) {
|
|
mode = Mode::AUTO;
|
|
mode = Mode::AUTO;
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
if(control.keys.test4.getDownTime() == 1) {
|
|
if(control.keys.test4.getDownTime() == 1) {
|
|
renderSettings.shadows = !renderSettings.shadows;
|
|
renderSettings.shadows = !renderSettings.shadows;
|
|
}
|
|
}
|
|
@@ -94,29 +105,21 @@ void Game::renderWorld(float lag, Renderer& renderer) const {
|
|
leftLength -= cameraPoints[index].distance;
|
|
leftLength -= cameraPoints[index].distance;
|
|
index = (index + 1) % cameraPoints.getLength();
|
|
index = (index + 1) % cameraPoints.getLength();
|
|
}
|
|
}
|
|
-
|
|
|
|
- uint prev = index;
|
|
|
|
float t = leftLength / cameraPoints[index].distance;
|
|
float t = leftLength / cameraPoints[index].distance;
|
|
- if(prev == 0) {
|
|
|
|
- prev = cameraPoints.getLength() - 1;
|
|
|
|
- } else {
|
|
|
|
- prev = (prev - 1) % cameraPoints.getLength();
|
|
|
|
- }
|
|
|
|
- uint currentA = (prev + 1) % cameraPoints.getLength();
|
|
|
|
- uint currentB = (prev + 2) % cameraPoints.getLength();
|
|
|
|
- uint next = (prev + 3) % cameraPoints.getLength();
|
|
|
|
-
|
|
|
|
- Vector tangentA = splineTangent(cameraPoints[prev].pos, cameraPoints[currentA].pos, cameraPoints[currentB].pos);
|
|
|
|
- Vector tangentB = splineTangent(cameraPoints[currentA].pos, cameraPoints[currentB].pos, cameraPoints[next].pos);
|
|
|
|
-
|
|
|
|
- Vector interpolatedPos = interpolate(cameraPoints[currentA].pos, cameraPoints[currentB].pos, tangentA, tangentB, t);
|
|
|
|
|
|
|
|
|
|
+ Vector a;
|
|
|
|
+ Vector b;
|
|
|
|
+ Vector tanA;
|
|
|
|
+ Vector tanB;
|
|
|
|
+ getPointsAndTangents(index, a, b, tanA, tanB);
|
|
|
|
+
|
|
|
|
+ Vector interpolatedPos = interpolate(a, b, tanA, tanB, t);
|
|
renderer.update(interpolatedPos, Quaternion(Vector(1.0f, 0.0f, 0.0f), -30.0f));
|
|
renderer.update(interpolatedPos, Quaternion(Vector(1.0f, 0.0f, 0.0f), -30.0f));
|
|
pos = interpolatedPos;
|
|
pos = interpolatedPos;
|
|
} else if(mode == Mode::PLAYER) {
|
|
} else if(mode == Mode::PLAYER) {
|
|
Vector v(lastPos);
|
|
Vector v(lastPos);
|
|
v.addMul(pos, lag).addMul(lastPos, -lag);
|
|
v.addMul(pos, lag).addMul(lastPos, -lag);
|
|
- renderer.update(v, Quaternion(Vector(1.0f, 0.0f, 0.0f), -80.0f));
|
|
|
|
|
|
+ renderer.update(v, lastRotation.slerp(lag, rotation));
|
|
}
|
|
}
|
|
worldRenderer.render(lag, renderer);
|
|
worldRenderer.render(lag, renderer);
|
|
}
|
|
}
|
|
@@ -127,7 +130,7 @@ void Game::renderTextOverlay(float lag, Renderer& renderer, FontRenderer& fr) co
|
|
|
|
|
|
String s;
|
|
String s;
|
|
fr.drawString(10, 10, s.append("FPS: ").append(fps.getUpdatesPerSecond())
|
|
fr.drawString(10, 10, s.append("FPS: ").append(fps.getUpdatesPerSecond())
|
|
- .append(" ").append("%0.8f", renderSettings.testBias).append(" ").append("%0.8f", renderSettings.testRadius));
|
|
|
|
|
|
+ .append(" ").append("%0.8f", renderSettings.testBias).append(" ").append("%0.8f", renderSettings.testRadius));
|
|
fr.drawString(10, 19, s.clear().append("TPS: ").append(tps.getUpdatesPerSecond()));
|
|
fr.drawString(10, 19, s.clear().append("TPS: ").append(tps.getUpdatesPerSecond()));
|
|
s.clear();
|
|
s.clear();
|
|
pos.toString(s);
|
|
pos.toString(s);
|
|
@@ -159,23 +162,35 @@ Vector Game::interpolate(const Vector& a, const Vector& b, const Vector& tanA, c
|
|
}
|
|
}
|
|
|
|
|
|
float Game::distance(uint index, uint splits) const {
|
|
float Game::distance(uint index, uint splits) const {
|
|
- uint prev = index == 0 ? cameraPoints.getLength() - 1 : index - 1;
|
|
|
|
- uint currentA = (prev + 1) % cameraPoints.getLength();
|
|
|
|
- uint currentB = (prev + 2) % cameraPoints.getLength();
|
|
|
|
- uint next = (prev + 3) % cameraPoints.getLength();
|
|
|
|
-
|
|
|
|
- Vector tangentA = splineTangent(cameraPoints[prev].pos, cameraPoints[currentA].pos, cameraPoints[currentB].pos);
|
|
|
|
- Vector tangentB = splineTangent(cameraPoints[currentA].pos, cameraPoints[currentB].pos, cameraPoints[next].pos);
|
|
|
|
|
|
+ Vector a;
|
|
|
|
+ Vector b;
|
|
|
|
+ Vector tanA;
|
|
|
|
+ Vector tanB;
|
|
|
|
+ getPointsAndTangents(index, a, b, tanA, tanB);
|
|
|
|
|
|
Vector currentPos;
|
|
Vector currentPos;
|
|
- Vector currentNext = interpolate(cameraPoints[currentA].pos, cameraPoints[currentB].pos, tangentA, tangentB, 0.0f);
|
|
|
|
|
|
+ Vector currentNext = interpolate(a, b, tanA, tanB, 0.0f);
|
|
|
|
|
|
float sum = 0.0f;
|
|
float sum = 0.0f;
|
|
for(uint i = 0; i <= splits; i++) {
|
|
for(uint i = 0; i <= splits; i++) {
|
|
currentPos = currentNext;
|
|
currentPos = currentNext;
|
|
float t = (i + 1.0f) / (splits + 1.0f);
|
|
float t = (i + 1.0f) / (splits + 1.0f);
|
|
- currentNext = interpolate(cameraPoints[currentA].pos, cameraPoints[currentB].pos, tangentA, tangentB, t);
|
|
|
|
- sum += currentPos.sub(currentNext).length();
|
|
|
|
|
|
+ currentNext = interpolate(a, b, tanA, tanB, t);
|
|
|
|
+ float l = currentPos.sub(currentNext).length();
|
|
|
|
+ sum += l;
|
|
}
|
|
}
|
|
return sum;
|
|
return sum;
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+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();
|
|
|
|
+ uint currentB = (prev + 2) % cameraPoints.getLength();
|
|
|
|
+ uint next = (prev + 3) % cameraPoints.getLength();
|
|
|
|
+
|
|
|
|
+ a.set(cameraPoints[currentA].pos);
|
|
|
|
+ b.set(cameraPoints[currentB].pos);
|
|
|
|
+
|
|
|
|
+ tanA = splineTangent(cameraPoints[prev].pos, a, b);
|
|
|
|
+ tanB = splineTangent(a, b, cameraPoints[next].pos);
|
|
|
|
+}
|