void GameController::LoadMap(const std::string &map) { //mLevel->Initialize(map); mCamera->MoveTo(mInstance->GetStartPosition()); mInstance->AddObject(mPlayer); mPlayer->MoveTo(mInstance->GetStartPosition()); auto physicsComponent = mPlayer->FindComponent<PhysicsComponent>(); physicsComponent->GetPhysicsObject()->SetPosition(mInstance->GetStartPosition()); }
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 RBTerrain::Load(const char *name) { RUDE_REPORT("Loading terrain %s\n", name); LoadMesh(name); LoadPhysicsMesh(0.0f); LoadMaterials(); RudePhysicsMesh *obj = (RudePhysicsMesh *) GetPhysicsObject(); btRigidBody *rb = obj->GetRigidBody(); rb->setFriction(50.0f); rb->setRestitution(0.99f); rb->setCollisionFlags(rb->getCollisionFlags() | btCollisionObject::CF_CUSTOM_MATERIAL_CALLBACK); rb->setCollisionFlags(rb->getCollisionFlags() | btCollisionObject::CF_STATIC_OBJECT); obj->SetNotifyOnContact(true); obj->SetContactCallback(RBTerrainContactCallback); LoadNodes(); m_holeTexture = RudeTextureManager::GetInstance()->LoadTextureFromPNGFile("hole"); RUDE_ASSERT(m_holeTexture, "Could not load hole texture"); btDiscreteDynamicsWorld *world = RudePhysics::GetInstance()->GetWorld(); btVector3 p0 = m_hole; p0.setY(m_hole.y() - 1000); btVector3 p1 = m_hole; p1.setY(m_hole.y() + 1000); btCollisionWorld::ClosestRayResultCallback cb(p0, p1); world->rayTest(p0, p1, cb); RUDE_ASSERT(cb.hasHit(), "Could not position hole.. is it over terrain? (%f %f %f)", m_hole.x(), m_hole.y(), m_hole.z()); RUDE_REPORT(" Hole %f %f %f -> %f %f %f\n", m_hole.x(), m_hole.y(), m_hole.z(), cb.m_hitPointWorld.x(), cb.m_hitPointWorld.y(), cb.m_hitPointWorld.z()); m_hole = cb.m_hitPointWorld; m_decorator.Load(name); }
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 ); } }
void FallingPlatformActor::Update(PBase::ResourceCore* core, float time, PWorld::RenderFrameInfo* world) { PlatformActor::Update(core, time, world); if (!dying_ && GetPhysicsObject()->Position.Y() > endPointY) { GetPhysicsObject()->Move(PGraphics::Vector3(0, -10.0f * time, 0)); } }