فهرست منبع

world: activate body after setting new transform

Fixes: #278
Daniele Bartolini 1 سال پیش
والد
کامیت
d2fbe7f22e
2فایلهای تغییر یافته به همراه10 افزوده شده و 5 حذف شده
  1. 1 0
      docs/changelog.rst
  2. 9 5
      src/world/physics_world_bullet.cpp

+ 1 - 0
docs/changelog.rst

@@ -19,6 +19,7 @@ Changelog
 * Fixed a crash when reloading unloaded or unsupported resources.
 * Added support to shaders and materials hot-reloading.
 * Data Compiler: #defines are now correctly exposed in vs_input_output and fs_input_output.
+* Fixed setting kinematic actor's position and rotation.
 * Lua API: fixed ``Math.ray_obb_intersection()`` with scaled OBBs.
 * Lua API: added ``Math.obb_merge()``.
 * Lua API: implemented ``PhysicsWorld.actor_{enable,disable}_collision()`` and ``PhysicsWorld.actor_set_collision_filter()``.

+ 9 - 5
src/world/physics_world_bullet.cpp

@@ -947,12 +947,16 @@ struct PhysicsWorldImpl
 			if (ai == UINT32_MAX)
 				continue;
 
-			const Quaternion rot = rotation(*begin_world);
-			const Vector3 pos = translation(*begin_world);
 			// http://www.bulletphysics.org/mediawiki-1.5.8/index.php/MotionStates
-			btMotionState *ms = _actor[ai].body->m_optionalMotionState;
-			if (ms)
-				ms->setWorldTransform(btTransform(to_btQuaternion(rot), to_btVector3(pos)));
+			btRigidBody *body = _actor[ai].body;
+			btMotionState *motion_state = body->m_optionalMotionState;
+			if (motion_state) {
+				const Quaternion rot = rotation(*begin_world);
+				const Vector3 pos = translation(*begin_world);
+				const btTransform new_transform(to_btQuaternion(rot), to_btVector3(pos));
+				motion_state->setWorldTransform(new_transform);
+				body->activate();
+			}
 		}
 	}