コード例 #1
0
void UMWBotSensorComponent::PostLoad()
{
	Super::PostLoad();

	// Remember the default (straight) rotation. We need it the sensor is not attached to a socket.
	DefaultRotation = DesiredRotation = GetRelativeTransform().Rotator();
}
コード例 #2
0
void UDebugSkelMeshComponent::ConsumeRootMotion(const FVector& FloorMin, const FVector& FloorMax)
{
	if (bPreviewRootMotion)
	{
		if (UAnimInstance* AnimInst = GetAnimInstance())
		{
			FRootMotionMovementParams ExtractedRootMotion = AnimInst->ConsumeExtractedRootMotion();
			if (ExtractedRootMotion.bHasRootMotion)
			{
				AddLocalTransform(ExtractedRootMotion.RootMotionTransform);

				//Handle moving component so that it stays within the editor floor
				FTransform CurrentTransform = GetRelativeTransform();
				FVector Trans = CurrentTransform.GetTranslation();
				Trans.X = WrapInRange(Trans.X, FloorMin.X, FloorMax.X);
				Trans.Y = WrapInRange(Trans.Y, FloorMin.Y, FloorMax.Y);
				CurrentTransform.SetTranslation(Trans);
				SetRelativeTransform(CurrentTransform);
			}
		}
	}
	else
	{
		SetWorldTransform(FTransform());
	}
}
コード例 #3
0
void UMWBotSensorComponent::UpdateRotation(float DeltaSeconds)
{
	// desRot is DesiredRotation with optionally added random angle
	const FRotator curRot = GetRelativeTransform().Rotator();
	FRotator desRot = bEnableSensorWander ? ApplyRandomAngle(DesiredRotation) : DesiredRotation;

	// clamp the aiming angle (desired rotation)

	const FVector defAim = DefaultRotation.Vector();
	const FVector desAim = desRot.Vector();

	const float maxAngRad = PI * ViewingAngle / 180.f;
	const float curCos = defAim | desAim;
	const float minCos = FMath::Cos(maxAngRad);
	if (curCos < minCos) // out of range
	{
		// Find quaternion which rotates the eye in the aimDef-aimDir plane
		const FVector axis = defAim ^ desAim;
		const FQuat quat(axis, maxAngRad);

		desRot = quat.RotateVector(defAim).Rotation();
	}

	// smoothly change the sensor aiming
	const float interpSpeed = bCrazy ? CrazyReaction : bAlarm ? AlarmReaction : Reaction;
	FRotator newRot = FMath::RInterpTo(curRot, desRot, DeltaSeconds, interpSpeed);
	SetRelativeRotation(newRot);
}
コード例 #4
0
bool UPrimitiveComponent::WeldToImplementation(USceneComponent * InParent, FName ParentSocketName /* = Name_None */, bool bWeldSimulatedChild /* = false */)
{
	//WeldToInternal assumes attachment is already done
	if (AttachParent != InParent || AttachSocketName != ParentSocketName)
	{
		return false;
	}

	//Check that we can actually our own socket name
	FBodyInstance* BI = GetBodyInstance(NAME_None, false);
	if (BI == NULL)
	{
		return false;
	}

	if (BI->ShouldInstanceSimulatingPhysics() && bWeldSimulatedChild == false)
	{
		return false;
	}

	UnWeldFromParent();	//make sure to unweld from wherever we currently are

	FName SocketName;
	UPrimitiveComponent * RootComponent = GetRootWelded(this, ParentSocketName, &SocketName, true);

	if (RootComponent)
	{
		if (FBodyInstance* RootBI = RootComponent->GetBodyInstance(SocketName, false))
		{
			if (BI->WeldParent == RootBI)	//already welded so stop
			{
				return true;
			}

			BI->bWelded = true;
			//There are multiple cases to handle:
			//Root is kinematic, simulated
			//Child is kinematic, simulated
			//Child always inherits from root

			//if root is kinematic simply set child to be kinematic and we're done
			if (RootComponent->IsSimulatingPhysics(SocketName) == false)
			{
				BI->WeldParent = NULL;
				SetSimulatePhysics(false);
				return false;	//return false because we need to continue with regular body initialization
			}

			//root is simulated so we actually weld the body
			FTransform RelativeTM = RootComponent == AttachParent ? GetRelativeTransform() : GetComponentToWorld().GetRelativeTransform(RootComponent->GetComponentToWorld());	//if direct parent we already have relative. Otherwise compute it
			RootBI->Weld(BI, GetComponentToWorld());
			BI->WeldParent = RootBI;

			return true;
		}
	}

	return false;
}
コード例 #5
0
ファイル: plAGAnim.cpp プロジェクト: Asteral/Plasma
// GetStartToEndTransform -----------------------------------------------
bool GetStartToEndTransform(const plAGAnim *anim, hsMatrix44 *startToEnd,
                            hsMatrix44 *endToStart, const plString &channelName)
{
    double start = 0.0f;    // assumed
    double end = anim->GetEnd();

    GetRelativeTransform(anim, start, end, startToEnd, endToStart, channelName);
    return true;
}
コード例 #6
0
void UDebugSkelMeshComponent::TickComponent(float DeltaTime, enum ELevelTick TickType, FActorComponentTickFunction *ThisTickFunction)
{
	if (TurnTableMode == EPersonaTurnTableMode::Playing)
	{
		FRotator Rotation = GetRelativeTransform().Rotator();
		// Take into account PlaybackSpeedScaling, so it doesn't affect turn table turn rate.
		Rotation.Yaw += 36.f * TurnTableSpeedScaling * DeltaTime / FMath::Max(PlaybackSpeedScaling, KINDA_SMALL_NUMBER);
		SetRelativeRotation(Rotation);
	}

	Super::TickComponent(DeltaTime, TickType, ThisTickFunction);
}
コード例 #7
0
void UDebugSkelMeshComponent::ConsumeRootMotion(const FVector& FloorMin, const FVector& FloorMax)
{
	//Extract root motion regardless of where we use it so that we don't hit
	//problems with it building up in the instance

	FRootMotionMovementParams ExtractedRootMotion;

	if (UAnimInstance* AnimInst = GetAnimInstance())
	{
		ExtractedRootMotion = AnimInst->ConsumeExtractedRootMotion(1.f);
	}

	if (bPreviewRootMotion)
	{
		if (ExtractedRootMotion.bHasRootMotion)
		{
			AddLocalTransform(ExtractedRootMotion.RootMotionTransform);

			//Handle moving component so that it stays within the editor floor
			FTransform CurrentTransform = GetRelativeTransform();
			FVector Trans = CurrentTransform.GetTranslation();
			Trans.X = WrapInRange(Trans.X, FloorMin.X, FloorMax.X);
			Trans.Y = WrapInRange(Trans.Y, FloorMin.Y, FloorMax.Y);
			CurrentTransform.SetTranslation(Trans);
			SetRelativeTransform(CurrentTransform);
		}
	}
	else
	{
		if (TurnTableMode == EPersonaTurnTableMode::Stopped)
		{
			SetWorldTransform(FTransform());
		}
		else
		{
			SetRelativeLocation(FVector::ZeroVector);
		}
	}
}
コード例 #8
0
void UTextRenderComponent::PostLoad()
{
	// Try and fix up assets created before the vertical alignment fix was implemented. Because we didn't flag that
	// fix with its own version, use the version number closest to that CL
	if (GetLinkerUE4Version() < VER_UE4_PACKAGE_REQUIRES_LOCALIZATION_GATHER_FLAGGING)
	{
		float Offset = CalculateVerticalAlignmentOffset(*Text.ToString(), Font, XScale, YScale, HorizSpacingAdjust, VerticalAlignment);
		FTransform RelativeTransform = GetRelativeTransform();
		FTransform CorrectionLeft = FTransform::Identity;
		FTransform CorrectionRight = FTransform::Identity;
		CorrectionLeft.SetTranslation(FVector(0.0f, 0.0f, -Offset));
		CorrectionRight.SetTranslation(FVector(0.0f, 0.0f, Offset));
		SetRelativeTransform(CorrectionLeft * RelativeTransform * CorrectionRight);
	}

	if (GetLinkerUE4Version() < VER_UE4_ADD_TEXT_COMPONENT_VERTICAL_ALIGNMENT)
	{
		VerticalAlignment = EVRTA_QuadTop;
	}

	if( GetLinkerUE4Version() < VER_UE4_TEXT_RENDER_COMPONENTS_WORLD_SPACE_SIZING )
	{
		if( Font )
		{
			WorldSize = Font->GetMaxCharHeight();
			InvDefaultSize = 1.0f / WorldSize;
		}
		else
		{
			//Just guess I suppose? If there is no font then there's no text to break so it's ok.
			WorldSize = 30.0f;
			InvDefaultSize = 1.0f / 30.0f;
		}
	}

	Super::PostLoad();
}