本文整理汇总了C++中util::toPixels方法的典型用法代码示例。如果您正苦于以下问题:C++ util::toPixels方法的具体用法?C++ util::toPixels怎么用?C++ util::toPixels使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类util
的用法示例。
在下文中一共展示了util::toPixels方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: render
void TopDownRaceState::render()
{
Display::getInstance().clear();
if(lockOn)
{
track_bg->drawRotated(camera.w/2, camera.h/2, -cameraAngle, camera.x, camera.y);
car_sprite->drawRotated(0.1*toPixels(player->m_body->GetPosition().x)-camera.x, 0.1*toPixels(player->m_body->GetPosition().y)-camera.y, M_PI - player->m_body->GetAngle()-cameraAngle, 23, 48);
}
else
{
track_bg->draw(-camera.x, -camera.y);
car_sprite->drawRotated(0.1*toPixels(player->m_body->GetPosition().x)-camera.x, 0.1*toPixels(player->m_body->GetPosition().y)-camera.y, M_PI - player->m_body->GetAngle(), 23, 48);
}
if(showDebug)
{
font->drawText(std::string("Using fgeal ")+fgeal::VERSION+" on "+fgeal::ADAPTED_LIBRARY_NAME+" "+fgeal::ADAPTED_LIBRARY_VERSION, 4, fgeal::Display::getInstance().getHeight() - font->getHeight(), fgeal::Color::CREAM);
font2->drawText("Linear velocity:", 25, 25, fgeal::Color::WHITE);
sprintf(buffer, "% 5.2f, % 5.2f, % 5.2f", player->m_body->GetLinearVelocity().x, player->m_body->GetLinearVelocity().y, player->m_body->GetLinearVelocity().Length());
font->drawText(std::string(buffer), 50, 50, fgeal::Color::WHITE);
font2->drawText("Scalar velocity:", 25, 75, fgeal::Color::WHITE);
sprintf(buffer, "% 5.2f", sqrt(pow(player->m_body->GetLinearVelocity().x, 2) + pow(player->m_body->GetLinearVelocity().y, 2)));
font->drawText(std::string(buffer), 150, 75, fgeal::Color::WHITE);
font2->drawText("Angle:", 25, 100, fgeal::Color::WHITE);
sprintf(buffer, "% 5.2f", player->m_body->GetAngle());
font->drawText(std::string(buffer), 65, 100, fgeal::Color::WHITE);
font2->drawText("FPS:", 25, 125, fgeal::Color::WHITE);
sprintf(buffer, "%d", game.getFpsCount());
font->drawText(std::string(buffer), 55, 125, fgeal::Color::WHITE);
}
fgeal::rest(0.01);
}
示例2: handlePhysics
void TopDownRaceState::handlePhysics(float delta)
{
const double forceFactorAbs = 50;
double forceFactor = 0;
if(Keyboard::isKeyPressed(Keyboard::KEY_ARROW_DOWN))
forceFactor = -forceFactorAbs/2;
else if(Keyboard::isKeyPressed(Keyboard::KEY_ARROW_UP))
{
forceFactor = forceFactorAbs;
int i;
for(i=0; i<player->m_body->GetLinearVelocity().Length() / 50;i++)
forceFactor *= 1.5;
}
float angle = 0;
if(Keyboard::isKeyPressed(Keyboard::KEY_ARROW_LEFT))
angle = -M_PI/4;
else if(Keyboard::isKeyPressed(Keyboard::KEY_ARROW_RIGHT))
angle = M_PI/4;
player->update(delta, forceFactor, angle);
//update world
world->Step(delta, 10, 10);
//update the camera
camera.x = 0.1*toPixels(player->m_body->GetPosition().x) - camera.w/2;
camera.y = 0.1*toPixels(player->m_body->GetPosition().y) - camera.h/2;
if(lockOn)
{
float angleDiff = cameraAngle - (M_PI - player->m_body->GetAngle());
cameraAngle -= angleDiff/10;
}
}