Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Make sf::Transform.getMatrix not const.  (Read 4232 times)

0 Members and 1 Guest are viewing this topic.

StephenLynx

  • Newbie
  • *
  • Posts: 2
    • View Profile
Make sf::Transform.getMatrix not const.
« on: August 17, 2018, 03:39:06 pm »
This is the use case: when you want to set a translation from something else into a sfml drawable, it's more practical to handle the whole transform at once directly from the source instead of converting and setting every single detail.

For example, bullet3d exposes rigid bodies' transformation both for reading and writing using opengl matrices. So it's much more practical to use getOpenGLMatrix and use this matrix to draw something rather than picking each value, converting and then setting into the transform.

As it stands, one has to cast the const float* into a regular float*, making it for less readable code and maybe performance loss. I didn't check but I wouldn't be surprised, after all it's more stuff being done.

I have an example here:
https://pastebin.com/NxBJJtYr

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Make sf::Transform.getMatrix not const.
« Reply #1 on: August 17, 2018, 10:15:54 pm »
sf::Transform is a 2D matrix (3x3), thus adding a way to directly stuff a 4x4 matrix there is a non-sense. The float[16] return of getMatrix() is there for convenience of use with OpenGL; a 2D matrix is a 3D matrix (with the proper padding), but not the other way round.

And if you want to directly set the 3x3 elements of the sf::Transform, then there is this constructor.

Quote
one has to cast the const float* into a regular float*, making it for less readable code and maybe performance loss
It would be ok if it was less readable and less performant. But it's actually undefined behavior. So don't do that ;)
Laurent Gomila - SFML developer