Esempio n. 1
0
void BatchCreateDialog::VarifyBtnClicked()
{
	startPoint = glm::ivec3(ui->startPointXSpinBox->text().toInt(), ui->startPointYSpinBox->text().toInt(), ui->startPointZSpinBox->text().toInt());
	endPoint = glm::ivec3(ui->endPointXSpinBox->text().toInt(), ui->endPointYSpinBox->text().toInt(), ui->endPointZSpinBox->text().toInt());
	
	emit OverlapTest(startPoint, endPoint);
}
bool UMovementComponent::ResolvePenetrationImpl(const FVector& ProposedAdjustment, const FHitResult& Hit, const FQuat& NewRotationQuat)
{
	// SceneComponent can't be in penetration, so this function really only applies to PrimitiveComponent.
	const FVector Adjustment = ConstrainDirectionToPlane(ProposedAdjustment);
	if (!Adjustment.IsZero() && UpdatedPrimitive)
	{
		// See if we can fit at the adjusted location without overlapping anything.
		AActor* ActorOwner = UpdatedComponent->GetOwner();
		if (!ActorOwner)
		{
			return false;
		}

		UE_LOG(LogMovement, Verbose, TEXT("ResolvePenetration: %s.%s at location %s inside %s.%s at location %s by %.3f (netmode: %d)"),
			   *ActorOwner->GetName(),
			   *UpdatedComponent->GetName(),
			   *UpdatedComponent->GetComponentLocation().ToString(),
			   *GetNameSafe(Hit.GetActor()),
			   *GetNameSafe(Hit.GetComponent()),
			   Hit.Component.IsValid() ? *Hit.GetComponent()->GetComponentLocation().ToString() : TEXT("<unknown>"),
			   Hit.PenetrationDepth,
			   (uint32)GetNetMode());

		// We really want to make sure that precision differences or differences between the overlap test and sweep tests don't put us into another overlap,
		// so make the overlap test a bit more restrictive.
		const float OverlapInflation = CVarPenetrationOverlapCheckInflation.GetValueOnGameThread();
		bool bEncroached = OverlapTest(Hit.TraceStart + Adjustment, NewRotationQuat, UpdatedPrimitive->GetCollisionObjectType(), UpdatedPrimitive->GetCollisionShape(OverlapInflation), ActorOwner);
		if (!bEncroached)
		{
			// Move without sweeping.
			MoveUpdatedComponent(Adjustment, NewRotationQuat, false, nullptr, ETeleportType::TeleportPhysics);
			UE_LOG(LogMovement, Verbose, TEXT("ResolvePenetration:   teleport by %s"), *Adjustment.ToString());
			return true;
		}
		else
		{
			// Disable MOVECOMP_NeverIgnoreBlockingOverlaps if it is enabled, otherwise we wouldn't be able to sweep out of the object to fix the penetration.
			TGuardValue<EMoveComponentFlags> ScopedFlagRestore(MoveComponentFlags, EMoveComponentFlags(MoveComponentFlags & (~MOVECOMP_NeverIgnoreBlockingOverlaps)));

			// Try sweeping as far as possible...
			FHitResult SweepOutHit(1.f);
			bool bMoved = MoveUpdatedComponent(Adjustment, NewRotationQuat, true, &SweepOutHit, ETeleportType::TeleportPhysics);
			UE_LOG(LogMovement, Verbose, TEXT("ResolvePenetration:   sweep by %s (success = %d)"), *Adjustment.ToString(), bMoved);
			
			// Still stuck?
			if (!bMoved && SweepOutHit.bStartPenetrating)
			{
				// Combine two MTD results to get a new direction that gets out of multiple surfaces.
				const FVector SecondMTD = GetPenetrationAdjustment(SweepOutHit);
				const FVector CombinedMTD = Adjustment + SecondMTD;
				if (SecondMTD != Adjustment && !CombinedMTD.IsZero())
				{
					bMoved = MoveUpdatedComponent(CombinedMTD, NewRotationQuat, true, nullptr, ETeleportType::TeleportPhysics);
					UE_LOG(LogMovement, Verbose, TEXT("ResolvePenetration:   sweep by %s (MTD combo success = %d)"), *CombinedMTD.ToString(), bMoved);
				}
			}

			// Still stuck?
			if (!bMoved)
			{
				// Try moving the proposed adjustment plus the attempted move direction. This can sometimes get out of penetrations with multiple objects
				const FVector MoveDelta = ConstrainDirectionToPlane(Hit.TraceEnd - Hit.TraceStart);
				if (!MoveDelta.IsZero())
				{
					bMoved = MoveUpdatedComponent(Adjustment + MoveDelta, NewRotationQuat, true, nullptr, ETeleportType::TeleportPhysics);
					UE_LOG(LogMovement, Verbose, TEXT("ResolvePenetration:   sweep by %s (adjusted attempt success = %d)"), *(Adjustment + MoveDelta).ToString(), bMoved);
				}
			}	

			return bMoved;
		}
	}

	return false;
}
Esempio n. 3
0
void CFish::BreedingUpdate(double elapsed)
{
	
	CAquarium *aquarium = GetAquarium();
	//fish logic for breeding
	if (mCanBreed == true && mAge >= MaxAge)
	{
		if (mInterestTime >= InterestTimePreBreed)
		{
			mIsInterested = true;
		}
		else if (mIsGestating == false)
			mInterestTime++;
		if (mIsGestating == true)
			mGestatingTime++;

		if (mIsInterested == true)
		{
			CBreedVisitor visitor(mIsMale, GetType());
			
			aquarium->Accept(&visitor);
			if (visitor.IsInterested())
			{
				// Compute a vector from (x1,y1) to (x2,y2)
					
				double dx = visitor.GetX() - GetX();
				double dy = visitor.GetY() - GetY();				
				
				// How long is that vector?
				double len = sqrt(dx * dx + dy * dy);
				if (len > 0)
				{
					// Normalize the vector
					dx /= len;
					dy /= len;
				}

				// Update the location
				if (GetType() == "beta")
				{
					mSpeedX = dx * (MaxSpeedX - BetaSpeed) * BreedMultuplier * elapsed;
					mSpeedY = dy * (MaxSpeedY - BetaSpeed) * BreedMultuplier * elapsed;
				}

				if (GetType() == "bubbles")
				{
					mSpeedX = dx * (MaxSpeedX - BubblesSpeed) * BreedMultuplier * elapsed;
					mSpeedY = dy * (MaxSpeedY - BubblesSpeed) * BreedMultuplier * elapsed;
				}

				if (GetType() == "dory")
				{
					mSpeedX = dx * (DorySpeed - MaxSpeedX) * BreedMultuplier * elapsed;
					mSpeedY = dy * (DorySpeed - MaxSpeedY) * BreedMultuplier * elapsed;
				}

				

				// check if the visited fish overlaps this one
				if (OverlapTest(visitor.GetX(), visitor.GetY()))
				{
					if (mIsMale == 0)
					{
						mIsGestating = true;
					}
					else
					{
						visitor.SetGestating();
					}
					mIsInterested = false;
					mInterestTime = 0;
					visitor.SetUninterested();
					if (GetType() == "beta")
					{
						mSpeedX = ((double)rand() / RAND_MAX) * (MaxSpeedX - BetaSpeed);
						mSpeedY = ((double)rand() / RAND_MAX) * (MaxSpeedY - BetaSpeed);
					}
					else if (GetType() == "bubbles")
					{
						mSpeedX = ((double)rand() / RAND_MAX) * (MaxSpeedX - BubblesSpeed);
						mSpeedY = ((double)rand() / RAND_MAX) * (MaxSpeedY - BubblesSpeed);
					}
					else if (GetType() == "dory")
					{
						mSpeedX = ((double)rand() / RAND_MAX) * (DorySpeed- MaxSpeedX);
						mSpeedY = ((double)rand() / RAND_MAX) * (DorySpeed- MaxSpeedY);
					}
					
										
				}
				
			}


		}

		if (mGestatingTime >= GestatingTime)
		{
			mIsGestating = false;
			mGestatingTime = 0;
			if (GetType() == "beta")
			{
				auto fish = make_shared<CFishBeta>(aquarium);
				fish->SetLocation(GetX(), GetY());
				aquarium->AddTempItem(fish);
			}

			if (GetType() == "bubbles")
			{
				auto fish = make_shared<CFishBubbles>(aquarium);
				fish->SetLocation(GetX(), GetY());
				aquarium->AddTempItem(fish);
			}
			if (GetType() == "dory")
			{
				auto fish = make_shared<CFishDory>(aquarium);
				fish->SetLocation(GetX(), GetY());
				aquarium->AddTempItem(fish);
			}

			
		}
		if (mSpeedX < 0)
			SetMirror(true);
		if (mSpeedX > 0)
			SetMirror(false);
	}

}