Пример #1
0
void UVREditorMode::PreTick( const float DeltaTime )
{
	if( !bIsFullyInitialized || !bIsActive || bWantsToExitMode )
	{
		return;
	}

	//Setting the initial position and rotation based on the editor viewport when going into VR mode
	if( bFirstTick && bActuallyUsingVR )
	{
		const FTransform RoomToWorld = GetRoomTransform();
		const FTransform WorldToRoom = RoomToWorld.Inverse();
		FTransform ViewportToWorld = FTransform( SavedEditorState.ViewRotation, SavedEditorState.ViewLocation );
		FTransform ViewportToRoom = ( ViewportToWorld * WorldToRoom );

		FTransform ViewportToRoomYaw = ViewportToRoom;
		ViewportToRoomYaw.SetRotation( FQuat( FRotator( 0.0f, ViewportToRoomYaw.GetRotation().Rotator().Yaw, 0.0f ) ) );

		FTransform HeadToRoomYaw = GetRoomSpaceHeadTransform();
		HeadToRoomYaw.SetRotation( FQuat( FRotator( 0.0f, HeadToRoomYaw.GetRotation().Rotator().Yaw, 0.0f ) ) );

		FTransform RoomToWorldYaw = RoomToWorld;
		RoomToWorldYaw.SetRotation( FQuat( FRotator( 0.0f, RoomToWorldYaw.GetRotation().Rotator().Yaw, 0.0f ) ) );

		FTransform ResultToWorld = ( HeadToRoomYaw.Inverse() * ViewportToRoomYaw ) * RoomToWorldYaw;
		SetRoomTransform( ResultToWorld );
	}

}
FRotator CombineRotators(FRotator A, FRotator B)
{
	FQuat AQuat = FQuat(A);
	FQuat BQuat = FQuat(B);

	return FRotator(BQuat*AQuat);
}
Пример #3
0
void FSimpleHMD::GetCurrentPose(FQuat& CurrentOrientation)
{
	// very basic.  no head model, no prediction, using debuglocalplayer
	ULocalPlayer* Player = GEngine->GetDebugLocalPlayer();

	if (Player != NULL && Player->PlayerController != NULL)
	{
		FVector RotationRate = Player->PlayerController->GetInputVectorKeyState(EKeys::RotationRate);

		double CurrentTime = FApp::GetCurrentTime();
		double DeltaTime = 0.0;

		if (LastSensorTime >= 0.0)
		{
			DeltaTime = CurrentTime - LastSensorTime;
		}

		LastSensorTime = CurrentTime;

		// mostly incorrect, but we just want some sensor input for testing
		RotationRate *= DeltaTime;
		CurrentOrientation *= FQuat(FRotator(FMath::RadiansToDegrees(-RotationRate.X), FMath::RadiansToDegrees(-RotationRate.Y), FMath::RadiansToDegrees(-RotationRate.Z)));
	}
	else
	{
		CurrentOrientation = FQuat(FRotator(0.0f, 0.0f, 0.0f));
	}
}
/**
* 姿勢をUEの座標系で返す。AXIS Neuron では YXZ の順としておくこと!
*/
FQuat PacketParserNeuron::GetQuaternion(const uint8* data, const int32 index)
{
	/* deg を rad にし、さらに半分にする係数*/
	static const float halfRadCoef = HALF_PI / 180.0f;

	/*  BVH 右手系 YXZ -> UE4 左手系 ZXY */
	FVector euler = FVector();
	euler.Z = -GetFloat(data, index);
	euler.X = -GetFloat(data, index + 4);
	euler.Y = -GetFloat(data, index + 8);

	float sx, sy, sz, cx, cy, cz;

#if (ENGINE_MAJOR_VERSION >= 4) && (ENGINE_MINOR_VERSION >= 8)
	FMath::SinCos(&sx, &cx, euler.X * halfRadCoef);
	FMath::SinCos(&sy, &cy, euler.Y * halfRadCoef);
	FMath::SinCos(&sz, &cz, euler.Z * halfRadCoef);
#else
	sx = FMath::Sin(euler.X * halfRadCoef);
	sy = FMath::Sin(euler.Y * halfRadCoef);
	sz = FMath::Sin(euler.Z * halfRadCoef);
	cx = FMath::Cos(euler.X * halfRadCoef);
	cy = FMath::Cos(euler.Y * halfRadCoef);
	cz = FMath::Cos(euler.Z * halfRadCoef);
#endif

	FQuat qx = FQuat(sx, 0, 0, cx);
	FQuat qy = FQuat(0, sy, 0, cy);
	FQuat qz = FQuat(0, 0, sz, cz);

	FQuat quat = qz * qx * qy;

	return quat;
}
FRotator UKismetMathLibrary::ComposeRotators(FRotator A, FRotator B)
{
	FQuat AQuat = FQuat(A);
	FQuat BQuat = FQuat(B);

	return FRotator(BQuat*AQuat);
}
Пример #6
0
// Sets default values
APilotPawn::APilotPawn()
{
	//Math_IP::Elbowposition(FVector(100, 0, 0), FVector(0, 0, 0), 100, 100);
	// Set this pawn to call Tick() every frame.  You can turn this off to improve performance if you don't need it.
	PrimaryActorTick.bCanEverTick = true;

	Origin = CreateDefaultSubobject<USceneComponent>(TEXT("Origin"));

	/*HandMesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("Hands"));
	HandMesh->SetupAttachment(BodyMesh);
	HandMesh->RelativeLocation = FVector(1.18f, -0.82f, 0.02f);*/

	FirstPersonCameraComponent = CreateDefaultSubobject<UCameraComponent>(TEXT("FirstPersonCamera"));
	FirstPersonCameraComponent->SetupAttachment(Origin);
	FirstPersonCameraComponent->RelativeLocation = FVector(-32.75f, 0, 99.151726f); // Position the camera
	FirstPersonCameraComponent->bUsePawnControlRotation = false;

	// 진짜 움직이는 팔
	RightArm = CreateDefaultSubobject<USkeletalMeshComponent>(TEXT("RightArm"));
	RightArm->SetupAttachment(Origin);

	RightRealHandScene = CreateDefaultSubobject<USceneComponent>(TEXT("RightRealHandScene"));
	RightShoulderScene = CreateDefaultSubobject<USceneComponent>(TEXT("RightShoulder"));
	RightShoulderScene->SetupAttachment(RightArm);

	//진짜 움직이는 몸통
	//RealBody = CreateDefaultSubobject<USkeletalMeshComponent>(TEXT("RealBody"));
	//RealBody->SetupAttachment(BodyMesh);

	// 오른손, 이 손의 트랜스폼은 가상세계에 반영되는 플레이어 오른손의 위치와 같다.
	RightHand = CreateDefaultSubobject<UHand>(TEXT("RealWorld_RightHand"));
	RightHand->SetupAttachment(RightArm);
	RightHand->DefaultSet(RightShoulderScene, RightRealHandScene);
	RightHand->SetRelativeLocation(FVector(0, 0, 0));
	RightHand->SetRelativeRotation(FQuat(FRotator(0, 0, 0)));
	//Dev_HandMesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("DevLeftHand"));
	//Dev_HandMesh->SetupAttachment(RightArm);

	LeftArm = CreateDefaultSubobject<USkeletalMeshComponent>(TEXT("LeftArm"));
	LeftArm->SetupAttachment(Origin);

	LeftRealHandScene = CreateDefaultSubobject<USceneComponent>(TEXT("LeftRealHandScene"));
	LeftShoulderScene = CreateDefaultSubobject<USceneComponent>(TEXT("LeftShoulder"));
	LeftShoulderScene->SetupAttachment(LeftArm);

	LeftHand = CreateDefaultSubobject<UHand>(TEXT("RealWorld_LeftHand"));
	LeftHand->SetupAttachment(LeftArm);
	LeftHand->DefaultSet(LeftShoulderScene, LeftRealHandScene);
	LeftHand->SetRelativeLocation(FVector(0, 0, 0));
	LeftHand->SetRelativeRotation(FQuat(FRotator(0, 0, 0)));

	// 머리통 HMD 위치
	Dev_HeadMesh = CreateDefaultSubobject<USkeletalMeshComponent>(TEXT("HeadMesh"));


	Hand_move_dirvec = FVector(10.0f, 0.0f, 0.0f);

}
Пример #7
0
void FAnimNode_Mirror::MirrorPose(FTransform& InPose, const uint8 InMirrorAxis, const uint8 InPosFowdMirror)
{

	FVector lMirroredLoc = InPose.GetLocation();

	if (InPosFowdMirror == 1)
	{
		lMirroredLoc.X = -lMirroredLoc.X;
	}
	else
	{
		if (InPosFowdMirror == 2)
		{
			lMirroredLoc.Y = -lMirroredLoc.Y;
		}
		else
		{
			if (InPosFowdMirror == 3)
			{
				lMirroredLoc.Z = -lMirroredLoc.Z;
			}
		}
	}

	InPose.SetLocation(lMirroredLoc);


	switch (InMirrorAxis)
	{
	case 1:
	{
		float lY = -InPose.GetRotation().Y;
		float lZ = -InPose.GetRotation().Z;
		InPose.SetRotation(FQuat(InPose.GetRotation().X, lY, lZ, InPose.GetRotation().W));
		break;
	}

	case 2:
	{
		float lX = -InPose.GetRotation().X;
		float lZ = -InPose.GetRotation().Z;
		InPose.SetRotation(FQuat(lX, InPose.GetRotation().Y, lZ, InPose.GetRotation().W));
		break;
	}

	case 3:
	{
		float lX = -InPose.GetRotation().X;
		float lY = -InPose.GetRotation().Y;
		InPose.SetRotation(FQuat(lX, lY, InPose.GetRotation().Z, InPose.GetRotation().W));
		break;
	}
	}
};
void USCarryObjectComponent::RotateActorAroundPoint(AActor* RotateActor, FVector RotationPoint, FRotator AddRotation)
{
	FVector Loc = RotateActor->GetActorLocation() - RotationPoint;
	FVector RotatedLoc = AddRotation.RotateVector(Loc);

	FVector NewLoc = RotationPoint + RotatedLoc;
	
	/* Compose the rotators, use Quats to avoid gimbal lock */
	FQuat AQuat = FQuat(RotateActor->GetActorRotation());
	FQuat BQuat = FQuat(AddRotation);

	FRotator NewRot = FRotator(BQuat*AQuat);

	RotateActor->SetActorLocationAndRotation(NewLoc, NewRot);
}
Пример #9
0
void ADKWeapon::AutoAttack()
{
	FOverlapResult overlaps;
	FVector CurrentLocation = GetActorLocation();
	FVector EndLocation = CurrentLocation + FVector(0, Range, 0) * DKOwner->GetActorRotation().Vector();
	FCollisionQueryParams Params;
	GetWorld()->OverlapSingle(overlaps, EndLocation, FQuat(),
		FCollisionShape::MakeSphere(CapsuleRadius), Params, EnemiesTypes);

	DrawDebugSphere(GetWorld(), EndLocation, CapsuleRadius, 16, FColor::Red, true, .5);
	//DrawDebugCapsule(GetWorld(), EndLocation, CapsuleHalfHeight, CapsuleRadius, FQuat(),
	//	FColor::Red, true, GetWorld()->TimeSeconds);

	if (overlaps.Actor.IsValid())
	{
		if (ADKEnemy* Enemy = Cast<ADKEnemy>(overlaps.Actor.Get()))
		{
			Enemy->Kill(DKOwner->GetDKPC());
			CurrentKilledEnemies++;
		}
	}

	if (CurrentKilledEnemies > MaximumKilledEnemies)
	{
		StopWeapon();
	}
}
/*  一つ分の受信データを解析し、AXIS Neuron の BVH データならば格納 */
bool PacketParserNeuron::Read(const uint8* raw, const int32 length, UMocapPose* pose)
{
	if (!CheckHeader(raw, length)) return false;

	/* ヘッダーを読んだ時点でユーザーIDが分るので設定 */
	pose->UserId = this->userId;

	/* 読み込まれないボーンを空にする */
	for (int i = 0; i < (sizeof(EmptyBoneIndices) / sizeof(EmptyBoneIndices[0])); i++) {
		pose->BoneRotations[EmptyBoneIndices[i]] = FQuat(0, 0, 0, 1);
	}

	/* 読込開始 */
	int index = 64;

	/*  Refecence ありの場合、float16 × 6 がヘッダー後に存在するのでスキップ */
	if (this->hasReference) index += 24;

	/*  最初はルート位置が届く */
	FVector position = GetPosition(raw, index);
	pose->OriginalRootPosition = position;
	index += 12;

	/*  各関節の角度 */
	for (int i = 0; i < BoneCount; i++) {
		ProcessSegment(raw, i, index, pose);
		index += (this->hasDisplacement ? 24 : 12);
	}

	return true;
}
Пример #11
0
//Conversion - use find and replace to change behavior, no scaling version is typically used for orientations
FVector convertLeapToUE(Leap::Vector leapVector)
{
    //Convert Axis
    FVector vect = FVector(-leapVector.z, leapVector.x, leapVector.y);

    //Hmd orientation adjustment
    if (LeapShouldAdjustForFacing)
    {
        FRotator rotation = FRotator(90.f, 0.f, 180.f);
        vect = FQuat(rotation).RotateVector(vect);

        if (LeapShouldAdjustRotationForHMD)
        {
            if (GEngine->HMDDevice.IsValid())
            {
                FQuat orientationQuat;
                FVector position;
                GEngine->HMDDevice->GetCurrentOrientationAndPosition(orientationQuat, position);
                vect = orientationQuat.RotateVector(vect);
            }
        }
    }

    return vect;
}
Пример #12
0
void ABETCharacter::OnInteract()
{
	FCollisionQueryParams TraceParams(FName(TEXT("Interact Trace")), true);
	TraceParams.bTraceComplex = true;
	TraceParams.bReturnPhysicalMaterial = false;
	TraceParams.AddIgnoredActor(this);

	// Re-init hit info

	TArray<FOverlapResult>Overlaps;
	
	if (GetWorld()->OverlapMultiByChannel(Overlaps,
		GetActorLocation(),
		FQuat(),
		ECC_GameTraceChannel2,
		FCollisionShape::MakeSphere(50.f),
		TraceParams))
	{
		for (FOverlapResult Result : Overlaps)
		{
			//if (ABETInteractable->InteractAudio != NULL)
			//{
				//UGameplayStatics::PlaySoundAtLocation(this, ABETInteractable->InteractableAudio, GetActorLocation());

				if (ABETInteractable* Interactable = Cast<ABETInteractable>(Result.Actor.Get()))
				{
					UE_LOG(LogTemp, Display, TEXT("INTERACTABLE FOUND"));
					Interactable->Interact();
					//Interactable->OnServerInteract();
				}
			//}
		}
	}

}
class AGSPersistentCue* UGSBlueprintFunctionLibrary::BeginSpawnCueActor(TSubclassOf<class AGSPersistentCue> CueActorClass
	, const FVector& Location
	, class AActor* CueInstigator)
{
	AGSPersistentCue* effectField = nullptr;

	if (CueInstigator)
	{
		FRotator Rotation = FRotator::ZeroRotator;
		Rotation = CueInstigator->GetActorRotation();
		Rotation.Pitch = 0;
		FTransform Trans;
		Trans.SetLocation(Location);
		Trans.SetRotation(FQuat(Rotation));
		effectField = CueInstigator->GetWorld()->SpawnActorDeferred<AGSPersistentCue>(CueActorClass,
			Trans, CueInstigator, CueInstigator->Instigator,
			ESpawnActorCollisionHandlingMethod::AlwaysSpawn); //change to get pawn
		if (effectField)
		{
			effectField->CueInstigator = CueInstigator;
		}
	}

	return effectField;
}
Пример #14
0
void ULibraries::SetHome(FRotator h)
{
	float q1, q2, q3, q4;
	bool sent = FemtoduinoPointer->WriteData("w\n", 32);
	char parse1[10], parse2[10], parse3[10], parse4[10];
	char incomingData[250];
	int dataLength = 250;
	Sleep(50);
	FemtoduinoPointer->ReadData(incomingData, dataLength);

	_memccpy(&parse1, incomingData, ',', 8);
	_memccpy(&parse2, &incomingData[9], ',', 8);
	_memccpy(&parse3, &incomingData[18], ',', 8);
	_memccpy(&parse4, &incomingData[27], ',', 8);



	hexasciitofloat(q1, parse1);
	hexasciitofloat(q2, parse2);
	hexasciitofloat(q3, parse3);
	hexasciitofloat(q4, parse4);


	FQuat newQ = FQuat(-q2, -q3, -q4, q1);
	hq = newQ;
}
Пример #15
0
bool FTransform::InitFromString( const FString& Source )
{
	TArray<FString> ComponentStrings;
	Source.ParseIntoArray(&ComponentStrings, TEXT("|"), true);
	const int32 NumComponents = ComponentStrings.Num();
	if(3 != NumComponents)
	{
		return false;
	}

	// Translation
	FVector ParsedTranslation = FVector::ZeroVector;
	if( !FDefaultValueHelper::ParseVector(ComponentStrings[0], ParsedTranslation) )
	{
		return false;
	}

	// Rotation
	FRotator ParsedRotation = FRotator::ZeroRotator;
	if( !FDefaultValueHelper::ParseRotator(ComponentStrings[1], ParsedRotation) )
	{
		return false;
	}

	// Scale
	FVector Scale = FVector(1.f);
	if( !FDefaultValueHelper::ParseVector(ComponentStrings[2], Scale) )
	{
		return false;
	}

	SetComponents(FQuat(ParsedRotation), ParsedTranslation, Scale);

	return true;
}
Пример #16
0
void FSimpleHMD::SetupView(FSceneViewFamily& InViewFamily, FSceneView& InView)
{
	InView.BaseHmdOrientation = FQuat(FRotator(0.0f,0.0f,0.0f));
	InView.BaseHmdLocation = FVector(0.f);
//	WorldToMetersScale = InView.WorldToMetersScale;
	InViewFamily.bUseSeparateRenderTarget = false;
}
//Conversion - use find and replace to change behavior, no scaling version is typically used for orientations
FVector ConvertLeapToUE(Leap::Vector LeapVector)
{
	//Convert Axis
	FVector ConvertedVector = FVector(-LeapVector.z, LeapVector.x, LeapVector.y);

	//Hmd orientation adjustment
	if (LeapShouldAdjustForFacing)
	{
		FRotator Rotation = FRotator(90.f, 0.f, 180.f);
		ConvertedVector = FQuat(Rotation).RotateVector(ConvertedVector);
		
		if (LeapShouldAdjustRotationForHMD)
		{
			if (GEngine->HMDDevice.IsValid())
			{
				FQuat orientationQuat;
				FVector position;
				GEngine->HMDDevice->GetCurrentOrientationAndPosition(orientationQuat, position);
				ConvertedVector = orientationQuat.RotateVector(ConvertedVector);
			}
		}
	}

	return ConvertedVector;
}
FQuat FAnimNode_RotationMultiplier::MultiplyQuatBasedOnSourceIndex(const FTransform& RefPoseTransform, const FTransform& LocalBoneTransform, const EBoneAxis Axis, float InMultiplier, const FQuat& ReferenceQuat)
{
	// Find delta angle for source bone.
	FQuat DeltaQuat = ExtractAngle(RefPoseTransform, LocalBoneTransform, Axis);

	// Turn to Axis and Angle
	FVector RotationAxis;
	float	RotationAngle;
	DeltaQuat.ToAxisAndAngle(RotationAxis, RotationAngle);

	const FVector DefaultAxis = GetAxisVector(Axis);

	// See if we need to invert angle - shortest path
	if( (RotationAxis | DefaultAxis) < 0.f )
	{
		RotationAxis = -RotationAxis;
		RotationAngle = -RotationAngle;
	}

	// Make sure it is the shortest angle.
	RotationAngle = FMath::UnwindRadians(RotationAngle);

	// New bone rotation
	FQuat OutQuat = ReferenceQuat * FQuat(RotationAxis, RotationAngle* InMultiplier);
	// Normalize resulting quaternion.
	OutQuat.Normalize();

#if 0 //DEBUG_TWISTBONECONTROLLER
	UE_LOG(LogSkeletalControl, Log, TEXT("\t RefQuat: %s, Rot: %s"), *ReferenceQuat.ToString(), *ReferenceQuat.Rotator().ToString() );
	UE_LOG(LogSkeletalControl, Log, TEXT("\t NewQuat: %s, Rot: %s"), *OutQuat.ToString(), *OutQuat.Rotator().ToString() );
	UE_LOG(LogSkeletalControl, Log, TEXT("\t RollAxis: %s, RollAngle: %f"), *RotationAxis.ToString(), RotationAngle );
#endif

	return OutQuat;
}
void SDestructibleMeshEditorViewport::RefreshViewport()
{
	// Update chunk visibilities
#if WITH_APEX
#if WITH_EDITORONLY_DATA
	if (DestructibleMesh != NULL && DestructibleMesh->FractureSettings != NULL && DestructibleMesh->ApexDestructibleAsset != NULL && PreviewComponent->IsRegistered())
	{
		const NxRenderMeshAsset* ApexRenderMeshAsset = DestructibleMesh->ApexDestructibleAsset->getRenderMeshAsset();
		if (ApexRenderMeshAsset != NULL)
		{
			NxExplicitHierarchicalMesh& EHM =  DestructibleMesh->FractureSettings->ApexDestructibleAssetAuthoring->getExplicitHierarchicalMesh();
			if (DestructibleMesh->ApexDestructibleAsset->getPartIndex(0) < ApexRenderMeshAsset->getPartCount())
			{
				const PxBounds3& Level0Bounds = ApexRenderMeshAsset->getBounds(DestructibleMesh->ApexDestructibleAsset->getPartIndex(0));
				const PxVec3 Level0Center = !Level0Bounds.isEmpty() ? Level0Bounds.getCenter() : PxVec3(0.0f);
				for (uint32 ChunkIndex = 0; ChunkIndex < DestructibleMesh->ApexDestructibleAsset->getChunkCount(); ++ChunkIndex)
				{
					const uint32 PartIndex = DestructibleMesh->ApexDestructibleAsset->getPartIndex(ChunkIndex);

					if (PartIndex >= ApexRenderMeshAsset->getPartCount())
					{
						continue;
					}
					
					uint32 ChunkDepth = 0;			
					for (int32 ParentIndex = DestructibleMesh->ApexDestructibleAsset->getChunkParentIndex(ChunkIndex); 
						ParentIndex >= 0; 
						ParentIndex = DestructibleMesh->ApexDestructibleAsset->getChunkParentIndex(ParentIndex))
					{
						++ChunkDepth;
					}

					const bool bChunkVisible = ChunkDepth == PreviewDepth;
					PreviewComponent->SetChunkVisible(ChunkIndex, bChunkVisible);
					if (bChunkVisible)
					{
						const PxBounds3& ChunkBounds = ApexRenderMeshAsset->getBounds(PartIndex);
						const PxVec3 ChunkCenter = !ChunkBounds.isEmpty() ? ChunkBounds.getCenter() : PxVec3(0.0f);
						const PxVec3 Displacement = ExplodeAmount*(ChunkCenter - Level0Center);
						PreviewComponent->SetChunkWorldRT(ChunkIndex, FQuat(0.0f, 0.0f, 0.0f, 1.0f), P2UVector(Displacement));
					}
				}

				PreviewComponent->BoundsScale = 100;
				// Send bounds to render thread at end of frame
				PreviewComponent->UpdateComponentToWorld();
		
				// Send bones to render thread right now, so the invalidated display is rerendered with
				// uptodate information
				PreviewComponent->DoDeferredRenderUpdates_Concurrent();
			}
		}
	}
#endif // WITH_EDITORONLY_DATA
#endif // WITH_APEX

	// Invalidate the viewport's display.
	SceneViewport->InvalidateDisplay();
}
// Called every frame
void AMyPlayer::Tick( float DeltaTime )
{


    Super::Tick( DeltaTime );
    SetActorRotation(FQuat(FRotator(0, 0, 0)));

}
Пример #21
0
bool UEnvQueryTest_Trace::RunBoxTraceFrom(const FVector& ItemPos, const FVector& ContextPos, AActor* ItemActor, UWorld* World, enum ECollisionChannel Channel, const FCollisionQueryParams& Params, const FVector& Extent)
{
	FCollisionQueryParams TraceParams(Params);
	TraceParams.AddIgnoredActor(ItemActor);

	const bool bHit = World->SweepTestByChannel(ItemPos, ContextPos, FQuat((ContextPos - ItemPos).Rotation()), Channel, FCollisionShape::MakeBox(Extent), TraceParams);
	return bHit;
}
Пример #22
0
// Set the Position of the Tile
// x -> x position
// y -> z position
// z -> contains the level
void ATile::SetPosition( FVector Position )
{
	FVector relativePosition = FVector( Position.X * 64.0f, -1.0f, Position.Y * -64.0f );
	X = Position.X;
	Y = Position.Y;

	TileVisual->SetRelativeLocation( relativePosition );
	TileVisual->SetRelativeRotation( FQuat( FRotator( 0.0f, 0.0f, 0.0f ) ) );
}
void UBMAgroCheck::TickNode(UBehaviorTreeComponent&OwnerComp, uint8* NodeMemory, float DeltaSeconds)
{
	Super::TickNode(OwnerComp, NodeMemory, DeltaSeconds);

	if (ThisTree == nullptr || ThisController == nullptr || ThisAICharacter == nullptr)
	{
		ThisTree = OwnerComp.GetCurrentTree();

		ThisController = Cast<ABMAIController>(OwnerComp.GetAIOwner());

		ThisAICharacter = Cast<ABMBossCharacter>(ThisController->GetPawn());

		if (ThisTree == nullptr || ThisController == nullptr || ThisAICharacter == nullptr)
		{
			UE_LOG(LogTemp, Warning, TEXT("Warning Agro Service performed on invalid AI"));
			return;
		}
	}

	// Initialize a sweep params struct with trace complex set to true
	FCollisionQueryParams SphereSweepParams(FName(TEXT("AgroCheckSweep")), true, ThisAICharacter);

	FCollisionObjectQueryParams ObjectQuery(ECC_GameTraceChannel1);

	// Initialize Hit Result
	FHitResult HitOut(ForceInit);

	DrawDebugSphere(ThisAICharacter->GetWorld(), ThisAICharacter->GetActorLocation(), 1500, 12, FColor::Red, false, 4.0f);

	// Perform the sweep and check boolean return, we will only be checking for BMCharacter objects
	bool bResult = ThisAICharacter->GetWorld()->SweepSingleByObjectType(HitOut,
																	    ThisAICharacter->GetActorLocation(),
																		ThisAICharacter->GetActorLocation() + FVector(0.0f, 0.0f, 10.0f),
															            FQuat(),
																		ObjectQuery,
																		FCollisionShape::MakeSphere(1500),
																		SphereSweepParams);



	if (bResult)
	{
		ThisController->GetBlackboard()->SetValueAsObject(TEXT("TargetToFollow"), HitOut.GetActor());

		ThisController->GetBlackboard()->SetValueAsVector(TEXT("HomeLocation"), ThisAICharacter->GetActorLocation());

		ThisController->GetBlackboard()->SetValueAsVector(TEXT("TargetLocation"), HitOut.GetActor()->GetActorLocation());

		ThisController->TrackToTarget();
	}
	else
	{
		ThisController->GetBlackboard()->SetValueAsObject(TEXT("TargetToFollow"), nullptr);
		ThisController->StopTrack();
	}
}
Пример #24
0
void ADynamicWeather::Update()
{
  // Modify this actor's rotation according to Sun position.
  if (!SetActorRotation(FQuat(GetSunDirection().Rotation()), ETeleportType::None)) {
    UE_LOG(LogCarla, Warning, TEXT("Unable to rotate actor"));
  }

  if (bRefreshAutomatically) {
    RefreshWeather();
  }
}
/**
 * Create the bones needed to hold the transforms for the destructible chunks associated with an Apex Destructible Asset.
 * @param ImportData - SkeletalMesh import data into which we are extracting information
 * @param ApexDestructibleAsset - the Apex Destructible Asset
 */
