载入中...
搜索中...
未找到
VehicleTires3D.cpp
浏览该文件的文档.
25V cross(V a, V b) { return {a.y * b.z - a.z * b.y, a.z * b.x - a.x * b.z, a.x * b.y - a.y * b.x}; }
54 // Only this synchronous native callback sees the borrowed wrappers. No user callbacks or query-cache mutation.
55 static float collect(b3ShapeId id, b3Pos point, b3Vec3 normal, float fraction, uint64_t, int triangle, int,
61 if (!shape || !ground || ground == &context.chassis || !ground->isValid() || !shape->isValid()) return -1;
65 if (!hit.ground || fraction < hit.fraction || (fraction == hit.fraction && shape->getId() < hit.shapeId)) {
84 const auto r = add(point, scale(vec(b3Body_GetWorldCenterOfMass(eve::physics::box3d::Access::bodyId(body))), -1));
85 const auto inertia = b3Body_GetWorldInverseRotationalInertia(eve::physics::box3d::Access::bodyId(body));
118 if (!definition || !world || !body.isValid()) return reject("Vehicle definition or spatial body is unavailable");
129 !nonnegative(definition->accel) || !nonnegative(config.maxTravel) || !nonnegative(config.driveForce) ||
130 !nonnegative(config.brakeTorque) || !nonnegative(config.maxSteerAngle) || config.maxSteerAngle > 1.4 ||
148 if (vehicle.suspension()->wheels.size() == wheels.size()) candidate = vehicle.suspension()->wheels;
151 static_cast<std::size_t>(std::count_if(wheels.begin(), wheels.end(), [](const auto& w) { return w.drive; }));
152 const auto up = vec(b3Body_GetWorldVector(eve::physics::box3d::Access::bodyId(body), {0, 1, 0}));
184 const auto mount = b3Body_GetWorldPoint(eve::physics::box3d::Access::bodyId(body), native(localMount));
192 const double steer = wheel.steer ? std::clamp(double(input.steer), -1.0, 1.0) * config.maxSteerAngle : 0;
198 if (!positive(norm) || norm < 1e-6) return reject("Wheel heading is perpendicular to the contact plane");
239 prepared.compression = std::clamp(double(wheel.restLength) - (contact.fraction * rayLength - wheel.radius),
263 if (c.contact.ground) relative = add(relative, scale(predicted[c.ground].velocity(c.point), -1));
267 c.contact.ground ? std::max(0.0, (c.spring - c.gain * vn) / (1 + dt * c.gain * c.diagonal[2])) : 0;
293 add(scale(c.normal, c.impulse[2]), add(scale(c.forward, c.impulse[0]), scale(c.lateral, c.impulse[1])));
static Diagnostic error(DiagnosticCode code, std::string message, std::string path={})
Construct an error diagnostic with the standard error severity.
Definition Diagnostic.cpp:21
static Result failure(Status status)
Construct a failed result from a structured status.
Definition Result.h:196
Backend-neutral 3D rigid body in meter-space coordinates (+Y up by convention). Owned by a World3D; c...
Definition Body3D.h:31
ForceVector add(ForceVector a, ForceVector b)
Definition ForceMath.h:13
Result< VehiclePhysicsStatus > submissionState(const std::shared_ptr< VehicleWheelRuntime > &runtime, const SimulationStep &step)
Definition VehicleTireRuntime.cpp:31
Result< VehiclePhysicsStatus > commit(physics::World &world, physics::ForceBatch &batch, std::shared_ptr< VehicleWheelRuntime > &runtime, std::vector< VehicleEntity::SuspensionState::WheelState > candidate, const SimulationStep &step)
Definition VehicleTireRuntime.cpp:87
Result< VehiclePhysicsStatus > submit3D(VehicleEntity &vehicle, physics::Body3D &body, std::shared_ptr< VehicleWheelRuntime > &runtime, const SimulationStep &step)
Definition VehicleTires3D.cpp:111
void driveInputs(physics::TireInput &target, const SuspensionConfig &config, const VehicleEntity::Input &input, const SuspensionWheel &wheel, std::size_t driven, double maximumSpeed, double traction)
Definition VehicleTireRuntime.cpp:61
@ InvalidArgument
@ Unsupported
static b3BodyId bodyId(const Body3D &body)
Borrows the native identifier synchronously; facade must belong to a Box3D world.
Definition Box3DBody.cpp:649
static b3WorldId worldId(const World3D &world)
Internal checked Box3D world ID; fails for another backend.
Definition Box3DWorld.cpp:13
Wheel mount for 3D ray suspension or 2D top-down tire contact.
Definition VehicleTypes.h:102
float x
Local mount in meters: 3D uses +Y up; top-down 2D uses XY with z = 0.
Definition VehicleTypes.h:104