mirror of
https://github.com/ApfelTeeSaft/PlanetFleet.git
synced 2026-08-26 19:33:38 +00:00
cleaned up method
This commit is contained in:
+9
-12
@@ -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
@@ -13,7 +13,7 @@ namespace battleship{
|
||||
FlightStage flightStage;
|
||||
vb01::Vector3 targetPoint;
|
||||
|
||||
void pitch(float);
|
||||
void pitch(float, vb01::Vector3);
|
||||
void cruise();
|
||||
void checkSurfaceCollision();
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user