Gistix / portal2vr

Portal 2 VR Mod
740 stars 19 forks source link

Optional camera pitch/roll adjustment when portalling #103

Open vittorioromeo opened 9 months ago

vittorioromeo commented 9 months ago

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 commented 8 months ago

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 commented 8 months ago

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 commented 8 months ago

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 commented 8 months ago

@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?

ORanGeOfficial commented 8 months ago

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:

ORanGeOfficial commented 8 months ago

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 commented 8 months ago

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

camUpdate.zip

ORanGeOfficial commented 8 months ago

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

camUpdate.zip

Thank you so much! Now everything works perfectly!