図1208a
ここから自動的にカメラが動き、右奥の赤いブロックを見せます。
図1208b
その後、カメラは中央を見るようになり、プレイヤーを動かせるようになります。
図1208c
プレイヤーを動かしていくと、プレイヤーの後ろの上方に、プレイヤーを追いかける白い球体があると思います。
図1208d
オブジェクトカメラの状態では、スティックは左スティックのみ有効です。
void GameStage::CreateViewLight() {
//OpeningCameraView用のビュー
m_OpeningCameraView = ObjectFactory::Create<SingleView>(GetThis<Stage>());
auto ptrOpeningCamera = ObjectFactory::Create<OpeningCamera>();
m_OpeningCameraView->SetCamera(ptrOpeningCamera);
//MyCamera用のビュー
m_MyCameraView = ObjectFactory::Create<SingleView>(GetThis<Stage>());
auto ptrMyCamera = ObjectFactory::Create<MyCamera>();
ptrMyCamera->SetEye(Vec3(0.0f, 5.0f, -5.0f));
ptrMyCamera->SetAt(Vec3(0.0f, 0.0f, 0.0f));
m_MyCameraView->SetCamera(ptrMyCamera);
//ObjCamera用のビュー
m_ObjCameraView = ObjectFactory::Create<SingleView>(GetThis<Stage>());
auto ptrObjCamera = ObjectFactory::Create<ObjCamera>();
m_ObjCameraView->SetCamera(ptrObjCamera);
//初期状態ではm_OpeningCameraViewを使う
SetView(m_OpeningCameraView);
m_CameraSelect = CameraSelect::openingCamera;
//マルチライトの作成
auto PtrMultiLight = CreateLight<MultiLight>();
//デフォルトのライティングを指定
PtrMultiLight->SetDefaultLighting();
}
void OpeningCameramanToGoalState::Enter(const shared_ptr<OpeningCameraman>& Obj) {
Obj->ToGoalEnterBehavior();
}
void OpeningCameraman::ToGoalEnterBehavior() { m_StartPos = Vec3(-20.0f, 10.0f, -20.0f); m_EndPos = Vec3(18.0f, 2.0f, 10.0f); m_AtStartPos = Vec3(-10.0f, 0.0f, 0.0f); m_AtEndPos = Vec3(18.0f, 0.0f, 18.0f); m_AtPos = m_AtStartPos; m_TotalTime = 0.0f; }
bool OpeningCameraman::ExcuteBehavior(float totaltime) { float ElapsedTime = App::GetApp()->GetElapsedTime(); m_TotalTime += ElapsedTime; if (m_TotalTime > totaltime) { return true; } Easing<Vec3> easing; auto TgtPos = easing.EaseInOut(EasingType::Cubic, m_StartPos, m_EndPos, m_TotalTime, totaltime); m_AtPos = easing.EaseInOut(EasingType::Cubic, m_AtStartPos, m_AtEndPos, m_TotalTime, totaltime); auto ptrTrans = GetComponent<Transform>(); ptrTrans->SetPosition(TgtPos); return false; }
void OpeningCameramanToGoalState::Execute(const shared_ptr<OpeningCameraman>& Obj) { if (Obj->ExcuteBehavior(5.0f)) { Obj->GetStateMachine()->ChangeState(OpeningCameramanToStartState::Instance()); } }
void OpeningCameramanEndState::Enter(const shared_ptr<OpeningCameraman>& Obj) { Obj->EndStateEnterBehavior(); }
void OpeningCameraman::EndStateEnterBehavior() { auto ptrGameGtage = GetTypeStage<GameStage>(); ptrGameGtage->ToMyCamera(); }
void GameStage::ToMyCamera() { auto ptrPlayer = GetSharedGameObject<Player>(L"Player"); //MyCameraに変更 auto ptrMyCamera = dynamic_pointer_cast<MyCamera>(m_MyCameraView->GetCamera()); if (ptrMyCamera) { ptrMyCamera->SetTargetObject(ptrPlayer); //m_MyCameraViewを使う SetView(m_MyCameraView); m_CameraSelect = CameraSelect::myCamera; } }
void Cameraman::OnUpdate() { auto ptrPlayer = GetStage()->GetSharedGameObject<Player>(L"Player"); auto playerPos = ptrPlayer->GetComponent<Transform>()->GetPosition(); auto ptrTrans = GetComponent<Transform>(); auto pos = ptrTrans->GetPosition(); Vec3 span = pos - playerPos; float nowLen = length(span); span.normalize(); span *= m_ToPlayerLen; Vec3 target = playerPos + span; target.y = playerPos.y + 1.0f; Easing<Vec3> easig; Vec3 v; if (nowLen < 1.5f) { v = easig.EaseIn(EasingType::Cubic, pos, target, 0.7, 1.0f); } else { v = easig.EaseIn(EasingType::Cubic, pos, target, 0.3f, 1.0f); } ptrTrans->SetPosition(v); }
void GameStage::OnPushB() { switch (m_CameraSelect) { case CameraSelect::myCamera: { ToObjCamera(); } break; case CameraSelect::objCamera: { ToMyCamera(); } break; } }
void GameStage::ToObjCamera() { auto ptrPlayer = GetSharedGameObject<Player>(L"Player"); //ObjCameraに変更 auto ptrCameraman = GetSharedGameObject<Cameraman>(L"Cameraman"); auto ptrObjCamera = dynamic_pointer_cast<ObjCamera>(m_ObjCameraView->GetCamera()); if (ptrObjCamera) { ptrObjCamera->SetCameraObject(ptrCameraman); ptrObjCamera->SetTargetObject(ptrPlayer); //m_ObjCameraViewを使う SetView(m_ObjCameraView); m_CameraSelect = CameraSelect::objCamera; } }
void Player::OnUpdate() {
auto ptrGameStage = dynamic_pointer_cast<GameStage>(GetStage());
if (ptrGameStage->GetCameraSelect() == CameraSelect::openingCamera) {
return;
}
//コントローラチェックして入力があればコマンド呼び出し
m_InputHandler.PushHandle(GetThis<Player>());
MovePlayer();
}