FVector2D AOrionPlaceableItem::GetAim(FVector WorldAim) { const FVector AimDirLS = ActorToWorld().InverseTransformVectorNoScale(WorldAim); const FRotator AimRotLS = AimDirLS.Rotation(); return FVector2D(AimRotLS.Yaw, AimRotLS.Pitch); }
void ANimModCharacter::OnCameraUpdate(const FVector& PreviousCameraLocation, const FVector& CameraLocation, const FRotator& CameraRotation) { USkeletalMeshComponent* DefMesh1P = Cast<USkeletalMeshComponent>(GetClass()->GetDefaultSubobjectByName(TEXT("PawnMesh1P"))); //USkeletalMeshComponent* DefMesh1P = Mesh1P; const FMatrix DefMeshLS = FRotationTranslationMatrix(DefMesh1P->RelativeRotation, DefMesh1P->RelativeLocation); const FMatrix LocalToWorld = ActorToWorld().ToMatrixWithScale(); // Mesh rotating code expect uniform scale in LocalToWorld matrix const FRotator RotCameraPitch(CameraRotation.Pitch, 0.0f, 0.0f); const FRotator RotCameraYaw(0.0f, CameraRotation.Yaw, 0.0f); const FMatrix LeveledCameraLS = FRotationTranslationMatrix(RotCameraYaw, CameraLocation) * LocalToWorld.Inverse(); const FMatrix PitchedCameraLS = FRotationMatrix(RotCameraPitch) * LeveledCameraLS; const FMatrix MeshRelativeToCamera = DefMeshLS * LeveledCameraLS.Inverse(); const FMatrix PitchedMesh = MeshRelativeToCamera * PitchedCameraLS; //FVector origin = PitchedMesh.GetOrigin(); FVector origin = Mesh1P->GetRelativeTransform().GetLocation(); //FVector originalLocation = Mesh1P->GetRelativeTransform().GetLocation(); ////FVector origin = Mesh1P->ComponentToWorld.GetLocation(); //if (bIsCrouched) //{ // //origin.Z = (origin.Z - (DefaultBaseEyeHeight - DefMesh1P->RelativeLocation.Z)); // origin.Z = (PreviousCameraLocation.Z - CameraLocation.Z); //} Mesh1P->SetRelativeLocationAndRotation(origin, PitchedMesh.Rotator(), false, nullptr, ETeleportType::TeleportPhysics); /*FVector newLocation = Mesh1P->GetRelativeTransform().GetLocation(); int i = -1;*/ }
void APacmanTerrain::PostInitializeComponents() { Super::PostInitializeComponents(); if (WorldMap) { // We are only concerned on top mip map level auto &Mip = WorldMap->PlatformData->Mips[0]; const FColor *Pixels = reinterpret_cast<const FColor*>(Mip.BulkData.LockReadOnly()); FVector MeshMin; FVector MeshMax; Mesh->GetLocalBounds(MeshMin, MeshMax); FTransform ToWorld = ActorToWorld(); MeshMin = ToWorld.TransformPosition(MeshMin); MeshMax = ToWorld.TransformPosition(MeshMax); FVector WorldStartLocation = MeshMin; FVector WorldSize = MeshMax - MeshMin; FVector PixelToWorld = FVector(WorldSize.X / static_cast<float>(Mip.SizeX), WorldSize.Y / static_cast<float>(Mip.SizeY), 1.f); float StartPixel = static_cast<float>((BlockSize / 2) + 1); // How many pixels we should skip to another block float Step = static_cast<float>(BlockSize) + 1.85f; PickupSpawner->Spawn(Pixels, Mip.SizeX, Mip.SizeY, StartPixel, Step, PixelToWorld, WorldStartLocation); NavigationSpawner->Spawn(Pixels, Mip.SizeX, Mip.SizeY, StartPixel, Step, PixelToWorld, WorldStartLocation); Mip.BulkData.Unlock(); } }
FRotator ANimModCharacter::GetAimOffsets() const { const FVector AimDirWS = GetBaseAimRotation().Vector(); const FVector AimDirLS = ActorToWorld().InverseTransformVectorNoScale(AimDirWS); const FRotator AimRotLS = AimDirLS.Rotation(); return AimRotLS; }
void AAmethystCharacter::OnCameraUpdate(const FVector& CameraLocation, const FRotator& CameraRotation) { USkeletalMeshComponent* DefMesh1P = Cast<USkeletalMeshComponent>(GetClass()->GetDefaultSubobjectByName(TEXT("PawnMesh1P"))); const FMatrix DefMeshLS = FRotationTranslationMatrix(DefMesh1P->RelativeRotation, DefMesh1P->RelativeLocation); const FMatrix LocalToWorld = ActorToWorld().ToMatrixWithScale(); // Mesh rotating code expect uniform scale in LocalToWorld matrix const FRotator RotCameraPitch(CameraRotation.Pitch, 0.0f, 0.0f); const FRotator RotCameraYaw(0.0f, CameraRotation.Yaw, 0.0f); const FMatrix LeveledCameraLS = FRotationTranslationMatrix(RotCameraYaw, CameraLocation) * LocalToWorld.Inverse(); const FMatrix PitchedCameraLS = FRotationMatrix(RotCameraPitch) * LeveledCameraLS; const FMatrix MeshRelativeToCamera = DefMeshLS * LeveledCameraLS.Inverse(); const FMatrix PitchedMesh = MeshRelativeToCamera * PitchedCameraLS; Mesh1P->SetRelativeLocationAndRotation(PitchedMesh.GetOrigin(), PitchedMesh.Rotator()); }
bool ARadiantWebViewActor::TraceScreenPoint(APawn* InPawn, FVector2D& OutUV) { FVector Location; FRotator Rotation; APlayerController *PC = Cast<APlayerController>(InPawn->GetController()); if (PC) { PC->GetPlayerViewPoint(Location, Rotation); } else { InPawn->GetActorEyesViewPoint(Location, Rotation); } const FVector VectorToTarget = Location - GetActorLocation(); const float DistanceToTrace = VectorToTarget.Size() + TraceOversize; const FVector EndTrace = Location + Rotation.Vector()*DistanceToTrace; // Is this actor "pointing" at our surface mesh? static FName TraceTag = FName(TEXT("RadiantGUITrace")); FCollisionQueryParams TraceParams(TraceTag, true, InPawn); // TraceParams.bTraceAsyncScene = true; TraceParams.bReturnFaceIndex = true; FHitResult HitResult; UWorld* const World = GetWorld(); if (World->LineTraceSingleByChannel(HitResult, Location, EndTrace, TraceChannel, TraceParams)) { if (HitResult.Actor.IsValid() && (HitResult.Actor.Get() == this)) { FVector ActorRelativeLocation = ActorToWorld().InverseTransformPosition(HitResult.Location); return GetUVForPoint(HitResult.FaceIndex, ActorRelativeLocation, OutUV); } } return false; }
FVector ACubiquityVolume::volumeDirectionToWorldDirection(const FVector& localDirection) const { return ActorToWorld().TransformVectorNoScale(localDirection); }
FVector ACubiquityVolume::worldDirectionToVolumeDirection(const FVector& worldDirection) const { return ActorToWorld().InverseTransformVectorNoScale(worldDirection); }
FVector ACubiquityVolume::volumePositionToWorldPosition(const FVector& localPosition) const { return ActorToWorld().TransformPosition(localPosition); }
FVector ACubiquityVolume::worldPositionToVolumePosition(const FVector& worldPosition) const { return ActorToWorld().InverseTransformPosition(worldPosition); //GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, FString::Printf(TEXT("World: %f %f %f, Mesh: %f %f %f, Voxel: %d %d %d"), worldPosition.X, worldPosition.Y, worldPosition.Z, meshSpacePosition.X, meshSpacePosition.Y, meshSpacePosition.Z, int32_t(meshSpacePosition.X), int32_t(meshSpacePosition.Y), int32_t(meshSpacePosition.Z))); //return{ int32_t(meshSpacePosition.X), int32_t(meshSpacePosition.Y), int32_t(meshSpacePosition.Z) }; }