AbsoluteTransform (can i get that data from outside?)

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
powerpop
Posts: 171
Joined: Thu Jan 08, 2004 1:39 am
Location: san francisco

AbsoluteTransform (can i get that data from outside?)

Post by powerpop »

i have been working on a tokamak object and someone here in the forums published the way to match the rotation by using scenenodes absolute transform - it seems like this method is private to scenenode - my tokamak object is not based on scenenode so i cant get access to it - is there another way to get this information? here is the code:

Code: Select all

   neQ q = body->GetRotationQ();
   neM4 neMatrix = q.BuildMatrix();
   neMatrix.SetTranslation(body->GetPos());
   for (int x=0; x < 4; x++)
   {
      for (int y=0; y < 4; y++)
      {
         node->AbsoluteTransformation(y,x) = neMatrix.M[x][y];
      }
   }
powerpop
Posts: 171
Joined: Thu Jan 08, 2004 1:39 am
Location: san francisco

Post by powerpop »

i found a method called getAbsoluteTransform - does this send back the pointer to the internal matrix or does it send back a copy? (I dont know what the & means in the method def - my c++ is a little rusty around the edges ;)

here is how i modified my code - and i dont know how to set an element of the trans matrix that i get from node?

Code: Select all

	irr::core::matrix4* trans;
	node->getAbsoluteTransformation();
	neQ q = body->GetRotationQ();
	neM4 neMatrix = q.BuildMatrix();
	neMatrix.SetTranslation(body->GetPos());

	for (int x=0; x < 4; x++)
	{
		for (int y=0; y < 4; y++)
		{
			trans(y,x) = neMatrix.M[x][y];
		}
	}
powerpop
Posts: 171
Joined: Thu Jan 08, 2004 1:39 am
Location: san francisco

Post by powerpop »

anyone have a lead for me here??

i almost have the tokamak objects finished if i can just figure out this matrix entry format! i made one object that gets associated with your scenenode (in a game object probably) - and then a physicsupdater that manages the update based on an outside clock - its nice and i will publish it as soon as i can test it out ...
keless
Posts: 805
Joined: Mon Dec 15, 2003 10:37 pm
Location: Los Angeles, California, USA

Post by keless »

core::matrix4& getAbsoluteTransformation() { return AbsoluteTransformation;}

it looks like it returns the address of its absolute transformation, in which case you could catch it with a matrix4 pointer, and therefore have direct access to its private absolute transformation matrix object.

in otherwords, yes.

also, in the code you posted above,
"node->getAbsoluteTransformation(); "
doesnt seem to do anything as you're not setting anything to it. (though thats probably just what you're trying to decide, i guess)
a screen cap is worth 0x100000 DWORDS
powerpop
Posts: 171
Joined: Thu Jan 08, 2004 1:39 am
Location: san francisco

Post by powerpop »

thanks

here is what i have now - everything seems to be running except i am not getting any position or rotation updates - hmmm, i have to sift through the rest of my code to make sure i didnt screw it up - but does this look right?

Code: Select all

	irr::core::matrix4 trans;
	trans = node->getAbsoluteTransformation();
	neQ q = body->GetRotationQ();
	neM4 neMatrix = q.BuildMatrix();
	neMatrix.SetTranslation(body->GetPos());

	for (int x=0; x < 4; x++)
	{
		for (int y=0; y < 4; y++)
		{
			(trans)(y,x) = 
				neMatrix.M[x][y];
		}
	}
keless
Posts: 805
Joined: Mon Dec 15, 2003 10:37 pm
Location: Los Angeles, California, USA

Post by keless »

what is body? something from ODE, I assume. and you're trying to stuff it into node's absolute transform.

*thinking aloud*
body.rotation into neMatrix, then body.translation into neMatrix. okay. (i assume you dont care about scale? and body doesnt just have a 'get matrix'?)

so, when you're changing trans, it doesnt seem to reflect itself graphically huh?

Im not all that sure on the '&' thing either, have you tried declaring trans as a matrix pointer?

another way you might try it is:

Code: Select all

   irr::core::matrix4 trans; 
   neQ q = body->GetRotationQ(); 
   neM4 neMatrix = q.BuildMatrix(); 
   neMatrix.SetTranslation(body->GetPos()); 

   for (int x=0; x < 4; x++) 
   { 
      for (int y=0; y < 4; y++) 
      { 
         (trans)(y,x) = 
            neMatrix.M[x][y]; 
      } 
   } 
  node->getAbsoluteTransformation() = trans; 
though, again, id worry about scale
a screen cap is worth 0x100000 DWORDS
powerpop
Posts: 171
Joined: Thu Jan 08, 2004 1:39 am
Location: san francisco

Post by powerpop »

right, body is the rigidbody object in Tokamak and i am trying to stuff the matrix from it into the one for irrlicht so they match (scale, have to think about that one - unless someone changes the scale of the object after the sim it wont change - but i might have to plan for that to possibly happen)

i will try your order of things and see if it gets set - the way i have it above the values dont get set inside the node

when i use SetPosition on node it works, of course, but i believe the code above was posted by someone on these boards as a way to move the matrix over so as not to introduce errors in rotation round off, etc - so i want to get the matrix copied over - seems like its time for an email directly to niko on this one!
powerpop
Posts: 171
Joined: Thu Jan 08, 2004 1:39 am
Location: san francisco

Post by powerpop »

okay - that bottom line that puts the absolutetransformation on the left seems to work - then i disovered another problem - earlier i have to set the tokamak body to match the transform of the irrlicht scenenode - i dont think i am doing it in a way that matches - one seems to be absolute and the other relative - here is the code to set the tokamak body transform at the beginning ...

