|
@@ -11,6 +11,7 @@ BlockRegistry Game::blockRegistry;
|
|
|
World Game::world{blockRegistry};
|
|
|
static WorldRenderer worldRenderer{Game::world};
|
|
|
Controller Game::controller;
|
|
|
+Player Game::player;
|
|
|
|
|
|
typedef void (*State)();
|
|
|
static State tickState;
|
|
@@ -19,11 +20,6 @@ static State renderState;
|
|
|
static BaseGUI baseGUI;
|
|
|
static StartGUI startGUI;
|
|
|
|
|
|
-static Vector3 lastPos;
|
|
|
-static Vector3 pos;
|
|
|
-static Quaternion lastRotation;
|
|
|
-static Quaternion rotation;
|
|
|
-
|
|
|
static void tickConnectedState() {
|
|
|
GameClient::consumeEvents();
|
|
|
}
|
|
@@ -58,60 +54,78 @@ bool Game::init() {
|
|
|
tickState = tickConnectState;
|
|
|
renderState = renderConnectState;
|
|
|
|
|
|
- pos = Vector3(0.0f, 30.0f, 0.0f);
|
|
|
- rotation = Quaternion(Vector3(1.0f, 0.0f, 0.0f), 30) * rotation;
|
|
|
- rotation = Quaternion(Vector3(0.0f, 1.0f, 0.0f), 30) * rotation;
|
|
|
+ player.position = Vector3(0.0f, 30.0f, 0.0f);
|
|
|
+ player.lastLengthAngle = 0.0f;
|
|
|
+ player.lengthAngle = 0.0f;
|
|
|
+ player.lastWidthAngle = 0.0f;
|
|
|
+ player.widthAngle = 0.0f;
|
|
|
+ world.addPlayer(&player);
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
void Game::tick() {
|
|
|
tickState();
|
|
|
+ world.preTick();
|
|
|
|
|
|
- lastRotation = rotation;
|
|
|
- lastPos = pos;
|
|
|
+ Quaternion q(Vector3(0.0f, 1.0f, 0.0f), player.lengthAngle);
|
|
|
+ q *= Quaternion(Vector3(1.0f, 0.0f, 0.0f), player.widthAngle);
|
|
|
|
|
|
- Vector3 right = rotation * Vector3(1.0f, 0.0f, 0.0f);
|
|
|
- Vector3 up = rotation * Vector3(0.0f, 1.0f, 0.0f);
|
|
|
- Vector3 back = rotation * Vector3(0.0f, 0.0f, -1.0f);
|
|
|
+ Vector3 up(0.0f, 1.0f, 0.0f);
|
|
|
+ Vector3 back = q * Vector3(0.0f, 0.0f, -1.0f);
|
|
|
+ // back.setAngles(player.widthAngle, player.lengthAngle);
|
|
|
+ // back[1] = 0.0f;
|
|
|
+ // back.normalize();
|
|
|
+ Vector3 right = back.cross(up);
|
|
|
|
|
|
- const float speed = 2.0f;
|
|
|
+ const float speed = 0.25f;
|
|
|
if(controller.down.isDown()) {
|
|
|
- pos += back * speed;
|
|
|
+ player.acceleration += back * speed;
|
|
|
}
|
|
|
if(controller.up.isDown()) {
|
|
|
- pos -= back * speed;
|
|
|
+ player.acceleration -= back * speed;
|
|
|
}
|
|
|
if(controller.left.isDown()) {
|
|
|
- pos -= right * speed;
|
|
|
+ player.acceleration -= right * speed;
|
|
|
}
|
|
|
if(controller.right.isDown()) {
|
|
|
- pos += right * speed;
|
|
|
+ player.acceleration += right * speed;
|
|
|
}
|
|
|
if(controller.jump.isDown()) {
|
|
|
- pos += up * speed;
|
|
|
+ player.acceleration += up * speed;
|
|
|
}
|
|
|
if(controller.sneak.isDown()) {
|
|
|
- pos -= up * speed;
|
|
|
+ player.acceleration -= up * speed;
|
|
|
}
|
|
|
|
|
|
const float rotationSpeed = 5.0f;
|
|
|
if(controller.camLeft.isDown()) {
|
|
|
- rotation = Quaternion(up, -rotationSpeed) * rotation;
|
|
|
+ player.lengthAngle -= rotationSpeed;
|
|
|
}
|
|
|
if(controller.camRight.isDown()) {
|
|
|
- rotation = Quaternion(up, rotationSpeed) * rotation;
|
|
|
+ player.lengthAngle += rotationSpeed;
|
|
|
}
|
|
|
- if(controller.camUp.isDown()) {
|
|
|
- rotation = Quaternion(right, -rotationSpeed) * rotation;
|
|
|
+ if(controller.camUp.isDown() &&
|
|
|
+ player.widthAngle - rotationSpeed > -90.0f) {
|
|
|
+ player.widthAngle -= rotationSpeed;
|
|
|
}
|
|
|
- if(controller.camDown.isDown()) {
|
|
|
- rotation = Quaternion(right, rotationSpeed) * rotation;
|
|
|
+ if(controller.camDown.isDown() &&
|
|
|
+ player.widthAngle + rotationSpeed < 90.0f) {
|
|
|
+ player.widthAngle += rotationSpeed;
|
|
|
}
|
|
|
+
|
|
|
+ world.tick();
|
|
|
}
|
|
|
|
|
|
void Game::renderWorld() {
|
|
|
- Engine::matrix.update(Utils::interpolate(lastPos, pos, Engine::lag),
|
|
|
- lastRotation.lerp(Engine::lag, rotation));
|
|
|
+ Quaternion q(Vector3(0.0f, 1.0f, 0.0f),
|
|
|
+ Utils::interpolate(player.lastLengthAngle, player.lengthAngle,
|
|
|
+ Engine::lag));
|
|
|
+ q *= Quaternion(Vector3(1.0f, 0.0f, 0.0f),
|
|
|
+ Utils::interpolate(player.lastWidthAngle, player.widthAngle,
|
|
|
+ Engine::lag));
|
|
|
+ Engine::matrix.update(
|
|
|
+ Utils::interpolate(player.lastPosition, player.position, Engine::lag),
|
|
|
+ q);
|
|
|
worldRenderer.render();
|
|
|
}
|
|
|
|