|
|

楼主 |
发表于 2004-12-14 18:54:00
|
显示全部楼层
Re:一瑞典游戏公司的招聘题
aprilsky和chenlee找到了问题所在
hitit: 建议你查阅一下运算符的优先级列表,括号是不需要的
参考代码如下:
bool EXG_UnitContainer::Intersect(
const MC_Vector3f& aStart,
const MC_Vector3f& anEnd,
const unsigned short aUnitToExclude,
Intersection& anIntersection)
{
unsigned short u;
EXG_Unit* unit;
Intersection ClosestIntersection;
ClosestIntersection.myUnit = NULL;
// iterate through contained units
for(u = 0; u < EX_MAX_UNITS; u++)
{
unit = myUnits; // obtain the unit at index u
// if valid unit and not a unit to exclude
if (unit && u != aUnitToExclude)
{
// do line-sphere intersection test
if ( EXM_Intersection: ineVsSphere(aStart, anEnd, unit->GetPosition(), unit->GetType().GetRadius(), anIntersection.myPosition) )
{
// intersecting! anIntersection.myPosition should have already been updated??? provided that it is a reference parameter
// update the ClosestIntersection only when 1. first time found an intersection, or 2. new distance is closer to the bullet starting position
if ( !ClosestIntersection.myUnit ||
DISTANCE(anIntersection.myPosition, aStart) < DISTANCE(ClosestIntersection.myPosition, aStart) )
{
// update position
ClosestIntersection.myPosition = anIntersection.myPosition;
// update direction
ClosestIntersection.myDirection = myDamageModel.CalculateHitDirection(aStart, anEnd, unit->GetBodyHeading());
// save intersected unit
ClosestIntersection.myUnit = unit;
}
}
}
}
// if ClosestIntersection has ever been updated, return it to user
if (ClosestIntersection.myUnit) {
anIntersection = ClosestIntersection;
return true;
}
return false;
}
|
|