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

Author Topic: I need the Transform.GetMatrix() function but it isn't there!  (Read 8401 times)

0 Members and 2 Guests are viewing this topic.

Rob92

  • Newbie
  • *
  • Posts: 35
    • View Profile
    • Email
Hello,

So I need to access some values from the matrix, in C++ I used to call transform.getMatrix() but there doesnt seem to be a function like this in the .NET version of SFML.

Why not?
And how can I still access the individual values of the matrix?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: I need the Transform.GetMatrix() function but it isn't there!
« Reply #1 on: March 13, 2016, 10:54:32 pm »
sf::Transform::getMatrix is used internally, for interaction with OpenGL. The internal matrix uses an undocumented layout and is thus hardly usable outside SFML.

So... why do you need this function?
Laurent Gomila - SFML developer

Rob92

  • Newbie
  • *
  • Posts: 35
    • View Profile
    • Email
Re: I need the Transform.GetMatrix() function but it isn't there!
« Reply #2 on: March 14, 2016, 12:53:30 am »
Hi Laurent, Thanks for you reply.

That's kinda what I suspected, I can probably do this another way as well.
I am porting my C++ framework to C#.
Currently in the C++ project I use the matrix values to extract the rotation at a specific point in time (when my world transform has been recalculated) which I need for setting my up and right vector. (I dont use the Transformable thing)

const float* m = m_worldTransform.getMatrix();
float rot = -atan2f(m[4], m[5]);

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: I need the Transform.GetMatrix() function but it isn't there!
« Reply #3 on: March 14, 2016, 08:16:13 am »
There is probably another way, yes. At worst you can extract a column from the matrix by multiplying it with the corresponding unit vector.
Laurent Gomila - SFML developer

Rob92

  • Newbie
  • *
  • Posts: 35
    • View Profile
    • Email
Re: I need the Transform.GetMatrix() function but it isn't there!
« Reply #4 on: March 14, 2016, 11:02:39 am »
I've googled around abit, everyone suggests accessing matrix values to do this.
My math isn't that good, do you know how to calculate this without access to the values?  :-\

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: I need the Transform.GetMatrix() function but it isn't there!
« Reply #5 on: March 14, 2016, 11:19:57 am »
Aren't your "up" and "right" vectors columns of the matrix? How do you recompute them? What's different?
Laurent Gomila - SFML developer

Rob92

  • Newbie
  • *
  • Posts: 35
    • View Profile
    • Email
Re: I need the Transform.GetMatrix() function but it isn't there!
« Reply #6 on: March 14, 2016, 12:42:49 pm »
I compute them likes this:

            const float* m = m_worldTransform.getMatrix();
                        float rot = -atan2f(m[4], m[5]);
                       
                        float upRot = rot - 1.57079633f;
                        int roti = (int)(-rot / (PI * 2) * LOOKUP_SIZE) & (LOOKUP_SIZE - 1);
                        int upRoti = (int)(-upRot / (PI * 2) * LOOKUP_SIZE) & (LOOKUP_SIZE - 1);

                        m_up.x          =  cosLookup[upRoti];
                        m_up.y          = -sinLookup[upRoti];
                        m_right.x       =  cosLookup[roti];
                        m_right.y       = -sinLookup[roti];

For calculation my local matrix I use roughly the same code as in sf::Transformable, then I multiple it by it's parent global matrix for my scene graph. After that I do this right/up calculation on my own global matrix.
If thats what you were asking?

zsbzsb

  • Hero Member
  • *****
  • Posts: 1409
  • Active Maintainer of CSFML/SFML.NET
    • View Profile
    • My little corner...
    • Email
Re: I need the Transform.GetMatrix() function but it isn't there!
« Reply #7 on: March 14, 2016, 04:41:59 pm »
Either way, it is missing from the SFML.Net bindings so it should be added as it is part of the public API.
Motion / MotionNET - Complete video / audio playback for SFML / SFML.NET

NetEXT - An SFML.NET Extension Library based on Thor

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: I need the Transform.GetMatrix() function but it isn't there!
« Reply #8 on: March 14, 2016, 05:47:27 pm »
Quote
Either way, it is missing from the SFML.Net bindings so it should be added as it is part of the public API.
Public access and public API are two different things. Just because something can be accessed in the C++ API doesn't mean that it should be published in bindings; sometimes things are for internal use only (C++ doesn't have a "internal" access keyword). And this is the case here, the function is not missing, it has been omitted on purpose.
Laurent Gomila - SFML developer

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: I need the Transform.GetMatrix() function but it isn't there!
« Reply #9 on: March 14, 2016, 06:55:58 pm »
friend should be considered for such cases. Contrary to popular belief, the friend keyword does not break but increase encapsulation if used meaningfully.

But I agree that it sometimes makes things more complicated, and it also adds a name dependency. It might still be worth the drawbacks, because as a user, it's impossible to know what is public API and what isn't, especially since both are documented the same way.

The access idiom is also a nice way to provide restricted access without knowing the clients:
namespace priv
{
    struct TransformAccess
    {
        static float* getMatrix(Transform& transform);
    };
}

class Transform
{
    friend struct TransformAccess;
};
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Rob92

  • Newbie
  • *
  • Posts: 35
    • View Profile
    • Email
Re: I need the Transform.GetMatrix() function but it isn't there!
« Reply #10 on: March 15, 2016, 01:11:34 am »
would make sense if the syntax was identical, unless the language doesnt allow it.
Also, I think its fairly common to access matrix values for various tasks.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: I need the Transform.GetMatrix() function but it isn't there!
« Reply #11 on: March 15, 2016, 08:52:53 am »
Quote
friend should be considered for such cases. Contrary to popular belief, the friend keyword does not break but increase encapsulation if used meaningfully.
I'm not the one to be convinced about the usefulness of this keyword ;)
I use it a lot, but only when the involved classes are clearly identified -- for example, when two classes work closely together. In this particular case, sf::Transform has no idea who will be in charge of passing its internal matrix to OpenGL, it may even be more than one class. Of course I could just have a look at the code and identify these classes, but this is the kind of things that may change often as the implementation evolves.

Quote
The access idiom is also a nice way to provide restricted access without knowing the clients
True.

After looking again at the function, I see that it is clearly documented and not marked "for internal use". There's even an example of how to use it directly with OpenGL. So I guess it was supposed to be part of the public API after all ;D (it's even in the C binding...)

Laurent Gomila - SFML developer

Rob92

  • Newbie
  • *
  • Posts: 35
    • View Profile
    • Email
Re: I need the Transform.GetMatrix() function but it isn't there!
« Reply #12 on: March 15, 2016, 04:42:05 pm »
I just noticed the ToString in the source, I can use this, parse the string and get the values ><

public override string ToString()
            {
                return string.Format("[Transform]" +
                       " Matrix(" +
                       "{0}, {1}, {2}," +
                       "{3}, {4}, {5}," +
                       "{6}, {7}, {8}, )",
                       m00, m01, m02,
                       m10, m11, m12,
                       m20, m21, m22);
            }

            float m00, m01, m02;
            float m10, m11, m12;
            float m20, m21, m22;

I'm joking of course, I figured another way to calculate it.
« Last Edit: March 15, 2016, 11:56:48 pm by Rob92 »

 

anything