Skip to content
Browse files

fix bug in TestTrajectoryCone for ballistic weapons

  • Loading branch information...
1 parent 264be57 commit 26e98fab770aef8a2476b79b53e90b756571bc82 rt committed Jan 24, 2012
Showing with 29 additions and 29 deletions.
  1. +29 −29 rts/Game/TraceRay.cpp
View
58 rts/Game/TraceRay.cpp
@@ -141,24 +141,25 @@ float TraceRay(const float3& start, const float3& dir, float length, int collisi
qf->GetQuadsOnRay(start, dir, length, begQuad, endQuad);
- //! feature intersection
+ // feature intersection
if (!ignoreFeatures) {
for (int* quadPtr = begQuad; quadPtr != endQuad; ++quadPtr) {
const CQuadField::Quad& quad = qf->GetQuad(*quadPtr);
for (std::list<CFeature*>::const_iterator ui = quad.features.begin(); ui != quad.features.end(); ++ui) {
CFeature* f = *ui;
- if (!f->blocking || f->collisionVolume == NULL) {
- //! NOTE: why check the blocking property?
+ // NOTE:
+ // if f is non-blocking, ProjectileHandler will not test
+ // for collisions with projectiles so we can skip it here
+ if (!f->blocking || f->collisionVolume == NULL)
continue;
- }
if (CCollisionHandler::DetectHit(f, start, start + dir * length, &cq, true)) {
const float3& intPos = (cq.b0)? cq.p0: cq.p1;
- const float len = (intPos - start).dot(dir); //! same as (intPos - start).Length()
+ const float len = (intPos - start).dot(dir); // same as (intPos - start).Length()
- //! we want the closest feature (intersection point) on the ray
+ // we want the closest feature (intersection point) on the ray
if (len < length) {
length = len;
hitFeature = f;
@@ -168,7 +169,7 @@ float TraceRay(const float3& start, const float3& dir, float length, int collisi
}
}
- //! unit intersection
+ // unit intersection
if (!ignoreUnits) {
for (int* quadPtr = begQuad; quadPtr != endQuad; ++quadPtr) {
const CQuadField::Quad& quad = qf->GetQuad(*quadPtr);
@@ -187,9 +188,9 @@ float TraceRay(const float3& start, const float3& dir, float length, int collisi
if (CCollisionHandler::DetectHit(u, start, start + dir * length, &cq, true)) {
const float3& intPos = (cq.b0)? cq.p0: cq.p1;
- const float len = (intPos - start).dot(dir); //! same as (intPos - start).Length()
+ const float len = (intPos - start).dot(dir); // same as (intPos - start).Length()
- //! we want the closest unit (intersection point) on the ray
+ // we want the closest unit (intersection point) on the ray
if (len < length) {
length = len;
hitUnit = u;
@@ -203,8 +204,8 @@ float TraceRay(const float3& start, const float3& dir, float length, int collisi
}
if (!ignoreGround) {
- //! ground intersection
- float groundLength = ground->LineGroundCol(start, start + dir * length);
+ // ground intersection
+ const float groundLength = ground->LineGroundCol(start, start + dir * length);
if (length > groundLength && groundLength > 0) {
length = groundLength;
hitUnit = NULL;
@@ -245,7 +246,7 @@ float GuiTraceRay(const float3 &start, const float3 &dir, float length, bool use
for (int* quadPtr = begQuad; quadPtr != endQuad; ++quadPtr) {
const CQuadField::Quad& quad = qf->GetQuad(*quadPtr);
- //! Unit Intersection
+ // Unit Intersection
for (ui = quad.units.begin(); ui != quad.units.end(); ++ui) {
CUnit* unit = *ui;
if (unit == exclude) {
@@ -260,20 +261,21 @@ float GuiTraceRay(const float3 &start, const float3 &dir, float length, bool use
CollisionVolume cv(unit->collisionVolume);
if (unit->isIcon) {
- //! for iconified units, just pretend the collision
- //! volume is a sphere of radius <unit->IconRadius>
+ // for iconified units, just pretend the collision
+ // volume is a sphere of radius <unit->IconRadius>
cv.Init(unit->iconRadius);
}
if (CCollisionHandler::MouseHit(unit, start, start + dir * origlength, &cv, &cq)) {
- //! get the distance to the ray-volume ingress point
+ // get the distance to the ray-volume ingress point
const float3& intPos = (cq.b0)? cq.p0 : cq.p1;
- const float len = (intPos - start).dot(dir); //! same as (intPos - start).Length()
+ const float len = (intPos - start).dot(dir); // same as (intPos - start).Length()
const bool isfactory = dynamic_cast<CFactory*>(unit);
const float3& intPos2 = (cq.b0 && cq.b1) ? cq.p1 : cq.p0;
- const float len2 = (intPos2 - start).dot(dir); //! same as (intPos2 - start).Length()
+ const float len2 = (intPos2 - start).dot(dir); // same as (intPos2 - start).Length()
- if (!hitUnit || //! give an unit in a factory a higher priority than the factory itself
+ // give units in a factory a higher priority than the factory itself
+ if (!hitUnit ||
(isfactory && ((hover_factory && len < length) || (!hover_factory && len2 < length))) ||
(!isfactory && ((hover_factory && len < length2) || (!hover_factory && len < length)))) {
hover_factory = isfactory;
@@ -286,7 +288,7 @@ float GuiTraceRay(const float3 &start, const float3 &dir, float length, bool use
}
}
- //! Feature Intersection
+ // Feature Intersection
// NOTE: switch this to custom volumes fully?
// (not used for any LOF checks, maybe wasteful)
for (fi = quad.features.begin(); fi != quad.features.end(); ++fi) {
@@ -305,10 +307,11 @@ float GuiTraceRay(const float3 &start, const float3 &dir, float length, bool use
if (CCollisionHandler::DetectHit(f, start, start + dir * origlength, &cq, true)) {
const float3& intPos = (cq.b0)? cq.p0 : cq.p1;
- const float len = (intPos - start).dot(dir); //! same as (intPos - start).Length()
+ const float len = (intPos - start).dot(dir); // same as (intPos - start).Length()
- //! we want the closest feature (intersection point) on the ray
- if (!hitUnit || //! give features in a factory a higher priority than the factory itself
+ // we want the closest feature (intersection point) on the ray
+ // give features in a factory (?) a higher priority than the factory itself
+ if (!hitUnit ||
((hover_factory && len < length2) || (!hover_factory && len < length))) {
hover_factory = false;
length = len;
@@ -320,7 +323,7 @@ float GuiTraceRay(const float3 &start, const float3 &dir, float length, bool use
}
}
- //! ground intersection
+ // ground intersection
float groundLen = ground->LineGroundCol(start, start + dir * origlength, false);
if (groundLen > 0.0f) {
if ((groundLen + 200.0f) < length) {
@@ -353,13 +356,10 @@ bool LineFeatureCol(const float3& start, const float3& dir, float length)
const CQuadField::Quad& quad = qf->GetQuad(*quadPtr);
for (std::list<CFeature*>::const_iterator ui = quad.features.begin(); ui != quad.features.end(); ++ui) {
- CFeature* f = *ui;
- CollisionVolume* cv = f->collisionVolume;
+ const CFeature* f = *ui;
- if (!f->blocking || cv == NULL) {
- // NOTE: why check the blocking property?
+ if (!f->blocking || f->collisionVolume == NULL)
continue;
- }
if (CCollisionHandler::DetectHit(f, start, start + dir * length, &cq, true)) {
return true;
@@ -513,7 +513,7 @@ bool TestTrajectoryCone(
for (featuresIt = features.begin(); featuresIt != features.end(); ++featuresIt) {
const CFeature* f = *featuresIt;
- if (f->collisionVolume == NULL)
+ if (!f->blocking || f->collisionVolume == NULL)
continue;
if (TestTrajectoryConeHelper(from, dir, length, linear, quadratic, spread, baseSize, f))
return true;

0 comments on commit 26e98fa

Please sign in to comment.
Something went wrong with that request. Please try again.