cleaned up method

This commit is contained in:
devZoGok
2024-01-21 17:18:44 +02:00
parent 43c843982a
commit f843d211da
2 changed files with 10 additions and 13 deletions
+9 -12
View File
@@ -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();
+1 -1
View File
@@ -13,7 +13,7 @@ namespace battleship{
FlightStage flightStage;
vb01::Vector3 targetPoint;
void pitch(float);
void pitch(float, vb01::Vector3);
void cruise();
void checkSurfaceCollision();
};