Example #1
0
void ABitPiece::AddPieceMesh(UStaticMesh *PieceMesh)
{
	PieceMeshComponent->SetStaticMesh(PieceMesh);

	PieceMeshComponent->OnClicked.AddDynamic(this, &ABitPiece::PieceClicked);
	PieceMeshComponent->OnBeginCursorOver.AddDynamic(this, &ABitPiece::PieceMouseOver);
	PieceMeshComponent->OnEndCursorOver.AddDynamic(this, &ABitPiece::PieceMouseOut);

	FVector orgin;
	FVector boundsExtent;
	GetActorBounds(false, orgin, boundsExtent);

	// Update Width whenever is added a mesh to the piece;
	Width = boundsExtent.X * 2;

	//Setting the highlight effect
	PieceHighlightMeshComponent->SetStaticMesh(PieceMesh);

	auto world = GetWorld();
	auto gameMode = (ABoardGameGameMode*)world->GetAuthGameMode();
	PieceHighlightMeshComponent->SetRenderCustomDepth(true);
	PieceHighlightMeshComponent->SetMaterial(0, gameMode->HighlightMaterial);
	PieceHighlightMeshComponent->SetVisibility(false); 
	
}
// Called when the game starts or when spawned
void AHunterProjectile::BeginPlay()
{
	Super::BeginPlay();
	
	FVector origin, extent;
	GetActorBounds(false, origin, extent);

	m_projectileHitRadius = extent.GetMax();
}
void AEyeXSimpleInteractorPawn::UpdateRegion()
{
	FVector Origin;
	FVector Extents;
	GetActorBounds(false, Origin, Extents);

	auto playerController = Cast<APlayerController>(Controller);
	ULocalPlayer* LocalPlayer = Cast<ULocalPlayer>(playerController->Player);

	auto ViewFamilyArguments = FSceneViewFamily::ConstructionValues(LocalPlayer->ViewportClient->Viewport, GetWorld()->Scene, LocalPlayer->ViewportClient->EngineShowFlags);
	ViewFamilyArguments.SetRealtimeUpdate(true);
	FSceneViewFamilyContext ViewFamily(ViewFamilyArguments);

	// Calculate a view where the player is to update the streaming from the players start location
	FVector ViewLocation;
	FRotator ViewRotation;
	FSceneView* SceneView = LocalPlayer->CalcSceneView(&ViewFamily, /*out*/ ViewLocation, /*out*/ ViewRotation, LocalPlayer->ViewportClient->Viewport);

	FVector2D ExtentPoints[8];
	SceneView->WorldToPixel(Origin + FVector(Extents.X, Extents.Y, Extents.Z), ExtentPoints[0]); //Right Top Front
	SceneView->WorldToPixel(Origin + FVector(Extents.X, Extents.Y, -Extents.Z), ExtentPoints[1]); //Right Top Back
	SceneView->WorldToPixel(Origin + FVector(Extents.X, -Extents.Y, Extents.Z), ExtentPoints[2]); //Right Bottom Front
	SceneView->WorldToPixel(Origin + FVector(Extents.X, -Extents.Y, -Extents.Z), ExtentPoints[3]); //Right Bottom Back
	SceneView->WorldToPixel(Origin + FVector(-Extents.X, Extents.Y, Extents.Z), ExtentPoints[4]); //Left Top Front
	SceneView->WorldToPixel(Origin + FVector(-Extents.X, Extents.Y, -Extents.Z), ExtentPoints[5]); //Left Top Back
	SceneView->WorldToPixel(Origin + FVector(-Extents.X, -Extents.Y, Extents.Z), ExtentPoints[6]); //Left Bottom Front
	SceneView->WorldToPixel(Origin + FVector(-Extents.X, -Extents.Y, -Extents.Z), ExtentPoints[7]); //Left Bottom Back

	FVector2D TopLeft = FVector2D(std::numeric_limits<float>::max(), std::numeric_limits<float>::max());
	FVector2D BottomRight = FVector2D(std::numeric_limits<float>::min(), std::numeric_limits<float>::min());

	for (auto Point : ExtentPoints)
	{
		if (Point.X < TopLeft.X)
			TopLeft.X = Point.X;
		else if (Point.X > BottomRight.X)
			BottomRight.X = Point.X;

		if (Point.Y < TopLeft.Y)
			TopLeft.Y = Point.Y;
		else if (Point.Y > BottomRight.Y)
			BottomRight.Y = Point.Y;
	}

	MyRegion->bounds.left = TopLeft.X;
	MyRegion->bounds.top = TopLeft.Y;
	MyRegion->bounds.right = BottomRight.X;
	MyRegion->bounds.bottom = BottomRight.Y;
}
Example #4
0
/** Returns the docking location in world space */
FVector ACargo::GetDockingLocation() {
    FVector pos = DockingLocation;
    FVector origin, extent;
    GetActorBounds(true, origin, extent);
    
    extent /= 2;
    
    pos *= extent;
    pos = GetActorRotation().RotateVector(pos);
    pos += origin;
    
    //GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, FString::Printf(TEXT("DockLoc: %f, %f, %f"), pos.X, pos.Y, pos.Z));
    
    return pos;
}