def add(self, obj, x, y, z=None): if z is None: t = Transform() min = Vector3f() max = Vector3f() obj.physics.getAabb(min, max) z = -min.z self.temp = obj if hasattr(obj, 'physics'): t = Transform() ms = obj.physics.motionState ms.getWorldTransform(t) m = Matrix4f() t.getMatrix(m) m.m03 = x m.m13 = y m.m23 = z t.set(m) ms.worldTransform = t obj.physics.motionState = ms self.physics.addRigidBody(obj.physics) if hasattr(obj, 'wheels'): tuning = VehicleTuning() obj.vehicle = RaycastVehicle( tuning, obj.physics, self.vehicle_raycaster) obj.physics.setActivationState( CollisionObject.DISABLE_DEACTIVATION) self.physics.addVehicle(obj.vehicle) obj.vehicle.setCoordinateSystem(1, 2, 0) for w in obj.wheels: wheel = obj.vehicle.addWheel(Vector3f(w.x, w.y, w.z), Vector3f(w.dir), Vector3f(w.axle), w.suspension_rest_len, w.radius, tuning, False) wheel.suspensionStiffness = w.suspension_stiffness wheel.maxSuspensionTravelCm = w.suspension_max_travel * 100 wheel.frictionSlip = w.friction wheel.wheelsDampingRelaxation = w.damping_relaxation wheel.wheelsDampingCompression = w.damping_compression wheel.rollInfluence = w.roll_influence self.objects.append(obj) self.world.addObject(obj.shape)
def physics_dump(self): d = {} for obj in self.objects: if hasattr(obj, 'physics'): t = Transform() obj.physics.getMotionState().getWorldTransform(t) m = Matrix4f() t.getMatrix(m) trans = Matrix() trans.set(3, 0, m.m03) trans.set(3, 1, m.m13) trans.set(3, 2, m.m23) rot = Matrix() for i in range(3): for j in range(3): rot.set(i, j, m.getElement(j, i)) d[obj] = (trans, rot) return d