Code: Select all

	irr::core::vector3df irrRot = node->getRotation()*irr::core::PI/180.000f; // in radians
	irr::core::vector3df irrPos = node->getPosition();

	neT3 geomTransform;
	neV3 tokRot;

	// Build transformation matrix for geometry
	tokRot.Set(irrRot.X,irrRot.Y,irrRot.Z);
	geomTransform.rot.RotateXYZ(tokRot);
	geomTransform.pos.Set(irrPos.X,irrPos.Y,irrPos.Z);

	geom->SetTransform(geomTransform);
so the problem is that i am getting changes from tokamak on values like (0,-234,0) - so the Y is being changed slowly and the object falls - great - except this is a relative value so ALL my object end up being positioned at 0,-234,0) - i either want a way to set the irrlicht scenenode to a relative transform OR a way to set the tokamak object to the relative transform
keless
Posts: 805
Joined: Mon Dec 15, 2003 10:37 pm
Location: Los Angeles, California, USA

Post by keless »

yeah, "getPosition" and "getRotation" will only return the 'relative' of each, you dont want to use those
a screen cap is worth 0x100000 DWORDS
powerpop
Posts: 171
Joined: Thu Jan 08, 2004 1:39 am
Location: san francisco

Post by powerpop »

i can try to do the reverse - i can get the AbsoluteTransformation of node and then try to fill a matrix for tokamak to use ... hopefully - be right back after trying ;)
powerpop
Posts: 171
Joined: Thu Jan 08, 2004 1:39 am
Location: san francisco

Post by powerpop »

AHA! I think I found the problem but I dont know how to fix it :(

SceneNode only updates the AbsolutePosition on every PostRender pass - so when I am setting up my Tokamak objects and try to get the current position of the node its not correct (it hasnt been updated yet)

the UpdateAbsolutePosition call on SceneNode is protected so I cant call it directly - so this means that when you set the position of an object you cannot test for its absoluteposition until the next time its rendered - that means i cannot set up the tokamak objects until after at least one pass of the renderer - yikes!

here is the relevant bit from scenenode:

Code: Select all

		//! returns the absolute transformation of the node. Is recalculated every OnPostRender()-call.
		core::matrix4& getAbsoluteTransformation()
		{
			return AbsoluteTransformation;
		}
[/code]
powerpop
Posts: 171
Joined: Thu Jan 08, 2004 1:39 am
Location: san francisco

Post by powerpop »

That corrected the problem!!!

I put the init code for all my physics objects after the first pass on the renderer. Now all the objects are falling correctly. As soon as i do some cleanup and speedup of the code (calling tokamak on very frame is deathly slow) i will post an example!
powerpop
Posts: 171
Joined: Thu Jan 08, 2004 1:39 am
Location: san francisco

not tumbling correctly

Post by powerpop »

things are getting better but the objects are not tumbling correctly - nearly so but they are tilted a little and i noticed that the tokamak objects seem to be off from what the irrlicht objects are in position (there is an offset) - but i dont know where that is coming from - here are the two relevant routines that set and get the data from the tokamak object - can anyone see where i am getting the offset from? or the quirky rotation?

Code: Select all

void CSceneNodeTokamak::updateDataFromNode()
{
	neV3 pos;

	pos.Set((float)node->getAbsolutePosition().X,(float)node->getAbsolutePosition().Y,(float)node->getAbsolutePosition().Z);

	body->SetPos(pos);	
}

void CSceneNodeTokamak::updateDataToNode()
{
	irr::core::matrix4 trans;
	neQ q = body->GetRotationQ();
	neM4 neMatrix = q.BuildMatrix();
	neMatrix.SetTranslation(body->GetPos());

	for (int x=0; x < 4; x++)
	{
		for (int y=0; y < 4; y++)
		{
			(trans)(y,x) = 
				neMatrix.M[x][y];
		}
	}
    
	node->getAbsoluteTransformation() = trans;
}
powerpop
Posts: 171
Joined: Thu Jan 08, 2004 1:39 am
Location: san francisco

Post by powerpop »

more problems - i notice that if i dont call the physics update every frame that the objects flip back to their original positions (they vibrate visually) - this means that the transform i am setting doesnt stay changed (the getAbsoluteTranform above doesnt leave a permanent mark) - thats a bad thing

okay, open to ideas - it feels close - with these problems out of the way i will be able to release a tokamakobject and a simulationobject for use in other games!
SwiftCoder
Posts: 32
Joined: Thu Jan 15, 2004 7:33 pm
Location: Carribean

Post by SwiftCoder »

powerpop wrote:more problems - i notice that if i dont call the physics update every frame that the objects flip back to their original positions (they vibrate visually) - this means that the transform i am setting doesnt stay changed (the getAbsoluteTranform above doesnt leave a permanent mark) - thats a bad thing

okay, open to ideas - it feels close - with these problems out of the way i will be able to release a tokamakobject and a simulationobject for use in other games!
I think I have the cause of your dilemma, and maybe the answer.
The UpdateAbsoluteTransform() function forms a just multiplies the SceneNode's Relative Matrix by it's parent node's Relative Matrix, (and so on up the scenegraph untill it reaches the root node), and stores it in the Absolute Matrix. Absolute Matrix is just a temporary value.
This means that if you change the Absolute Matrix, it will be overwritten when UpdateAbsoluteTransform() is called.
The answer is to change the relative Position, Rotation, and Scale, which you should be able to find with minimal calculation. Then when UpdateAbsoluteTransform() is called, it will use your modifications.

SwiftCoder
Post Reply