Phase 2C: Mouse click raycast input for face rotation

- Added ProcessClick(RayOrigin, RayDirection, bCounterClockwise)
- Maps hit normal to cube face and queues RotateFace()
- Ignores clicks on internal/non-axis-aligned faces
- Build: TBD
This commit is contained in:
axiomlogicnexus 2026-06-10 06:29:18 +00:00
parent 5040d00ec0
commit 8551a726fa
2 changed files with 49 additions and 0 deletions

View file

@ -58,6 +58,45 @@ void AHyperTwistClassicCubeActor::ResetCube()
GenerateCube();
}
bool AHyperTwistClassicCubeActor::ProcessClick(const FVector& RayOrigin, const FVector& RayDirection, bool bCounterClockwise)
{
if (!GetWorld())
{
return false;
}
FHitResult Hit;
FCollisionQueryParams Params(SCENE_QUERY_STAT(CubeClick), false, this);
const FVector End = RayOrigin + RayDirection * 10000.0f;
bool bHit = GetWorld()->LineTraceSingleByChannel(Hit, RayOrigin, End, ECC_Visibility, Params);
if (!bHit || !Hit.GetComponent())
{
return false;
}
// Map hit normal to cube face
const FVector& Normal = Hit.ImpactNormal;
EHyperTwistClassicCubeFace Face = EHyperTwistClassicCubeFace::Up;
bool bValidFace = true;
if (FMath::IsNearlyEqual(Normal.Z, 1.0f)) Face = EHyperTwistClassicCubeFace::Up;
else if (FMath::IsNearlyEqual(Normal.Z, -1.0f)) Face = EHyperTwistClassicCubeFace::Down;
else if (FMath::IsNearlyEqual(Normal.Y, 1.0f)) Face = EHyperTwistClassicCubeFace::Front;
else if (FMath::IsNearlyEqual(Normal.Y, -1.0f)) Face = EHyperTwistClassicCubeFace::Back;
else if (FMath::IsNearlyEqual(Normal.X, 1.0f)) Face = EHyperTwistClassicCubeFace::Right;
else if (FMath::IsNearlyEqual(Normal.X, -1.0f)) Face = EHyperTwistClassicCubeFace::Left;
else bValidFace = false;
if (!bValidFace)
{
return false;
}
RotateFace(Face, bCounterClockwise ? EHyperTwistRotationDirection::CounterClockwise : EHyperTwistRotationDirection::Clockwise);
return true;
}
void AHyperTwistClassicCubeActor::ClearPieces()
{
for (const FTrackedPiece& Piece : TrackedPieces)

View file

@ -54,6 +54,16 @@ public:
UFUNCTION(BlueprintCallable, Category = "HyperTwist|Cube")
void ResetCube();
/**
* Process a click ray. If it hits a visible cube face, rotates that face.
* @param RayOrigin World-space ray origin (e.g. camera location)
* @param RayDirection World-space ray direction (normalized)
* @param bCounterClockwise If true, rotate counter-clockwise; else clockwise
* @return True if a face was hit and rotation was queued
*/
UFUNCTION(BlueprintCallable, Category = "HyperTwist|Cube")
bool ProcessClick(const FVector& RayOrigin, const FVector& RayDirection, bool bCounterClockwise = false);
virtual void OnConstruction(const FTransform& Transform) override;
protected: