本文整理汇总了C++中Point2f::Length方法的典型用法代码示例。如果您正苦于以下问题:C++ Point2f::Length方法的具体用法?C++ Point2f::Length怎么用?C++ Point2f::Length使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Point2f
的用法示例。
在下文中一共展示了Point2f::Length方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Update
void Body::Update(float dt)
{
//-------------------------------------------------------
// Integrate position (verlet integration)
//-------------------------------------------------------
Point2f xAccel = netForce * invMass;
pos += velocity * dt;// + 0.5f * xAccel * dt*dt;
orientation += angVelocity * dt;
assert(xAccel.Length() < 1e3);
//-------------------------------------------------------
// Integrate velocity (implicit linear velocity)
//-------------------------------------------------------
velocity += xAccel * dt;
angVelocity += netTorque * (invInertia * dt);
//-------------------------------------------------------
// clear forces
//-------------------------------------------------------
netForce = Point2f(0.0f, 0.0f);
netTorque = 0.0f;
if (shape)
shape->update();
}
示例2: viewerRange
void TargetIndicator::GraphicEntity::render(float gameTime, float deltaTime)
{
int frameTime = int(gameTime * 60);
const Rectf viewerRange(-379, 379, -279, 279); // slightly smaller than windowViewRange
const Point2f &windowSize = iRenderQueue::getSingleton().getWindowSize();
const Rectf windowRange(0, windowSize.x, 0, windowSize.y);
const Rectf windowViewRange(windowRange.leftTop.x + 20, windowRange.rightBottom.x - 20, windowRange.leftTop.y + 20, windowRange.rightBottom.y - 20);
const Point2f posOffset(windowRange.rightBottom / 2);
const Point2f viewerPos = iRenderQueue::getSingleton().getViewerPos() + posOffset;
Point2f pos;
deltaTime;
for (vector<iAttacheeEntity*>::const_iterator ie = getEntity().entities.begin(); ie != getEntity().entities.end(); ++ie)
{
if (((iTargetEntity*)*ie)->getEntity().getStatus(ESI_Position, &pos))
{
Point2f dir = pos - viewerPos;
if (viewerRange & dir)
continue;
if (dir.Length() > 500)
continue;
float direction = -atan2(dir.y, dir.x);
if (fabs(dir.x) > 1e-5)
{
Point2f pos = dir * (viewerRange.rightBottom.x / fabs(dir.x)) + posOffset;
if (windowViewRange & pos)
iRenderQueue::getSingleton().render(pos, direction, frameTime, anim, GLI_UI, true);
else
{
pos = dir * (viewerRange.rightBottom.y / fabs(dir.y)) + posOffset;
//if (windowViewRange & pos)
iRenderQueue::getSingleton().render(pos, direction, frameTime, anim, GLI_UI, true);
}
}
else
{
assert(fabs(dir.y) > 1e-5);
Point2f pos = dir * (viewerRange.rightBottom.y / fabs(dir.y)) + posOffset;
if (windowViewRange & pos)
iRenderQueue::getSingleton().render(pos, direction, frameTime, anim, GLI_UI, true);
else
{
pos = dir * (viewerRange.rightBottom.x / fabs(dir.x)) + posOffset;
//if (windowViewRange & pos)
iRenderQueue::getSingleton().render(pos, direction, frameTime, anim, GLI_UI, true);
}
}
}
}
}
示例3: stepMoveTo
void AiTankController::stepMoveTo()
{
if (!isAttached())
{
bCheckMoveTo = false;
return;
}
Point2f posTank;
float orientionTank;
Entity &e = entity->getEntity();
if (e.getStatus(Entity::ESI_Position, &posTank) &&
e.getStatus(Entity::ESI_Orientation, &orientionTank))
{
//#ifndef NDEBUG
iRenderQueue::getSingleton().render(moveToPos, posTank, ARGB(255, 0, 0, 0));
//#endif
Point2f dir = moveToPos - posTank;
float len = dir.Length();
float len2 = (nextMoveToPos - posTank).Length();
if (len < 10 || len > len2)
{
bCheckMoveTo = false;
bForward = false;
sendCommand(Tank::TCI_Forward, (void *)bForward);
return;
}
dir.Normalize();
if (fabs(dir ^ Point2f(cos(orientionTank), sin(orientionTank))) < 0.3f)
{
if (!bForward)
{
bForward = true;
sendCommand(Tank::TCI_Forward, (void *)bForward);
}
}
else
{
float lerpValue = (float)rand() / RAND_MAX;
lerpValue *= lerpValue;
turnTo(moveToPos);//lerp(moveToPos, nextMoveToPos, lerpValue));
if (bForward)
{
bForward = false;
sendCommand(Tank::TCI_Forward, (void *)bForward);
}
}
}
else
{
bCheckMoveTo = false;
}
}
示例4: collide
size_t collide(CircleShape &circle1, CircleShape &circle2, float dt, Contact *pxContacts, size_t numMaxContacts)
{
dt, numMaxContacts;
float rR = circle1.GetRadius() + circle2.GetRadius();
const Point2f &p1 = circle1.body.getPosition();
const Point2f &p2 = circle2.body.getPosition();
Point2f d = p2 - p1;
float len = d.Length();
if (len > rR)
{
return 0;
}
d.Normalize();
pxContacts[0] = Contact(p1 + d * circle1.GetRadius(), p1 + d * (len - circle1.GetRadius()), &circle1.body, &circle2.body);
return 1;
}
示例5: Attack
void Player::Attack()
{
Enemy *pEnemy = MainGameState::getSingleton().getNearestEnemy(pos);
if (!pEnemy)
return;
Point2f dir = pEnemy->pos - pos;
float len = dir.Length();
if (len > attackRange)
{
MainGameState::getSingleton().pauseGame(0.5f, 2.0f);
return;
}
//bAttack = true;
dir.Normalize();
pos = pEnemy->pos - dir * 20 * MainGameState::getSingleton().getTimeScale();
pEnemy->hit(pos);
MainGameState::getSingleton().pauseGame(0.5f, 0.1f);
}