void RPG_Pickup::ThinkFunction() { const float deltaTime = Vision::GetTimer()->GetTimeDifference(); if(m_elapsedTime < m_spawnIdleTime) { // don't do anything if we haven't been idle long enough m_elapsedTime += deltaTime; return; } if(m_rigidBodyComponent) { RemoveComponent(m_rigidBodyComponent); m_rigidBodyComponent = NULL; m_currentMagnetSpeed = 0.0f; m_currentMagnetVelocity.setZero(); } UpdateRotation(deltaTime); UpdateMagnetForces(deltaTime); IncPosition(deltaTime * m_currentMagnetVelocity); CheckCharacterContact(); }
void VFreeCamera::ProcessInput(float fTimeDiff) { hkvVec3 vMoveDelta = hkvVec3::ZeroVector(); // Handle movement. hkvVec3 vForward(hkvNoInitialization), vRight(hkvNoInitialization), vUp(hkvNoInitialization); GetCurrentMoveAxes(vForward, vRight, vUp); float fMaxSpeed = m_fMoveSpeed; if (m_pInputMap->GetTrigger(CONTROL_SPEED_FAST)) fMaxSpeed *= 3.0f; else if (m_pInputMap->GetTrigger(CONTROL_SPEED_FASTER)) fMaxSpeed *= 9.0f; // Accumulate move directions (multiply in order to take analog input into account). vMoveDelta += vForward * m_pInputMap->GetTrigger(CONTROL_MOVE_FORWARD); vMoveDelta -= vForward * m_pInputMap->GetTrigger(CONTROL_MOVE_BACKWARD); vMoveDelta -= vRight * m_pInputMap->GetTrigger(CONTROL_MOVE_RIGHT); vMoveDelta += vRight * m_pInputMap->GetTrigger(CONTROL_MOVE_LEFT); vMoveDelta += vUp * m_pInputMap->GetTrigger(CONTROL_MOVE_UP); vMoveDelta -= vUp * m_pInputMap->GetTrigger(CONTROL_MOVE_DOWN); vMoveDelta *= fMaxSpeed; // Clamp movement, so that moving diagonally is not faster than moving straight when using digital input. const float fSpeed = vMoveDelta.getLength(); if (fSpeed > fMaxSpeed) vMoveDelta.setLength(fMaxSpeed); vMoveDelta *= fTimeDiff; // Look around. const float dx = m_pInputMap->GetTrigger(CONTROL_HORIZONTAL_LOOK); const float dy = m_pInputMap->GetTrigger(CONTROL_VERTICAL_LOOK); hkvVec3 vOrientation = GetOrientation(); vOrientation.x += -dx * m_fSensitivity; vOrientation.y = hkvMath::clamp(vOrientation.y + dy * m_fSensitivity, -89.5f, 89.5f); SetOrientation(vOrientation); // Apply delta. if (GetPhysicsObject() != NULL) { IncMotionDeltaWorldSpace(vMoveDelta); } else { IncPosition(vMoveDelta); } }
void VisMouseCamera_cl::TickFunction(float fTimeDiff) { hkvVec3 vMove = hkvVec3::ZeroVector(); BOOL bUpDownMode = FALSE; float dx = m_pInputMap->GetTrigger(API_CAMERA_HORIZONTAL_LOOK); float dy = m_pInputMap->GetTrigger(API_CAMERA_VERTICAL_LOOK); if (m_pInputMap->GetTrigger(API_CAMERA_ACTION_1) && m_pInputMap->GetTrigger(API_CAMERA_ACTION_2)) bUpDownMode = TRUE; else if (m_pInputMap->GetTrigger(API_CAMERA_ACTION_2)) m_SpeedMode = 1; else if (m_pInputMap->GetTrigger(API_CAMERA_ACTION_3)) m_SpeedMode = 2; else m_SpeedMode = 0; // handle keyboard status #if !defined(_VISION_MOBILE) && !defined(_VISION_WINRT) if (m_pInputMap->GetTrigger(API_CAMERA_ANY_ACTION)) #endif { hkvVec3 vDir(hkvNoInitialization), vRight(hkvNoInitialization), vUp(hkvNoInitialization); vUp.set(0.f,0.f,1.f); if (GetPhysicsObject()) { // local space vDir.set(1.f,0.f,0.f); vRight.set(0.f,1.f,0.f); } else { hkvMat3 mat(hkvNoInitialization); GetRotationMatrix(mat); vDir = mat.getAxis(0); vRight = mat.getAxis(1); } float fMaxSpeed = m_fMoveSpeed; if (m_SpeedMode == 1) fMaxSpeed *= 3.0f; else if (m_SpeedMode == 2) fMaxSpeed *= 9.0f; // Accumulate move directions (multiply in order to take analog input into account). vMove += vDir * m_pInputMap->GetTrigger(API_CAMERA_MOVE_FORWARD); vMove -= vDir * m_pInputMap->GetTrigger(API_CAMERA_MOVE_BACKWARD); vMove -= vRight * m_pInputMap->GetTrigger(API_CAMERA_MOVE_RIGHT); vMove += vRight * m_pInputMap->GetTrigger(API_CAMERA_MOVE_LEFT); vMove += vUp * m_pInputMap->GetTrigger(API_CAMERA_MOVE_UP); vMove -= vUp * m_pInputMap->GetTrigger(API_CAMERA_MOVE_DOWN); vMove *= fMaxSpeed; // Clamp movement, so that moving diagonally is not faster than moving straight // when using digital input. const float fSpeed = vMove.getLength(); if (fSpeed > fMaxSpeed) vMove.setLength(fMaxSpeed); vMove *= fTimeDiff; } if (m_pInputMap->GetTrigger(API_CAMERA_LOOK_CHANGED)) { if (bUpDownMode) { IncOrientation(-dx * m_fSensitivity, 0, 0); vMove.z -= dy * m_fUpDownSpeed; } else { IncOrientation(-dx * m_fSensitivity, dy * m_fSensitivity, 0); } } switch(m_walkMode) { case WALK: // constrain vMove to the ground float len = vMove.getLength(); vMove.z = 0.f; vMove.setLength(len); break; } if (GetPhysicsObject()) { IncMotionDeltaLocalSpace(vMove); } else { IncPosition( vMove ); } }