载入中...
搜索中...
未找到
Box3DWorldInternal.h
浏览该文件的文档.
1#pragma once
2#include <box3d/box3d.h>
12inline Body3D *bodyFromShape(b3ShapeId shapeId) {
13 if (!b3Shape_IsValid(shapeId)) return nullptr;
14 return static_cast<Body3D *>(b3Body_GetUserData(b3Shape_GetBody(shapeId)));
15}
16
24inline Shape3D *shapeFromShape(b3ShapeId shapeId) {
25 if (!b3Shape_IsValid(shapeId)) return nullptr;
26 return static_cast<Shape3D *>(b3Shape_GetUserData(shapeId));
27}
28
29inline b3Quat normalizedQueryQuat(float qx, float qy, float qz, float qw, const char *operation) {
30 if (!std::isfinite(qx) || !std::isfinite(qy) || !std::isfinite(qz) || !std::isfinite(qw))
31 throw eve::Exception("%s: quaternion must be finite", operation);
32 const float lengthSquared = qx * qx + qy * qy + qz * qz + qw * qw;
33 if (!(lengthSquared > 1e-12f)) throw eve::Exception("%s: quaternion must be non-zero", operation);
34 const float inverseLength = 1.f / std::sqrt(lengthSquared);
35 return b3Quat{{qx * inverseLength, qy * inverseLength, qz * inverseLength}, qw * inverseLength};
36}
37
38inline void makeBoxProxyPoints(b3Vec3 (&points)[8], float width, float height, float depth, b3Quat q,
39 const char *operation) {
40 if (!(width > 0.f) || !(height > 0.f) || !(depth > 0.f) || !std::isfinite(width) || !std::isfinite(height) ||
41 !std::isfinite(depth))
42 throw eve::Exception("%s: box dimensions must be finite and > 0", operation);
43 const float hx = 0.5f * width, hy = 0.5f * height, hz = 0.5f * depth;
44 int point = 0;
45 for (int z = -1; z <= 1; z += 2)
46 for (int y = -1; y <= 1; y += 2)
47 for (int x = -1; x <= 1; x += 2)
48 points[point++] = b3RotateVector(
49 q, b3Vec3{static_cast<float>(x) * hx, static_cast<float>(y) * hy, static_cast<float>(z) * hz});
50}
51
52
53} // namespace eve::physics::world3d_detail
double z
double y
double x
ActionParameterOperation operation
std::array< double, 10 > q
std::uint32_t height
std::uint32_t width
std::shared_ptr< const std::vector< glm::vec2 > > points
std::uint32_t depth
int shapeId
glm::vec3 point
EVENGINE_API_FOUNDATION public API.
Definition Exception.h:13
Backend-neutral 3D rigid body in meter-space coordinates (+Y up by convention). Owned by a World3D; c...
Definition Body3D.h:31
3D shape (box/sphere/capsule) attached to a Body3D with material settings. Created via Body3D::new*Sh...
Definition Shape3D.h:34
Body3D * bodyFromShape(b3ShapeId shapeId)
Resolves a native Box3D user-data observer for an immediate internal call.
void makeBoxProxyPoints(b3Vec3(&points)[8], float width, float height, float depth, b3Quat q, const char *operation)
Shape3D * shapeFromShape(b3ShapeId shapeId)
Resolves a native Box3D user-data observer for an immediate internal call.
b3Quat normalizedQueryQuat(float qx, float qy, float qz, float qw, const char *operation)