本文整理汇总了C++中PhysicsComponent::GetVelocity方法的典型用法代码示例。如果您正苦于以下问题:C++ PhysicsComponent::GetVelocity方法的具体用法?C++ PhysicsComponent::GetVelocity怎么用?C++ PhysicsComponent::GetVelocity使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PhysicsComponent
的用法示例。
在下文中一共展示了PhysicsComponent::GetVelocity方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: VUpdate
void RenderComponent::VUpdate()
{
/*
All of this code must go!!! This is shit! Rewrite animation system as a seperate component, starting with a virtual base
class (AnimationComponent) that can then fork off into a bunch of other more specific animation types (e.g. HumanoidAnimationComponent,
MachineAnimationComponent, ParticleAnimationComponent, etc.).
*/
if(_animated)
{
PhysicsComponent* physicsComponent = GetOwner()->GetComponent<PhysicsComponent>(COMPONENT_PHYSICS);
const uint UP = 1, DOWN = 0, RIGHT = 2, LEFT = 3;
int direction = -1;// By default, don't change
if(physicsComponent->GetVelocity().x > 0.5)
{
direction = RIGHT;
}
else if(physicsComponent->GetVelocity().x < -0.5)
{
direction = LEFT;
}
else if(physicsComponent->GetVelocity().y > 0.5)
{
direction = DOWN;
}
else if(physicsComponent->GetVelocity().y < -0.5)
{
direction = UP;
}
if(direction != -1)// If the texture should change...
{
_textureY = direction*(_textureHeight/4);
_textureX = _currentAnimationFrame*(_textureWidth/3);
if(SDL_GetTicks() - _lastAnimationChange >= (100))
{
_currentAnimationFrame++;
if(_currentAnimationFrame == 3)
_currentAnimationFrame = 0;
_lastAnimationChange = SDL_GetTicks();
}
}
else
{
_textureX = 0;
}
}
}
示例2: Update
void LocomotionSystem::Update( float i_dt )
{
for ( std::map<EntityHandle, Component*>::iterator it = m_components.begin(); it != m_components.end(); it++ )
{
LocomotionComponent* pComponent = (LocomotionComponent*) it->second;
if ( pComponent )
{
if ( pComponent->m_locomotionMode )
{
pComponent->m_locomotionMode->Update( i_dt );
}
PhysicsComponent* pPhysicsComponent = EntitySystem::GetInstance()->GetComponent<PhysicsComponent>( pComponent->m_entityHandle );
if ( pPhysicsComponent )
{
float yVel = pPhysicsComponent->GetVelocity().y;
JumpState pJumpState;
if ( yVel > 0.5f )
{
pJumpState = JumpState::JUMPING;
}
else if ( yVel < 0.5f )
{
pJumpState = JumpState::FALLING;
}
else if ( yVel == 0.0f )
{
pJumpState = JumpState::NOT_JUMPING;
}
if ( pJumpState == JumpState::FALLING && pComponent->m_jumpState == JumpState::JUMPING )
{
EventManager::GetInstance()->SendEvent( "VelocityApexReached", &pComponent->m_entityHandle );
}
pComponent->m_jumpState = pJumpState;
}
}
}
}