载入中...
搜索中...
未找到
OceanBoat.cpp
浏览该文件的文档.
20bool finite(glm::dvec3 v) { return std::isfinite(v.x) && std::isfinite(v.y) && std::isfinite(v.z); }
31Result<std::unique_ptr<OceanBoat>> OceanBoat::create(physics::Body3D& body, const OceanHullSettings& s) {
32 if (s.cells.empty() || s.cells.size() > 64 || !std::isfinite(s.waterDensity) || s.waterDensity <= 0.0 ||
33 s.waterDensity > 1e5 || !std::isfinite(s.gravity) || s.gravity <= 0.0 || s.gravity > 100.0 || !finite(s.drag) ||
34 glm::any(glm::lessThan(s.drag, glm::dvec3(0.0))) || glm::length(s.drag) > 100.0 || !finite(s.propeller) ||
35 glm::length(s.propeller) > 1000.0 || !std::isfinite(s.thrust) || s.thrust < 0.0 || s.thrust > 1e8 ||
37 return failure<std::unique_ptr<OceanBoat>>(DiagnosticCode::InvalidArgument, "Invalid hull settings");
39 if (!finite(c.center) || glm::length(c.center) > 1000.0 || !std::isfinite(c.radius) || c.radius <= 0.0 ||
41 return failure<std::unique_ptr<OceanBoat>>(DiagnosticCode::InvalidArgument, "Invalid hull cell");
51 return Result<std::unique_ptr<OceanBoat>>::success(std::unique_ptr<OceanBoat>(new OceanBoat(std::move(impl))));
54Result<OceanBoatReceipt> OceanBoat::apply(const OceanWaterView& frame, double dt, double throttle, double rudder) {
55 if (!std::isfinite(dt) || dt <= 0.0 || dt > 1.0 / 30.0 || !std::isfinite(throttle) || std::abs(throttle) > 1.0 ||
57 return failure<OceanBoatReceipt>(DiagnosticCode::InvalidArgument, "Invalid or repeated boat step");
59 if (!world) return failure<OceanBoatReceipt>(DiagnosticCode::StaleHandle, "Boat world no longer exists");
68 return failure<OceanBoatReceipt>(DiagnosticCode::InvalidArgument, "Boat body is no longer dynamic");
75 auto p = body.localToWorldPointOwned(float(cell.center.x), float(cell.center.y), float(cell.center.z));
77 auto v = body.getLocalPointVelocityOwned(float(cell.center.x), float(cell.center.y), float(cell.center.z));
100 auto propeller = body.localToWorldPointOwned(float(h.propeller.x), float(h.propeller.y), float(h.propeller.z));
106 body.getLocalPointVelocityOwned(float(h.propeller.x), float(h.propeller.y), float(h.propeller.z));
111 std::clamp(-rudder * h.rudderCoefficient * relative.z * std::abs(relative.z), -mass * 10.0, mass * 10.0);
112 forces.push_back({p, rotation * (glm::dvec3(rudderForce, 0.0, throttle * h.thrust) * wet), 0.0});
115 return failure<OceanBoatReceipt>(DiagnosticCode::InvalidArgument, "Hull force exceeds supported range");
Typed composition link from a gameplay entity to a physics body.
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
Water-force adapter over a World3D-owned rigid body, storing generation-qualified links only....
Definition OceanBoat.h:59
EVENGINE_API_DOMAINS Result< OceanBoatReceipt > apply(const OceanWaterView &frame, double dt, double throttle, double rudder)
Submit buoyancy, body-local directional drag, submerged thrust and rudder forces before physics.
Definition OceanBoat.cpp:54
OceanBoat(const OceanBoat &)=delete
static EVENGINE_API_DOMAINS Result< std::unique_ptr< OceanBoat > > create(physics::Body3D &body, const OceanHullSettings &settings)
Validate/copy a bounded hull and attach to a live dynamic body.
Definition OceanBoat.cpp:31
EVENGINE_API_DOMAINS ~OceanBoat()
Synchronous borrowed composition of the spectral sea and an optional local wake. Both owners must out...
Definition OceanWaterView.h:17
Backend-neutral 3D rigid body in meter-space coordinates (+Y up by convention). Owned by a World3D; c...
Definition Body3D.h:31
static World3D * findWorld(PhysicsWorldHandle handle) noexcept
Resolve a live process-local world handle, or null after teardown. @thread Owning physics thread only...
Definition World3D.cpp:296
Result< OceanCellForce > evaluateOceanCellForce(const OceanBuoyancyCell &cell, const OceanSurfaceSample &water, double density, double gravity)
Integrate spherical-cap buoyancy and isotropic quadratic water drag.
Definition OceanSurface.cpp:100
@ InvalidArgument
@ StaleHandle
Definition Container.h:602
Owning fixed-step force receipt; consumers may retain it for wake injection.
Definition OceanBoat.h:36
std::vector< OceanBoatContact > contacts
Definition OceanBoat.h:40
Definition OceanBoat.cpp:14
Sphere with assigned displacement volume; several disjoint volumes approximate a hull.
Definition OceanSurface.h:79
Hull water response; local +Z forward, +X starboard, +Y up.
Definition OceanBoat.h:20
Generation-qualified relationship between one world and one body.
Definition PhysicsLink.h:35
static eve::Result< PhysicsLink > fromBody(const Body &body)
Creates a link from a live 2D body.
Definition PhysicsLink.cpp:39
Allocation-free owning three-dimensional physics value.
Definition RigidTypes3D.h:4