void handleUpdate(UpdateEventDetails* const details, PhysicsBody* const CharacterPhysicsBody, PhysicsLMotorJoint* const CharacterMover) { ForceOnCharacter.setValues(0.0,0.0,0.0); Real32 PushForce(55000.0); Real32 Speed(10.0); if(_IsUpKeyDown) { ForceOnCharacter += Vec3f(0.0, PushForce, 0.0); } if(_IsDownKeyDown) { ForceOnCharacter += Vec3f(0.0, -PushForce, 0.0); } if(_IsLeftKeyDown) { ForceOnCharacter += Vec3f(-PushForce, 0.0, 0.0); } if(_IsRightKeyDown) { ForceOnCharacter += Vec3f(PushForce, 0.0, 0.0); } if(_ShouldJump) { ForceOnCharacter += Vec3f(0.0, 0.0, 50000.0); _ShouldJump = false; } if(ForceOnCharacter != Vec3f(0.0,0.0,0.0)) { CharacterPhysicsBody->setEnable(true); } if(ForceOnCharacter.x() !=0.0) { CharacterMover->setFMax(osgAbs(ForceOnCharacter.x())); CharacterMover->setVel(osgSgn(ForceOnCharacter.x())*Speed); } else { CharacterMover->setFMax(0.0); CharacterMover->setVel(0.0); } if(ForceOnCharacter.y() !=0.0) { CharacterMover->setFMax2(osgAbs(ForceOnCharacter.y())); CharacterMover->setVel2(osgSgn(ForceOnCharacter.y())*Speed); } else { CharacterMover->setFMax2(0.0); CharacterMover->setVel2(0.0); } if(ForceOnCharacter.z() !=0.0) { CharacterMover->setFMax3(osgAbs(ForceOnCharacter.z())); CharacterMover->setVel3(osgSgn(ForceOnCharacter.z())*Speed); } else { CharacterMover->setFMax3(0.0); CharacterMover->setVel3(0.0); } Real32 RotationRate(1.57); if(_IsAKeyDown) { Quaternion newRotation(CharacterPhysicsBody->getQuaternion()); newRotation.mult(Quaternion(Vec3f(0.0,0.0,1.0),RotationRate*details->getElapsedTime())); CharacterPhysicsBody->setQuaternion( newRotation ); } if(_IsDKeyDown) { Quaternion newRotation(CharacterPhysicsBody->getQuaternion()); newRotation.mult(Quaternion(Vec3f(0.0,0.0,1.0),-RotationRate*details->getElapsedTime())); CharacterPhysicsBody->setQuaternion( newRotation ); } }
void FWiimoteInputDevice::handle_event(struct wiimote_t* wm, int id) { UE_LOG(LogWiimote, Log, TEXT("\n\n--- EVENT [id %i] ---"), wm->unid); CurrentStates[0] = IS_PRESSED(wm, WIIMOTE_BUTTON_A) || IS_HELD(wm, WIIMOTE_BUTTON_A); CurrentStates[1] = IS_PRESSED(wm, WIIMOTE_BUTTON_B) || IS_HELD(wm, WIIMOTE_BUTTON_B); CurrentStates[2] = IS_PRESSED(wm, WIIMOTE_BUTTON_ONE) || IS_HELD(wm, WIIMOTE_BUTTON_ONE); CurrentStates[3] = IS_PRESSED(wm, WIIMOTE_BUTTON_TWO) || IS_HELD(wm, WIIMOTE_BUTTON_TWO); CurrentStates[4] = IS_PRESSED(wm, WIIMOTE_BUTTON_PLUS) || IS_HELD(wm, WIIMOTE_BUTTON_PLUS); CurrentStates[5] = IS_PRESSED(wm, WIIMOTE_BUTTON_MINUS) || IS_HELD(wm, WIIMOTE_BUTTON_MINUS); CurrentStates[6] = IS_PRESSED(wm, WIIMOTE_BUTTON_UP) || IS_HELD(wm, WIIMOTE_BUTTON_UP); CurrentStates[7] = IS_PRESSED(wm, WIIMOTE_BUTTON_DOWN) || IS_HELD(wm, WIIMOTE_BUTTON_DOWN); CurrentStates[8] = IS_PRESSED(wm, WIIMOTE_BUTTON_LEFT) || IS_HELD(wm, WIIMOTE_BUTTON_LEFT); CurrentStates[9] = IS_PRESSED(wm, WIIMOTE_BUTTON_RIGHT) || IS_HELD(wm, WIIMOTE_BUTTON_RIGHT); if (IS_PRESSED(wm, WIIMOTE_BUTTON_HOME)) { UE_LOG(LogWiimote, Log, TEXT("HOME pressed")); } /* show events specific to supported expansions */ if (wm->exp.type == EXP_NUNCHUK || wm->exp.type == EXP_MOTION_PLUS_NUNCHUK) { /* nunchuk */ struct nunchuk_t* nc = (nunchuk_t*)&wm->exp.nunchuk; const float DEADZONE = 0.6f; CurrentStates[10] = IS_PRESSED(nc, NUNCHUK_BUTTON_C) || IS_HELD(wm, NUNCHUK_BUTTON_C); CurrentStates[11] = IS_PRESSED(nc, NUNCHUK_BUTTON_Z) || IS_HELD(wm, NUNCHUK_BUTTON_Z); CurrentStates[12] = nc->js.y > DEADZONE; CurrentStates[13] = nc->js.y < -DEADZONE; CurrentStates[14] = nc->js.x < -DEADZONE; CurrentStates[15] = nc->js.x > DEADZONE; UE_LOG(LogWiimote, Log, TEXT("nunchuk roll = %f"), nc->orient.roll); UE_LOG(LogWiimote, Log, TEXT("nunchuk pitch = %f"), nc->orient.pitch); UE_LOG(LogWiimote, Log, TEXT("nunchuk yaw = %f"), nc->orient.yaw); UE_LOG(LogWiimote, Log, TEXT("nunchuk joystick angle: %f"), nc->js.ang); UE_LOG(LogWiimote, Log, TEXT("nunchuk joystick magnitude: %f"), nc->js.mag); UE_LOG(LogWiimote, Log, TEXT("nunchuk joystick vals: %f, %f"), nc->js.x, nc->js.y); UE_LOG(LogWiimote, Log, TEXT("nunchuk joystick calibration (min, center, max): x: %i, %i, %i y: %i, %i, %i"), nc->js.min.x, nc->js.center.x, nc->js.max.x, nc->js.min.y, nc->js.center.y, nc->js.max.y); } /* * If IR tracking is enabled then print the coordinates * on the virtual screen that the wiimote is pointing to. * * Also make sure that we see at least 1 dot. */ if (WIIUSE_USING_IR(wm)) { /* go through each of the 4 possible IR sources */ for (int i = 0; i < 4; ++i) { /* check if the source is visible */ if (wm->ir.dot[i].visible) { UE_LOG(LogWiimote, Log, TEXT("IR source %i: (%u, %u)"), i, wm->ir.dot[i].x, wm->ir.dot[i].y); } } UE_LOG(LogWiimote, Log, TEXT("IR cursor: (%u, %u)"), wm->ir.x, wm->ir.y); UE_LOG(LogWiimote, Log, TEXT("IR z distance: %f"), wm->ir.z); } // Update motion controls. FVector Tilt(0, 0, 0); FVector RotationRate(0, 0, 0); FVector Gravity(0, 0, 0); FVector Acceleration(0, 0, 0); /* if the accelerometer is turned on then print angles */ if (WIIUSE_USING_ACC(wm)) { Tilt.X = -wm->orient.pitch; Tilt.Y = wm->orient.yaw; Tilt.Z = wm->orient.roll; Acceleration.X = wm->accel.x; Acceleration.Y = wm->accel.y; Acceleration.Z = wm->accel.z; } if (wm->exp.type == EXP_MOTION_PLUS || wm->exp.type == EXP_MOTION_PLUS_NUNCHUK) { RotationRate.X = -wm->exp.mp.angle_rate_gyro.pitch; RotationRate.Y = wm->exp.mp.angle_rate_gyro.yaw; RotationRate.Z = wm->exp.mp.angle_rate_gyro.roll; } Gravity.X = wm->gforce.x; Gravity.Y = wm->gforce.y; Gravity.Z = wm->gforce.z; MessageHandler->OnMotionDetected(Tilt, RotationRate, Gravity, Acceleration, id); }