question about matrix transformation

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
Zeus
Posts: 24
Joined: Sun Dec 13, 2009 1:03 pm
Location: Germany :P

question about matrix transformation

Post by Zeus »

Hi,

i have a question about the matrix in irrlicht ... for my needs i have to initialize a matrix like that

Code: Select all

  matTransform._11(AgentHeading.x); matTransform._12(AgentSide.x);
  matTransform._21(AgentHeading.y); matTransform._22(AgentSide.y);
  matTransform._31(Tx);           matTransform._32(Ty);
but i have no acces to the members of the matrix ...

does anyone knows a way to do taht ?

thanks for helping
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Post by Acki »

I didn't try, but maybe something like this:

Code: Select all

matrix4 matTransform;
matTransform(1,1) = AgentHeading.x;
EDIT: I don't know if the indices of the matrix you used are starting with 0
if not then it also can be like this:

Code: Select all

matrix4 matTransform;
matTransform(0,0) = AgentHeading.x;
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

You can also access the fields via operator[]. Both functions start with 0 index.
Zeus
Posts: 24
Joined: Sun Dec 13, 2009 1:03 pm
Location: Germany :P

Post by Zeus »

thanks for your answers ... ;) ... i'll try it, but it will take a while till i can say you if it works ...

thanks again ;)

zeus
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Post by Acki »

I had a quick search and I found that your matrix probably is a DX matrix:

Code: Select all

// D3DMATRIX
typedef struct _D3DMATRIX {
    union {
        struct {
            float        _11, _12, _13, _14;
            float        _21, _22, _23, _24;
            float        _31, _32, _33, _34;
            float        _41, _42, _43, _44;

        };
        float m[4][4];
    };
} D3DMATRIX;
so it doesn't start with index 0, but with index 1 !!!
and because of this you'll have to decrement the indices !!!

Code: Select all

matrix4 matTransform;
matTransform(0,0) = AgentHeading.x; matTransform(0,1) = AgentSide.x
matTransform(1,0) = AgentHeading.y; matTransform(1,1) = AgentSide.y
matTransform(2,0) = Tx;             matTransform(2,1) = Ty;
if you want to use the [] operator the indices are like this:

Code: Select all

(0,0) => [0]
(0,1) => [1]
(0,2) => [2]
(0,3) => [3]
(1,0) => [4]
(1,1) => [5]
(1,2) => [6]
...
(3,3) => [15]
and then your code should look like this:

Code: Select all

matrix4 matTransform;
matTransform[0] = AgentHeading.x; matTransform[1] = AgentSide.x
matTransform[4] = AgentHeading.y; matTransform[5] = AgentSide.y
matTransform[8] = Tx;             matTransform[9] = Ty;
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
Zeus
Posts: 24
Joined: Sun Dec 13, 2009 1:03 pm
Location: Germany :P

Post by Zeus »

hey ... thanks for your answer ... i couldn't test it so far couse an other problem occourred ...

i could determinate it to the function where the local space should be convert to global sapce ...

the function (with the 3x3 matrix out of my "tutorial") should look like this

Code: Select all

inline Vector2D PointToWorldSpace(const Vector2D &point,
                                    const Vector2D &AgentHeading,
                                    const Vector2D &AgentSide,
                                    const Vector2D &AgentPosition)
{
	//make a copy of the point
  Vector2D TransPoint = point;
  
  //create a transformation matrix
	C2DMatrix matTransform;

	//rotate
	matTransform.Rotate(AgentHeading, AgentSide);

	//and translate
	matTransform.Translate(AgentPosition.x, AgentPosition.y);
	
  //now transform the vertices
  matTransform.TransformVector2Ds(TransPoint);

  return TransPoint;
}
i tryed to do it (with the irrlicht matrix) like this

Code: Select all

	core::vector3df PointToWorldSpace(	core::vector3df point,
										core::vector3df agentHeading,
										core::vector3df agentSide,
										core::vector3df agentPosition )
	{
		core::vector3df TPoint = point;
		core::CMatrix4<float> transformMatrix;
		transformMatrix.rotateVect(agentHeading,agentSide);

		transformMatrix.translateVect(agentPosition);
		transformMatrix.transformVect(TPoint);
		return TPoint;
	}
(there should only be a rotation on the z-axis ) ...

but the problem is thet somthing dont work correct ... TPoint is always the same like point ... does someone knows what dosn't works ?

regards zeus
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Post by Acki »

you create a new matrix, so everything is initialised to 0 by default for it:

Code: Select all

core::CMatrix4<float> transformMatrix;
you rotate agentSide by the matrix (still everything is 0 for the matrix) and return it by agentHeading, so no changes to agentSide, but agentHeading gets the same value as agentSide:

Code: Select all

transformMatrix.rotateVect(agentHeading,agentSide);
then you translate agentPosition by the matrix (still everything is 0 for the matrix):

Code: Select all

transformMatrix.translateVect(agentPosition);
and finally you transform TPoint by the matrix (still everything is 0 for the matrix)

Code: Select all

transformMatrix.transformVect(TPoint);
I hope you see that TPoint can't be changed, because the matrix has set all values to defaults (0) for the whole function !!! :lol:
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
Post Reply