settransform issue

Hello,

I just moved from 2.0.1 to the new 2.1.0 and I am experiencing a problem.

In my editor I set gravity to zero and use body.settransform(position, angle); (previously setXform) to move an object with the mouse.

But settransform doesn't appear to move the object in real-time, even when you try to wake the body.

What I found was that I would move an object to a new location (even though it doesn't move there) and then create a new box2d object. Only when the new object contacts the surface of a ground fixture does the original object suddenly pop to the location i previously requested.

i have no idea why its doing that. I looked in the manual but it doesn't suggest I have to do anything more after the settransform.

Is this a bug?

Thanks,

Cameron
😐
Here is the code:
Code:
void b2Body::SetTransform(const b2Vec2& position, float32 angle)
{
   b2Assert(m_world->IsLocked() == false);
   if (m_world->IsLocked() == true)
   {
      return;
   }

   m_xf.R.Set(angle);
   m_xf.position = position;

   m_sweep.c0 = m_sweep.c = b2Mul(m_xf, m_sweep.localCenter);
   m_sweep.a0 = m_sweep.a = angle;

   b2BroadPhase* broadPhase = &m_world->m_contactManager.m_broadPhase;
   for (b2Fixture* f = m_fixtureList; f; f = f->m_next)
   {
      f->Synchronize(broadPhase, m_xf, m_xf);
   }

   m_world->m_contactManager.FindNewContacts();
}


The only early return occurs if the world is locked. In that case it should also assert.
"The only early return occurs if the world is locked. In that case it should also assert."

I'm not clever enough to comprehend if you're telling me the behaviour of this function is correct. 🙂

I confirmed with print outs in b2Body::SetTransform that my code is not returning early and it is in fact modifying the position and angle as it should.

So from this confirmation plus the description I would conclude that the transform is in the system but the state is somewhere not updated.

Previously with SetXForm, when the gravity is off, the function allows an object to be placed instantaneously.

The problem here I'm seeing is that settransform is only showing movement results once there has been a general contact event.

Thanks thanks!

Cameron
Erin Catto wrote:
But settransform doesn't appear to move the object in real-time, even when you try to wake the body.


So what do you mean by "move"? b2Body::GetTransform should return the transform you just set.
Ok. But by "move" I mean if I SetTransform a body to a new location I previously expected it to be reflected in Body->GetPosition();

const b2Transform& GetTransform() const;

const b2Vec2& GetPosition() const;

I see, but why is there now "position" and "transform" and not just "position"?

Thanks,

Cameron
Here are the two functions:
Code:
inline const b2Transform& b2Body::GetTransform() const
{
   return m_xf;
}

inline const b2Vec2& b2Body::GetPosition() const
{
   return m_xf.position;
}


The first one returns the whole transform (position and rotation) and the second just returns the position.

It seems there is nothing going on here that would distort the position you just set. Perhaps there is something else going on in your system. You could set a data breakpoint and determine when the position is being modified.
Ok, I can only say I don't understand. I'll go with forces to move objects in my editor.

I can see in my code when the position is being modified, I can see the exact moment the correct b2Vec2 position and float32 angle are given to SetTransform.

I swapped out
Body->SetXForm(position, angle);
for the new
Body->SetTransform(position, angle);

Under 2.0.1 this worked as I expected it to. Under 2.1.0, not so much.

position = Body->GetPosition();
angle = Body->GetAngle();

These commands aren't giving me the latest transform. -Unless they are not supposed to and I'm supposed to access the state through GetTransform now?
As I said, the SetTransform doesn't appear to affect the object (as determined by GetPosition) until there has been a contact event somewhere in the system.

I guess it's my bug somewhere. I don't know what could block a state change like that though.

If I find out what I did wrong I'll update this thread.

Thanks for your help Erin.
😳

I made a testbed example and it worked. So I investigated and found I was using
BodyDef.awake = true; instead of Body->SetAwake(true);

Cameron

Original thread: https://box2d.org/forum/viewtopic.php?t=4797