Beispiel #1
0
void CTAAirMoveType::UpdateBanking(bool noBanking)
{
    SyncedFloat3 &frontdir = owner->frontdir;
    SyncedFloat3 &updir = owner->updir;

    if (!owner->upright) {
        float wantedPitch = 0;

        if (aircraftState == AIRCRAFT_FLYING && flyState == FLY_ATTACKING && circlingPos.y < owner->pos.y) {
            wantedPitch = (circlingPos.y - owner->pos.y) / circlingPos.distance(owner->pos);
        }

        currentPitch = currentPitch * 0.95f + wantedPitch * 0.05f;
    }

    frontdir = GetVectorFromHeading(owner->heading);
    frontdir.y = currentPitch;
    frontdir.Normalize();

    float3 rightdir(frontdir.cross(UpVector));		//temp rightdir
    rightdir.Normalize();

    float wantedBank = 0.0f;
    if (!noBanking && bankingAllowed) wantedBank = rightdir.dot(deltaSpeed)/accRate*0.5f;

    const float limit = std::min(1.0f,goalPos.SqDistance2D(owner->pos)*Square(0.15f));
    if (Square(wantedBank) > limit) {
        wantedBank =  math::sqrt(limit);
    } else if (Square(wantedBank) < -limit) {
        wantedBank = -math::sqrt(limit);
    }

    //Adjust our banking to the desired value
    if (currentBank > wantedBank) {
        currentBank -= std::min(0.03f, currentBank - wantedBank);
    } else {
        currentBank += std::min(0.03f, wantedBank - currentBank);
    }

    // Calculate a suitable upvector
    updir = rightdir.cross(frontdir);
    updir = updir * cos(currentBank) + rightdir * sin(currentBank);
    owner->rightdir = frontdir.cross(updir);
}
void CTAAirMoveType::UpdateBanking(bool noBanking)
{
	float3 &frontdir = owner->frontdir;
	float3 &updir = owner->updir;

	float wantedPitch=0;
	if(aircraftState==AIRCRAFT_FLYING && flyState==FLY_ATTACKING && circlingPos.y<owner->pos.y){
		wantedPitch=(circlingPos.y-owner->pos.y)/circlingPos.distance(owner->pos);
	}
	currentPitch=currentPitch*0.95+wantedPitch*0.05;

	frontdir = GetVectorFromHeading(owner->heading);
	frontdir.y=currentPitch;
	frontdir.Normalize();

	float3 rightdir(frontdir.cross(UpVector));		//temp rightdir
	rightdir.Normalize();

	float wantedBank = 0.0f;
	if (!noBanking) wantedBank = rightdir.dot(deltaSpeed)/accRate*0.5;

	float limit=min(1.0f,goalPos.distance2D(owner->pos)*0.15f);
	if(wantedBank>limit)
		wantedBank=limit;
	else if(wantedBank<-limit)
		wantedBank=-limit;

	//Adjust our banking to the desired value
	if (currentBank > wantedBank)
		currentBank -= min(0.03f, currentBank - wantedBank);
	else 
		currentBank += min(0.03f, wantedBank - currentBank);

	//Calculate a suitable upvector
	updir= rightdir.cross(frontdir);
	updir = updir*cos(currentBank)+rightdir*sin(currentBank);
	owner->rightdir = frontdir.cross(updir);
}