本文整理汇总了C++中TransformComponent::acceleration方法的典型用法代码示例。如果您正苦于以下问题:C++ TransformComponent::acceleration方法的具体用法?C++ TransformComponent::acceleration怎么用?C++ TransformComponent::acceleration使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TransformComponent
的用法示例。
在下文中一共展示了TransformComponent::acceleration方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: process
void PlayerControllerSubsystem::process(unsigned int dt)
{
ALLEGRO_EVENT ev;
while (events.get(&ev))
{
if (ev.type == ALLEGRO_EVENT_KEY_DOWN)
{
switch (ev.keyboard.keycode)
{
case ALLEGRO_KEY_W: button_states[MOVE_FORWARD] = true; break;
case ALLEGRO_KEY_A: button_states[ROTATE_LEFT] = true; break;
case ALLEGRO_KEY_S: button_states[MOVE_BACKWARD] = true; break;
case ALLEGRO_KEY_D: button_states[ROTATE_RIGHT] = true; break;
}
}
else if (ev.type == ALLEGRO_EVENT_KEY_UP)
{
switch (ev.keyboard.keycode)
{
case ALLEGRO_KEY_W: button_states[MOVE_FORWARD] = false; break;
case ALLEGRO_KEY_A: button_states[ROTATE_LEFT] = false; break;
case ALLEGRO_KEY_S: button_states[MOVE_BACKWARD] = false; break;
case ALLEGRO_KEY_D: button_states[ROTATE_RIGHT] = false; break;
}
}
}
for (std::set<Entity>::const_iterator iter = active.begin(); iter != active.end(); iter++)
{
TransformComponent *tc = world->get<TransformComponent>(*iter);
static const float max_speed = 0.3;
if (tc->velocity.squaredNorm() > max_speed * max_speed)
{
tc->velocity *= 1 / tc->velocity.norm() * max_speed;
}
if (button_states[MOVE_FORWARD])
{
tc->acceleration(0) += cos(tc->rotation) / 1000;
tc->acceleration(1) += sin(tc->rotation) / 1000;
}
if (button_states[MOVE_BACKWARD])
{
tc->acceleration(0) -= cos(tc->rotation) / 1000;
tc->acceleration(1) -= sin(tc->rotation) / 1000;
}
if (button_states[ROTATE_LEFT])
{
tc->rotation += 0.1;
}
if (button_states[ROTATE_RIGHT])
{
tc->rotation -= 0.1;
}
}
}