From 36dc74a39eb142b0467db4cce7470b1c273dec91 Mon Sep 17 00:00:00 2001 From: jancoow Date: Tue, 21 Jun 2016 14:00:04 +0200 Subject: [PATCH] Fixed crash at startup, improved walking speed --- ControllerHandler.cpp | 17 +++++++++-------- CrystalPoint.cpp | 12 ++++++------ 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/ControllerHandler.cpp b/ControllerHandler.cpp index 03aaf2f..5e12a15 100644 --- a/ControllerHandler.cpp +++ b/ControllerHandler.cpp @@ -113,16 +113,17 @@ void ControllerHandler::commandDebug(std::vector data) { void ControllerHandler::commandControllerData(std::vector data) { if(data.size() == 10){ Controller* c = controllers[std::stoi(data[1])]; + if(c != nullptr && c->isConnected()){ + c->ypr.x = std::stoi(data[5])/100.0f; + c->ypr.y = std::stoi(data[6])/100.0f; + c->ypr.z = std::stoi(data[7])/100.0f; - c->ypr.x = std::stoi(data[5])/100.0f; - c->ypr.y = std::stoi(data[6])/100.0f; - c->ypr.z = std::stoi(data[7])/100.0f; + c->joystick.x = std::stoi(data[2])/2000.0f; + c->joystick.y = std::stoi(data[3])/2000.0f; + c->joystickButton = !(data[4] == "0"); - c->joystick.x = std::stoi(data[2])/2000.0f; - c->joystick.y = std::stoi(data[3])/2000.0f; - c->joystickButton = !(data[4] == "0"); - - c->magnetSwitch = !(data[9] == "0"); + c->magnetSwitch = !(data[9] == "0"); + } } } diff --git a/CrystalPoint.cpp b/CrystalPoint.cpp index 30e550b..a22821e 100644 --- a/CrystalPoint.cpp +++ b/CrystalPoint.cpp @@ -101,16 +101,16 @@ void CrystalPoint::update() if (leftControllerJoystick->y > 0.3) { - player->setPosition(270, leftControllerJoystick->y * deltaTime, false); + player->setPosition(270, leftControllerJoystick->y * deltaTime * 2.0f, false); } else if (leftControllerJoystick->y < -0.3) { - player->setPosition(90, leftControllerJoystick->y * -1 * deltaTime, false); + player->setPosition(90, leftControllerJoystick->y * -1 * deltaTime * 2.0f, false); } if (leftControllerJoystick->x > 0.3) { - player->setPosition(180, leftControllerJoystick->x * deltaTime, false); + player->setPosition(180, leftControllerJoystick->x * deltaTime * 2.0f, false); } else if (leftControllerJoystick->x < -0.3) { - player->setPosition(0, leftControllerJoystick->x * -1 * deltaTime, false); + player->setPosition(0, leftControllerJoystick->x * -1 * deltaTime * 2.0f, false); } player->leftWeapon->rotateWeapon(Vec3f(leftcontroller->ypr.y + 140, 0, -leftcontroller->ypr.z)); @@ -120,11 +120,11 @@ void CrystalPoint::update() if(rightcontroller != nullptr){ Vec2f *rightControllerJoystick = &rightcontroller->joystick; if (rightControllerJoystick->y > 0.3 || rightControllerJoystick->y < -0.3) { - player->rotation.x += rightcontroller->joystick.y/2; + player->rotation.x += rightcontroller->joystick.y/4; } if (rightControllerJoystick->x > 0.3 || rightControllerJoystick->x < -0.3) { - player->rotation.y += rightcontroller->joystick.x/2; + player->rotation.y += rightcontroller->joystick.x/4; } player->rightWeapon->rotateWeapon(Vec3f(rightcontroller->ypr.y + 140, 0, -rightcontroller->ypr.z)); }