Real DynamicChain2D::GetKineticEnergy(int i) const { Vector2 comVel; Real comAngVel; GetWorldVelocity(links[i].com,i,dq,comVel); GetWorldAngularVelocity(i,dq,comAngVel); Real inertiaWorld; links[i].GetWorldInertia(inertiaWorld); return Half*(links[i].mass*comVel.normSquared() + inertiaWorld*comAngVel*comAngVel); }
void CMinotaur::Activate() { if (m_bIsActive == false) { SetPosition(m_tSpawnPosition); for (unsigned int i = 0; i < GetColliders().size(); i++) { if (GetColliders()[i]->GetBounds()->GetType() == Bounds::Capsule) { ((CCapsule*)GetColliders()[i]->GetBounds())->SetStart(XMFLOAT3(GetWorldMatrix()._41, GetWorldMatrix()._42 + 150.0f, GetWorldMatrix()._43)); ((CCapsule*)GetColliders()[i]->GetBounds())->SetEnd(XMFLOAT3(GetWorldMatrix()._41, GetWorldMatrix()._42 + 135.0f, GetWorldMatrix()._43)); ((CCapsule*)GetColliders()[i]->GetBounds())->SetRadius(150.0f); } else if (GetColliders()[i]->GetBounds()->GetType() == Bounds::AABB) { ((CAABB*)GetColliders()[i]->GetBounds())->SetCenter({ GetWorldMatrix()._41, GetWorldMatrix()._42 + 45, GetWorldMatrix()._43 }); } GetColliders()[i]->UpdatePosition(GetWorldVelocity()); } m_cpRenderMesh->GetRender() = true; m_cDropShadow->GetRender() = true; m_cpRenderMesh->SetTexture(L"../Game/Assets/Art/2D/Textures/Minotaur.dds"); IObject::UpdatePosition(); // Create a AddObj Message CAddObjectMessage* addObj = new CAddObjectMessage(this, CObjectManager::AI); CAddObjectMessage* addObj2 = new CAddObjectMessage(m_pMinotaurZone, CObjectManager::AI); //ChangeState(eIdleState); // Send the message ChangeState(ePatrolState); addObj->Send(); addObj2->Send(); m_fCurrentHealth = m_fMaxHealth; m_bInvincible = false; m_bIsActive = true; m_vDoors = m_cpObjectManager->FindObjectsWithTag("Door", CObjectManager::Static); m_pCamera = (CCamera*)m_cpObjectManager->GetCamera(); AudioSystemWwise::Get()->PostEvent(AK::EVENTS::MINOALERT, m_tSpawnPosition); } }
/***************************************************************** * UpdatePosition(): Updates position and colliders based on Velocity * * Ins: N/A * * Outs: N/A * * Returns: N/A * * Mod. Date: 8/20/2015 * Mod. Initials: MZ *****************************************************************/ void IObject::UpdatePosition() { XMFLOAT4X4 oldWorldMAtrix = m_mWorld; XMMATRIX d3dTranslateZ = XMMatrixTranslation(m_f3Velocity.x * DELTA_TIME(), m_f3Velocity.y * DELTA_TIME(), m_f3Velocity.z * DELTA_TIME()); XMStoreFloat4x4(&m_mWorld, XMMatrixMultiply(d3dTranslateZ, XMLoadFloat4x4(&m_mWorld))); if (m_cpRenderMesh != nullptr) { m_cpRenderMesh->GetPositionMatrix() = m_mWorld; } XMFLOAT3 f3VelocityUpdate = GetWorldVelocity(); f3VelocityUpdate.x *= DELTA_TIME(); f3VelocityUpdate.y *= DELTA_TIME(); f3VelocityUpdate.z *= DELTA_TIME(); //if (f3VelocityUpdate.y < -30.0f) //{ // f3VelocityUpdate.y = -30.0f; //} for (unsigned int collider = 0; collider < m_pvColliders.size(); collider++) { XMFLOAT3 fResetVel = m_pvColliders[collider]->GetResetVelocity(); fResetVel.x *= DELTA_TIME(); fResetVel.y *= DELTA_TIME(); fResetVel.z *= DELTA_TIME(); m_pvColliders[collider]->UpdatePosition(fResetVel); m_pvColliders[collider]->UpdatePosition(f3VelocityUpdate); } UpdateAttachments(); }
/***************************************************************** * Update() Updates the skeleton behaviour. * * Ins: None * * Outs: None * * Returns: void * * Mod. Date: 08/20/2015 * Mod. Initials: NS *****************************************************************/ void CSkeleton::Update() { if (m_bIsActive) { //CCapsule* tempCapsule = (CCapsule*)GetColliders()[1]->GetBounds(); //DEBUG_UTIL::DrawCapsuleCollider(tempCapsule->GetStart(), tempCapsule->GetEnd(), tempCapsule->GetRadius()); if (m_eCurrState != SPAWN) { float3 target = float3(0.0f, 0.0f, 0.0f); m_f3Velocity = float3(0.0f, m_f3Velocity.y, 0.0f); m_pParticleManager->Update(); if (m_bInvincible) { m_fInvincibilityTimer -= DELTA_TIME(); if (m_fInvincibilityTimer < 0.0f) { m_bInvincible = false; } } UpdateBlockSide(); UpdateDayStatus(); } if (m_bPoweringUp) { if (m_pDayNight->IsDay()) { m_fScale -= DELTA_TIME() * 0.5f; if (m_fScale < 1.0f) { m_fScale = 1.0f; m_bPoweringUp = false; } } else { m_fScale += DELTA_TIME() * 0.5f; if (m_fScale > 1.25f) { m_fScale = 1.25f; m_bPoweringUp = false; } } } if (GetPosition()->y < -900.0f) { m_bHit = true; m_fCurrentHealth = 0; m_bIsGrounded = true; } // Exeute the current action if (m_bIsGrounded) { //AdjustRotation(); CheckState(); switch (m_eCurrState) { case SPAWN: m_eNewState = Spawn(); break; case MANUVERING: m_eNewState = Manuver(); break; case MOVING_IN: m_eNewState = Move(true); break; case BACKING_OUT: m_eNewState = Move(false); break; case SWINGING: m_eNewState = Swinging(); break; /*case BLOCKING: m_eNewState = Blocking(); break;*/ case RETREAT: m_eNewState = Retreating(); break; case DEATH: m_eNewState = Die(); break; case HURT: m_eNewState = Hurt(); break; case FOLLOW: m_eNewState = Follow(); break; default: break; } m_vtPointLights[0].m_fPosition[0] = GetPosition()->x; m_vtPointLights[0].m_fPosition[1] = 150.0f; m_vtPointLights[0].m_fPosition[2] = GetPosition()->z; } else { SetWorldVelocity({ knockBackVelocity.x, m_f3Velocity.y, knockBackVelocity.z }); m_vtPointLights[0].m_fPosition[0] += GetWorldVelocity().x * DELTA_TIME(); m_vtPointLights[0].m_fPosition[1] += GetWorldVelocity().y * DELTA_TIME(); m_vtPointLights[0].m_fPosition[2] += GetWorldVelocity().z * DELTA_TIME(); } if (m_eCurrState != SPAWN) { //m_bIsGrounded = false; // Update the rotation // velocity.x *= DELTA_TIME(); // velocity.y *= DELTA_TIME(); // velocity.z *= DELTA_TIME(); XMFLOAT3 start = ((CCapsule*)m_pvColliders[1]->GetBounds())->GetStart(); XMFLOAT3 end = ((CCapsule*)m_pvColliders[1]->GetBounds())->GetEnd(); m_f3Velocity.y += GRAVITY * DELTA_TIME(); if (m_mWorld.m[3][1] < 0.0f) { m_bIsGrounded = false; } CCapsule* pCapsule = (CCapsule*)m_pvColliders[1]->GetBounds(); XMFLOAT3 f3NewStart = pCapsule->GetStart(); XMFLOAT3 f3NewEnd = pCapsule->GetEnd(); f3NewStart.x = f3NewEnd.x = m_mWorld._41; f3NewStart.z = f3NewEnd.z = m_mWorld._43; pCapsule->SetStart(f3NewStart); pCapsule->SetEnd(f3NewEnd); for (unsigned int collider = 0; collider < m_pvColliders.size(); collider++) { m_pvColliders[collider]->UpdatePosition({ GetWorldVelocity().x * DELTA_TIME(), GetWorldVelocity().y * DELTA_TIME(), GetWorldVelocity().z * DELTA_TIME() }); } #pragma region DebugStuff /*if (m_vPath.size()) { for (size_t i = 0; i < m_vPath.size() - 1; i++) { XMFLOAT3 thisPos = m_vPath[i]; XMFLOAT3 nextPos = m_vPath[i + 1]; GRAPHICS->DrawLine(thisPos, nextPos, { 100, 100, 0 }); } } */ //for (size_t i = 0; i < m_pPathPlanner->GetGraph()->GetNodes().size(); i++) //{ // // XMFLOAT3 start = m_vPath[i]->GetPosition(); // // XMFLOAT3 end = m_vPath[i + 1]->GetPosition(); // // // // GRAPHICS->DrawLine(start, end, XMFLOAT3(100, 100, 0)); // // for (size_t k = 0; k < m_pPathPlanner->GetGraph()->GetNodeAtIndex(i)->GetEdges().size(); k++) // { // CEdge* edge = m_pPathPlanner->GetGraph()->GetNodeAtIndex(i)->GetEdges()[k]; // XMFLOAT3 edgeEnd = m_pPathPlanner->GetGraph()->GetNodeAtIndex(edge->GetAdjNode())->GetPosition(); // // GRAPHICS->DrawLine(m_pPathPlanner->GetGraph()->GetNodeAtIndex(i)->GetPosition(), edgeEnd, XMFLOAT3(0, 200, 0)); // // } //} #pragma endregion } } SnapPosition(m_cDropShadow->GetTransformMatrix(), m_mWorld); m_cDropShadow->GetTransformMatrix().m[3][1] += 10.0f; if (m_mWorld.m[3][1] < -10.0f || !m_bIsActive) m_cDropShadow->GetTransformMatrix().m[3][1] = -20000.0f; }
void CMinotaur::Update() { if (m_bChargeParticlePlaying) { m_pParticleManager->GetEmitter(m_unParticleEmitters[eChargeParticle])->GetPosition(0) = GetPosition()->x; m_pParticleManager->GetEmitter(m_unParticleEmitters[eChargeParticle])->GetPosition(2) = GetPosition()->z; } m_pParticleManager->Update(); int nNewState = 0; if (m_bIsGrounded) { if (m_fStompTimer > 0.0f) { m_fStompTimer -= DELTA_TIME(); if (m_fStompTimer < 0.0f) m_fStompTimer = 0.0f; } if (m_fSlowTimer > 0.0f) { m_fSlowTimer -= DELTA_TIME(); if (m_fSlowTimer < 0.0f) m_fSlowTimer = 0.0f; } if (m_nCurrState != eDeadState) { AdjustRotation(); } //Run the current State m_pStates[m_nCurrState]->Execute(this); } m_f3Velocity.y += GRAVITY * DELTA_TIME(); if (GetPosition()->y < -900.0f) DeActivate(); if (m_mWorld.m[3][1] < 0.0f) { m_bIsGrounded = false; } // Update the rotation CCapsule* pCapsule = (CCapsule*)m_pvColliders[1]->GetBounds(); XMFLOAT3 f3NewStart = pCapsule->GetStart(); XMFLOAT3 f3NewEnd = pCapsule->GetEnd(); f3NewStart.x = f3NewEnd.x = m_mWorld._41; f3NewStart.z = f3NewEnd.z = m_mWorld._43; pCapsule->SetStart(f3NewStart); pCapsule->SetEnd(f3NewEnd); m_pMinotaurZone->UpdateColliders(GetWorldVelocity()); UpdateColliders(GetWorldVelocity()); // Update states if (m_bIsGrounded) { nNewState = m_pStates[m_nCurrState]->UpdateState(this); } if (nNewState == -1) { DeActivate(); return; } if (nNewState != m_nCurrState) ChangeState(nNewState); #if _DEBUG /*if (m_vPath.size()) { for (size_t i = 0; i < m_vPath.size() - 1; i { XMFLOAT3 thisPos = m_vPath[i]; XMFLOAT3 nextPos = m_vPath[i + 1]; GRAPHICS->DrawLine(thisPos, nextPos, { 100, 100, 0 }); } }*/ XMFLOAT3 start = ((CCapsule*)m_pvColliders[1]->GetBounds())->GetStart(); XMFLOAT3 end = ((CCapsule*)m_pvColliders[1]->GetBounds())->GetEnd(); //GRAPHICS->DrawLine(start, end, { 1, 0, 1 }); DEBUG_UTIL::DrawCapsuleCollider(start, end, 150.0f); #endif SnapPosition(m_cDropShadow->GetTransformMatrix(), m_mWorld); m_cDropShadow->GetTransformMatrix().m[3][1] += 10.0f; if (m_bIsActive == false) m_cDropShadow->GetTransformMatrix().m[3][1] = -20000.0f; }