Setting initial rotation of transform (motionstate)

Post Reply
RisaStenr
Posts: 2
Joined: Sat Jun 26, 2021 2:25 am

Setting initial rotation of transform (motionstate)

Post by RisaStenr »

I am trying to set the initial rotation of a btTransform using x, y, z and w.

Code: Select all

MotionState::MotionState(object *_object) : m_pObject(object)
{
	float x = m_pObject->getPosition().x;
	float y = m_pObject->getPosition().y;
	float z = m_pObject->getPosition().z;

	float qx = m_pObject->getRotation().q.x;
	float qy = m_pObject->getRotation().q.y;
	float qz = m_pObject->getRotation().q.z;
	float qw = m_pObject->getRotation().q.w;

	btTransform transform;
	transform.setIdentity();
	transform.setOrigin({ x, y, z });
	transform.setRotation({ qx, qy, qz, qw });
	
	m_Pos1 = transform;
	}
The above code does not display the objects and crashes when I advance the physics.
The code worked (objects showed and moved) when I didnt set the rotation (ie I just set the origin or location).
How would I go about setting the initial rotation of the object? I am using motionstates and read in one of the manuals this was the way to do it, but I can't figure out how to set the rotation.
RisaStenr
Posts: 2
Joined: Sat Jun 26, 2021 2:25 am

Re: Setting initial rotation of transform (motionstate)

Post by RisaStenr »

OK so it looks like what I was doing was correct, but bullet didn't like that i set the initial rotation to zeroes. After adjusting the rotation to be a small number, it works.
Post Reply