|
@@ -22,6 +22,7 @@ static StartGUI startGUI;
|
|
|
|
|
|
static void tickConnectedState() {
|
|
|
GameClient::consumeEvents();
|
|
|
+ Game::world.tick();
|
|
|
}
|
|
|
|
|
|
static void renderConnectedState() {
|
|
@@ -54,78 +55,60 @@ bool Game::init() {
|
|
|
tickState = tickConnectState;
|
|
|
renderState = renderConnectState;
|
|
|
|
|
|
- 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;
|
|
|
+ player.setPosition(Vector3(0.0f, 30.0f, 0.0f));
|
|
|
world.addPlayer(&player);
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
void Game::tick() {
|
|
|
tickState();
|
|
|
- world.preTick();
|
|
|
|
|
|
- Quaternion q(Vector3(0.0f, 1.0f, 0.0f), player.lengthAngle);
|
|
|
- q *= Quaternion(Vector3(1.0f, 0.0f, 0.0f), player.widthAngle);
|
|
|
+ Quaternion q = player.getRotation();
|
|
|
|
|
|
Vector3 up(0.0f, 1.0f, 0.0f);
|
|
|
Vector3 back = q * Vector3(0.0f, 0.0f, -1.0f);
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
+ back[1] = 0.0f;
|
|
|
+ back.normalize();
|
|
|
Vector3 right = back.cross(up);
|
|
|
|
|
|
- const float speed = 0.25f;
|
|
|
+ constexpr float speed = 0.1f;
|
|
|
if(controller.down.isDown()) {
|
|
|
- player.acceleration += back * speed;
|
|
|
+ player.addForce(back * speed);
|
|
|
}
|
|
|
if(controller.up.isDown()) {
|
|
|
- player.acceleration -= back * speed;
|
|
|
+ player.addForce(back * -speed);
|
|
|
}
|
|
|
if(controller.left.isDown()) {
|
|
|
- player.acceleration -= right * speed;
|
|
|
+ player.addForce(right * -speed);
|
|
|
}
|
|
|
if(controller.right.isDown()) {
|
|
|
- player.acceleration += right * speed;
|
|
|
+ player.addForce(right * speed);
|
|
|
}
|
|
|
- if(controller.jump.isDown()) {
|
|
|
- player.acceleration += up * speed;
|
|
|
+ if(controller.jump.isDown() && player.isOnGround()) {
|
|
|
+ player.addForce(up * 0.5f);
|
|
|
}
|
|
|
if(controller.sneak.isDown()) {
|
|
|
- player.acceleration -= up * speed;
|
|
|
+ player.addForce(up * -speed);
|
|
|
}
|
|
|
|
|
|
- const float rotationSpeed = 5.0f;
|
|
|
+ constexpr float rotationSpeed = 4.0f;
|
|
|
if(controller.camLeft.isDown()) {
|
|
|
- player.lengthAngle -= rotationSpeed;
|
|
|
+ player.addLengthAngle(-rotationSpeed);
|
|
|
}
|
|
|
if(controller.camRight.isDown()) {
|
|
|
- player.lengthAngle += rotationSpeed;
|
|
|
+ player.addLengthAngle(rotationSpeed);
|
|
|
}
|
|
|
- if(controller.camUp.isDown() &&
|
|
|
- player.widthAngle - rotationSpeed > -90.0f) {
|
|
|
- player.widthAngle -= rotationSpeed;
|
|
|
+ if(controller.camUp.isDown()) {
|
|
|
+ player.addWidthAngle(-rotationSpeed * 0.5f);
|
|
|
}
|
|
|
- if(controller.camDown.isDown() &&
|
|
|
- player.widthAngle + rotationSpeed < 90.0f) {
|
|
|
- player.widthAngle += rotationSpeed;
|
|
|
+ if(controller.camDown.isDown()) {
|
|
|
+ player.addWidthAngle(rotationSpeed * 0.5f);
|
|
|
}
|
|
|
-
|
|
|
- world.tick();
|
|
|
}
|
|
|
|
|
|
void Game::renderWorld() {
|
|
|
- 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);
|
|
|
+ Engine::matrix.update(player.getRenderPosition(Engine::lag),
|
|
|
+ player.getRenderRotation(Engine::lag));
|
|
|
worldRenderer.render();
|
|
|
}
|
|
|
|