bool CEntityPhysics::BoundingCircleCollide(const CEntityPhysics& that, const CEntityTransform& thistransform, const CEntityTransform& thattransform) const { CVector3 thatPos = thattransform.GetPosition(); CVector3 thisPos = thistransform.GetPosition(); CVector3 centerToCenter = thatPos - thisPos; return centerToCenter.LengthSq() <= (this->GetBoundingCircleRadiusSq() + that.GetBoundingCircleRadiusSq()); }
void EnemyTest::Update() { CVector3 nextPosition = position; const float MOVE_SPEED = 5.0f; if (state == enStateRun || state == enStateStand) { if (Pad(0).IsTrigger(enButtonRB3)) { isPointLightOn = !isPointLightOn; } if (Pad(0).IsPress(enButtonA)) { //Aボタンが押された。 //車との距離を調べる。 CVector3 diff = g_car->GetPosition(); diff.Subtract(position); if (diff.Length() < 2.0f) { //車との距離が2m以内。 state = enState_RideOnCar; skinModel.SetShadowReceiverFlag(false); skinModel.SetShadowCasterFlag(false); g_car->SetRideOnFlag(true); g_camera->SetCar(g_car); return; } else if(!isJump){ //車との距離が離れていたらジャンプ。 moveSpeed.y = 8.0f; isJump = true; } } //走りか立ち状態の時。 CVector3 moveDirLocal; moveDirLocal.y = 0.0f; moveDirLocal.x = Pad(0).GetLStickXF(); moveDirLocal.z = Pad(0).GetLStickYF(); const CMatrix& mViewInv = g_camera->GetCamera().GetViewMatrixInv(); //カメラ空間から見た奥方向のベクトルを取得。 CVector3 cameraZ; cameraZ.x = mViewInv.m[2][0]; cameraZ.y = 0.0f; //Y軸いらない。 cameraZ.z = mViewInv.m[2][2]; cameraZ.Normalize(); //Y軸を打ち消しているので正規化する。 //カメラから見た横方向のベクトルを取得。 CVector3 cameraX; cameraX.x = mViewInv.m[0][0]; cameraX.y = 0.0f; //Y軸はいらない。 cameraX.z = mViewInv.m[0][2]; cameraX.Normalize(); //Y軸を打ち消しているので正規化する。 CVector3 moveDir; moveDir.x = cameraX.x * moveDirLocal.x + cameraZ.x * moveDirLocal.z; moveDir.y = 0.0f; //Y軸はいらない。 moveDir.z = cameraX.z * moveDirLocal.x + cameraZ.z * moveDirLocal.z; moveSpeed.x = moveDir.x * MOVE_SPEED; moveSpeed.z = moveDir.z * MOVE_SPEED; //Y方向には重力落下を加える。 const float GRAVITY = -18.8f; moveSpeed.y += GRAVITY * GameTime().GetFrameDeltaTime(); CVector3 addPos = moveSpeed; addPos.Scale(GameTime().GetFrameDeltaTime()); nextPosition.Add(addPos); if (moveDir.LengthSq() > 0.0001f) { rotation.SetRotation(CVector3::Up, atan2f(moveDir.x, moveDir.z)); //走り状態に遷移。 state = enStateRun; } else { //立ち状態。 state = enStateStand; } ShadowMap().SetLightTarget(position); CVector3 lightPos; lightPos.Add(position, toLightPos); ShadowMap().SetLightPosition(lightPos); //コリジョン検出と解決を行う。 CollisionDetectAndResolve(nextPosition); } else if (state == enState_RideOnCar) { ShadowMap().SetLightTarget(g_car->GetPosition()); CVector3 lightPos; lightPos.Add(g_car->GetPosition(), toLightPos); ShadowMap().SetLightPosition(lightPos); if (g_car->GetMoveSpeed().Length() < 0.1f) { //車が停止状態。 if (Pad(0).IsPress(enButtonB)) { //降車。 g_camera->SetCar(NULL); g_car->SetRideOnFlag(false); skinModel.SetShadowReceiverFlag(true); skinModel.SetShadowCasterFlag(true); position = g_car->GetPosition(); state = enStateStand; } } } skinModel.Update(position, rotation, CVector3::One); //ポイントライトの位置を更新。 UpdatePointLightPosition(); //アニメーションコントロール。 AnimationControl(); lastFrameState = state; }