diff --git a/src/physics/physical_object.cpp b/src/physics/physical_object.cpp index 28cd58d97..bb1698b4d 100644 --- a/src/physics/physical_object.cpp +++ b/src/physics/physical_object.cpp @@ -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) diff --git a/src/tracks/track_object.cpp b/src/tracks/track_object.cpp index 5e9e054be..187d83b7a 100644 --- a/src/tracks/track_object.cpp +++ b/src/tracks/track_object.cpp @@ -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 // ----------------------------------------------------------------------------