|
@@ -1,4 +1,5 @@
|
|
#include <cmath>
|
|
#include <cmath>
|
|
|
|
+#include <vector>
|
|
|
|
|
|
#include "client/Game.h"
|
|
#include "client/Game.h"
|
|
#include "client/utils/Utils.h"
|
|
#include "client/utils/Utils.h"
|
|
@@ -7,9 +8,10 @@
|
|
#include "common/utils/Random.h"
|
|
#include "common/utils/Random.h"
|
|
#include "math/Quaternion.h"
|
|
#include "math/Quaternion.h"
|
|
|
|
|
|
-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.125f), movedLength(0.0f), mode(Mode::AUTO) {
|
|
|
|
|
|
+Game::Game(const Control& control, const Clock& fps, const Clock& tps, RenderSettings& renderSettings,
|
|
|
|
+ const WindowSize& size) :
|
|
|
|
+control(control), fps(fps), tps(tps), renderSettings(renderSettings), size(size), world(blockRegistry),
|
|
|
|
+worldRenderer(world), pointIndex(0), moveSpeed(0.125f), movedLength(0.0f), mode(Mode::AUTO) {
|
|
Random r(0);
|
|
Random r(0);
|
|
float h = World::WORLD_SIZE * 0.6f;
|
|
float h = World::WORLD_SIZE * 0.6f;
|
|
float mid = World::WORLD_SIZE * 0.5f;
|
|
float mid = World::WORLD_SIZE * 0.5f;
|
|
@@ -33,21 +35,33 @@ pointIndex(0), moveSpeed(0.125f), movedLength(0.0f), mode(Mode::AUTO) {
|
|
}
|
|
}
|
|
updateDistances();
|
|
updateDistances();
|
|
|
|
|
|
- lines.add(Vector3(0, 0, 0), Vector3(0, 0, 50));
|
|
|
|
- lines.add(Vector3(0, 0, 0), Vector3(0, 50, 0));
|
|
|
|
- lines.add(Vector3(0, 0, 50), Vector3(0, 50, 0));
|
|
|
|
- lines.build();
|
|
|
|
|
|
+ std::vector<KDTree::Triangle> data;
|
|
|
|
+ //generateSphere(data);
|
|
|
|
+ generateRandom(data);
|
|
|
|
+
|
|
|
|
+ for(KDTree::Triangle& t : data) {
|
|
|
|
+ treeData.add(Triangle(
|
|
|
|
+ Vertex(t[0], Vector2(8.0f / 16.0f, 0.0f)),
|
|
|
|
+ Vertex(t[1], Vector2(9.0f / 16.0f, 0.0f)),
|
|
|
|
+ Vertex(t[2], Vector2(9.0f / 16.0f, 1.0f / 16.0f))
|
|
|
|
+ ));
|
|
|
|
+ }
|
|
|
|
+ treeData.build();
|
|
|
|
+
|
|
|
|
+ kdTree.build(data);
|
|
|
|
+ kdTree.fillLines(lines, data);
|
|
}
|
|
}
|
|
|
|
|
|
void Game::tick() {
|
|
void Game::tick() {
|
|
lastRotation = rotation;
|
|
lastRotation = rotation;
|
|
lastPos = pos;
|
|
lastPos = pos;
|
|
- if(mode == Mode::PLAYER) {
|
|
|
|
- Matrix m = rotation.toMatrix();
|
|
|
|
- Vector3 right = m * Vector3(1.0f, 0.0f, 0.0f);
|
|
|
|
- Vector3 up = m * Vector3(0.0f, 1.0f, 0.0f);
|
|
|
|
- Vector3 back = m * Vector3(0.0f, 0.0f, -1.0f);
|
|
|
|
|
|
|
|
|
|
+ Matrix m = rotation.toMatrix();
|
|
|
|
+ Vector3 right = m * Vector3(1.0f, 0.0f, 0.0f);
|
|
|
|
+ Vector3 up = m * Vector3(0.0f, 1.0f, 0.0f);
|
|
|
|
+ Vector3 back = m * Vector3(0.0f, 0.0f, -1.0f);
|
|
|
|
+
|
|
|
|
+ if(mode == Mode::PLAYER) {
|
|
const float speed = 1.0f;
|
|
const float speed = 1.0f;
|
|
if(control.keys.down.isDown()) {
|
|
if(control.keys.down.isDown()) {
|
|
pos += back * speed;
|
|
pos += back * speed;
|
|
@@ -137,6 +151,26 @@ void Game::tick() {
|
|
}
|
|
}
|
|
renderSettings.dirtyFactor = true;
|
|
renderSettings.dirtyFactor = true;
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ if(control.buttons.primary.getDownTime() == 1) {
|
|
|
|
+ float hWidth = size.width * 0.5f;
|
|
|
|
+ float hHeight = size.height * 0.5f;
|
|
|
|
+
|
|
|
|
+ float x = (control.buttons.getX() - hWidth) / hWidth;
|
|
|
|
+ float y = -(control.buttons.getY() - hHeight) / hHeight;
|
|
|
|
+
|
|
|
|
+ float aspect = hWidth / hHeight;
|
|
|
|
+ float tan = tanf((0.5f * 60.0f) * M_PI / 180.0f);
|
|
|
|
+ float q = 1.0f / tan;
|
|
|
|
+
|
|
|
|
+ Vector3 direction(x / (q / aspect), y / q, 1.0f);
|
|
|
|
+ direction.normalize();
|
|
|
|
+ direction = m * direction;
|
|
|
|
+
|
|
|
|
+ clickLine.clear();
|
|
|
|
+ clickLine.add(pos, pos + direction * 100.0f, 0xFF00FF);
|
|
|
|
+ clickLine.build();
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
void Game::renderWorld(float lag, Renderer& renderer) const {
|
|
void Game::renderWorld(float lag, Renderer& renderer) const {
|
|
@@ -162,6 +196,7 @@ void Game::renderWorld(float lag, Renderer& renderer) const {
|
|
renderer.update(v, lastRotation.slerp(lag, rotation));
|
|
renderer.update(v, lastRotation.slerp(lag, rotation));
|
|
}
|
|
}
|
|
worldRenderer.render(lag, renderer);
|
|
worldRenderer.render(lag, renderer);
|
|
|
|
+ treeData.draw();
|
|
}
|
|
}
|
|
|
|
|
|
void Game::renderWorldLines(float lag, Renderer& renderer) const {
|
|
void Game::renderWorldLines(float lag, Renderer& renderer) const {
|
|
@@ -169,6 +204,7 @@ void Game::renderWorldLines(float lag, Renderer& renderer) const {
|
|
renderer.translateTo(0.0f, 0.0f, 0.0f);
|
|
renderer.translateTo(0.0f, 0.0f, 0.0f);
|
|
renderer.update();
|
|
renderer.update();
|
|
lines.draw();
|
|
lines.draw();
|
|
|
|
+ clickLine.draw();
|
|
}
|
|
}
|
|
|
|
|
|
void Game::renderTextOverlay(float lag, Renderer& renderer, FontRenderer& fr) const {
|
|
void Game::renderTextOverlay(float lag, Renderer& renderer, FontRenderer& fr) const {
|
|
@@ -270,3 +306,50 @@ void Game::updateDistances() {
|
|
cameraPoints[i].distance = distance(i, 10000);
|
|
cameraPoints[i].distance = distance(i, 10000);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+void Game::generateSphere(std::vector<KDTree::Triangle>& data) {
|
|
|
|
+ int fieldSize = 8;
|
|
|
|
+ int quality = 3;
|
|
|
|
+ float radius = 30;
|
|
|
|
+
|
|
|
|
+ int triangles = fieldSize * quality;
|
|
|
|
+ int layers = (2 + fieldSize) * quality;
|
|
|
|
+
|
|
|
|
+ for(int l = 0; l < layers; l++) {
|
|
|
|
+ float high1 = cosf((M_PI * l) / layers);
|
|
|
|
+ float high2 = cosf((M_PI * (l + 1)) / layers);
|
|
|
|
+
|
|
|
|
+ float r1 = sqrtf(1 - high1 * high1) * radius;
|
|
|
|
+ float r2 = sqrtf(1 - high2 * high2) * radius;
|
|
|
|
+
|
|
|
|
+ high1 *= radius;
|
|
|
|
+ high2 *= radius;
|
|
|
|
+
|
|
|
|
+ for(int i = 0; i < triangles; i++) {
|
|
|
|
+ float first = 2 * M_PI * i / triangles;
|
|
|
|
+ float second = 2 * M_PI * (i + 1) / triangles;
|
|
|
|
+
|
|
|
|
+ data.push_back(KDTree::Triangle(
|
|
|
|
+ Vector3(r2 * cosf(first), high2, r2 * sinf(first)),
|
|
|
|
+ Vector3(r1 * cosf(first), high1, r1 * sinf(first)),
|
|
|
|
+ Vector3(r1 * cosf(second), high1, r1 * sinf(second))));
|
|
|
|
+
|
|
|
|
+ data.push_back(KDTree::Triangle(
|
|
|
|
+ Vector3(r2 * cosf(first), high2, r2 * sinf(first)),
|
|
|
|
+ Vector3(r1 * cosf(second), high1, r1 * sinf(second)),
|
|
|
|
+ Vector3(r2 * cosf(second), high2, r2 * sinf(second))));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+void Game::generateRandom(std::vector<KDTree::Triangle>& data) {
|
|
|
|
+ float radius = 25.0f;
|
|
|
|
+ float diff = 5.0f;
|
|
|
|
+ Random r(0);
|
|
|
|
+ for(int i = 0; i < 7; i++) {
|
|
|
|
+ Vector3 a(r.nextFloat() * radius, r.nextFloat() * radius, r.nextFloat() * radius);
|
|
|
|
+ Vector3 b = a + Vector3(r.nextFloat() * diff, r.nextFloat() * diff, r.nextFloat() * diff);
|
|
|
|
+ Vector3 c = a + Vector3(r.nextFloat() * diff, r.nextFloat() * diff, r.nextFloat() * diff);
|
|
|
|
+ data.push_back(KDTree::Triangle(a, b, c));
|
|
|
|
+ }
|
|
|
|
+}
|