Skip to content

Conversation

@Dtsitos
Copy link

@Dtsitos Dtsitos commented Dec 17, 2025

Describe your changes

This PR adds read-only getters to the camera API to retrieve derived world-space
camera parameters (azimuth, elevation, and distance).

The values are computed from the camera position and focal point and do not
modify camera state. This enables external applications and bindings to query
camera orientation consistently without duplicating math.

No existing behavior is changed.

Issue ticket number and link if any

Fixes #1419
#1419

Checklist for finalizing the PR

  • I have performed a self-review of my code
  • I have added tests for new features and bugfixes
  • I have added documentation for new features
  • If it is a modifying the libf3d API, I have updated bindings
  • If it is a modifying the .github/workflows/versions.json, I have updated docker_timestamp

Continuous integration

\ci fast

@github-actions
Copy link

You are modifying libf3d public API! ⚠️Please update bindings accordingly⚠️!
You can find them in their respective directories: c, python, java, webassembly.

@mwestphal
Copy link
Member

Hello @Dtsitos

You do not seem to have used #2470 as a base, is that intended ?

@Dtsitos
Copy link
Author

Dtsitos commented Dec 17, 2025

Hello there @mwestphal and thank you for the quick reply,

I implemented the getters using the camera’s position and focal point with standard mathematical functions (sqrt, atan etc.) to provide world-space azimuth, elevation, and distance. This makes the code more simple, self-contained, and does not rely on renderer-specific environment vectors. Based on the issue description I think this is more desirable and less complex both to maintain and to understand.

If this is alright with you I will start working on the bindings ASAP.

@mwestphal
Copy link
Member

Hello there @mwestphal and thank you for the quick reply,

I implemented the getters using the camera’s position and focal point with standard mathematical functions (sqrt, atan etc.) to provide world-space azimuth, elevation, and distance. This makes the code more simple, self-contained, and does not rely on renderer-specific environment vectors. Based on the issue description I think this is more desirable and less complex both to maintain and to understand.

Indeed, that looks fine, but I defer to @snoyer and @Meakk for the actual implementation review.

shouldn't the method be called simply getElevation though ?

If this is alright with you I will start working on the bindings ASAP.

Lets add test first :)

@snoyer
Copy link
Contributor

snoyer commented Dec 17, 2025

does not rely on renderer-specific environment vectors

It does rely on the assumption that the environment's horizontal plane is XY and Z is up, which is not always the case in f3d because the user can provide a custom up direction vector.

@mwestphal
Copy link
Member

does not rely on renderer-specific environment vectors

It does rely on the assumption that the environment's horizontal plane is XY and Z is up, which is not always the case in f3d because the user can provide a custom up direction vector.

Right! It couldnt be that simple :)

@mwestphal
Copy link
Member

Need any help @Dtsitos ?

@Dtsitos
Copy link
Author

Dtsitos commented Dec 24, 2025

I am sorry for not responding earlier I was packing for vacation. I have made progress and I think my solution is correct now. I will try to send it here when I get back home in three days. If I am causing a delay in the project and someone else wants to solve it feel free to unassign me and thank you for your co-operation.

@mwestphal
Copy link
Member

No worries! enjoy your vacation :)

@Dtsitos
Copy link
Author

Dtsitos commented Dec 30, 2025

I think my solution should be complete now at least mathematically. I did work on the previous attempt another user made and mostly improved by avoiding code reuse with the helper function and doing the floating point check before normalising. Also I added some basic tests. If this solution seems alright I will try to work on the bindings. To be totally honest I have never worked with bindings before but I started reading up on that today.

Copy link
Member

Choose a reason for hiding this comment

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

@mwestphal
Copy link
Member

I think my solution should be complete now at least mathematically. I did work on the previous attempt another user made and mostly improved by avoiding code reuse with the helper function and doing the floating point check before normalising. Also I added some basic tests. If this solution seems alright I will try to work on the bindings. To be totally honest I have never worked with bindings before but I started reading up on that today.

Indeed, it looks fine :), lets focus on improving the testing first, but you can work on the bindings as well.

Copy link
Member

@mwestphal mwestphal left a comment

Choose a reason for hiding this comment

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

LGTM, please rebase on master and also push a to a feature branch instead of master, even on your own branch.

Comment on lines 91 to +93
class internals;
std::unique_ptr<internals> Internals;
void getPositionToFocalVector(vector3_t& vec) const;
Copy link
Member

@mwestphal mwestphal Jan 1, 2026

Choose a reason for hiding this comment

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

Suggested change
class internals;
std::unique_ptr<internals> Internals;
void getPositionToFocalVector(vector3_t& vec) const;
/**
* Add some doc
*/
void GetPositionToFocalVector(vector3_t& vec) const;
class internals;
std::unique_ptr<internals> Internals;


/** Return the camera azimuth angle in degrees */
[[nodiscard]] virtual double getWorldAzimuth() const = 0;
/** Return the camera elevation angle in degrees */
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
/** Return the camera elevation angle in degrees */
/** Return the camera elevation angle in degrees */

Comment on lines +145 to +150
vector3_t cross;
vtkMath::Cross(right, horizontal.data(), cross.data());
double sign = (vtkMath::Dot(cross.data(), up) >= 0.0) ? 1.0 : -1.0;

double angleRad = vtkMath::AngleBetweenVectors(right, horizontal.data());
return sign * vtkMath::DegreesFromRadians(angleRad);
Copy link
Contributor

Choose a reason for hiding this comment

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

can that be simplified with vtkMath::SignedAngleBetweenVectors?

Comment on lines +164 to +167
double dot = vtkMath::Dot(view.data(), up);
dot = std::clamp(dot, -1.0, 1.0);

return vtkMath::DegreesFromRadians(std::asin(dot));
Copy link
Contributor

Choose a reason for hiding this comment

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

can that be written in terms of AngleBetweenVectors?

@Dtsitos
Copy link
Author

Dtsitos commented Jan 2, 2026

Good evening (in my timezone at least) and happy new year!! I improved my documentation and my implementation for Azimuth based on the comment from @snoyer. I will start working on testing now. I made a new feature branch on my local repo as you requested but I am not accustomed to github and not sure how to change the pull request to not pull into f3d-app:master, could you help me with that?

@mwestphal
Copy link
Member

Good evening (in my timezone at least) and happy new year!! I improved my documentation and my implementation for Azimuth based on the comment from @snoyer. I will start working on testing now. I made a new feature branch on my local repo as you requested but I am not accustomed to github and not sure how to change the pull request to not pull into f3d-app:master, could you help me with that?

I'm afraid you need to create a new PR, there is no work around for this :)

@Dtsitos
Copy link
Author

Dtsitos commented Jan 2, 2026

Will do!

@mwestphal
Copy link
Member

Superseed by: #2767

@mwestphal mwestphal closed this Jan 2, 2026
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.

Add getters for camera parameters

3 participants