Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 32 additions & 1 deletion StarryExpanse/EverPresent/StrangerController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,44 @@ void AStrangerController::AddHorizontalMouseScan(float amount) {
if (!IsCursorLockedToCenter) {
HorizontalMousePosition =
FMath::Clamp(HorizontalMousePosition + amount, 0.0f, 1.0f);

// check to see if we're within +tolerance for screen border
if (1 - HorizontalMousePosition < HorizontalMouseNudgeThreshold)
{
//rotate the camera in accordance with how close the cursor is to the edge of the screen
this->AddYawInput(HorizontalMouseNudgeThreshold -
(1 - HorizontalMousePosition));
}

// check to see if we're within -tolerance for screen border
if (HorizontalMousePosition < HorizontalMouseNudgeThreshold)
{
// rotate the camera in accordance with how close the cursor is to the edge of the screen
this->AddYawInput(
-(HorizontalMouseNudgeThreshold - HorizontalMousePosition));
}
}
}

void AStrangerController::AddVerticalMouseScan(float amount) {
if (!IsCursorLockedToCenter) {
VerticalMousePosition =
FMath::Clamp(VerticalMousePosition + amount, 0.0f, 1.0f);

// check to see if we're within +tolerance for screen border
if (1 - VerticalMousePosition < VerticalMouseNudgeThreshold)
{
// rotate the camera in accordance with how close the cursor is to the edge of the screen
this->AddPitchInput(
VerticalMouseNudgeThreshold - (1 - VerticalMousePosition));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not certain this is the right expression. We would want the amount nudged to be proportional to how much of the threshold has been moved across. If the cursor has barely impinged into the threshold, let's say 1% of the threshold, then this pitch input argument would be VerticalMouseNudgeThreshold * 99%. If the cursor has impinged a lot (50%), the number would be less, VerticalMouseNudgeThreshold * 50%. Does that sound right? Either way, some more explicit variable names would make things a bit clearer. For instance

auto farImpingement = FMath::Clamp(1 - VerticalMousePosition, 0.0f, 1.0f);
auto nearImpingement = FMath::Clamp(VerticalMousePosition, 0.0f, 1.0f);

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in testing the current code appears to do just that - if the cursor is closer to the edge, the camera moves faster. if nearer to the center, it moves slower.
intent was to avoid making more variables/function calls than necessary.
may be more of a style thing. happy to use clamp instead if desired.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I think I ironed out why this is weird to me: the bigger the threshold is, the more the maximum camera spin velocity will be. Basically you have v = t - y where v is velocity, t is threshold size, and y is measured coordinate. The maximum velocity will be y = 0, so v = t - 0 = t. So v is proportional to t. What seems more natural to me would be v = (displacement of cursor into threshold region) / (size of threshold region). In other words, for the top region, that'd be v = y / t and so on.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i see what you're saying. it's a bit counter-intuitive but knowing that the screen space in this function is measured from -1.0 to 1.0 it seemed to be the method that required the fewest calculations and function calls. also, the commit last night allows for a multiplier so you can have a really small threshold and a really fast (or slow) turn rate.

}

// check to see if we're within -tolerance for screen border
if (VerticalMousePosition < VerticalMouseNudgeThreshold)
{
// rotate the camera in accordance with how close the cursor is to the edge of the screen
this->AddPitchInput(-(VerticalMouseNudgeThreshold - VerticalMousePosition));
}
}
}

Expand All @@ -111,7 +142,7 @@ void AStrangerController::EnterCursorMode(bool fixed) {
VerticalMousePosition = 0.5;
} else {
this->IsCursorLockedToCenter = false;
this->IgnoreLookInput = 1;
//this->IgnoreLookInput = 1;
}
}

Expand Down
8 changes: 8 additions & 0 deletions StarryExpanse/EverPresent/StrangerController.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,14 @@ class STARRYEXPANSE_API AStrangerController : public APlayerController {
UPROPERTY()
float VerticalMousePosition = 0.5;

//how close (%) to the edge of the left/right of the screen you can get (in cursor mode) before the camera begins to pan
UPROPERTY(BlueprintReadWrite)
float HorizontalMouseNudgeThreshold = 0.25;

//how close (%) to the edge of the top/bottom of the screen you can get (in cursor mode) before the camera begins to pan
UPROPERTY(BlueprintReadWrite)
float VerticalMouseNudgeThreshold = 0.25;

UFUNCTION()
void Cbk_MenuStateChanged();

Expand Down
Empty file modified fix-formatting.sh
100755 → 100644
Empty file.
Empty file modified process-devices.py
100755 → 100644
Empty file.