diff --git a/cruiseMissile.cpp b/cruiseMissile.cpp index 76424ae..c4f52b3 100644 --- a/cruiseMissile.cpp +++ b/cruiseMissile.cpp @@ -21,22 +21,16 @@ namespace battleship{ orientAt(Quaternion(angle, Vector3::VEC_J) * rot); } - //TODO clean up method code - void CruiseMissile::pitch(float rotAngle){ + void CruiseMissile::pitch(float rotAngle, Vector3 compVec){ float minHeight = 20; + float angleToCompVec = dirVec.getAngleBetween(compVec); + float angle = (angleToCompVec > rotAngle ? rotAngle : angleToCompVec); if(flightStage == FlightStage::ASCENT && pos.y - initPos.y > minHeight){ - Vector3 horDir = Vector3(dirVec.x, 0, dirVec.z).norm(); - float angleToVertDir = dirVec.getAngleBetween(horDir); - Quaternion rotQuat = Quaternion(angleToVertDir > rotAngle ? rotAngle : angleToVertDir, leftVec) * rot; - orientAt(rotQuat); - - if(dirVec.y <= 0) - flightStage = FlightStage::CRUISE; + orientAt(Quaternion(angle, leftVec) * rot); + if(dirVec.y <= 0) flightStage = FlightStage::CRUISE; } else if(flightStage == FlightStage::DESCENT){ - float angleFromHorDir = dirVec.getAngleBetween(-Vector3::VEC_J); - float angle = (angleFromHorDir > rotAngle ? rotAngle : angleFromHorDir); Vector3 targDir = (Vector3(targetPoint.x, initPos.y, targetPoint.z) - initPos).norm(); if(dirVec.getAngleBetween(targDir) < PI / 2) @@ -63,11 +57,14 @@ namespace battleship{ void CruiseMissile::update(){ GameObject::update(); placeAt(pos + dirVec * speed); + float rotAngle = .1; switch(flightStage){ case FlightStage::ASCENT: + pitch(rotAngle, Vector3(dirVec.x, 0, dirVec.z).norm()); + break; case FlightStage::DESCENT: - pitch(.1); + pitch(rotAngle, -Vector3::VEC_J); break; case FlightStage::CRUISE: cruise(); diff --git a/cruiseMissile.h b/cruiseMissile.h index 76eeec4..b7b84d9 100644 --- a/cruiseMissile.h +++ b/cruiseMissile.h @@ -13,7 +13,7 @@ namespace battleship{ FlightStage flightStage; vb01::Vector3 targetPoint; - void pitch(float); + void pitch(float, vb01::Vector3); void cruise(); void checkSurfaceCollision(); };