static void CreateBones(FSkeletalMeshImportData &ImportData, const NxDestructibleAsset& ApexDestructibleAsset)
{
	// Just need to create ApexDestructibleAsset.getChunkCount() bones, all with identity transform poses
	const uint32 ChunkCount = ApexDestructibleAsset.getChunkCount();
	if( ChunkCount == 0 )
	{
		UE_LOG(LogApexDestructibleAssetImport, Warning,TEXT("%s has no chunks"), ANSI_TO_TCHAR(ApexDestructibleAsset.getName()) );
		return;
	}

	const uint32 BoneCount = ChunkCount + 1;	// Adding one more bone for the root bone, required by the skeletal mesh

	// Format for bone names
	uint32 Q = ChunkCount-1;
	int32 MaxNumberWidth = 1;
	while ((Q /= 10) != 0)
	{
		++MaxNumberWidth;
	}

	// Turn parts into bones
	for (uint32 BoneIndex=0; BoneIndex<BoneCount; ++BoneIndex)
	{
		ImportData.RefBonesBinary.Add( VBone() );
		// Set bone
		VBone& Bone = ImportData.RefBonesBinary[BoneIndex];
		if (BoneIndex == 0)
		{
			// Bone 0 is the required root bone
			Bone.Name = TEXT("Root");
			Bone.NumChildren = ChunkCount;
			Bone.ParentIndex = INDEX_NONE;
		}
		else
		{
			// The rest are the parts
			Bone.Name = FString::Printf( TEXT("Part%0*d"), MaxNumberWidth, BoneIndex-1);
			Bone.NumChildren = 0;
			// Creates a simple "flat" hierarchy
			Bone.ParentIndex = 0;
		}

		// Set transform to identity
		VJointPos& JointMatrix = Bone.BonePos;
		JointMatrix.Orientation = FQuat(0.0f,0.0f,0.0f,1.0f);
		JointMatrix.Position = FVector(0.0f,0.0f,0.0f);
		JointMatrix.Length = 1.0f;
		JointMatrix.XSize = 100.0f;
		JointMatrix.YSize = 100.0f;
		JointMatrix.ZSize = 100.0f;
	}
}
Пример #26
0
void FEdModeHaste::UpdateBrushRotation()
{
	BrushRotation = FQuat::FindBetween(FVector(0, 0, 1), LastHitImpact);

	// Append the brush rotation
	if (UISettings->bRotateOnScroll) {
		float RotSnapWidth = GEditor->GetRotGridSize().Yaw;
		float SnappedOffsetX = SnapRotation(RotationOffset.X, RotSnapWidth);
		float SnappedOffsetY = SnapRotation(RotationOffset.Y, RotSnapWidth);
		float SnappedOffsetZ = SnapRotation(RotationOffset.Z, RotSnapWidth);
		BrushRotation = BrushRotation * FQuat(FVector(0, 0, 1), SnappedOffsetZ * PI / 180.0f);
	}
}
Пример #27
0
AActor* UWorld::SpawnActor( UClass* Class, FVector const* Location, FRotator const* Rotation, const FActorSpawnParameters& SpawnParameters )
{
	FTransform Transform;
	if (Location)
	{
		Transform.SetLocation(*Location);
	}
	if (Rotation)
	{
		Transform.SetRotation(FQuat(*Rotation));
	}

	return SpawnActor(Class, &Transform, SpawnParameters);
}
Пример #28
0
float UAblTargetingBox::CalculateRange() const
{
	FVector RotatedBox;
	FQuat Rotation = FQuat(m_Location.GetRotation());

	RotatedBox = Rotation.GetForwardVector() + m_HalfExtents.X;
	RotatedBox += Rotation.GetRightVector() + m_HalfExtents.Y;
	RotatedBox += Rotation.GetUpVector() + m_HalfExtents.Z;

	if (m_CalculateAs2DRange)
	{
		return m_Location.GetOffset().Size2D() + RotatedBox.Size2D();
	}
	
	return m_Location.GetOffset().Size() + RotatedBox.Size();
}
Пример #29
0
bool ASkill::SphereTrace(AActor* actorToIgnore, const FVector& start, const FVector& end, const float radius, TArray<FHitResult>& hitOut, ECollisionChannel traceChannel /* = ECC_Pawn */)
{
    FCollisionQueryParams traceParams(FName(TEXT("Sphere Trace")), true, actorToIgnore);
    traceParams.bTraceComplex = true;
    traceParams.bReturnPhysicalMaterial = false;

    traceParams.AddIgnoredActor(actorToIgnore);

    TObjectIterator<APlayerController> pc;
    if (!pc)
        return false;

    DrawDebugSphere(pc->GetWorld(), start, radius, 8, FColor::Red, true);

    return pc->GetWorld()->SweepMultiByChannel(hitOut, start, end, FQuat(), traceChannel, FCollisionShape::MakeSphere(radius), traceParams);
}
Пример #30
0
void AFournoidKeeper::FollowMaster(float DeltaTime)
{
	// Make sure the keeper's distance to master is within KeeperFollowDistance
	if (MasterCharacter)
	{
		auto MyLocaiton = StaticMeshComp->GetComponentLocation();
		auto MasterLocation = MasterCharacter->GetRootComponent()->GetComponentLocation();
		auto DirectionVector = MasterLocation - MyLocaiton;
		
		// Get direction and distance from this keeper to the master.
		FVector Direction;
		float Distance;
		DirectionVector.ToDirectionAndLength(Direction, Distance);
		// Lerp velocity and move keeper towards character
		float Velocity = UKismetMathLibrary::Lerp(.0f, KeeperMovementSpeed, FMath::Abs(((Distance - KeeperPropelDistance) / KeeperStickDistance)));
		KeeperMovement->MoveUpdatedComponent(Direction * Velocity * DeltaTime, FQuat(), false);
	}
}