X Tutup
Skip to content

Vector3 ZERO#6259

Merged
sturnclaw merged 1 commit intopioneerspacesim:masterfrom
fluffyfreak:vector3-ZERO
Jan 2, 2026
Merged

Vector3 ZERO#6259
sturnclaw merged 1 commit intopioneerspacesim:masterfrom
fluffyfreak:vector3-ZERO

Conversation

@fluffyfreak
Copy link
Contributor

@fluffyfreak fluffyfreak commented Dec 5, 2025

Added a static const member variable for ZERO Zero values to vector3 and replaced all instances of using vector3d(0, 0, 0) in the code I could find.

Did not do the same for cases of vector3f(0.f, 0.f, 0.f) as this often made sense in the situatiuns that it is used.

EDIT:
Changed the usage of matrix3x3::Identity() and matrix4x4::Identity() static functions to be a static const member named Identity and the Identity() renamed to IdentityFunc(). Also deleted the lightly used matrix4x4fIdentity and other values in favour of matrix4x4f::Identity

@sturnclaw
Copy link
Member

Devil's advocate: does this make a difference in codegen outside of non-optimizing builds (i.e. debug without -Og)? The vector3 constructor is trivial and a candidate for constexpr. Additionally, the zero-argument default constructor initializes a vector3 to zero automatically (to prevent bugs with uninitialized vectors).

On the whole, this is probably better for consistency. It's easier to miss a non-zero constant in the explicit initializer form. One thing I'd like to see is for the matrix4x4fIdentity variables be moved to matrix4x4f::IDENTITY instead.

Final thought: the all-uppercase naming is appropriate for enumeration constants and macros, but as this is neither a macro nor an enum I think vector3f::Zero is more appropriate?

@fluffyfreak
Copy link
Contributor Author

This was initially less about the quality of code gen and was more of a quality of life coding change for me. It was really annoying me seeing all of these calls to vector3f(0.f, 0.f, 0.f) everywhere! I initially changed them to use the default ctor but in some places the code became less readable, so I added the constant ZERO to make them clearer.

I've now done the matrix classes Identity functions making them into a static const and removed the other static const matrix4x4fIdentity like values

Copy link
Member

@sturnclaw sturnclaw left a comment

Choose a reason for hiding this comment

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

Hurray!

@sturnclaw sturnclaw merged commit 112c6a7 into pioneerspacesim:master Jan 2, 2026
4 checks passed
@fluffyfreak fluffyfreak deleted the vector3-ZERO branch January 3, 2026 12:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

X Tutup