本文整理汇总了C++中Point2f::Normalize方法的典型用法代码示例。如果您正苦于以下问题:C++ Point2f::Normalize方法的具体用法?C++ Point2f::Normalize怎么用?C++ Point2f::Normalize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Point2f
的用法示例。
在下文中一共展示了Point2f::Normalize方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: step
void Bullet::step(float gameTime, float deltaTime)
{
Point2f delta = dest_pos - pos;
float len;
if (!bExplode)
{
len = delta.DotProduct();
if (len < 1)
{
bExplode = false;
explodePos = pos;
Explode(gameTime);
return;
}
}
else
{
bExplode = false;
Explode(gameTime);
return;
}
Point2f vel = delta.Normalize(min(sqrtf(len) / deltaTime, speed));// 可能引发爆发事件
collisionEntity.getBody().setVelocity(vel);
collisionEntity.getBody().Update(deltaTime);
}
示例2: step
void Player::step(float gameTime, float deltaTime)
{
gameTime, deltaTime;
Point2f dir = Point2f(400, 300) - pos;
float speed = 1 * MainGameState::getSingleton().getTimeScale();
dir.Normalize(speed);
pos += dir;
}
示例3:
std::vector<int> ptsubsetBetween2Line( std::vector<Point2f> points2d, Point2f p0, Point2f p1, Point2f t0){
t0.Normalize() ;
std::vector<int> res ;
for( int i=0; i<points2d.size(); ++i ){
Point2f p0p1 = p1-p0 ;
if( p0p1 * (points2d[i]-p1) <= 0 && !ReconstructorUtility::vectorIntersect(p0-t0*100, p0+t0*100, points2d[i], p1 ) )
res.push_back( i ) ;
}
return res ;
}
示例4: 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;
}
}
示例5: collide
size_t collide(CircleShape &circle, BoxShape &box, float dt, Contact *pxContacts, size_t numMaxContacts)
{
dt, pxContacts, numMaxContacts;
const Point2f &p1 = circle.body.getPosition();
const Point2f &p2 = box.body.getPosition();
// work in the box's coordinate system
const Point2f kDiff = p1 - p2;
// compute squared distance and closest point on box
float fSqrDistance = 0.0f, fDelta;
Point2f kClosest(kDiff * box.GetDir(0), kDiff * box.GetDir(1));
const Point2f &extents = box.GetExtents();
if (kClosest.x < -extents.x)
{
fDelta = kClosest.x + extents.x;
fSqrDistance += fDelta*fDelta;
kClosest.x = -extents.x;
}
else if (kClosest.x > extents.x)
{
fDelta = kClosest.x - extents.x;
fSqrDistance += fDelta*fDelta;
kClosest.x = extents.x;
}
if (kClosest.y < -extents.y)
{
fDelta = kClosest.y + extents.y;
fSqrDistance += fDelta*fDelta;
kClosest.y = -extents.y;
}
else if (kClosest.y > extents.y)
{
fDelta = kClosest.y - extents.y;
fSqrDistance += fDelta*fDelta;
kClosest.y = extents.y;
}
if (fSqrDistance > circle.GetRadius() * circle.GetRadius())
{
return 0;
}
Point2f d = p2 + kClosest - p1;
d.Normalize();
pxContacts[0] = Contact(p1 + d * circle.GetRadius(), p2 + kClosest, &circle.body, &box.body);
return 1;
}
示例6: Explode
void Bullet::Explode(float gameTime)
{
Explosive *e = new Explosive(graphicEntity.animResManager);
Point2f delta = dest_pos - pos;
float len = delta.DotProduct();
if (len > 1)
{
delta = delta.Normalize(speed);
}
e->orientation = orientation;
e->init("data/tank/bulletexplode.xml", gameTime, gun->explosive);
e->setPostion(explodePos, explodePos + delta);
EntityManager::getSingleton().attach(e);
active = false;
}
示例7: 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);
}
示例8: ResolveCollision
void Contact::ResolveCollision()
{
if (!m_pxBodies[0] || !m_pxBodies[1])
return;
//------------------------------------------------------------------------------------------------------
// parameters
//------------------------------------------------------------------------------------------------------
Point2f C0 = m_xContacts[0];
Point2f C1 = m_xContacts[1];
Point2f Ncoll = C1 - C0;
// assert(Ncoll.x != 0 || Ncoll.y != 0);
Ncoll.Normalize();
float m0 = m_pxBodies[0]->getInvMass();
float m1 = m_pxBodies[1]->getInvMass();
float i0 = m_pxBodies[0]->getInvInertia();
float i1 = m_pxBodies[1]->getInvInertia();
const Point2f& P0 = m_pxBodies[0]->getPosition();
const Point2f& P1 = m_pxBodies[1]->getPosition();
const Point2f& V0 = m_pxBodies[0]->getVelocity();
const Point2f& V1 = m_pxBodies[1]->getVelocity();
float w0 = m_pxBodies[0]->getAngVelocity();
float w1 = m_pxBodies[1]->getAngVelocity();
//------------------------------------------------------------------------------------------------------
// pre-computations
//------------------------------------------------------------------------------------------------------
Point2f R0 = C0 - P0;
Point2f R1 = C1 - P1;
Point2f T0 = Point2f(-R0.y, R0.x);
Point2f T1 = Point2f(-R1.y, R1.x);
Point2f VP0 = V0 + T0 * w0; // point velocity
Point2f VP1 = V1 + T1 * w1; // point velocity
//------------------------------------------------------------------------------------------------------
// impact velocity
//------------------------------------------------------------------------------------------------------
Point2f Vcoll = VP0 - VP1;
float vn = Vcoll * Ncoll;
Point2f Vn = Ncoll * vn;
Point2f Vt = Vcoll - Vn;
if (vn > 0.0f) // separation
return;
if (Vt * Vt < 0.0001f)
Vt = Point2f(0.0f, 0.0f);
// float vt = Vt.Length();
Vt.Normalize();
//------------------------------------------------------------------------------------------------------
// compute impulse (frction and restitution).
// ------------------------------------------
//
// -(1+Cor)(Vel.norm)
// j = ------------------------------------------------------------
// [1/Ma + 1/Mb] + [Ia' * (ra x norm)²] + [Ib' * (rb x norm)²]
//------------------------------------------------------------------------------------------------------
Point2f J;
Point2f Jt(0.0f, 0.0f);
Point2f Jn(0.0f, 0.0f);
float fCoR = s_xContactMaterial.GetRestitution();
float fCoF = s_xContactMaterial.GetFriction();
float t0 = (R0 ^ Ncoll) * (R0 ^ Ncoll) * i0;
float t1 = (R1 ^ Ncoll) * (R1 ^ Ncoll) * i1;
float m = m0 + m1;
float denom = m + t0 + t1;
float jn = vn / denom;
Jn = Ncoll * (-(1.0f + fCoR) * jn);
//if (dbg_UseFriction)
Jt = Vt * (fCoF * jn);
J = Jn + Jt;
//------------------------------------------------------------------------------------------------------
// changes in momentum
//------------------------------------------------------------------------------------------------------
Point2f dV0 = J * m0;
Point2f dV1 =-J * m1;
float dw0 = (R0 ^ J) * i0;
float dw1 =-(R1 ^ J) * i1;
//------------------------------------------------------------------------------------------------------
// apply changes in momentum
//------------------------------------------------------------------------------------------------------
if (!m_pxBodies[0]->isStaticBody())
{
if (m0 > 0.0f)
{
//.........这里部分代码省略.........