void UTangoARCamera::TickComponent(float DeltaTime, enum ELevelTick TickType, FActorComponentTickFunction *ThisTickFunction)
{
	if (UTangoDevice::Get().GetCurrentConfig().AreaDescription.UUID.Len() > 0)
	{
		FrameOfReference = FTangoCoordinateFramePair(ETangoCoordinateFrameType::AREA_DESCRIPTION, ETangoCoordinateFrameType::CAMERA_COLOR);
	}
	else
	{
		FrameOfReference = FTangoCoordinateFramePair(ETangoCoordinateFrameType::START_OF_SERVICE, ETangoCoordinateFrameType::CAMERA_COLOR);
	}

	if (ARScreen == nullptr && TangoARHelpers::DataIsReady())
	{
		ARScreen = NewObject<UTangoARScreenComponent>(this, TEXT("TangoCameraARScreen"));
		if (ARScreen)
		{
			ARScreen->RegisterComponent();
            ARScreen->AttachToComponent(this, FAttachmentTransformRules::KeepWorldTransform, NAME_None);

			FVector2D LowerLeft, UpperRight, NearFar;
			TangoARHelpers::GetNearPlane(LowerLeft, UpperRight, NearFar);
			FVector2D UVShift = TangoARHelpers::GetARUVShift();

			NearFar.Y *= 0.99f;
			FVector LL = FVector(NearFar.Y, LowerLeft.X*(NearFar.Y / NearFar.X), LowerLeft.Y*(NearFar.Y / NearFar.X));
			FVector UR = FVector(NearFar.Y, UpperRight.X*(NearFar.Y / NearFar.X), UpperRight.Y*(NearFar.Y / NearFar.X));

			ARScreen->SetRelativeLocation((LL + UR)*0.5f);
			ARScreen->SetRelativeRotation(FQuat::Identity);
			ARScreen->SetRelativeScale3D(FVector(1, FMath::Abs(UR.Y - LL.Y) / (100.0f*(1.0f - 2.0f*UVShift.X)), FMath::Abs(LL.Z - UR.Z) / (100.0f*(1.0f - 2.0f*UVShift.Y))));
		}
		else
		{
			UE_LOG(ProjectTangoPlugin, Error, TEXT("UTangoARCamera::TickComponent: Could not instantiate TangoARScreen for TangoARCamera. There will be no camera passthrough."));
		}
	}
	Super::TickComponent(DeltaTime, TickType, ThisTickFunction);

	if (UTangoDevice::Get().getTangoDeviceMotionPointer())
	{
		FTangoPoseData LatestPose = UTangoDevice::Get().getTangoDeviceMotionPointer()->GetPoseAtTime(FrameOfReference, 0);
		//Only move the component if the pose status is valid.
		if (LatestPose.StatusCode == ETangoPoseStatus::VALID)
		{
			SetRelativeLocation(LatestPose.Position);
			SetRelativeRotation(FRotator(LatestPose.QuatRotation));
		}
	}
	else
	{
		UE_LOG(ProjectTangoPlugin, Warning, TEXT("UTangoARCamera::TickComponent: Could not update transfrom because Tango Service is not connect or has motion tracking disabled!"));
	}

	if (!ViewExtension.IsValid() && GEngine)
	{
		TSharedPtr< FTangoViewExtension, ESPMode::ThreadSafe > NewViewExtension(new FTangoViewExtension(Cast<ITangoARInterface>(this)));
		ViewExtension = NewViewExtension;
		GEngine->ViewExtensions.Add(ViewExtension);
	}
}
Exemplo n.º 2
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);
}
Exemplo n.º 3
0
void UTankTurret::Rotate(float RelativeSpeed)
{
	RelativeSpeed = FMath::Clamp<float>(RelativeSpeed, -1, +1);
	auto RotationChange = RelativeSpeed * MaxDegreesPerSecond * GetWorld()->DeltaTimeSeconds;
	auto Rotation = RelativeRotation.Yaw + RotationChange;
	SetRelativeRotation(FRotator(0, Rotation, 0));
}
Exemplo n.º 4
0
void UTankBarrel::Elevate(float RelativeSpeed)
{
    RelativeSpeed = FMath::Clamp<float>(RelativeSpeed, -1, +1);
    auto ElevationChange = RelativeSpeed * MaxDegreesPerSecond * GetWorld()->DeltaTimeSeconds;

    auto RawNewElevation = RelativeRotation.Pitch + ElevationChange;
    auto Elevation = FMath::Clamp<float>(RawNewElevation, MinElevationDegrees, MaxElevationDegrees);
    SetRelativeRotation(FRotator(Elevation, 0, 0));
}
Exemplo n.º 5
0
void UTankBarrel::Elevate(float RelativeSpeed)
{
	RelativeSpeed = FMath::Clamp<float>(RelativeSpeed, -1,1);
//	UE_LOG(LogTemp, Warning, TEXT("Barrel elevates: %f"), RelativeSpeed);
	auto ElevationChange = RelativeSpeed *MaxDegreesPerSecond * GetWorld()->DeltaTimeSeconds;
	auto RawNewElevation = RelativeRotation.Pitch + ElevationChange;
	auto Elevation = FMath::Clamp(RawNewElevation, MinElevationDegrees, MaxElevationDegrees);
	SetRelativeRotation(FRotator(Elevation, 0, 0));
}
void UTankTurret::Rotate(float RelativeSpeed)
{
	//Move Barrell the right amount this frame
	//Given a max elevation speed. and the frame time.
	RelativeSpeed = FMath::Clamp<float>(RelativeSpeed, -1, 1);
	auto RotationChange = RelativeSpeed * MaxDegreesPerSecond * GetWorld()->DeltaTimeSeconds;
	auto Rotation = RelativeRotation.Yaw + RotationChange;
	SetRelativeRotation(FRotator(0., Rotation, 0.));
}
Exemplo n.º 7
0
void UTankBarrel::Elevate(float RelativeSpeed)
{
	RelativeSpeed = FMath::Clamp<float>(RelativeSpeed, -1, 1);									// Clamp the relative space, protection	

	auto ElevationChange = RelativeSpeed * MaxDegreesPerSecond * GetWorld()->DeltaTimeSeconds;	// Elevation change this frame
	auto RawNewElevation = RelativeRotation.Pitch + ElevationChange;							// Calculating the new elevation

	RawNewElevation = FMath::Clamp(RawNewElevation, MinDegreesElevation, MaxDegreesElevation);	// Clamp the new elevation

	SetRelativeRotation(FRotator(RawNewElevation, 0, 0));										// Set the new rotation/elevation
}
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);
}
Exemplo n.º 9
0
void UTankBarrel::Elevate(float RelativeSpeed)
{
	// Move the barrel the right amount this frame
	// Given max elevation speed and the frame time
	RelativeSpeed = FMath::Clamp<float>(RelativeSpeed, -1, 1);
	auto ElevationChange = RelativeSpeed * MaxDegreesPerSecond * GetWorld()->DeltaTimeSeconds;
	auto RawNewElevation = RelativeRotation.Pitch + ElevationChange;
	auto Elevation = FMath::Clamp<float>(RawNewElevation, MinElevationDegrees, MaxElevationDegrees);
	SetRelativeRotation(FRotator(Elevation, 0, 0));

	
}
void UTangoMotionComponent::LateUpdate()
{
	if (UTangoDevice::Get().getTangoDeviceMotionPointer())
	{
		//Only move the component if the pose status is valid.
		FTangoPoseData LatestPose = UTangoDevice::Get().getTangoDeviceMotionPointer()->GetPoseAtTime(MotionComponentFrameOfReference, ARImage == nullptr ? 0 : ARImage->GetLatestImageTimeStamp());
		if (LatestPose.StatusCode == ETangoPoseStatus::VALID)
		{
			SetRelativeLocation(LatestPose.Position);
			SetRelativeRotation(FRotator(LatestPose.QuatRotation));
		}
	}
	else
	{
		UE_LOG(ProjectTangoPlugin, Warning, TEXT("UTangoMotionComponent::LateUpdate: Could not update transfrom because Tango Service is not connect or has motion tracking disabled!"));
	}
}
Exemplo n.º 11
0
void ARobotCharacter::ConfigureMeshAndAnimation()
{
	// Configure the skeletal mesh and animation blueprints
	static auto SkeletalMeshName = TEXT("SkeletalMesh'/Game/Characters/Mannequin/Mesh/SK_Mannequin.SK_Mannequin'");
	static auto SkeletalMeshFinder = ConstructorHelpers::FObjectFinder<USkeletalMesh>(SkeletalMeshName);
	if (SkeletalMeshFinder.Succeeded())
	{
		auto MeshComponent = GetMesh();
		MeshComponent->SetSkeletalMesh(SkeletalMeshFinder.Object);
		MeshComponent->SetRelativeLocation(FVector(0.f, 0.f, -95.f));
		MeshComponent->SetRelativeRotation(FRotator(0.f, 270.f, 0.f));

		ConfigureMeshCollision();

	}

	static auto AnimBlueprintName = TEXT("AnimBlueprint'/Game/Characters/Mannequin/Animations/ThirdPerson_AnimBP.ThirdPerson_AnimBP_C'");
	static auto AnimBlueprintFinder = ConstructorHelpers::FObjectFinder<UAnimBlueprintGeneratedClass>(AnimBlueprintName);
	if (AnimBlueprintFinder.Succeeded())
	{
		GetMesh()->SetAnimInstanceClass(AnimBlueprintFinder.Object);
	}
}
Exemplo n.º 12
0
void UAimPredictionSC::smoothRotation()
{
	//FRotator tempRot = FMath::RInterpTo(currentRotation, nextRotation, GetWorld()->GetDeltaSeconds(), 3);
	FRotator tempRot = FMath::RInterpTo(RelativeRotation, nextRotation, GetWorld()->GetDeltaSeconds(), 10);
	SetRelativeRotation(FQuat(tempRot));
}
Exemplo n.º 13
0
void UAimPredictionSC::CLIENT_sendCorrection_Implementation(FRotator correctedRotation)
{
	///apply Rotation correction 
	SetRelativeRotation(FQuat(correctedRotation));
}