Added controller cursor in menu
This commit is contained in:
+38
-23
@@ -65,7 +65,10 @@ void CrystalPoint::update()
|
||||
|
||||
if (keyboardState.keys[27] && !prevKeyboardState.keys[27])
|
||||
state = !state;
|
||||
|
||||
|
||||
Controller *rightcontroller = controller.getRightController();
|
||||
Controller *leftcontroller = controller.getLeftController();
|
||||
|
||||
if (state)
|
||||
{
|
||||
if (keyboardState.special[GLUT_KEY_LEFT] && !prevKeyboardState.special[GLUT_KEY_LEFT])
|
||||
@@ -100,42 +103,43 @@ 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 || leftControllerJoystick->y < -0.3) {
|
||||
player->rotation.x += leftControllerJoystick->y/4;
|
||||
}
|
||||
|
||||
if (leftControllerJoystick->y > 0.3) {
|
||||
player->setPosition(270, leftControllerJoystick->y * deltaTime * 2.0f, false);
|
||||
}
|
||||
else if (leftControllerJoystick->y < -0.3) {
|
||||
player->setPosition(90, leftControllerJoystick->y * -1 * deltaTime * 2.0f, false);
|
||||
}
|
||||
if (leftControllerJoystick->x > 0.3) {
|
||||
player->setPosition(180, leftControllerJoystick->x * deltaTime * 2.0f, false);
|
||||
}
|
||||
else if (leftControllerJoystick->x < -0.3) {
|
||||
player->setPosition(0, leftControllerJoystick->x * -1 * deltaTime * 2.0f, false);
|
||||
if (leftControllerJoystick->x > 0.3 || leftControllerJoystick->x < -0.3) {
|
||||
player->rotation.y += leftControllerJoystick->x/4;
|
||||
}
|
||||
|
||||
player->leftWeapon->rotateWeapon(Vec3f(leftcontroller->ypr.y + 140, 0, -leftcontroller->ypr.z));
|
||||
|
||||
if(leftcontroller->button && leftcontroller->joystickButton){
|
||||
state = !state;
|
||||
}
|
||||
}
|
||||
Controller *rightcontroller = controller.getRightController();
|
||||
if(rightcontroller != nullptr){
|
||||
Vec2f *rightControllerJoystick = &rightcontroller->joystick;
|
||||
if (rightControllerJoystick->y > 0.3 || rightControllerJoystick->y < -0.3) {
|
||||
player->rotation.x += rightcontroller->joystick.y/4;
|
||||
|
||||
if (rightControllerJoystick->y > 0.3) {
|
||||
player->setPosition(270, rightControllerJoystick->y * deltaTime * 2.0f, false);
|
||||
}
|
||||
else if (rightControllerJoystick->y < -0.3) {
|
||||
player->setPosition(90, rightControllerJoystick->y * -1 * deltaTime * 2.0f, false);
|
||||
}
|
||||
if (rightControllerJoystick->x > 0.3) {
|
||||
player->setPosition(180, rightControllerJoystick->x * deltaTime * 2.0f, false);
|
||||
}
|
||||
else if (rightControllerJoystick->x < -0.3) {
|
||||
player->setPosition(0, rightControllerJoystick->x * -1 * deltaTime * 2.0f, false);
|
||||
}
|
||||
|
||||
if (rightControllerJoystick->x > 0.3 || rightControllerJoystick->x < -0.3) {
|
||||
player->rotation.y += rightcontroller->joystick.x/4;
|
||||
}
|
||||
player->rightWeapon->rotateWeapon(Vec3f(rightcontroller->ypr.y + 140, 0, -rightcontroller->ypr.z));
|
||||
}
|
||||
|
||||
@@ -151,10 +155,21 @@ void CrystalPoint::update()
|
||||
}
|
||||
else
|
||||
{
|
||||
if (keyboardState.keys[27]){
|
||||
glutExit();
|
||||
}
|
||||
menu->update();
|
||||
if (leftcontroller != nullptr) {
|
||||
Vec2f *leftControllerJoystick = &leftcontroller->joystick;
|
||||
if (leftControllerJoystick->y > 0.3 || leftControllerJoystick->y < -0.3) {
|
||||
cursor->update(Vec2f(cursor->mousePosition.x,cursor->mousePosition.y+leftControllerJoystick->y ));
|
||||
}
|
||||
if (leftControllerJoystick->x > 0.3 || leftControllerJoystick->x < -0.3) {
|
||||
cursor->update(Vec2f(cursor->mousePosition.x+leftControllerJoystick->x ,cursor->mousePosition.y));
|
||||
}
|
||||
if(leftcontroller->button){
|
||||
cursor->state = 137;
|
||||
}else if(cursor->state == 137){
|
||||
cursor->state = GLUT_UP;
|
||||
}
|
||||
}
|
||||
cursor->update(cursor->mousePosition + mouseOffset);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user