载入中...
搜索中...
未找到
Math.cpp
浏览该文件的文档.
459bool Math::segmentsIntersect(float ax, float ay, float bx, float by, float cx, float cy, float dx,
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))); }
699float Math::perlin2(float x, float y) const { return noiseToUnit(glm::perlin(glm::vec2(x, y))); }
933float Math::swiss2(float x, float y, int octaves, float lacunarity, float gain, float warpStrength) const {
970float Math::jordan2(float x, float y, int octaves, float lacunarity, float gain, float warpStrength) const {
1071float Math::fbmColor2(float x, float y, int channel, int octaves, float lacunarity, float gain) const {
1078float Math::white3(float x, float y, float z) const { return hash31(std::floor(x), std::floor(y), std::floor(z)); }
1145float Math::bezierQuadratic2X(float t, float x0, float /*y0*/, float x1, float /*y1*/, float x2,
1150float Math::bezierQuadratic2Y(float t, float /*x0*/, float y0, float /*x1*/, float y1, float /*x2*/,
1160float Math::bezierCubic2Y(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
float warpNoise2Deep(float x, float y, float warpAmp=1.f) const
Two-pass iq-style domain warp (noisecreater DomainWarp / Smoke).
Definition Math.cpp:817
float value3(float x, float y, float z) const
Smooth 3D value noise in [0,1].
Definition Math.cpp:1080
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
float jordan2(float x, float y, int octaves, float lacunarity, float gain, float warpStrength) const
Musgrave Jordan turbulence remapped to [0,1].
Definition Math.cpp:970
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:1131
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:811
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:700
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:797
float approach(float current, float target, float maxDelta) const
Moves current toward target by at most maxDelta.
Definition Math.cpp:194
float worleySmooth2(float x, float y, float smoothness) const
Smooth-min Worley (metaball cellular) in [0,1].
Definition Math.cpp:857
float gyroidFbm3(float x, float y, float z, int octaves) const
Absolute-gyroid fBm remapped to [0,1].
Definition Math.cpp:918
float turbulence2(float x, float y, int octaves=4, float lacunarity=2.f, float gain=0.5f) const
2D turbulence / billow (absolute fBm).
Definition Math.cpp:780
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
float gaborFbm2(float x, float y, int octaves, float dirX, float dirY) const
Absolute-Gabor fBm remapped to [0,1].
Definition Math.cpp:1022
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 curlNoise2Y(float x, float y, float eps) const
Curl-noise Y from value-noise potential (finite differences).
Definition Math.cpp:878
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 fbmColor2(float x, float y, int channel, int octaves, float lacunarity, float gain) const
Decorrelated fBm color channel (0/1/2).
Definition Math.cpp:1071
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:1145
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 valueSlope2(float x, float y, float eps) const
Gradient magnitude of value2.
Definition Math.cpp:1049
float angleBetween2(float x1, float y1, float x2, float y2) const
Signed angle from first vector to second.
Definition Math.cpp:382
float smoothMax(float a, float b, float width) const
C1 smooth maximum of two finite heights; see common/SmoothMax.h.
Definition MathSmooth.cpp:6
float normalize3Y(float x, float y, float z) const
Y of the normalized 3D vector (zero-safe).
Definition Math.cpp:406
float gyroid3(float x, float y, float z) const
Gyroid field remapped to [0,1].
Definition Math.cpp:913
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
float valueDy2(float x, float y, float eps) const
∂/∂y of value2 via central differences.
Definition Math.cpp:1044
float noise1(float x) const
1D Simplex noise in [0,1]. Kept as noise1 for script compatibility; prefer simplex1 for clarity.
Definition Math.cpp:689
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 simplex3(float x, float y, float z) const
Alias of noise3 (explicit Simplex).
Definition Math.cpp:697
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 gabor2(float x, float y, float dirX, float dirY, float frequency) const
Gabor / Voronoi-mix wavelet remapped to [0,1].
Definition Math.cpp:992
float rotate2X(float x, float y, float radians) const
Rotate (x,y) by radians around origin.
Definition Math.cpp:415
float worleyManhattan2(float x, float y) const
Worley with Manhattan metric; F1 distance.
Definition Math.cpp:831
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 swiss2(float x, float y, int octaves, float lacunarity, float gain, float warpStrength) const
Musgrave Swiss turbulence remapped to [0,1].
Definition Math.cpp:933
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:1160
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:1150
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
float curlNoise2X(float x, float y, float eps) const
Curl-noise X from value-noise potential (finite differences).
Definition Math.cpp:873
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:764
float bezierCubic(float t, float p0, float p1, float p2, float p3) const
1D cubic Bezier at t in [0,1].
Definition Math.cpp:1137
float worleyChebyshev2(float x, float y) const
Worley with Chebyshev metric; F1 distance.
Definition Math.cpp:844
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:748
float isoLine2(float x, float y, int levels, float width) const
Contour mask of value2 in [0,1] (1 on lines).
Definition Math.cpp:1055
float billow2(float x, float y, int octaves=4, float lacunarity=2.f, float gain=0.5f) const
Alias of turbulence2 (NoiseCreator billow naming).
Definition Math.cpp:793
float pingPong(float t, float length) const
Triangle-wave ping-pong of t over [0, length].
Definition Math.cpp:209
float voronoiF2_2(float x, float y) const
Worley F2 distance (second-nearest feature).
Definition Math.cpp:825
float worley3(float x, float y, float z) const
Texture-friendly 3D Worley clamp(1-F1).
Definition Math.cpp:1107
float hexEdge2(float x, float y, float width, float soft) const
Hex edge line mask in [0,1].
Definition Math.cpp:906
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 hybrid2(float x, float y, int octaves, float lacunarity, float gain, float offset) const
Musgrave hybrid multifractal remapped to [0,1].
Definition Math.cpp:950
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:1155
float banding2(float x, float y, int bands) const
Quantized banding of value2 in [0,1].
Definition Math.cpp:1065
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:735
float dot2(float x1, float y1, float x2, float y2) const
2D dot product of two vectors.
Definition Math.cpp:374
float white3(float x, float y, float z) const
Lattice white noise from floor(x,y,z) in [0,1].
Definition Math.cpp:1078
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
float white2(float x, float y) const
Lattice white noise from floor(x), floor(y) in [0,1].
Definition Math.cpp:704
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
float valueDx2(float x, float y, float eps) const
∂/∂x of value2 via central differences.
Definition Math.cpp:1039
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:722
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
float worley2(float x, float y) const
Texture-friendly Worley: clamp(1 - F1, 0, 1).
Definition Math.cpp:809
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 Vec2.cpp:111
Vec3 * add(const Vec3 *other) const
Arithmetic helpers returning new (caller-owned) vectors.
Definition Vec2.cpp:99
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 SmoothMax.h:10
Stateless steering vector algorithms shared by 2D and 3D callers.
Definition Steering.h:17