Bugfix : objects with a physics collision from a library should rotate and scale according to the parent library object
This commit is contained in:
parent
ea9520863d
commit
7b8da0ef34
@ -252,8 +252,14 @@ void PhysicalObject::init()
|
||||
Log::fatal("PhysicalObject", "Unknown node type");
|
||||
}
|
||||
|
||||
max = max * Vec3(m_init_scale);
|
||||
min = min * Vec3(m_init_scale);
|
||||
Vec3 parent_scale(1.0f, 1.0f, 1.0f);
|
||||
if (m_object->getParentLibrary() != NULL)
|
||||
{
|
||||
parent_scale = m_object->getParentLibrary()->getScale();
|
||||
}
|
||||
|
||||
max = max * (Vec3(m_init_scale) * parent_scale);
|
||||
min = min * (Vec3(m_init_scale) * parent_scale);
|
||||
|
||||
Vec3 extend = max-min;
|
||||
// Adjust the mesth of the graphical object so that its center is where it
|
||||
@ -466,6 +472,26 @@ void PhysicalObject::init()
|
||||
m_init_pos.setOrigin(m_init_pos.getOrigin() +
|
||||
btVector3(0, extend.getY()*0.5f, 0));
|
||||
}
|
||||
|
||||
|
||||
// If this object has a parent, apply the parent's rotation
|
||||
if (m_object->getParentLibrary() != NULL)
|
||||
{
|
||||
core::vector3df parent_rot_hpr = m_object->getParentLibrary()->getInitRotation();
|
||||
core::matrix4 parent_rot_matrix;
|
||||
parent_rot_matrix.setRotationDegrees(parent_rot_hpr);
|
||||
|
||||
btQuaternion child_rot_quat = m_init_pos.getRotation();
|
||||
core::matrix4 child_rot_matrix;
|
||||
Vec3 axis = child_rot_quat.getAxis();
|
||||
child_rot_matrix.setRotationAxisRadians(child_rot_quat.getAngle(), axis.toIrrVector());
|
||||
|
||||
irr::core::quaternion tempQuat(parent_rot_matrix * child_rot_matrix);
|
||||
btQuaternion q(tempQuat.X, tempQuat.Y, tempQuat.Z, tempQuat.W);
|
||||
|
||||
m_init_pos.setRotation(q);
|
||||
}
|
||||
|
||||
m_motion_state = new btDefaultMotionState(m_init_pos);
|
||||
btVector3 inertia(1,1,1);
|
||||
if (m_body_type != MP_EXACT)
|
||||
|
@ -544,7 +544,7 @@ const core::vector3df& TrackObject::getScale() const
|
||||
if (m_presentation != NULL)
|
||||
return m_presentation->getScale();
|
||||
else
|
||||
return m_init_xyz;
|
||||
return m_init_scale;
|
||||
} // getScale
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
Loading…
Reference in New Issue
Block a user