Skip to content

Template function fixes and left-handedness consistency#46

Open
srinbeen wants to merge 7 commits into
NVIDIA-RTX:mainfrom
srinbeen:fixes
Open

Template function fixes and left-handedness consistency#46
srinbeen wants to merge 7 commits into
NVIDIA-RTX:mainfrom
srinbeen:fixes

Conversation

@srinbeen
Copy link
Copy Markdown

@srinbeen srinbeen commented Apr 1, 2026

  • rotationQuat in quat.h used an undefined constructor, template was edited to use the fromWXYZ function instead
  • distance and distanceSquared defined in vector.h. dm::box3::distance calls dm::float3::distance but template is not defined for vector. dm::box3::distance now calls dm::float3::length instead
  • dm::box3::operator*= has a const qualifier even though *= is modifying the internals, and is now removed
  • created separate projection matrix and view matrix setters so that application does not have to rewrite both if only one needs to get updated. Useful for example where projection matrix stays constant between frames (unless window size changes).
  • FirstPersonCamera now updates its basis vectors in accordance with a left-handed coordinate system. Fixes a bug where calling FirstPersonCamera::LookTo in application would flicker camera when updating position or direction of camera with keyboard/mouse because the wrong basis vectors are updated with translation and roll/pitch/yaw

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 1, 2026

CLA Assistant Lite bot All contributors have signed the CLA ✍️ ✅

@srinbeen
Copy link
Copy Markdown
Author

srinbeen commented Apr 1, 2026

I have read the CLA Document and I hereby sign the CLA

Comment thread include/donut/core/math/vector.h Outdated
template <typename T, int n>
T distance(vector<T, n> const & a, vector<T, n> const & b)
{ return length(a-b); }

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

this is redundant with the length functions - please remove

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

should I update box3::distance to use float3::length instead?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

yes please - good catch

@manuelkNVDA
Copy link
Copy Markdown
Contributor

calling FirstPersonCamera::LookTo in application

i don't think these functions have been used in a long time (or the donut samples)

has this change been tested and is working in both Vk and D3D ?

@srinbeen
Copy link
Copy Markdown
Author

srinbeen commented Apr 2, 2026

has this change been tested and is working in both Vk and D3D ?

I've tested my application and the FeatureDemo with both Vk and D3D and they work as expected!

@manuelkNVDA
Copy link
Copy Markdown
Contributor

right - but neither use this code path because they do not toggle between orbit / fps modes

i take it that your app is left-handed only ? (D3D ?)

donut needs to be both IIRC

@srinbeen
Copy link
Copy Markdown
Author

srinbeen commented Apr 2, 2026

right - but neither use this code path because they do not toggle between orbit / fps modes

I believe the feature demo does toggle between the two.
Is this what you meant?

FeatureDemo.cpp

BaseCamera& GetActiveCamera() const
{
    return m_ui.UseThirdPersonCamera ? (BaseCamera&)m_ThirdPersonCamera : (BaseCamera&)m_FirstPersonCamera;
}
...
void CopyActiveCameraToFirstPerson()
{
    if (m_ui.ActiveSceneCamera)
    {
        dm::affine3 viewToWorld = m_ui.ActiveSceneCamera->GetViewToWorldMatrix();
        dm::float3 cameraPos = viewToWorld.m_translation;
        m_FirstPersonCamera.LookAt(cameraPos, cameraPos + viewToWorld.m_linear.row2, viewToWorld.m_linear.row1);
    }
    else if (m_ui.UseThirdPersonCamera)
    {
        m_FirstPersonCamera.LookAt(m_ThirdPersonCamera.GetPosition(), m_ThirdPersonCamera.GetPosition() + m_ThirdPersonCamera.GetDir(), m_ThirdPersonCamera.GetUp());
    }
}

@manuelkNVDA
Copy link
Copy Markdown
Contributor

i stand corrected : feature demo does use it with the 'T' button switch

if your change works for both Vk & D3D when toggling, then all good (for some reason feature demo crashes on launch for me, so i can't test on my end right now)

@srinbeen
Copy link
Copy Markdown
Author

srinbeen commented Apr 2, 2026

Seems to work on both backends for me. I had to change the path of the glTF sample assets in order for it to run I think. And I am specifically using LookAt to initialize my first person camera in my own application.

@srinbeen
Copy link
Copy Markdown
Author

srinbeen commented Apr 4, 2026

If it makes it easier to merge the other changes, I can undo the changes to Camera.cpp and make a separate PR for that later.

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.

2 participants