Added controller code

This commit is contained in:
2016-06-20 20:33:28 +02:00
parent da0b1f5588
commit 83557c7ba7
8 changed files with 172 additions and 4 deletions
+27
View File
@@ -40,6 +40,7 @@ void CrystalPoint::draw()
glLoadIdentity();
worldhandler->draw();
player->draw();
//cursor->draw();
@@ -79,6 +80,32 @@ void CrystalPoint::update()
if (keyboardState.keys['q']) player->setPosition(1, deltaTime*speed, true);
if (keyboardState.keys['e']) player->setPosition(-1, deltaTime*speed, true);
Controller *leftcontroller = controller.getLeftController();
if (leftcontroller != nullptr) {
Vec2f *leftControllerJoystick = &leftcontroller->joystick;
if (leftcontroller->joystickButton) {
controller.rumble(leftcontroller->controllerId, 100, 100);
}
if (leftControllerJoystick->y > 0.3) {
player->setPosition(270, leftControllerJoystick->y*deltaTime, false);
}
else if (leftControllerJoystick->y < -0.3) {
player->setPosition(90, leftControllerJoystick->y*-1 * deltaTime, false);
}
if (leftControllerJoystick->x > 0.3) {
player->setPosition(180, leftControllerJoystick->x*deltaTime, false);
}
else if (leftControllerJoystick->x < -0.3) {
player->setPosition(0, leftControllerJoystick->x*-1 * deltaTime, false);
}
player->leftWeapon->rotateWeapon(Vec3f(leftcontroller->ypr.y + 140, 0, -leftcontroller->ypr.z));
}
if (!worldhandler->isPlayerPositionValid())
player->position = oldPosition;