载入中...
搜索中...
未找到
Math.cpp
浏览该文件的文档.
557bool Math::pointInBox(float px, float py, float pz, float minX, float minY, float minZ, float maxX,
690float Math::noise2(float x, float y) const { return noiseToUnit(glm::simplex(glm::vec2(x, y))); }
695float Math::perlin2(float x, float y) const { return noiseToUnit(glm::perlin(glm::vec2(x, y))); }
742float Math::ridged3(float x, float y, float z, int octaves, float lacunarity, float gain) const {
808float Math::bezierQuadratic2Y(float t, float /*x0*/, float y0, float /*x1*/, float y1, float /*x2*/,
void scale(float sx, float sy, float sz)
Scales by scalar s. @ownership Caller deletes.
Definition Mat4.cpp:25
void multiply(const Mat4 *other)
Post-multiplies by other (column-vector convention).
Definition Mat4.cpp:29
Math module — glm-backed vectors/matrices, noise, bezier, random. Script: math <- eve....
Definition Math.h:23
Vec2 * steeringFlee2(float x, float y, float targetX, float targetY, float maxSpeed) const
Creates a 2D flee velocity. @ownership owned @lifetime Caller deletes the result.
Definition Math.cpp:227
Vec2 * steeringAvoid2(float x, float y, float velocityX, float velocityY, float obstacleX, float obstacleY, float obstacleRadius, float lookAhead, float maxAcceleration) const
Creates 2D avoidance acceleration. @ownership owned @lifetime Caller deletes the result.
Definition Math.cpp:281
bool pointInSphere(float px, float py, float pz, float cx, float cy, float cz, float radius) const
True if point is inside or on the sphere.
Definition Math.cpp:551
float bezierQuadratic(float t, float p0, float p1, float p2) const
1D quadratic Bezier at t in [0,1].
Definition Math.cpp:789
Vec3 * steeringFlee3(float x, float y, float z, float targetX, float targetY, float targetZ, float maxSpeed) const
Creates a 3D flee velocity. @ownership owned @lifetime Caller deletes the result.
Definition Math.cpp:233
bool spheresOverlap(float x1, float y1, float z1, float r1, float x2, float y2, float z2, float r2) const
True if two spheres overlap.
Definition Math.cpp:562
Mat4 * newMat4Scale(float sx, float sy, float sz)
Allocates a scale Mat4. @ownership Caller deletes.
Definition Math.cpp:152
float warpNoise2(float x, float y, float warpAmp=1.f) const
Domain warp: sample noise at (x,y) + warpAmp * (noise-0.5). Useful for organic terrain / caves.
Definition Math.cpp:783
float normalize3X(float x, float y, float z) const
X of the normalized 3D vector (zero-safe).
Definition Math.cpp:402
bool boxesOverlap(float minAx, float minAy, float minAz, float maxAx, float maxAy, float maxAz, float minBx, float minBy, float minBz, float maxBx, float maxBy, float maxBz) const
True if two AABBs overlap.
Definition Math.cpp:570
float normalize3Z(float x, float y, float z) const
Z of the normalized 3D vector (zero-safe).
Definition Math.cpp:410
float perlin3(float x, float y, float z) const
Perlin noise in 3D, range [0,1].
Definition Math.cpp:696
float voronoi2(float x, float y) const
Worley / Voronoi F1 distance in [0, ~1.5] (cell size 1). voronoiEdge2 = F2 - F1 (cell borders).
Definition Math.cpp:771
float approach(float current, float target, float maxDelta) const
Moves current toward target by at most maxDelta.
Definition Math.cpp:194
float turbulence2(float x, float y, int octaves=4, float lacunarity=2.f, float gain=0.5f) const
2D turbulence (absolute fBm).
Definition Math.cpp:758
int steeringPathTarget3(float x, float y, float z, const std::string &points, int current, float tolerance) const
Selects a 3D path point from CSV x:y:z points, or -1 for no valid points.
Definition Math.cpp:275
float closestPointOnSegment2Y(float px, float py, float ax, float ay, float bx, float by) const
Y of the closest point on segment AB to P.
Definition Math.cpp:545
Mat4 * newMat4Translation(float x, float y, float z)
Allocates a translation Mat4. @ownership Caller deletes.
Definition Math.cpp:146
float normalize2Y(float x, float y) const
Y of the normalized 2D vector (zero-safe).
Definition Math.cpp:398
Vec2 * steeringSeek2(float x, float y, float targetX, float targetY, float maxSpeed) const
Creates a 2D seek velocity. @ownership owned @lifetime Caller deletes the result.
Definition Math.cpp:215
float length3(float x, float y, float z) const
3D vector length from components.
Definition Math.cpp:362
float ease(float t, const std::string &kind) const
Easing on [0,1]. kind: "linear"|"inQuad"|"outQuad"|"inOutQuad"|"inCubic"|"outCubic"|"inOutCubic"| "in...
Definition Math.cpp:324
float bezierQuadratic2X(float t, float x0, float y0, float x1, float y1, float x2, float y2) const
X of a 2D quadratic Bezier at t.
Definition Math.cpp:803
float raycastPlane(float ox, float oy, float oz, float dx, float dy, float dz, float px, float py, float pz, float nx, float ny, float nz) const
Ray vs infinite plane through (px,py,pz) with normal (nx,ny,nz). Returns parametric t,...
Definition Math.cpp:619
int steeringPathTarget2(float x, float y, const std::string &points, int current, float tolerance) const
Selects a 2D path point from CSV x:y points, or -1 for no valid points.
Definition Math.cpp:269
float raycastBox(float ox, float oy, float oz, float dx, float dy, float dz, float minX, float minY, float minZ, float maxX, float maxY, float maxZ) const
Ray vs AABB; parametric t >= 0 on hit, else -1.
Definition Math.cpp:595
float angleBetween2(float x1, float y1, float x2, float y2) const
Signed angle from first vector to second.
Definition Math.cpp:382
float normalize3Y(float x, float y, float z) const
Y of the normalized 3D vector (zero-safe).
Definition Math.cpp:406
float closestPointOnSegment2X(float px, float py, float ax, float ay, float bx, float by) const
X of the closest point on segment AB to P.
Definition Math.cpp:540
bool circleRectOverlap(float cx, float cy, float radius, float rx, float ry, float rw, float rh) const
True if circle and axis-aligned rect overlap.
Definition Math.cpp:450
float smootherstep(float edge0, float edge1, float x) const
Ken Perlin smootherstep between edge0 and edge1.
Definition Math.cpp:305
float closestPointOnSegment3Y(float px, float py, float pz, float ax, float ay, float az, float bx, float by, float bz) const
Y of the closest point on segment AB to P.
Definition Math.cpp:632
Vec2 * steeringSeparation2(float x, float y, const std::string &neighbors, float radius, float maxAcceleration) const
Creates 2D separation acceleration from CSV. @ownership owned @lifetime Caller deletes the result.
Definition Math.cpp:254
float smoothstep(float edge0, float edge1, float x) const
Hermite smoothstep between edge0 and edge1.
Definition Math.cpp:171
bool rectsOverlap(float x1, float y1, float w1, float h1, float x2, float y2, float w2, float h2) const
True if two axis-aligned rects overlap.
Definition Math.cpp:445
float normalize2X(float x, float y) const
X of the normalized 2D vector (zero-safe).
Definition Math.cpp:394
Vec3 * steeringSeparation3(float x, float y, float z, const std::string &neighbors, float radius, float maxAcceleration) const
Creates 3D separation acceleration from CSV. @ownership owned @lifetime Caller deletes the result.
Definition Math.cpp:262
Vec3 * steeringSeek3(float x, float y, float z, float targetX, float targetY, float targetZ, float maxSpeed) const
Creates a 3D seek velocity. @ownership owned @lifetime Caller deletes the result.
Definition Math.cpp:221
Vec3 * steeringArrive3(float x, float y, float z, float targetX, float targetY, float targetZ, float maxSpeed, float slowRadius, float stopRadius) const
Creates a 3D arrive velocity. @ownership owned @lifetime Caller deletes the result.
Definition Math.cpp:247
float rotate2X(float x, float y, float radians) const
Rotate (x,y) by radians around origin.
Definition Math.cpp:415
float cross2(float x1, float y1, float x2, float y2) const
2D cross product (scalar z-component).
Definition Math.cpp:379
float closestPointOnSegment3X(float px, float py, float pz, float ax, float ay, float az, float bx, float by, float bz) const
X of the closest point on segment AB to P.
Definition Math.cpp:627
float rotate2Y(float x, float y, float radians) const
Y after rotating (x,y) by radians about the origin.
Definition Math.cpp:419
float closestPointOnSegment3Z(float px, float py, float pz, float ax, float ay, float az, float bx, float by, float bz) const
Z of the closest point on segment AB to P.
Definition Math.cpp:637
float bezierCubic2Y(float t, float x0, float y0, float x1, float y1, float x2, float y2, float x3, float y3) const
Y of a 2D cubic Bezier at t.
Definition Math.cpp:818
bool pointInCircle(float px, float py, float cx, float cy, float radius) const
True if point is inside or on the circle.
Definition Math.cpp:429
float bezierQuadratic2Y(float t, float x0, float y0, float x1, float y1, float x2, float y2) const
Y of a 2D quadratic Bezier at t.
Definition Math.cpp:808
float dot3(float x1, float y1, float z1, float x2, float y2, float z2) const
3D dot product of two vectors.
Definition Math.cpp:375
Vec3 * steeringAvoid3(float x, float y, float z, float velocityX, float velocityY, float velocityZ, float obstacleX, float obstacleY, float obstacleZ, float obstacleRadius, float lookAhead, float maxAcceleration) const
Creates 3D avoidance acceleration. @ownership owned @lifetime Caller deletes the result.
Definition Math.cpp:291
bool pointInBox(float px, float py, float pz, float minX, float minY, float minZ, float maxX, float maxY, float maxZ) const
Inclusive AABB test against [min,max] on each axis.
Definition Math.cpp:557
Vec3 * newVec3(float x=0.f, float y=0.f, float z=0.f)
Allocates a Vec3. @ownership Caller deletes.
Definition Math.cpp:142
float ridged3(float x, float y, float z, int octaves=4, float lacunarity=2.f, float gain=0.5f) const
3D ridged multifractal noise.
Definition Math.cpp:742
float bezierCubic(float t, float p0, float p1, float p2, float p3) const
1D cubic Bezier at t in [0,1].
Definition Math.cpp:795
float bilinear(float v00, float v10, float v01, float v11, float u, float v) const
Bilinear sample of 4 corners (v00,v10,v01,v11) with u,v in [0,1].
Definition Math.cpp:643
float ridged2(float x, float y, int octaves=4, float lacunarity=2.f, float gain=0.5f) const
2D ridged multifractal noise.
Definition Math.cpp:726
float pingPong(float t, float length) const
Triangle-wave ping-pong of t over [0, length].
Definition Math.cpp:209
float distance2(float x1, float y1, float x2, float y2) const
2D distance between two points.
Definition Math.cpp:366
float bias(float t, float b) const
Schlick bias/gain — shape [0,1] distributions (procgen falloff).
Definition Math.cpp:311
float raycastRect2(float ox, float oy, float dx, float dy, float rx, float ry, float rw, float rh) const
Ray vs axis-aligned rect (x,y,w,h). Returns parametric t >= 0, else -1.
Definition Math.cpp:499
float distance3(float x1, float y1, float z1, float x2, float y2, float z2) const
3D distance between two points.
Definition Math.cpp:370
float inverseLerp(float a, float b, float x) const
Linear interpolation between a and b by t.
Definition Math.cpp:300
bool segmentsIntersect(float ax, float ay, float bx, float by, float cx, float cy, float dx, float dy) const
True if segments AB and CD intersect (including endpoints).
Definition Math.cpp:459
float remap(float x, float inMin, float inMax, float outMin, float outMax) const
Maps x from [inMin,inMax] into [outMin,outMax].
Definition Math.cpp:177
Mat4 * newMat4RotationZ(float radians)
Allocates a Z-rotation Mat4 (radians). @ownership Caller deletes.
Definition Math.cpp:158
Vec2 * newVec2(float x=0.f, float y=0.f)
Allocates a Vec2. @ownership Caller deletes.
Definition Math.cpp:141
float randomGaussian(float mean, float stddev)
Box-Muller Gaussian (mean, stddev).
Definition Math.cpp:680
float lerpAngle(float a, float b, float t) const
Shortest-path angle interpolation.
Definition Math.cpp:386
Vec2 * steeringArrive2(float x, float y, float targetX, float targetY, float maxSpeed, float slowRadius, float stopRadius) const
Creates a 2D arrive velocity. @ownership owned @lifetime Caller deletes the result.
Definition Math.cpp:239
float bezierCubic2X(float t, float x0, float y0, float x1, float y1, float x2, float y2, float x3, float y3) const
X of a 2D cubic Bezier at t.
Definition Math.cpp:813
float fbm3(float x, float y, float z, int octaves=4, float lacunarity=2.f, float gain=0.5f) const
3D fractal Brownian motion.
Definition Math.cpp:713
float dot2(float x1, float y1, float x2, float y2) const
2D dot product of two vectors.
Definition Math.cpp:374
float raycastCircle2(float ox, float oy, float dx, float dy, float cx, float cy, float radius) const
Ray vs circle. Hit point = (ox,oy) + t*(dx,dy). Returns t >= 0 on hit, else -1. Direction need not be...
Definition Math.cpp:481
bool pointInRect(float px, float py, float rx, float ry, float rw, float rh) const
True if point is inside or on the axis-aligned rect.
Definition Math.cpp:434
float lerp(float a, float b, float t) const
Linear interpolation between a and b by t.
Definition Math.cpp:169
float quantize(float x, float stepSize) const
Quantizes x to multiples of stepSize.
Definition Math.cpp:351
bool circlesOverlap(float x1, float y1, float r1, float x2, float y2, float r2) const
True if two circles overlap.
Definition Math.cpp:438
float fbm2(float x, float y, int octaves=4, float lacunarity=2.f, float gain=0.5f) const
Fractal Brownian Motion / ridged / turbulence. octaves >= 1; lacunarity ~2; gain/persistence ~0....
Definition Math.cpp:700
float raycastSphere(float ox, float oy, float oz, float dx, float dy, float dz, float cx, float cy, float cz, float radius) const
Ray vs sphere; parametric t >= 0 on hit, else -1.
Definition Math.cpp:577
int randomInt(int min, int maxInclusive)
Uniform inclusive integer in [min, maxInclusive].
Definition Math.cpp:674
float hash3(float x, float y, float z) const
Deterministic 3D hash mapped to [0,1].
Definition Math.cpp:687
Vec2 * add(const Vec2 *other) const
Arithmetic helpers returning new (caller-owned) vectors.
Definition Vec2.cpp:42
Vec2 * lerpTo(const Vec2 *other, float t) const
Linear interpolation to other at t in [0,1].
Definition Vec2.cpp:54
Vec3 * lerpTo(const Vec3 *other, float t) const
Linear interpolation to other at t in [0,1].
Definition Vec3.cpp:55
Vec3 * add(const Vec3 *other) const
Arithmetic helpers returning new (caller-owned) vectors.
Definition Vec3.cpp:43
Vector2 arrive(Vector2 position, Vector2 target, float maxSpeed, float slowRadius, float stopRadius)
Slows toward target inside slowRadius and stops inside stopRadius.
Definition Steering.cpp:161
Vector2 seek(Vector2 position, Vector2 target, float maxSpeed)
Returns a velocity of at most maxSpeed directed from position to target.
Definition Steering.cpp:149
Vector2 avoid(Vector2 position, Vector2 velocity, Vector2 obstacle, float obstacleRadius, float lookAhead, float maxAcceleration)
Computes avoidance acceleration away from a predicted obstacle overlap.
Definition Steering.cpp:185
Vector2 separation(Vector2 position, std::span< const Vector2 > neighbors, float radius, float maxAcceleration)
Computes bounded separation acceleration from a borrowed neighbor snapshot.
Definition Steering.cpp:169
Vector2 flee(Vector2 position, Vector2 target, float maxSpeed)
Returns a velocity of at most maxSpeed directed away from target.
Definition Steering.cpp:155
int pathTarget(Vector2 position, std::span< const Vector2 > points, int current, float tolerance)
Selects the current path point, advancing across points within tolerance.
Definition Steering.cpp:177
Definition Mat4.cpp:10
Stateless steering vector algorithms shared by 2D and 3D callers.
Definition Steering.h:17