bool Enemy::noticeFollower() { bool returnBool = false; D3DXVECTOR3 followerPos = gFollower->getPosition(); float distanceSq = D3DXVec3LengthSq(&(mPosition - followerPos)); if (distanceSq > mSightRangeSq)//if not within range, they can't see follower { bAttackFollower = false; return false; } // they are close enough to hear the follower through a wall or behind them if (distanceSq < mHearRangeSq) returnBool = true; //if the follower would be behind the enemy, they don't get a chance to see them //current enemy rotation is mRotation.y //find rotation towards follower D3DXVECTOR3 toFollower = gFollower->getPosition() - mPosition; float followerDirection = atan2(toFollower.x, toFollower.z); //if not within VISION_RANGE degrees/PI radians of each other //this only applies if the player has not injured them. If player has, they are more //watchful if (mHealth == mHealthMax && returnBool == false) { //1.57 ~ 1/2 * PI 6.28 ~ 2 * PI if ((fabs(followerDirection - mRotation.y) > 1.57) && ((fabs(followerDirection - 6.28)) + mRotation.y > 1.57) && ((fabs(mRotation.y - 6.28)) + followerDirection > 1.57)) { bAttackFollower = false; return false; } } //if they are between max hearing and max sight range, see if they are line of sight to player //make a line segment between enemy and player location //only take into account x and z here since map is flat, will save time LineSegment line3D(mPosition, followerPos); for (Mesh* M : gCurrentLevel->getWorldGeometry()) { for (AxisAlignedBoundingBox AABB : M->getBoundsBoxList()) { //if further out than sight range, no point in checking it if (D3DXVec3LengthSq(&(AABB.mMin - mPosition)) > mSightRangeSq) continue; //see if it collides with the line if (collides(AABB, line3D)) { bAttackPlayer = false; return returnBool; } } } //if it gets through the above checks, then it can see the player mLoseSightFollower = 0.0f; bAttackFollower = true; bSeenPlayer = true; return true; }
TEST_F(LineSegmentTest, getPointsTest) { LineSegment<1> line1D(Point<1>(1.0), Point<1>(2.0)); LineSegment<2> line2D(Point<2>(1.0, 2.0), Point<2>(2.0, 3.0)); LineSegment<3> line3D(Point<3>(1.0, 2.0, 3.0), Point<3>(2.0, 3.0, 4.0)); EXPECT_EQ(1.0, line1D.getPoints().first.x()); EXPECT_EQ(2.0, line2D.getPoints().first.y()); EXPECT_EQ(3.0, line3D.getPoints().first.z()); EXPECT_EQ(2.0, line1D.getPoints().second.x()); EXPECT_EQ(3.0, line2D.getPoints().second.y()); EXPECT_EQ(4.0, line3D.getPoints().second.z()); }
TEST_F(LineSegmentTest, minAndMaxTest) { LineSegment<1> line1D(Point<1>(1.0), Point<1>(2.0)); LineSegment<2> line2D(Point<2>(1.0, 2.0), Point<2>(2.0, 3.0)); LineSegment<3> line3D(Point<3>(1.0, 2.0, 3.0), Point<3>(2.0, 3.0, 4.0)); EXPECT_EQ(1.0, line1D.startPoint().x()); EXPECT_EQ(2.0, line2D.startPoint().y()); EXPECT_EQ(3.0, line3D.startPoint().z()); EXPECT_EQ(2.0, line1D.endPoint().x()); EXPECT_EQ(3.0, line2D.endPoint().y()); EXPECT_EQ(4.0, line3D.endPoint().z()); }
TEST_F(LineSegmentTest, ConstructorTest) { EXPECT_NO_THROW(LineSegment<1> line1D(Point<1>(1.0), Point<1>(2.0))); EXPECT_NO_THROW(LineSegment<2> line2D(Point<2>(1.0, 2.0), Point<2>(2.0, 3.0))); EXPECT_NO_THROW(LineSegment<3> line3D(Point<3>(1.0, 2.0, 3.0), Point<3>(2.0, 3.0, 4.0))); }