Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optional camera pitch/roll adjustment when portalling #103

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

vittorioromeo
Copy link

@vittorioromeo vittorioromeo commented Oct 13, 2023

Adds a new optional feature: the camera's pitch/roll can now follow the orientation of the exit portal when portalling. It looks like this:

https://i.imgur.com/CCBm79q.mp4

The feature is customizable through three config variables:

float m_PortallingDetectionDistanceThreshold; // The distance threshold used to detect portalling
bool m_ApplyPitchAndRollPortalRotationOffset; // If `true`, the camera pitch/roll follows the exit portal's orientation when portalling
float m_CameraUprightRecoverySpeed; // If the above is `true`, this controls how quickly the camera turns back upright after portalling

@sd805
Copy link

sd805 commented Oct 19, 2023

Just tested this out, the portaling feels a lot better to me! Nice work.

FYI, the pitch angle was slerping properly but the roll angle was still snapping instantly upright (since QAngle::VectorAngles was always giving finalAngles a roll value of 0). There's another QAngle::VectorAngles function that takes a forward vector and an up vector which will give the needed roll value.

Another thing to note is that slerping the roll value when it's at 180 is undefined (or in my case when the upSrc vector was opposite the upTarget vector). If you put two portals on the ground and go into one, it works, but the view stays upside down longer than it should. Clamping m_RotationOffset.z between -179 and 179 seems to fix it.

@sd805
Copy link

sd805 commented Oct 19, 2023

I'm also getting a bug where if a portal is on a 45 degree surface and another portal is on the floor, jumping into the floor portal tends to rotate my yaw by 180 when I exit. Not sure what's causing that one.

@sd805
Copy link

sd805 commented Oct 19, 2023

So I fixed the 180 degree yaw issue by setting finalAngles.y = lastYaw, but then when I jumped into the floor portal, coming out of the 45 degree portal caused the view to do a needless 180 degree roll. I figured out that if you come out of the 45 degree portal with a yaw greater than 90 (or less than -90), then that yaw value gets transformed to a negative roll value in QAngle::VectorAngles after slerping is done.

Instead of slerping the forward and up vectors, it seems like lerping m_RotationOffset's pitch, yaw, and roll individually to targetRotation's values fixes these issues.

@vittorioromeo
Copy link
Author

@sd805: nice! Those sound like good improvements. Do you have a full diff you can apply on top of this PR, or as GitHub review suggestions?

L4D2VR/vr.cpp Outdated Show resolved Hide resolved
Co-authored-by: sd805 <50186767+sd805@users.noreply.github.com>
@ORanGeOfficial
Copy link

Thank you for your hard work on this! I've been waiting for this fix since the VR mod release.
Could someone please help me to make it work?

Here's what I did:

  • I created a local copy of the original repository using:
    git clone --recurse-submodules https://github.com/Gistix/portal2vr.git
  • merged this PR using:
    git fetch origin pull/103/head
    git checkout -b pullrequest FETCH_HEAD
  • Replaced vr.cpp with this one
  • Fixed the game paths in l4d2vr.vcxproj
  • Opened l4d2vr.sln in VS2022, changed x64 to x86 and built it.
  • Copied d3d9.dll from the Release folder to the Portal 2\bin folder.
  • Got 3 errors on the game start, so I added the following lines to the Portal 2\VR\config.txt file:
    PortallingDetectionDistanceThreshold=35
    ApplyPitchAndRollPortalRotationOffset=true
    CameraUprightRecoverySpeed=0.2
    The errors disappeared, but the camera transition is still instant, so I can't play the game.
    I also tried CameraUprightRecoverySpeed 0.0001, 0.001 and 0.01, nothing changed.

@ORanGeOfficial
Copy link

So I fixed the 180 degree yaw issue by setting finalAngles.y = lastYaw, but then when I jumped into the floor portal, coming out of the 45 degree portal caused the view to do a needless 180 degree roll. I figured out that if you come out of the 45 degree portal with a yaw greater than 90 (or less than -90), then that yaw value gets transformed to a negative roll value in QAngle::VectorAngles after slerping is done.

Instead of slerping the forward and up vectors, it seems like lerping m_RotationOffset's pitch, yaw, and roll individually to targetRotation's values fixes these issues.

Can you please help me to make this fix work? Or just share the compiled d3d9.dll? Above I posted what I tried.

It seems like the mod creator doesn't care about merging this branch, but lack of this feature stops me and a many other guys issues/107, issues/55 from starting to play.

Thank you!

@sd805
Copy link

sd805 commented Oct 31, 2023

@ORanGeOfficial Sure. Here's my d3d9.dll and config.txt

camUpdate.zip

@ORanGeOfficial
Copy link

@ORanGeOfficial Sure. Here's my d3d9.dll and config.txt

camUpdate.zip

Thank you so much! Now everything works perfectly!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants