diff --git a/src/base/base_math.c b/src/base/base_math.c index 15e75628..d821022a 100644 --- a/src/base/base_math.c +++ b/src/base/base_math.c @@ -800,26 +800,26 @@ Rng2I32 DivRng2I32Vec2I32(Rng2I32 r, Vec2I32 v) } //////////////////////////////////////////////////////////// -//~ Xform +//~ Affine -b32 MatchXform(Xform xf1, Xform xf2) +b32 MatchAffine(Affine af1, Affine af2) { - return MatchVec2(xf1.og, xf2.og) && MatchVec2(xf1.bx, xf2.bx) && MatchVec2(xf1.by, xf2.by); + return MatchVec2(af1.og, af2.og) && MatchVec2(af1.bx, af2.bx) && MatchVec2(af1.by, af2.by); } //- Initialization -Xform XformFromPos(Vec2 v) +Affine AffineFromPos(Vec2 v) { - Xform xf; - xf.bx = VEC2(1, 0); - xf.by = VEC2(0, 1); - xf.og = v; - return xf; + Affine af; + af.bx = VEC2(1, 0); + af.by = VEC2(0, 1); + af.og = v; + return af; } -Xform XformFromRot(f32 r) +Affine AffineFromRot(f32 r) { - Xform result; + Affine result; f32 c = CosF32(r); f32 s = SinF32(r); result.bx = VEC2(c, s); @@ -828,83 +828,83 @@ Xform XformFromRot(f32 r) return result; } -Xform XformFromScale(Vec2 scale) +Affine AffineFromScale(Vec2 scale) { - Xform result; + Affine result; result.bx = VEC2(scale.x, 0); result.by = VEC2(0, scale.y); result.og = VEC2(0, 0); return result; } -Xform XformFromTrs(Trs trs) +Affine AffineFromTrs(Trs trs) { - Xform xf = XformFromPos(trs.t); - xf = RotateXform(xf, trs.r); - xf = ScaleXform(xf, trs.s); - return xf; + Affine af = AffineFromPos(trs.t); + af = RotateAffine(af, trs.r); + af = ScaleAffine(af, trs.s); + return af; } //- Translation -Xform TranslateXform(Xform xf, Vec2 v) +Affine TranslateAffine(Affine af, Vec2 v) { - xf.og = VEC2(xf.bx.x * v.x + xf.by.x * v.y + xf.og.x, xf.bx.y * v.x + xf.by.y * v.y + xf.og.y); - return xf; + af.og = VEC2(af.bx.x * v.x + af.by.x * v.y + af.og.x, af.bx.y * v.x + af.by.y * v.y + af.og.y); + return af; } -Xform WorldTranslateXform(Xform xf, Vec2 v) +Affine WorldTranslateAffine(Affine af, Vec2 v) { - xf.og = AddVec2(xf.og, v); - return xf; + af.og = AddVec2(af.og, v); + return af; } //- Rotation -Xform RotateXform(Xform xf, f32 r) +Affine RotateAffine(Affine af, f32 r) { - return MulXform(xf, XformFromRot(r)); + return MulAffine(af, AffineFromRot(r)); } -Xform WorldRotateXform(Xform xf, f32 r) +Affine WorldRotateAffine(Affine af, f32 r) { - return MulXform(XformFromRot(r), xf); + return MulAffine(AffineFromRot(r), af); } -Xform WorldRotateXformBasis(Xform xf, f32 r) +Affine WorldRotateAffineBasis(Affine af, f32 r) { f32 diff = r; f32 c = CosF32(diff); f32 s = SinF32(diff); - xf.bx = VEC2(xf.bx.x * c - xf.bx.y * s, xf.bx.x * s + xf.bx.y * c); - xf.by = VEC2(xf.by.x * c - xf.by.y * s, xf.by.x * s + xf.by.y * c); - return xf; + af.bx = VEC2(af.bx.x * c - af.bx.y * s, af.bx.x * s + af.bx.y * c); + af.by = VEC2(af.by.x * c - af.by.y * s, af.by.x * s + af.by.y * c); + return af; } -Xform XformWithWorldRotation(Xform xf, f32 r) +Affine AffineWithWorldRotation(Affine af, f32 r) { - return WorldRotateXformBasis(xf, r - RotationFromXform(xf)); + return WorldRotateAffineBasis(af, r - RotationFromAffine(af)); } //- Scale -Xform ScaleXform(Xform xf, Vec2 scale) +Affine ScaleAffine(Affine af, Vec2 scale) { - xf.bx = MulVec2(xf.bx, scale.x); - xf.by = MulVec2(xf.by, scale.y); - return xf; + af.bx = MulVec2(af.bx, scale.x); + af.by = MulVec2(af.by, scale.y); + return af; } -Xform WorldScaleXform(Xform xf, Vec2 scale) +Affine WorldScaleAffine(Affine af, Vec2 scale) { - Xform result; - result.bx = MulVec2Vec2(xf.bx, scale); - result.by = MulVec2Vec2(xf.by, scale); - result.og = MulVec2Vec2(xf.og, scale); + Affine result; + result.bx = MulVec2Vec2(af.bx, scale); + result.by = MulVec2Vec2(af.by, scale); + result.og = MulVec2Vec2(af.og, scale); return result; } //- Lerp -Xform LerpXform(Xform a, Xform b, f32 t) +Affine LerpAffine(Affine a, Affine b, f32 t) { - Xform result; + Affine result; result.bx = SlerpVec2(a.bx, b.bx, t); result.by = SlerpVec2(a.by, b.by, t); result.og = LerpVec2(a.og, b.og, t); @@ -912,109 +912,109 @@ Xform LerpXform(Xform a, Xform b, f32 t) } //- Invert -Xform InvertXform(Xform xf) +Affine InvertAffine(Affine af) { - f32 det = DeterminantFromXform(xf); + f32 det = DeterminantFromAffine(af); f32 inv_det = 1.0f / det; - f32 old_bx_x = xf.bx.x; - xf.bx.x = xf.by.y; - xf.by.y = old_bx_x; + f32 old_bx_x = af.bx.x; + af.bx.x = af.by.y; + af.by.y = old_bx_x; - xf.bx = MulVec2Vec2(xf.bx, VEC2(inv_det, -inv_det)); - xf.by = MulVec2Vec2(xf.by, VEC2(-inv_det, inv_det)); + af.bx = MulVec2Vec2(af.bx, VEC2(inv_det, -inv_det)); + af.by = MulVec2Vec2(af.by, VEC2(-inv_det, inv_det)); - xf.og = MulXformBasisV2(xf, NegVec2(xf.og)); + af.og = MulAffineBasisV2(af, NegVec2(af.og)); - return xf; + return af; } //- Mul -Xform MulXform(Xform a, Xform b) +Affine MulAffine(Affine a, Affine b) { - Xform result; + Affine result; result.bx.x = a.bx.x * b.bx.x + a.by.x * b.bx.y; result.bx.y = a.bx.y * b.bx.x + a.by.y * b.bx.y; result.by.x = a.bx.x * b.by.x + a.by.x * b.by.y; result.by.y = a.bx.y * b.by.x + a.by.y * b.by.y; - result.og = MulXformV2(a, b.og); + result.og = MulAffineV2(a, b.og); return result; } -Vec2 MulXformBasisV2(Xform xf, Vec2 v) +Vec2 MulAffineBasisV2(Affine af, Vec2 v) { return VEC2( - xf.bx.x * v.x + xf.by.x * v.y, - xf.bx.y * v.x + xf.by.y * v.y + af.bx.x * v.x + af.by.x * v.y, + af.bx.y * v.x + af.by.y * v.y ); } -Vec2 MulXformV2(Xform xf, Vec2 v) +Vec2 MulAffineV2(Affine af, Vec2 v) { - Vec2 result = MulXformBasisV2(xf, v); - result = AddVec2(result, xf.og); + Vec2 result = MulAffineBasisV2(af, v); + result = AddVec2(result, af.og); return result; } -Vec2 InvertXformBasisMulV2(Xform xf, Vec2 v) +Vec2 InvertAffineBasisMulV2(Affine af, Vec2 v) { - Xform inv = InvertXform(xf); - Vec2 result = MulXformBasisV2(inv, v); + Affine inv = InvertAffine(af); + Vec2 result = MulAffineBasisV2(inv, v); return result; } // TODO: Get rid of this? Just force caller to use invert manually since it's expensive. -Vec2 InvertXformMulV2(Xform xf, Vec2 v) +Vec2 InvertAffineMulV2(Affine af, Vec2 v) { - Xform inv = InvertXform(xf); - return MulXformV2(inv, v); + Affine inv = InvertAffine(af); + return MulAffineV2(inv, v); } //- Helpers -Xform BasisFromXform(Xform xf) +Affine BasisFromAffine(Affine af) { - Xform result = Zi; - result.bx = xf.bx; - result.by = xf.by; + Affine result = Zi; + result.bx = af.bx; + result.by = af.by; return result; } -f32 DeterminantFromXform(Xform xf) +f32 DeterminantFromAffine(Affine af) { - return WedgeVec2(xf.bx, xf.by); + return WedgeVec2(af.bx, af.by); } -Vec2 RightFromXform(Xform xf) +Vec2 RightFromAffine(Affine af) { - return xf.bx; + return af.bx; } -Vec2 LeftFromXform(Xform xf) +Vec2 LeftFromAffine(Affine af) { - return NegVec2(xf.bx); + return NegVec2(af.bx); } -Vec2 UpFromXform(Xform xf) +Vec2 UpFromAffine(Affine af) { - return NegVec2(xf.by); + return NegVec2(af.by); } -Vec2 DownFromXform(Xform xf) +Vec2 DownFromAffine(Affine af) { - return xf.by; + return af.by; } -f32 RotationFromXform(Xform xf) +f32 RotationFromAffine(Affine af) { - return AngleFromVec2(xf.bx); + return AngleFromVec2(af.bx); } -Vec2 ScaleFromXform(Xform xf) +Vec2 ScaleFromAffine(Affine af) { - f32 det = DeterminantFromXform(xf); + f32 det = DeterminantFromAffine(af); i32 det_sign = (det >= 0) - (det < 0); - return VEC2(Vec2Len(xf.bx), det_sign * Vec2Len(xf.by)); + return VEC2(Vec2Len(af.bx), det_sign * Vec2Len(af.by)); } //////////////////////////////////////////////////////////// @@ -1046,15 +1046,15 @@ SoftSpring MakeSpring(f32 hertz, f32 damping_ratio, f32 dt) //////////////////////////////////////////////////////////// //~ Mat4x4 -Mat4x4 Mat4x4FromXform(Xform xf) +Mat4x4 Mat4x4FromAffine(Affine af) { return (Mat4x4) { .e = { - {xf.bx.x, xf.bx.y, 0, 0}, - {xf.by.x, xf.by.y, 0, 0}, + {af.bx.x, af.bx.y, 0, 0}, + {af.by.x, af.by.y, 0, 0}, {0, 0, 1, 0}, - {xf.og.x, xf.og.y, 0, 1}, + {af.og.x, af.og.y, 0, 1}, } }; } @@ -1111,9 +1111,9 @@ Mat4x4 MulMat4x4(Mat4x4 m1, Mat4x4 m2) return result; } -Mat4x4 ProjectMat4x4View(Xform view, f32 viewport_width, f32 viewport_height) +Mat4x4 ProjectMat4x4View(Affine view, f32 viewport_width, f32 viewport_height) { Mat4x4 projection = Mat4x4FromOrtho(0.0, viewport_width, viewport_height, 0.0, -1.0, 1.0); - Mat4x4 view4x4 = Mat4x4FromXform(view); + Mat4x4 view4x4 = Mat4x4FromAffine(view); return MulMat4x4(projection, view4x4); } diff --git a/src/base/base_math.h b/src/base/base_math.h index 8a41a7cf..5c71fea2 100644 --- a/src/base/base_math.h +++ b/src/base/base_math.h @@ -147,9 +147,9 @@ Struct(Rng3U64) { Vec3U64 p0, p1; }; #define RNG3U64(p0, p1) (Rng3U64) { (p0), (p1) } //////////////////////////////////////////////////////////// -//~ Xform types +//~ Affine types -Struct(Xform) +Struct(Affine) { Vec2 bx; // X basis vector (x axis) Vec2 by; // Y basis vector (y axis) @@ -436,54 +436,54 @@ Rng2I32 MulRng2I32Vec2I32(Rng2I32 a, Vec2I32 v); Rng2I32 DivRng2I32Vec2I32(Rng2I32 a, Vec2I32 v); //////////////////////////////////////////////////////////// -//~ Xform +//~ Affine -b32 MatchXform(Xform xf1, Xform xf2); +b32 MatchAffine(Affine af1, Affine af2); //- Initialization -#define XformIdentity (Xform) { .bx = { .x = 1 }, .by = { .y = 1 } } -#define CompXformIdentity { .bx = { .x = 1 }, .by = { .y = 1 } } -Xform XformFromPos(Vec2 v); -Xform XformFromRot(f32 r); -Xform XformFromScale(Vec2 scale); -Xform XformFromTrs(Trs trs); +#define AffineIdentity (Affine) { .bx = { .x = 1 }, .by = { .y = 1 } } +#define CompAffineIdentity { .bx = { .x = 1 }, .by = { .y = 1 } } +Affine AffineFromPos(Vec2 v); +Affine AffineFromRot(f32 r); +Affine AffineFromScale(Vec2 scale); +Affine AffineFromTrs(Trs trs); //- Translation -Xform TranslateXform(Xform xf, Vec2 v); -Xform WorldTranslateXform(Xform xf, Vec2 v); +Affine TranslateAffine(Affine af, Vec2 v); +Affine WorldTranslateAffine(Affine af, Vec2 v); //- Rotation -Xform RotateXform(Xform xf, f32 r); -Xform WorldRotateXform(Xform xf, f32 r); -Xform WorldRotateXformBasis(Xform xf, f32 r); -Xform XformWithWorldRotation(Xform xf, f32 r); +Affine RotateAffine(Affine af, f32 r); +Affine WorldRotateAffine(Affine af, f32 r); +Affine WorldRotateAffineBasis(Affine af, f32 r); +Affine AffineWithWorldRotation(Affine af, f32 r); //- Scale -Xform ScaleXform(Xform xf, Vec2 scale); -Xform WorldScaleXform(Xform xf, Vec2 scale); +Affine ScaleAffine(Affine af, Vec2 scale); +Affine WorldScaleAffine(Affine af, Vec2 scale); //- Lerp -Xform LerpXform(Xform a, Xform b, f32 t); +Affine LerpAffine(Affine a, Affine b, f32 t); //- Invert -Xform InvertXform(Xform xf); +Affine InvertAffine(Affine af); //- Mul -Vec2 MulXformV2(Xform xf, Vec2 v); -Xform MulXform(Xform a, Xform b); -Vec2 MulXformBasisV2(Xform xf, Vec2 v); -Vec2 InvertXformMulV2(Xform xf, Vec2 v); -Vec2 InvertXformBasisMulV2(Xform xf, Vec2 v); +Vec2 MulAffineV2(Affine af, Vec2 v); +Affine MulAffine(Affine a, Affine b); +Vec2 MulAffineBasisV2(Affine af, Vec2 v); +Vec2 InvertAffineMulV2(Affine af, Vec2 v); +Vec2 InvertAffineBasisMulV2(Affine af, Vec2 v); //- Helpers -Xform BasisFromXform(Xform xf); -f32 DeterminantFromXform(Xform xf); -Vec2 RightFromXform(Xform xf); -Vec2 LeftFromXform(Xform xf); -Vec2 UpFromXform(Xform xf); -Vec2 DownFromXform(Xform xf); -f32 RotationFromXform(Xform xf); -Vec2 ScaleFromXform(Xform xf); +Affine BasisFromAffine(Affine af); +f32 DeterminantFromAffine(Affine af); +Vec2 RightFromAffine(Affine af); +Vec2 LeftFromAffine(Affine af); +Vec2 UpFromAffine(Affine af); +Vec2 DownFromAffine(Affine af); +f32 RotationFromAffine(Affine af); +Vec2 ScaleFromAffine(Affine af); //- Trs #define TRS(...) ((Trs) { .t = VEC2(0,0), .s = VEC2(1, 1), .r = 0, __VA_ARGS__ }) @@ -496,7 +496,7 @@ SoftSpring MakeSpring(f32 hertz, f32 damping_ratio, f32 dt); //////////////////////////////////////////////////////////// //~ Mat4x4 -Mat4x4 Mat4x4FromXform(Xform xf); +Mat4x4 Mat4x4FromAffine(Affine af); Mat4x4 Mat4x4FromOrtho(f32 left, f32 right, f32 bottom, f32 top, f32 near_z, f32 far_z); Mat4x4 MulMat4x4(Mat4x4 m1, Mat4x4 m2); -Mat4x4 ProjectMat4x4View(Xform view, f32 viewport_width, f32 viewport_height); +Mat4x4 ProjectMat4x4View(Affine view, f32 viewport_width, f32 viewport_height); diff --git a/src/base/base_shader.gh b/src/base/base_shader.gh index 7be63cd7..6149c852 100644 --- a/src/base/base_shader.gh +++ b/src/base/base_shader.gh @@ -14,7 +14,7 @@ typedef int4 Vec4I32; typedef uint2 Vec2U32; typedef uint3 Vec3U32; typedef uint4 Vec4U32; -typedef float2x3 Xform; +typedef float2x3 Affine; typedef float4 Rect; typedef float4 ClipRect; typedef float4 Aabb; diff --git a/src/collider/collider.c b/src/collider/collider.c index 174a7f4a..b2085c6d 100644 --- a/src/collider/collider.c +++ b/src/collider/collider.c @@ -28,14 +28,14 @@ CLD_Shape CLD_ShapeFromQuad(Quad quad) //////////////////////////////////////////////////////////// //~ Menkowski support point -CLD_SupportPoint CLD_SupportPointFromDirEx(CLD_Shape *shape, Xform xf, Vec2 dir, i32 ignore) +CLD_SupportPoint CLD_SupportPointFromDirEx(CLD_Shape *shape, Affine af, Vec2 dir, i32 ignore) { Vec2 *points = shape->points; u32 count = shape->count; f32 radius = shape->radius; - dir = RotateVec2(dir, -RotationFromXform(xf)); - dir = MulVec2Vec2(dir, ScaleFromXform(xf)); + dir = RotateVec2(dir, -RotationFromAffine(af)); + dir = MulVec2Vec2(dir, ScaleFromAffine(af)); if (count == 1) { @@ -69,7 +69,7 @@ CLD_SupportPoint CLD_SupportPointFromDirEx(CLD_Shape *shape, Xform xf, Vec2 dir, furthest = AddVec2(furthest, dir); } - furthest = MulXformV2(xf, furthest); + furthest = MulAffineV2(af, furthest); CLD_SupportPoint result; result.p = furthest; @@ -77,16 +77,16 @@ CLD_SupportPoint CLD_SupportPointFromDirEx(CLD_Shape *shape, Xform xf, Vec2 dir, return result; } -CLD_SupportPoint CLD_SupportPointFromDir(CLD_Shape *shape, Xform xf, Vec2 dir) +CLD_SupportPoint CLD_SupportPointFromDir(CLD_Shape *shape, Affine af, Vec2 dir) { - return CLD_SupportPointFromDirEx(shape, xf, dir, -1); + return CLD_SupportPointFromDirEx(shape, af, dir, -1); } -CLD_MenkowskiPoint CLD_MenkowskiPointFromDir(CLD_Shape *shape0, CLD_Shape *shape1, Xform xf0, Xform xf1, Vec2 dir) +CLD_MenkowskiPoint CLD_MenkowskiPointFromDir(CLD_Shape *shape0, CLD_Shape *shape1, Affine af0, Affine af1, Vec2 dir) { CLD_MenkowskiPoint result; - result.s0 = CLD_SupportPointFromDir(shape0, xf0, dir); - result.s1 = CLD_SupportPointFromDir(shape1, xf1, NegVec2(dir)); + result.s0 = CLD_SupportPointFromDir(shape0, af0, dir); + result.s1 = CLD_SupportPointFromDir(shape1, af1, NegVec2(dir)); result.p = SubVec2(result.s0.p, result.s1.p); return result; } @@ -94,13 +94,13 @@ CLD_MenkowskiPoint CLD_MenkowskiPointFromDir(CLD_Shape *shape0, CLD_Shape *shape //////////////////////////////////////////////////////////// //~ Aabb -Aabb CLD_AabbFromShape(CLD_Shape *shape, Xform xf) +Aabb CLD_AabbFromShape(CLD_Shape *shape, Affine af) { Aabb result; - result.p0.x = CLD_SupportPointFromDir(shape, xf, VEC2(-1, 0)).p.x - CLD_CollisionTolerance; - result.p0.y = CLD_SupportPointFromDir(shape, xf, VEC2(0, -1)).p.y - CLD_CollisionTolerance; - result.p1.x = CLD_SupportPointFromDir(shape, xf, VEC2(1, 0)).p.x + CLD_CollisionTolerance; - result.p1.y = CLD_SupportPointFromDir(shape, xf, VEC2(0, 1)).p.y + CLD_CollisionTolerance; + result.p0.x = CLD_SupportPointFromDir(shape, af, VEC2(-1, 0)).p.x - CLD_CollisionTolerance; + result.p0.y = CLD_SupportPointFromDir(shape, af, VEC2(0, -1)).p.y - CLD_CollisionTolerance; + result.p1.x = CLD_SupportPointFromDir(shape, af, VEC2(1, 0)).p.x + CLD_CollisionTolerance; + result.p1.y = CLD_SupportPointFromDir(shape, af, VEC2(0, 1)).p.y + CLD_CollisionTolerance; return result; } @@ -138,9 +138,9 @@ b32 CLD_TestAabb(Aabb box0, Aabb box1) // #if COLLIDER_DEBUG -CLD_GjkData CLD_GjkDataFromShapes(CLD_Shape *shape0, CLD_Shape *shape1, Xform xf0, Xform xf1, f32 min_unique_pt_dist_sq, u32 dbg_step) +CLD_GjkData CLD_GjkDataFromShapes(CLD_Shape *shape0, CLD_Shape *shape1, Affine af0, Affine af1, f32 min_unique_pt_dist_sq, u32 dbg_step) #else -CLD_GjkData CLD_GjkDataFromShapes(CLD_Shape *shape0, CLD_Shape *shape1, Xform xf0, Xform xf1, f32 min_unique_pt_dist_sq) +CLD_GjkData CLD_GjkDataFromShapes(CLD_Shape *shape0, CLD_Shape *shape1, Affine af0, Affine af1, f32 min_unique_pt_dist_sq) #endif { b32 overlapping = 0; @@ -149,9 +149,9 @@ CLD_GjkData CLD_GjkDataFromShapes(CLD_Shape *shape0, CLD_Shape *shape1, Xform xf CLD_MenkowskiPoint m = Zi; // First point is support point in shape's general directions to eachother - dir = SubVec2(xf1.og, xf0.og); + dir = SubVec2(af1.og, af0.og); if (IsVec2Zero(dir)) dir = VEC2(1, 0); - s.a = CLD_MenkowskiPointFromDir(shape0, shape1, xf0, xf1, dir); + s.a = CLD_MenkowskiPointFromDir(shape0, shape1, af0, af1, dir); s.len = 1; Vec2 removed_a = Zi; @@ -168,7 +168,7 @@ CLD_GjkData CLD_GjkDataFromShapes(CLD_Shape *shape0, CLD_Shape *shape1, Xform xf dir = NegVec2(s.a.p); CLD_DBGSTEP; - m = CLD_MenkowskiPointFromDir(shape0, shape1, xf0, xf1, dir); + m = CLD_MenkowskiPointFromDir(shape0, shape1, af0, af1, dir); // Check that new point is far enough away from existing point if (Vec2LenSq(SubVec2(m.p, s.a.p)) < min_unique_pt_dist_sq) { @@ -188,7 +188,7 @@ CLD_GjkData CLD_GjkDataFromShapes(CLD_Shape *shape0, CLD_Shape *shape1, Xform xf { CLD_DBGSTEP; - m = CLD_MenkowskiPointFromDir(shape0, shape1, xf0, xf1, dir); + m = CLD_MenkowskiPointFromDir(shape0, shape1, af0, af1, dir); // Check that new point is far enough away from existing points if ( Vec2LenSq(SubVec2(m.p, s.a.p)) < min_unique_pt_dist_sq || @@ -325,9 +325,9 @@ CLD_GjkData CLD_GjkDataFromShapes(CLD_Shape *shape0, CLD_Shape *shape1, Xform xf // closest edge when shapes are overlapping #if COLLIDER_DEBUG -CLD_EpaData CLD_EpaDataFromShapes(CLD_Shape *shape0, CLD_Shape *shape1, Xform xf0, Xform xf1, CLD_GjkData gjk_result, f32 min_unique_pt_dist_sq, u32 max_iterations, u32 dbg_step) +CLD_EpaData CLD_EpaDataFromShapes(CLD_Shape *shape0, CLD_Shape *shape1, Affine af0, Affine af1, CLD_GjkData gjk_result, f32 min_unique_pt_dist_sq, u32 max_iterations, u32 dbg_step) #else -CLD_EpaData CLD_EpaDataFromShapes(CLD_Shape *shape0, CLD_Shape *shape1, Xform xf0, Xform xf1, CLD_GjkData gjk_result, f32 min_unique_pt_dist_sq, u32 max_iterations) +CLD_EpaData CLD_EpaDataFromShapes(CLD_Shape *shape0, CLD_Shape *shape1, Affine af0, Affine af1, CLD_GjkData gjk_result, f32 min_unique_pt_dist_sq, u32 max_iterations) #endif { TempArena scratch = BeginScratchNoConflict(); @@ -389,7 +389,7 @@ CLD_EpaData CLD_EpaDataFromShapes(CLD_Shape *shape0, CLD_Shape *shape1, Xform xf // Find new point in dir Vec2 dir = MulVec2(PerpVec2(vab), winding); - CLD_MenkowskiPoint m = CLD_MenkowskiPointFromDir(shape0, shape1, xf0, xf1, dir); + CLD_MenkowskiPoint m = CLD_MenkowskiPointFromDir(shape0, shape1, af0, af1, dir); #if COLLIDER_DEBUG { @@ -545,7 +545,7 @@ Vec2 CLD_ClipPointToLine(Vec2 a, Vec2 b, Vec2 p, Vec2 normal) //////////////////////////////////////////////////////////// //~ Collision points -CLD_CollisionData CLD_CollisionDataFromShapes(CLD_Shape *shape0, CLD_Shape *shape1, Xform xf0, Xform xf1) +CLD_CollisionData CLD_CollisionDataFromShapes(CLD_Shape *shape0, CLD_Shape *shape1, Affine af0, Affine af1) { CLD_CollisionData result = Zi; @@ -567,19 +567,19 @@ CLD_CollisionData CLD_CollisionDataFromShapes(CLD_Shape *shape0, CLD_Shape *shap // Run GJK #if COLLIDER_DEBUG - gjk_result = CLD_GjkDataFromShapes(shape0, shape1, xf0, xf1, min_unique_pt_dist_sq, dbg_step); + gjk_result = CLD_GjkDataFromShapes(shape0, shape1, af0, af1, min_unique_pt_dist_sq, dbg_step); dbg_step = gjk_result.dbg_step; #else - gjk_result = CLD_GjkDataFromShapes(shape0, shape1, xf0, xf1, min_unique_pt_dist_sq); + gjk_result = CLD_GjkDataFromShapes(shape0, shape1, af0, af1, min_unique_pt_dist_sq); #endif CLD_DBGSTEP; // Run EPA #if COLLIDER_DEBUG - epa_result = CLD_EpaDataFromShapes(shape0, shape1, xf0, xf1, gjk_result, min_unique_pt_dist_sq, max_epa_iterations, dbg_step); + epa_result = CLD_EpaDataFromShapes(shape0, shape1, af0, af1, gjk_result, min_unique_pt_dist_sq, max_epa_iterations, dbg_step); dbg_step = epa_result.dbg_step; #else - epa_result = CLD_EpaDataFromShapes(shape0, shape1, xf0, xf1, gjk_result, min_unique_pt_dist_sq, max_epa_iterations); + epa_result = CLD_EpaDataFromShapes(shape0, shape1, af0, af1, gjk_result, min_unique_pt_dist_sq, max_epa_iterations); #endif normal = epa_result.normal; CLD_DBGSTEP; @@ -639,7 +639,7 @@ CLD_CollisionData CLD_CollisionDataFromShapes(CLD_Shape *shape0, CLD_Shape *shap { if (shape0->count > 1) { - b0 = CLD_SupportPointFromDirEx(shape0, xf0, normal, b0.i); + b0 = CLD_SupportPointFromDirEx(shape0, af0, normal, b0.i); } else { @@ -651,7 +651,7 @@ CLD_CollisionData CLD_CollisionDataFromShapes(CLD_Shape *shape0, CLD_Shape *shap { if (shape1->count > 1) { - b1 = CLD_SupportPointFromDirEx(shape1, xf1, NegVec2(normal), b1.i); + b1 = CLD_SupportPointFromDirEx(shape1, af1, NegVec2(normal), b1.i); } else { @@ -828,7 +828,7 @@ CLD_CollisionData CLD_CollisionDataFromShapes(CLD_Shape *shape0, CLD_Shape *shap // TODO: De-duplicate code between CLD_ClosestPointDataFromShapes & CLD_CollisionDataFromShapes -CLD_ClosestPointData CLD_ClosestPointDataFromShapes(CLD_Shape *shape0, CLD_Shape *shape1, Xform xf0, Xform xf1) +CLD_ClosestPointData CLD_ClosestPointDataFromShapes(CLD_Shape *shape0, CLD_Shape *shape1, Affine af0, Affine af1) { CLD_ClosestPointData result = Zi; @@ -851,10 +851,10 @@ CLD_ClosestPointData CLD_ClosestPointDataFromShapes(CLD_Shape *shape0, CLD_Shape //- Run GJK #if COLLIDER_DEBUG - gjk_result = CLD_GjkDataFromShapes(shape0, shape1, xf0, xf1, min_unique_pt_dist_sq, dbg_step); + gjk_result = CLD_GjkDataFromShapes(shape0, shape1, af0, af1, min_unique_pt_dist_sq, dbg_step); dbg_step = gjk_result.dbg_step; #else - gjk_result = CLD_GjkDataFromShapes(shape0, shape1, xf0, xf1, min_unique_pt_dist_sq); + gjk_result = CLD_GjkDataFromShapes(shape0, shape1, af0, af1, min_unique_pt_dist_sq); #endif CLD_DBGSTEP; @@ -862,10 +862,10 @@ CLD_ClosestPointData CLD_ClosestPointDataFromShapes(CLD_Shape *shape0, CLD_Shape //- Run EPA #if COLLIDER_DEBUG - epa_result = CLD_EpaDataFromShapes(shape0, shape1, xf0, xf1, gjk_result, min_unique_pt_dist_sq, max_epa_iterations, dbg_step); + epa_result = CLD_EpaDataFromShapes(shape0, shape1, af0, af1, gjk_result, min_unique_pt_dist_sq, max_epa_iterations, dbg_step); dbg_step = epa_result.dbg_step; #else - epa_result = CLD_EpaDataFromShapes(shape0, shape1, xf0, xf1, gjk_result, min_unique_pt_dist_sq, max_epa_iterations); + epa_result = CLD_EpaDataFromShapes(shape0, shape1, af0, af1, gjk_result, min_unique_pt_dist_sq, max_epa_iterations); #endif CLD_DBGSTEP; @@ -919,9 +919,9 @@ CLD_ClosestPointData CLD_ClosestPointDataFromShapes(CLD_Shape *shape0, CLD_Shape //////////////////////////////////////////////////////////// //~ Time of impact -// Takes 2 shapes and their xforms at t=0 and t=1. +// Takes 2 shapes and their Affines at t=0 and t=1. // Returns time of impact in range [0, 1]. -f32 CLD_TimeOfImpact(CLD_Shape *c0, CLD_Shape *c1, Xform xf0_t0, Xform xf1_t0, Xform xf0_t1, Xform xf1_t1, f32 tolerance, u32 max_iterations) +f32 CLD_TimeOfImpact(CLD_Shape *c0, CLD_Shape *c1, Affine af0_t0, Affine af1_t0, Affine af0_t1, Affine af1_t1, f32 tolerance, u32 max_iterations) { f32 t0 = 0; f32 t1 = 1; @@ -934,7 +934,7 @@ f32 CLD_TimeOfImpact(CLD_Shape *c0, CLD_Shape *c1, Xform xf0_t0, Xform xf1_t0, X Vec2 dir; Vec2 dir_neg; { - CLD_ClosestPointData closest_points = CLD_ClosestPointDataFromShapes(c0, c1, xf0_t0, xf1_t0); + CLD_ClosestPointData closest_points = CLD_ClosestPointDataFromShapes(c0, c1, af0_t0, af1_t0); if (closest_points.colliding) { // Shapes are penetrating at t=0 @@ -947,8 +947,8 @@ f32 CLD_TimeOfImpact(CLD_Shape *c0, CLD_Shape *c1, Xform xf0_t0, Xform xf1_t0, X } { - Vec2 p0 = CLD_SupportPointFromDir(c0, xf0_t1, dir).p; - Vec2 p1 = CLD_SupportPointFromDir(c1, xf1_t1, dir_neg).p; + Vec2 p0 = CLD_SupportPointFromDir(c0, af0_t1, dir).p; + Vec2 p1 = CLD_SupportPointFromDir(c1, af1_t1, dir_neg).p; t1_sep = DotVec2(dir, SubVec2(p1, p0)); if (t1_sep > 0) { @@ -974,11 +974,11 @@ f32 CLD_TimeOfImpact(CLD_Shape *c0, CLD_Shape *c1, Xform xf0_t0, Xform xf1_t0, X t = (-t1_sep / m) + t1; } - Xform xf0 = LerpXform(xf0_t0, xf0_t1, t); - Xform xf1 = LerpXform(xf1_t0, xf1_t1, t); + Affine af0 = LerpAffine(af0_t0, af0_t1, t); + Affine af1 = LerpAffine(af1_t0, af1_t1, t); - Vec2 p0 = CLD_SupportPointFromDir(c0, xf0, dir).p; - Vec2 p1 = CLD_SupportPointFromDir(c1, xf1, dir_neg).p; + Vec2 p0 = CLD_SupportPointFromDir(c0, af0, dir).p; + Vec2 p1 = CLD_SupportPointFromDir(c1, af1, dir_neg).p; t_sep = DotVec2(dir, SubVec2(p1, p0)); // Update bracket @@ -1003,14 +1003,14 @@ f32 CLD_TimeOfImpact(CLD_Shape *c0, CLD_Shape *c1, Xform xf0_t0, Xform xf1_t0, X //~ Point cloud debug // TODO: Remove this (debugging) -Vec2Array CLD_Menkowski(Arena *arena, CLD_Shape *shape0, CLD_Shape *shape1, Xform xf0, Xform xf1, u32 detail) +Vec2Array CLD_Menkowski(Arena *arena, CLD_Shape *shape0, CLD_Shape *shape1, Affine af0, Affine af1, u32 detail) { Vec2Array result = { .points = ArenaNext(arena, Vec2) }; for (u64 i = 0; i < detail; ++i) { f32 angle = ((f32)i / detail) * (2 * Pi); Vec2 dir = Vec2FromAngle(angle); - CLD_MenkowskiPoint m = CLD_MenkowskiPointFromDir(shape0, shape1, xf0, xf1, dir); + CLD_MenkowskiPoint m = CLD_MenkowskiPointFromDir(shape0, shape1, af0, af1, dir); if (result.count == 0 || !MatchVec2(m.p, result.points[result.count - 1])) { *PushStructNoZero(arena, Vec2) = m.p; @@ -1021,7 +1021,7 @@ Vec2Array CLD_Menkowski(Arena *arena, CLD_Shape *shape0, CLD_Shape *shape1, Xfor } // TODO: Remove this (debugging) -Vec2Array CLD_PointCloud(Arena *arena, CLD_Shape *shape0, CLD_Shape *shape1, Xform xf0, Xform xf1) +Vec2Array CLD_PointCloud(Arena *arena, CLD_Shape *shape0, CLD_Shape *shape1, Affine af0, Affine af1) { // FIXME: Account for radius Vec2Array result = { .points = ArenaNext(arena, Vec2) }; @@ -1031,10 +1031,10 @@ Vec2Array CLD_PointCloud(Arena *arena, CLD_Shape *shape0, CLD_Shape *shape1, Xfo u32 count1 = shape1->count; for (u64 i = 0; i < count0; ++i) { - Vec2 p0 = MulXformV2(xf0, points0[i]); + Vec2 p0 = MulAffineV2(af0, points0[i]); for (u64 j = 0; j < count1; ++j) { - Vec2 p1 = MulXformV2(xf1, points1[j]); + Vec2 p1 = MulAffineV2(af1, points1[j]); *PushStructNoZero(arena, Vec2) = SubVec2(p0, p1); ++result.count; } diff --git a/src/collider/collider.h b/src/collider/collider.h index 6a715592..6c71616c 100644 --- a/src/collider/collider.h +++ b/src/collider/collider.h @@ -160,14 +160,14 @@ CLD_Shape CLD_ShapeFromQuad(Quad quad); //////////////////////////////////////////////////////////// //~ Menkowski -CLD_SupportPoint CLD_SupportPointFromDirEx(CLD_Shape *shape, Xform xf, Vec2 dir, i32 ignore); -CLD_SupportPoint CLD_SupportPointFromDir(CLD_Shape *shape, Xform xf, Vec2 dir); -CLD_MenkowskiPoint CLD_MenkowskiPointFromDir(CLD_Shape *shape0, CLD_Shape *shape1, Xform xf0, Xform xf1, Vec2 dir); +CLD_SupportPoint CLD_SupportPointFromDirEx(CLD_Shape *shape, Affine af, Vec2 dir, i32 ignore); +CLD_SupportPoint CLD_SupportPointFromDir(CLD_Shape *shape, Affine af, Vec2 dir); +CLD_MenkowskiPoint CLD_MenkowskiPointFromDir(CLD_Shape *shape0, CLD_Shape *shape1, Affine af0, Affine af1, Vec2 dir); //////////////////////////////////////////////////////////// //~ Aabb -Aabb CLD_AabbFromShape(CLD_Shape *shape, Xform xf); +Aabb CLD_AabbFromShape(CLD_Shape *shape, Affine af); Aabb CLD_CombineAabb(Aabb b0, Aabb b1); b32 CLD_TestAabb(Aabb box0, Aabb box1); @@ -175,18 +175,18 @@ b32 CLD_TestAabb(Aabb box0, Aabb box1); //~ Gjk #if COLLIDER_DEBUG -CLD_GjkData CLD_GjkDataFromShapes(CLD_Shape *shape0, CLD_Shape *shape1, Xform xf0, Xform xf1, f32 min_unique_pt_dist_sq, u32 dbg_step); +CLD_GjkData CLD_GjkDataFromShapes(CLD_Shape *shape0, CLD_Shape *shape1, Affine af0, Affine af1, f32 min_unique_pt_dist_sq, u32 dbg_step); #else -CLD_GjkData CLD_GjkDataFromShapes(CLD_Shape *shape0, CLD_Shape *shape1, Xform xf0, Xform xf1, f32 min_unique_pt_dist_sq); +CLD_GjkData CLD_GjkDataFromShapes(CLD_Shape *shape0, CLD_Shape *shape1, Affine af0, Affine af1, f32 min_unique_pt_dist_sq); #endif //////////////////////////////////////////////////////////// //~ Epa #if COLLIDER_DEBUG -CLD_EpaData CLD_EpaDataFromShapes(CLD_Shape *shape0, CLD_Shape *shape1, Xform xf0, Xform xf1, CLD_GjkData gjk_result, f32 min_unique_pt_dist_sq, u32 max_iterations, u32 dbg_step); +CLD_EpaData CLD_EpaDataFromShapes(CLD_Shape *shape0, CLD_Shape *shape1, Affine af0, Affine af1, CLD_GjkData gjk_result, f32 min_unique_pt_dist_sq, u32 max_iterations, u32 dbg_step); #else -CLD_EpaData CLD_EpaDataFromShapes(CLD_Shape *shape0, CLD_Shape *shape1, Xform xf0, Xform xf1, CLD_GjkData gjk_result, f32 min_unique_pt_dist_sq, u32 max_iterations); +CLD_EpaData CLD_EpaDataFromShapes(CLD_Shape *shape0, CLD_Shape *shape1, Affine af0, Affine af1, CLD_GjkData gjk_result, f32 min_unique_pt_dist_sq, u32 max_iterations); #endif //////////////////////////////////////////////////////////// @@ -198,20 +198,20 @@ Vec2 CLD_ClipPointToLine(Vec2 a, Vec2 b, Vec2 p, Vec2 normal); //////////////////////////////////////////////////////////// //~ Collision point -CLD_CollisionData CLD_CollisionDataFromShapes(CLD_Shape *shape0, CLD_Shape *shape1, Xform xf0, Xform xf1); +CLD_CollisionData CLD_CollisionDataFromShapes(CLD_Shape *shape0, CLD_Shape *shape1, Affine af0, Affine af1); //////////////////////////////////////////////////////////// //~ Closest point -CLD_ClosestPointData CLD_ClosestPointDataFromShapes(CLD_Shape *shape0, CLD_Shape *shape1, Xform xf0, Xform xf1); +CLD_ClosestPointData CLD_ClosestPointDataFromShapes(CLD_Shape *shape0, CLD_Shape *shape1, Affine af0, Affine af1); //////////////////////////////////////////////////////////// //~ Time of impact -f32 CLD_TimeOfImpact(CLD_Shape *c0, CLD_Shape *c1, Xform xf0_t0, Xform xf1_t0, Xform xf0_t1, Xform xf1_t1, f32 tolerance, u32 max_iterations); +f32 CLD_TimeOfImpact(CLD_Shape *c0, CLD_Shape *c1, Affine af0_t0, Affine af1_t0, Affine af0_t1, Affine af1_t1, f32 tolerance, u32 max_iterations); //////////////////////////////////////////////////////////// //~ Point cloud debug -Vec2Array CLD_Menkowski(Arena *arena, CLD_Shape *shape0, CLD_Shape *shape1, Xform xf0, Xform xf1, u32 detail); -Vec2Array CLD_PointCloud(Arena *arena, CLD_Shape *shape0, CLD_Shape *shape1, Xform xf0, Xform xf1); +Vec2Array CLD_Menkowski(Arena *arena, CLD_Shape *shape0, CLD_Shape *shape1, Affine af0, Affine af1, u32 detail); +Vec2Array CLD_PointCloud(Arena *arena, CLD_Shape *shape0, CLD_Shape *shape1, Affine af0, Affine af1); diff --git a/src/draw/draw.c b/src/draw/draw.c index 5229f543..a263b446 100644 --- a/src/draw/draw.c +++ b/src/draw/draw.c @@ -16,7 +16,7 @@ void D_DrawMaterial(GPU_RenderSig *sig, D_MaterialParams params) { GPU_RenderCmdDesc cmd = ZI; cmd.kind = GP_RENDER_CMD_KIND_DRAW_MATERIAL; - cmd.material.xf = params.xf; + cmd.material.af = params.af; cmd.material.texture = params.texture; cmd.material.clip = params.clip; cmd.material.tint = params.tint; @@ -216,7 +216,7 @@ void D_DrawArrowRay(GPU_RenderSig *sig, Vec2 pos, Vec2 rel, f32 thickness, f32 a D_DrawArrowLine(sig, pos, end, thickness, arrowhead_height, color); } -void D_DrawColliderLine(GPU_RenderSig *sig, CLD_Shape shape, Xform shape_xf, f32 thickness, u32 color, u32 detail) +void D_DrawColliderLine(GPU_RenderSig *sig, CLD_Shape shape, Affine shape_af, f32 thickness, u32 color, u32 detail) { TempArena scratch = BeginScratchNoConflict(); Vec2Array poly = ZI; @@ -226,7 +226,7 @@ void D_DrawColliderLine(GPU_RenderSig *sig, CLD_Shape shape, Xform shape_xf, f32 poly.points = PushStructsNoZero(scratch.arena, Vec2, shape.count); for (u32 i = 0; i < shape.count; ++i) { - Vec2 p = MulXformV2(shape_xf, shape.points[i]); + Vec2 p = MulAffineV2(shape_af, shape.points[i]); poly.points[i] = p; } } @@ -238,7 +238,7 @@ void D_DrawColliderLine(GPU_RenderSig *sig, CLD_Shape shape, Xform shape_xf, f32 { f32 angle = ((f32)i / (f32)detail) * Tau; Vec2 dir = VEC2(CosF32(angle), SinF32(angle)); - Vec2 p = CLD_SupportPointFromDir(&shape, shape_xf, dir).p; + Vec2 p = CLD_SupportPointFromDir(&shape, shape_af, dir).p; poly.points[i] = p; } } @@ -249,7 +249,7 @@ void D_DrawColliderLine(GPU_RenderSig *sig, CLD_Shape shape, Xform shape_xf, f32 //////////////////////////////////////////////////////////// //~ Grid -void D_DrawGrid(GPU_RenderSig *sig, Xform xf, u32 bg0_color, u32 bg1_color, u32 line_color, u32 x_color, u32 y_color, f32 thickness, f32 spacing, Vec2 offset) +void D_DrawGrid(GPU_RenderSig *sig, Affine af, u32 bg0_color, u32 bg1_color, u32 line_color, u32 x_color, u32 y_color, f32 thickness, f32 spacing, Vec2 offset) { i32 grid_id = 0; { @@ -268,7 +268,7 @@ void D_DrawGrid(GPU_RenderSig *sig, Xform xf, u32 bg0_color, u32 bg1_color, u32 GPU_RenderCmdDesc cmd = ZI; cmd.kind = GP_RENDER_CMD_KIND_DRAW_MATERIAL; - cmd.material.xf = xf; + cmd.material.af = af; cmd.material.tint = Color_White; cmd.material.grid_cmd_id = grid_id; GPU_PushRenderCmd(sig, &cmd); @@ -281,7 +281,7 @@ void D_DrawUiRect(GPU_RenderSig *sig, D_UiRectParams params) { GPU_RenderCmdDesc cmd = ZI; cmd.kind = GP_RENDER_CMD_KIND_DRAW_UI_RECT; - cmd.ui_rect.xf = params.xf; + cmd.ui_rect.af = params.af; cmd.ui_rect.texture = params.texture; cmd.ui_rect.clip = params.clip; cmd.ui_rect.tint = params.tint; @@ -455,8 +455,8 @@ Rect draw_text(GPU_RenderSig *sig, D_TextParams params) D_TextGlyph *tg = &line->glyphs[i]; Vec2 pos = VEC2(draw_pos.x + tg->off_x, draw_pos.y + tg->off_y); Vec2 size = VEC2(tg->width, tg->height); - Xform xf = XformFromRect(RectFromVec2(pos, size)); - D_DrawUiRect(sig, D_UIRECTPARAMS(.xf = xf, .texture = params.font->texture, .tint = params.color, .clip = tg->clip)); + Affine af = AffineFromRect(RectFromVec2(pos, size)); + D_DrawUiRect(sig, D_UIRECTPARAMS(.af = af, .texture = params.font->texture, .tint = params.color, .clip = tg->clip)); draw_pos.x += tg->advance; } diff --git a/src/draw/draw.h b/src/draw/draw.h index 9915b580..403aac84 100644 --- a/src/draw/draw.h +++ b/src/draw/draw.h @@ -3,7 +3,7 @@ Struct(D_MaterialParams) { - Xform xf; + Affine af; GPU_Resource *texture; ClipRect clip; u32 tint; @@ -21,7 +21,7 @@ Struct(D_MaterialParams) Struct(D_UiRectParams) { - Xform xf; + Affine af; GPU_Resource *texture; ClipRect clip; u32 tint; @@ -137,12 +137,12 @@ void D_DrawCircleLine(GPU_RenderSig *sig, Vec2 pos, f32 radius, f32 thickness, u void D_DrawQuadLine(GPU_RenderSig *sig, Quad quad, f32 thickness, u32 color); void D_DrawArrowLine(GPU_RenderSig *sig, Vec2 start, Vec2 end, f32 thickness, f32 arrowhead_height, u32 color); void D_DrawArrowRay(GPU_RenderSig *sig, Vec2 pos, Vec2 rel, f32 thickness, f32 arrowhead_height, u32 color); -void D_DrawColliderLine(GPU_RenderSig *sig, CLD_Shape shape, Xform shape_xf, f32 thickness, u32 color, u32 detail); +void D_DrawColliderLine(GPU_RenderSig *sig, CLD_Shape shape, Affine shape_af, f32 thickness, u32 color, u32 detail); //////////////////////////////////////////////////////////// //~ Grid -void D_DrawGrid(GPU_RenderSig *sig, Xform xf, u32 bg0_color, u32 bg1_color, u32 line_color, u32 x_color, u32 y_color, f32 thickness, f32 spacing, Vec2 offset); +void D_DrawGrid(GPU_RenderSig *sig, Affine af, u32 bg0_color, u32 bg1_color, u32 line_color, u32 x_color, u32 y_color, f32 thickness, f32 spacing, Vec2 offset); //////////////////////////////////////////////////////////// //~ Ui diff --git a/src/playback/playback_wasapi/playback_wasapi.c b/src/playback/playback_wasapi/playback_wasapi.c index b5bd738f..aa8f0122 100644 --- a/src/playback/playback_wasapi/playback_wasapi.c +++ b/src/playback/playback_wasapi/playback_wasapi.c @@ -100,7 +100,7 @@ void PB_WSP_InitializeWasapi(void) IAudioClient_Initialize(PB_WSP.client, AUDCLNT_SHAREMODE_SHARED, flags, duration, 0, wfx, 0); } - IAudioClient_GetMixFormat(PB_WSP.client, &PB_WSP.buffer_format); + IAudioClient_GetMiAffineat(PB_WSP.client, &PB_WSP.buffer_format); // Set up event handler to wait on PB_WSP.event = CreateEventW(0, 0, 0, 0); diff --git a/src/pp/pp.c b/src/pp/pp.c index b4ac3e0c..e4e9ee04 100644 --- a/src/pp/pp.c +++ b/src/pp/pp.c @@ -2,7 +2,7 @@ P_Ctx P = Zi; ThreadLocal P_ThreadLocalCtx P_tl = Zi; Readonly P_Ent P_NilEnt = { - .xf = CompXformIdentity, + .af = CompAffineIdentity, .control.look = { 0, -1 }, }; @@ -124,17 +124,17 @@ P_Shape P_ShapeFromDescEx(P_ShapeDesc desc) return result; } -P_Shape P_MulXformShape(Xform xf, P_Shape shape) +P_Shape P_MulAffineShape(Affine af, P_Shape shape) { P_Shape result = shape; for (i32 i = 0; i < shape.points_count; ++i) { - result.points[i] = MulXformV2(xf, shape.points[i]); + result.points[i] = MulAffineV2(af, shape.points[i]); } - Vec2 scale = ScaleFromXform(xf); + Vec2 scale = ScaleFromAffine(af); result.radius *= MaxF32(scale.x, scale.y); - result.centroid = MulXformV2(xf, shape.centroid); - result.center_of_mass = MulXformV2(xf, shape.center_of_mass); + result.centroid = MulAffineV2(af, shape.centroid); + result.center_of_mass = MulAffineV2(af, shape.center_of_mass); return result; } @@ -193,7 +193,7 @@ P_Shape P_LocalShapeFromEnt(P_Ent *ent) P_Shape P_WorldShapeFromEnt(P_Ent *ent) { P_Shape local = P_LocalShapeFromEnt(ent); - P_Shape world = P_MulXformShape(ent->xf, local); + P_Shape world = P_MulAffineShape(ent->af, local); return world; } @@ -231,8 +231,8 @@ P_Anim P_AnimFromEnt(P_Ent *ent, i64 time_ns) // P_Anim result = Zi; - // // result.slice_to_world_xf = XformIdentity; - // // result.slice_to_world_xf = ent->xf; + // // result.slice_to_world_af = AffineIdentity; + // // result.slice_to_world_af = ent->af; // i64 animation_rate_ns = NsFromSeconds(0.100); @@ -256,12 +256,12 @@ P_Anim P_AnimFromEnt(P_Ent *ent, i64 time_ns) // // FIXME: Use origin ray // { // Vec2 world_dims = DivVec2(sframe.dims, P_CellsPerMeter); - // result.body_to_world_xf = XformIdentity; - // result.body_to_world_xf.og = ent->xf.og; - // // result.body_to_world_xf.og = SubVec2(result.body_to_world_xf.og, MulVec2(world_dims, 0.25)); - // result.body_to_world_xf = XformWithWorldRotation(result.body_to_world_xf, AngleFromVec2(ent->control.look)); - // result.body_to_world_xf = TranslateXform(result.body_to_world_xf, MulVec2(world_dims, -0.5)); - // result.body_to_world_xf = ScaleXform(result.body_to_world_xf, world_dims); + // result.body_to_world_af = AffineIdentity; + // result.body_to_world_af.og = ent->af.og; + // // result.body_to_world_af.og = SubVec2(result.body_to_world_af.og, MulVec2(world_dims, 0.25)); + // result.body_to_world_af = AffineWithWorldRotation(result.body_to_world_af, AngleFromVec2(ent->control.look)); + // result.body_to_world_af = TranslateAffine(result.body_to_world_af, MulVec2(world_dims, -0.5)); + // result.body_to_world_af = ScaleAffine(result.body_to_world_af, world_dims); // } // { @@ -284,12 +284,12 @@ P_Anim P_AnimFromEnt(P_Ent *ent, i64 time_ns) // // // Vec2 world_dims = VEC2(0.5, 0.5); // // Vec2 px_dims = slice.dims; // // Vec2 world_dims = DivVec2(px_dims, P_CellsPerMeter); - // // result.slice_to_world_xf = XformIdentity; - // // result.slice_to_world_xf.og = ent->xf.og; - // // // result.slice_to_world_xf.og = SubVec2(result.slice_to_world_xf.og, MulVec2(world_dims, 0.25)); - // // result.slice_to_world_xf = XformWithWorldRotation(result.slice_to_world_xf, AngleFromVec2(ent->control.look)); - // // result.slice_to_world_xf = TranslateXform(result.slice_to_world_xf, MulVec2(world_dims, -0.5)); - // // result.slice_to_world_xf = ScaleXform(result.slice_to_world_xf, world_dims); + // // result.slice_to_world_af = AffineIdentity; + // // result.slice_to_world_af.og = ent->af.og; + // // // result.slice_to_world_af.og = SubVec2(result.slice_to_world_af.og, MulVec2(world_dims, 0.25)); + // // result.slice_to_world_af = AffineWithWorldRotation(result.slice_to_world_af, AngleFromVec2(ent->control.look)); + // // result.slice_to_world_af = TranslateAffine(result.slice_to_world_af, MulVec2(world_dims, -0.5)); + // // result.slice_to_world_af = ScaleAffine(result.slice_to_world_af, world_dims); // // } // // result.slice = SPR_SliceFromSheet(sheet, @@ -312,8 +312,8 @@ P_Anim P_AnimFromEnt(P_Ent *ent, i64 time_ns) // P_Anim result = Zi; - // // result.slice_to_world_xf = XformIdentity; - // // result.slice_to_world_xf = ent->xf; + // // result.slice_to_world_af = AffineIdentity; + // // result.slice_to_world_af = ent->af; // i64 animation_rate_ns = NsFromSeconds(0.100); @@ -347,12 +347,12 @@ P_Anim P_AnimFromEnt(P_Ent *ent, i64 time_ns) // // Vec2 world_dims = VEC2(0.5, 0.5); // Vec2 px_dims = slice.dims; // Vec2 world_dims = DivVec2(px_dims, P_CellsPerMeter); - // result.slice_to_world_xf = XformIdentity; - // result.slice_to_world_xf.og = ent->xf.og; - // // result.slice_to_world_xf.og = SubVec2(result.slice_to_world_xf.og, MulVec2(world_dims, 0.25)); - // result.slice_to_world_xf = XformWithWorldRotation(result.slice_to_world_xf, AngleFromVec2(ent->control.look)); - // result.slice_to_world_xf = TranslateXform(result.slice_to_world_xf, MulVec2(world_dims, -0.5)); - // result.slice_to_world_xf = ScaleXform(result.slice_to_world_xf, world_dims); + // result.slice_to_world_af = AffineIdentity; + // result.slice_to_world_af.og = ent->af.og; + // // result.slice_to_world_af.og = SubVec2(result.slice_to_world_af.og, MulVec2(world_dims, 0.25)); + // result.slice_to_world_af = AffineWithWorldRotation(result.slice_to_world_af, AngleFromVec2(ent->control.look)); + // result.slice_to_world_af = TranslateAffine(result.slice_to_world_af, MulVec2(world_dims, -0.5)); + // result.slice_to_world_af = ScaleAffine(result.slice_to_world_af, world_dims); // } // // result.slice = SPR_SliceFromSheet(sheet, @@ -1363,7 +1363,7 @@ void P_DebugDrawFrame(P_Frame *frame) { Vec4 color = VEC4(0.8, 0.8, 0.8, 1); Vec2 p0 = world_shape.centroid; - Vec2 p1 = P_EdgePointFromShape(world_shape, UpFromXform(ent->xf)); + Vec2 p1 = P_EdgePointFromShape(world_shape, UpFromAffine(ent->af)); P_DebugDrawLine(p0, p1, color); } @@ -1647,7 +1647,7 @@ void P_StepFrame(P_Frame *frame) for (P_Ent *ent = P_FirstEnt(frame); !P_IsEntNil(ent); ent = P_NextEnt(ent)) { - ent->prev_xf = ent->xf; + ent->prev_af = ent->af; } ////////////////////////////// @@ -1700,17 +1700,17 @@ void P_StepFrame(P_Frame *frame) { P_Control control = guy->control; - // Xform xf = guy->xf; - // Xform desired_xf = xf; + // Affine af = guy->af; + // Affine desired_af = af; // if (!IsVec2Zero(control.look)) // { - // desired_xf = XformWithWorldRotation(xf, AngleFromVec2(control.look)); + // desired_af = AffineWithWorldRotation(af, AngleFromVec2(control.look)); // } // f32 move_speed = TweakFloat("Guy move speed", 6.5, 0, 20); - // desired_xf.og = AddVec2(xf.og, MulVec2(control.move, move_speed * sim_dt)); + // desired_af.og = AddVec2(af.og, MulVec2(control.move, move_speed * sim_dt)); - // Vec2 pos_diff = SubVec2(desired_xf.og, xf.og); - // f32 angle_diff = UnwindAngleF32(RotationFromXform(desired_xf) - RotationFromXform(xf)); + // Vec2 pos_diff = SubVec2(desired_af.og, af.og); + // f32 angle_diff = UnwindAngleF32(RotationFromAffine(desired_af) - RotationFromAffine(af)); // guy->solved_v = pos_diff; // guy->solved_w = angle_diff; @@ -2405,10 +2405,10 @@ void P_StepFrame(P_Frame *frame) { if (!is_predicting || ent == local_guy) { - Xform xf = ent->xf; - xf.og = AddVec2(xf.og, MulVec2(ent->solved_v, solver_dt)); - xf = RotateXform(xf, ent->solved_w * solver_dt); - ent->xf = xf; + Affine af = ent->af; + af.og = AddVec2(af.og, MulVec2(ent->solved_v, solver_dt)); + af = RotateAffine(af, ent->solved_w * solver_dt); + ent->af = af; } } } diff --git a/src/pp/pp.h b/src/pp/pp.h index 401899f9..1890a1a8 100644 --- a/src/pp/pp.h +++ b/src/pp/pp.h @@ -112,8 +112,8 @@ Struct(P_Ent) b32 is_dummy; f32 health; - Xform prev_xf; - Xform xf; + Affine prev_af; + Affine af; // TODO: Remove this (weapon testing) i64 last_fire_ns; @@ -481,7 +481,7 @@ String P_NameFromTileKind(P_TileKind kind); P_Shape P_ShapeFromDescEx(P_ShapeDesc desc); #define P_ShapeFromDesc(...) P_ShapeFromDescEx((P_ShapeDesc) { __VA_ARGS__ }) -P_Shape P_MulXformShape(Xform xf, P_Shape shape); +P_Shape P_MulAffineShape(Affine af, P_Shape shape); Rng2 P_BoundingBoxFromShape(P_Shape shape); P_Shape P_LocalShapeFromEnt(P_Ent *ent); diff --git a/src/pp/pp_sim/pp_sim_core.c b/src/pp/pp_sim/pp_sim_core.c index eb88911b..dc3c7766 100644 --- a/src/pp/pp_sim/pp_sim_core.c +++ b/src/pp/pp_sim/pp_sim_core.c @@ -594,7 +594,7 @@ void S_TickForever(WaveLaneCtx *lane) P_Ent *guy = P_PushTempEnt(frame_arena, &ents); *guy = P_NilEnt; guy->key = msg->key; - guy->xf = XformFromPos(msg->pos); + guy->af = AffineFromPos(msg->pos); guy->is_guy = 1; guy->has_weapon = 1; guy->exists = 1; @@ -604,7 +604,7 @@ void S_TickForever(WaveLaneCtx *lane) P_Ent *guy = P_PushTempEnt(frame_arena, &ents); *guy = P_NilEnt; guy->key = P_RandKey(); - guy->xf = XformFromPos(msg->pos); + guy->af = AffineFromPos(msg->pos); guy->is_guy = 1; guy->has_weapon = 1; guy->exists = 1; @@ -621,7 +621,7 @@ void S_TickForever(WaveLaneCtx *lane) // P_Ent *ent = P_PushTempEnt(frame_arena, &ents); // *ent = P_NilEnt; // ent->key = msg->key; - // ent->xf = XformFromPos(msg->pos); + // ent->af = AffineFromPos(msg->pos); // ent->is_guy = 1; // ent->is_dummy = 1; // ent->has_weapon = 1; diff --git a/src/pp/pp_transcode.c b/src/pp/pp_transcode.c index a60cf09c..9b92586f 100644 --- a/src/pp/pp_transcode.c +++ b/src/pp/pp_transcode.c @@ -60,8 +60,8 @@ String P_PackWorld(Arena *arena, P_World *src_world) } } result.len += StringF(arena, " }\n").len; - result.len += StringF(arena, " pos: \"%F\"\n", FmtFloat2(ent->xf.og)).len; - result.len += StringF(arena, " rot: \"%F\"\n", FmtFloat2(RightFromXform(ent->xf))).len; + result.len += StringF(arena, " pos: \"%F\"\n", FmtFloat2(ent->af.og)).len; + result.len += StringF(arena, " rot: \"%F\"\n", FmtFloat2(RightFromAffine(ent->af))).len; result.len += StringF(arena, " exists: \"%F\"\n", FmtFloat(ent->exists)).len; result.len += StringF(arena, " look: \"%F\"\n", FmtFloat2(ent->control.look)).len; } @@ -163,12 +163,12 @@ P_UnpackedWorld P_UnpackWorld(Arena *arena, String packed) if (MatchString(attr->name, Lit("pos"))) { Vec2 pos = CR_Vec2FromString(attr->value); - ent->xf.og = pos; + ent->af.og = pos; } if (MatchString(attr->name, Lit("rot"))) { Vec2 rot = CR_Vec2FromString(attr->value); - ent->xf = XformWithWorldRotation(ent->xf, AngleFromVec2(rot)); + ent->af = AffineWithWorldRotation(ent->af, AngleFromVec2(rot)); } if (MatchString(attr->name, Lit("exists"))) { diff --git a/src/pp/pp_vis/pp_vis_core.c b/src/pp/pp_vis/pp_vis_core.c index 3ffa5f85..c2c16fc5 100644 --- a/src/pp/pp_vis/pp_vis_core.c +++ b/src/pp/pp_vis/pp_vis_core.c @@ -824,20 +824,20 @@ void V_TickForever(WaveLaneCtx *lane) b32 should_zoom = prev_frame->zooms != 0 && (frame->edit_camera_zoom != prev_frame->edit_camera_zoom); if (prev_frame->is_editing && (should_zoom || (frame->is_panning && prev_frame->is_panning))) { - Xform prev_frame_edit_to_screen_xf = Zi; - Xform edit_to_screen_xf = Zi; + Affine prev_frame_edit_to_screen_af = Zi; + Affine edit_to_screen_af = Zi; { f32 prev_edit_camera_scale = (f32)prev_frame->screen_dims.x / (meters_per_camera_width * prev_frame->edit_camera_zoom); f32 edit_camera_scale = (f32)frame->screen_dims.x / (meters_per_camera_width * frame->edit_camera_zoom); - prev_frame_edit_to_screen_xf = XformFromScale(VEC2(prev_edit_camera_scale, prev_edit_camera_scale)); - prev_frame_edit_to_screen_xf = TranslateXform(prev_frame_edit_to_screen_xf, NegVec2(prev_frame->edit_camera_pos)); - prev_frame_edit_to_screen_xf = WorldTranslateXform(prev_frame_edit_to_screen_xf, MulVec2(Vec2FromVec(frame->screen_dims), 0.5)); - edit_to_screen_xf = XformFromScale(VEC2(edit_camera_scale, edit_camera_scale)); - edit_to_screen_xf = TranslateXform(edit_to_screen_xf, NegVec2(frame->edit_camera_pos)); - edit_to_screen_xf = WorldTranslateXform(edit_to_screen_xf, MulVec2(Vec2FromVec(frame->screen_dims), 0.5)); + prev_frame_edit_to_screen_af = AffineFromScale(VEC2(prev_edit_camera_scale, prev_edit_camera_scale)); + prev_frame_edit_to_screen_af = TranslateAffine(prev_frame_edit_to_screen_af, NegVec2(prev_frame->edit_camera_pos)); + prev_frame_edit_to_screen_af = WorldTranslateAffine(prev_frame_edit_to_screen_af, MulVec2(Vec2FromVec(frame->screen_dims), 0.5)); + edit_to_screen_af = AffineFromScale(VEC2(edit_camera_scale, edit_camera_scale)); + edit_to_screen_af = TranslateAffine(edit_to_screen_af, NegVec2(frame->edit_camera_pos)); + edit_to_screen_af = WorldTranslateAffine(edit_to_screen_af, MulVec2(Vec2FromVec(frame->screen_dims), 0.5)); } - Vec2 prev_target_cursor = MulXformV2(InvertXform(prev_frame_edit_to_screen_xf), prev_frame->screen_cursor); - Vec2 target_cursor = MulXformV2(InvertXform(edit_to_screen_xf), ui_frame->cursor_pos); + Vec2 prev_target_cursor = MulAffineV2(InvertAffine(prev_frame_edit_to_screen_af), prev_frame->screen_cursor); + Vec2 target_cursor = MulAffineV2(InvertAffine(edit_to_screen_af), ui_frame->cursor_pos); Vec2 diff = SubVec2(prev_target_cursor, target_cursor); frame->edit_camera_pos = AddVec2(frame->edit_camera_pos, diff); } @@ -855,7 +855,7 @@ void V_TickForever(WaveLaneCtx *lane) P_Ent *guy = P_EntFromKey(local_world->last_frame, player->guy); Vec2 guy_center = P_WorldShapeFromEnt(guy).centroid; Vec2 screen_center = MulVec2(frame->screen_dims, 0.5); - Vec2 look = MulXformBasisV2(prev_frame->xf.screen_to_world, SubVec2(ui_frame->cursor_pos, screen_center)); + Vec2 look = MulAffineBasisV2(prev_frame->af.screen_to_world, SubVec2(ui_frame->cursor_pos, screen_center)); target_camera_pos = guy_center; target_camera_pos = AddVec2(target_camera_pos, MulVec2Vec2(look, look_ratio)); target_camera_zoom = 1; @@ -895,66 +895,66 @@ void V_TickForever(WaveLaneCtx *lane) } ////////////////////////////// - //- Compute frame xforms + //- Compute frame Affines // World <-> screen - frame->xf.world_to_screen = XformIdentity; - frame->xf.screen_to_world = XformIdentity; + frame->af.world_to_screen = AffineIdentity; + frame->af.screen_to_world = AffineIdentity; { f32 camera_scale = frame->screen_dims.x / (meters_per_camera_width * frame->camera_zoom); - frame->xf.world_to_screen = XformFromScale(VEC2(camera_scale, camera_scale)); - frame->xf.world_to_screen = TranslateXform(frame->xf.world_to_screen, NegVec2(frame->camera_pos)); - frame->xf.world_to_screen = WorldTranslateXform(frame->xf.world_to_screen, MulVec2(frame->screen_dims, 0.5)); - frame->xf.world_to_screen.og = RoundVec2(frame->xf.world_to_screen.og); - frame->xf.screen_to_world = InvertXform(frame->xf.world_to_screen); + frame->af.world_to_screen = AffineFromScale(VEC2(camera_scale, camera_scale)); + frame->af.world_to_screen = TranslateAffine(frame->af.world_to_screen, NegVec2(frame->camera_pos)); + frame->af.world_to_screen = WorldTranslateAffine(frame->af.world_to_screen, MulVec2(frame->screen_dims, 0.5)); + frame->af.world_to_screen.og = RoundVec2(frame->af.world_to_screen.og); + frame->af.screen_to_world = InvertAffine(frame->af.world_to_screen); } // World <-> shade - frame->xf.world_to_shade = XformIdentity; - frame->xf.shade_to_world = XformIdentity; + frame->af.world_to_shade = AffineIdentity; + frame->af.shade_to_world = AffineIdentity; { f32 camera_scale = (frame->shade_dims.x - shade_extra_dims.x) / (meters_per_camera_width * frame->camera_zoom); - frame->xf.world_to_shade = XformFromScale(VEC2(camera_scale, camera_scale)); - frame->xf.world_to_shade = TranslateXform(frame->xf.world_to_shade, NegVec2(frame->camera_pos)); - frame->xf.world_to_shade = WorldTranslateXform(frame->xf.world_to_shade, MulVec2(frame->shade_dims, 0.5)); - frame->xf.world_to_shade.og = RoundVec2(frame->xf.world_to_shade.og); - frame->xf.shade_to_world = InvertXform(frame->xf.world_to_shade); + frame->af.world_to_shade = AffineFromScale(VEC2(camera_scale, camera_scale)); + frame->af.world_to_shade = TranslateAffine(frame->af.world_to_shade, NegVec2(frame->camera_pos)); + frame->af.world_to_shade = WorldTranslateAffine(frame->af.world_to_shade, MulVec2(frame->shade_dims, 0.5)); + frame->af.world_to_shade.og = RoundVec2(frame->af.world_to_shade.og); + frame->af.shade_to_world = InvertAffine(frame->af.world_to_shade); } // Shade <-> screen - frame->xf.shade_to_screen = XformIdentity; - frame->xf.screen_to_shade = XformIdentity; + frame->af.shade_to_screen = AffineIdentity; + frame->af.screen_to_shade = AffineIdentity; { - frame->xf.shade_to_screen = MulXform(frame->xf.world_to_screen, frame->xf.shade_to_world); - frame->xf.screen_to_shade = InvertXform(frame->xf.shade_to_screen); + frame->af.shade_to_screen = MulAffine(frame->af.world_to_screen, frame->af.shade_to_world); + frame->af.screen_to_shade = InvertAffine(frame->af.shade_to_screen); } // World <-> cell // TODO: This never changes, should be #defined (so shaders don't need to read it every frame) - frame->xf.world_to_cell = XformIdentity; - frame->xf.cell_to_world = XformIdentity; + frame->af.world_to_cell = AffineIdentity; + frame->af.cell_to_world = AffineIdentity; { - frame->xf.world_to_cell = ScaleXform(frame->xf.world_to_cell, VEC2(P_CellsPerMeter, P_CellsPerMeter)); - frame->xf.world_to_cell = TranslateXform(frame->xf.world_to_cell, VEC2((P_WorldPitch / 2.0), (P_WorldPitch / 2.0))); - frame->xf.cell_to_world = InvertXform(frame->xf.world_to_cell); + frame->af.world_to_cell = ScaleAffine(frame->af.world_to_cell, VEC2(P_CellsPerMeter, P_CellsPerMeter)); + frame->af.world_to_cell = TranslateAffine(frame->af.world_to_cell, VEC2((P_WorldPitch / 2.0), (P_WorldPitch / 2.0))); + frame->af.cell_to_world = InvertAffine(frame->af.world_to_cell); } // World <-> tile // TODO: This never changes, should be #defined (so shaders don't need to read it every frame) - frame->xf.world_to_tile = XformIdentity; - frame->xf.tile_to_world = XformIdentity; + frame->af.world_to_tile = AffineIdentity; + frame->af.tile_to_world = AffineIdentity; { - frame->xf.world_to_tile = ScaleXform(frame->xf.world_to_tile, VEC2(P_TilesPerMeter, P_TilesPerMeter)); - frame->xf.world_to_tile = TranslateXform(frame->xf.world_to_tile, VEC2((P_WorldPitch / 2.0), (P_WorldPitch / 2.0))); - frame->xf.tile_to_world = InvertXform(frame->xf.world_to_tile); + frame->af.world_to_tile = ScaleAffine(frame->af.world_to_tile, VEC2(P_TilesPerMeter, P_TilesPerMeter)); + frame->af.world_to_tile = TranslateAffine(frame->af.world_to_tile, VEC2((P_WorldPitch / 2.0), (P_WorldPitch / 2.0))); + frame->af.tile_to_world = InvertAffine(frame->af.world_to_tile); } ////////////////////////////// //- Update cursors / selection frame->screen_cursor = ui_frame->cursor_pos; - frame->shade_cursor = MulXformV2(frame->xf.screen_to_shade, frame->screen_cursor); - frame->world_cursor = MulXformV2(frame->xf.screen_to_world, frame->screen_cursor); + frame->shade_cursor = MulAffineV2(frame->af.screen_to_shade, frame->screen_cursor); + frame->world_cursor = MulAffineV2(frame->af.screen_to_world, frame->screen_cursor); b32 show_editor_ui = TweakBool("Show editor UI", 1); @@ -984,11 +984,11 @@ void V_TickForever(WaveLaneCtx *lane) frame->world_selection.p1.x = MaxF32(frame->world_cursor.x, frame->world_selection_start.x); frame->world_selection.p1.y = MaxF32(frame->world_cursor.y, frame->world_selection_start.y); - frame->screen_selection.p0 = MulXformV2(frame->xf.world_to_screen, frame->world_selection.p0); - frame->screen_selection.p1 = MulXformV2(frame->xf.world_to_screen, frame->world_selection.p1); + frame->screen_selection.p0 = MulAffineV2(frame->af.world_to_screen, frame->world_selection.p0); + frame->screen_selection.p1 = MulAffineV2(frame->af.world_to_screen, frame->world_selection.p1); - frame->shade_selection.p0 = MulXformV2(frame->xf.world_to_shade, frame->world_selection.p0); - frame->shade_selection.p1 = MulXformV2(frame->xf.world_to_shade, frame->world_selection.p1); + frame->shade_selection.p0 = MulAffineV2(frame->af.world_to_shade, frame->world_selection.p0); + frame->shade_selection.p1 = MulAffineV2(frame->af.world_to_shade, frame->world_selection.p1); ////////////////////////////// //- Place tiles @@ -1001,8 +1001,8 @@ void V_TickForever(WaveLaneCtx *lane) { // TODO: Fix clamp when both start & end are outside of world Rng2I32 tile_range = Zi; - tile_range.p0 = Vec2I32FromVec(FloorVec2(MulXformV2(frame->xf.world_to_tile, prev_frame->world_selection.p0))); - tile_range.p1 = Vec2I32FromVec(CeilVec2(MulXformV2(frame->xf.world_to_tile, prev_frame->world_selection.p1))); + tile_range.p0 = Vec2I32FromVec(FloorVec2(MulAffineV2(frame->af.world_to_tile, prev_frame->world_selection.p0))); + tile_range.p1 = Vec2I32FromVec(CeilVec2(MulAffineV2(frame->af.world_to_tile, prev_frame->world_selection.p1))); P_Msg *msg = P_PushMsg(P_MsgKind_TileEdit, Zstr); msg->tile_kind = prev_frame->equipped_tile; @@ -1743,7 +1743,7 @@ void V_TickForever(WaveLaneCtx *lane) // // else // // { // // // TODO: Unified blend logic between local world & correct world - // // correct_ent->xf = LerpXform(correct_ent->xf, predict_ent->xf, correction_rate); + // // correct_ent->af = LerpAffine(correct_ent->af, predict_ent->af, correction_rate); // // correct_ent->solved_v = LerpVec2(correct_ent->solved_v, predict_ent->solved_v, correction_rate); // // correct_ent->solved_w = LerpF32(correct_ent->solved_w, predict_ent->solved_w, correction_rate); // // } @@ -1841,21 +1841,21 @@ void V_TickForever(WaveLaneCtx *lane) if (body_slice.ready) { - Xform body_to_world_xf = XformIdentity; + Affine body_to_world_af = AffineIdentity; { // FIXME: Use origin ray Vec2 world_dims = DivVec2(body_slice.dims, P_CellsPerMeter); - body_to_world_xf.og = ent->xf.og; - // body_to_world_xf.og = SubVec2(body_to_world_xf.og, MulVec2(world_dims, 0.25)); - body_to_world_xf = XformWithWorldRotation(body_to_world_xf, AngleFromVec2(ent->control.look)); - body_to_world_xf = TranslateXform(body_to_world_xf, MulVec2(world_dims, -0.5)); - body_to_world_xf = ScaleXform(body_to_world_xf, world_dims); + body_to_world_af.og = ent->af.og; + // body_to_world_af.og = SubVec2(body_to_world_af.og, MulVec2(world_dims, 0.25)); + body_to_world_af = AffineWithWorldRotation(body_to_world_af, AngleFromVec2(ent->control.look)); + body_to_world_af = TranslateAffine(body_to_world_af, MulVec2(world_dims, -0.5)); + body_to_world_af = ScaleAffine(body_to_world_af, world_dims); } // Push body quad { V_Quad *quad = PushStruct(frame->quads_arena, V_Quad); - quad->to_shade_xf = MulXform(frame->xf.world_to_shade, body_to_world_xf); + quad->to_shade_af = MulAffine(frame->af.world_to_shade, body_to_world_af); quad->tex = body_slice.tex; quad->uv_rect = body_slice.uv_rect; } @@ -1864,13 +1864,13 @@ void V_TickForever(WaveLaneCtx *lane) // SPR_Slice wep_slice = SPR_FrameFromSheet(anim.weapon_sheet, anim.span, anim.frame_seq); - // Xform wep_to_world_xf = XformIdentity; + // Affine wep_to_world_af = AffineIdentity; // { // } // // Push weapon quad // { // V_Quad *quad = PushStruct(frame->quads_arena, V_Quad); - // quad->xf = MulXform(frame->xf.world_to_shade, wep_to_world_xf); + // quad->af = MulAffine(frame->af.world_to_shade, wep_to_world_af); // quad->slice = wep_sframe.slice; // } } @@ -1904,8 +1904,8 @@ void V_TickForever(WaveLaneCtx *lane) { skip = 1; } - // V_DrawPoint(MulXformV2(frame->xf.world_to_screen, start), Color_Red); - // V_DrawPoint(MulXformV2(frame->xf.world_to_screen, end), Color_Purple); + // V_DrawPoint(MulAffineV2(frame->af.world_to_screen, start), Color_Red); + // V_DrawPoint(MulAffineV2(frame->af.world_to_screen, end), Color_Purple); end = hit_pos; } @@ -2147,8 +2147,8 @@ void V_TickForever(WaveLaneCtx *lane) // { // if (firer->fire_held) // { - // Xform firer_xf = firer->xf; - // P_Shape firer_world_shape = P_MulXformShape(firer_xf, firer->local_shape); + // Affine firer_af = firer->af; + // P_Shape firer_world_shape = P_MulAffineShape(firer_af, firer->local_shape); // Vec2 ray_start = firer_world_shape.centroid; // Vec2 ray_dir = firer->look; @@ -2162,8 +2162,8 @@ void V_TickForever(WaveLaneCtx *lane) // { // if (victim != firer) // { - // Xform victim_xf = victim->xf; - // P_Shape victim_world_shape = P_MulXformShape(victim_xf, victim->local_shape); + // Affine victim_af = victim->af; + // P_Shape victim_world_shape = P_MulAffineShape(victim_af, victim->local_shape); // P_RaycastResult raycast = P_RaycastShape(victim_world_shape, ray_start, ray_dir); // if (raycast.is_intersecting) @@ -2295,28 +2295,28 @@ void V_TickForever(WaveLaneCtx *lane) { case P_DebugDrawKind_Point: { - Vec2 ui_p = MulXformV2(frame->xf.world_to_screen, n->point.p); + Vec2 ui_p = MulAffineV2(frame->af.world_to_screen, n->point.p); V_DrawPoint(ui_p, color); } break; case P_DebugDrawKind_Line: { - Vec2 ui_p0 = MulXformV2(frame->xf.world_to_screen, n->line.p0); - Vec2 ui_p1 = MulXformV2(frame->xf.world_to_screen, n->line.p1); + Vec2 ui_p0 = MulAffineV2(frame->af.world_to_screen, n->line.p0); + Vec2 ui_p1 = MulAffineV2(frame->af.world_to_screen, n->line.p1); V_DrawLine(ui_p0, ui_p1, color); } break; case P_DebugDrawKind_Rect: { Rng2 ui_rect = Zi; - ui_rect.p0 = MulXformV2(frame->xf.world_to_screen, n->rect.p0); - ui_rect.p1 = MulXformV2(frame->xf.world_to_screen, n->rect.p1); + ui_rect.p0 = MulAffineV2(frame->af.world_to_screen, n->rect.p0); + ui_rect.p1 = MulAffineV2(frame->af.world_to_screen, n->rect.p1); V_DrawRect(ui_rect, color, V_DrawFlag_Line); } break; case P_DebugDrawKind_Shape: { - P_Shape ui_shape = P_MulXformShape(frame->xf.world_to_screen, n->shape); + P_Shape ui_shape = P_MulAffineShape(frame->af.world_to_screen, n->shape); V_DrawShape(ui_shape, color, detail, V_DrawFlag_Line); } break; } @@ -3663,8 +3663,8 @@ void V_TickForever(WaveLaneCtx *lane) } UI_BuildSpacer(UI_PIX(padding, 1), Axis_Y); { - Vec2 tile_pos = MulXformV2(frame->xf.world_to_tile, frame->world_cursor); - Vec2 cell_pos = MulXformV2(frame->xf.world_to_cell, frame->world_cursor); + Vec2 tile_pos = MulAffineV2(frame->af.world_to_tile, frame->world_cursor); + Vec2 cell_pos = MulAffineV2(frame->af.world_to_cell, frame->world_cursor); i32 tile_idx = P_TileIdxFromTilePos(tile_pos); UI_BuildLabelF("Camera pos: %F", FmtFloat2(frame->camera_pos)); UI_BuildLabelF("Cursor world pos: %F", FmtFloat2(frame->world_cursor)); @@ -4067,7 +4067,7 @@ void V_TickForever(WaveLaneCtx *lane) // P_Ent *ent = &cmd->ent; // *ent = P_NilEnt; // ent->key = V.guy_key; - // ent->xf = XformFromPos(guy_pos); + // ent->af = AffineFromPos(guy_pos); // ent->is_guy = 1; // ent->has_weapon = 1; // ent->exists = 1; @@ -4208,7 +4208,7 @@ void V_TickForever(WaveLaneCtx *lane) params.dt = frame->dt; params.tick = frame->tick; params.seed = RandU64FromState(&frame->rand); - params.xf = frame->xf; + params.af = frame->af; params.selection_mode = frame->selection_mode; params.equipped_tile = frame->equipped_tile; diff --git a/src/pp/pp_vis/pp_vis_core.h b/src/pp/pp_vis/pp_vis_core.h index f55699c3..9f7de71a 100644 --- a/src/pp/pp_vis/pp_vis_core.h +++ b/src/pp/pp_vis/pp_vis_core.h @@ -270,8 +270,8 @@ Struct(V_Frame) Vec2 camera_pos; f32 camera_zoom; - // Xforms; - V_Xforms xf; + // Affines; + V_Affines af; // Cursors Vec2 screen_cursor; diff --git a/src/pp/pp_vis/pp_vis_gpu.g b/src/pp/pp_vis/pp_vis_gpu.g index a227da1e..14ad4eee 100644 --- a/src/pp/pp_vis/pp_vis_gpu.g +++ b/src/pp/pp_vis/pp_vis_gpu.g @@ -89,7 +89,7 @@ VertexShader(V_QuadVS, V_QuadPSInput) V_Quad quad = quads[SV_InstanceID]; Vec2 rect_uv = RectUvFromIdx(SV_VertexID); - Vec2 shade_pos = mul(quad.to_shade_xf, Vec3(rect_uv, 1)); + Vec2 shade_pos = mul(quad.to_shade_af, Vec3(rect_uv, 1)); Vec2 tex_uv = lerp(quad.uv_rect.p0, quad.uv_rect.p1, rect_uv); // Vec2 shade_pos = lerp(quad.p0, quad.p1, rect_uv); @@ -138,16 +138,16 @@ PixelShader(V_QuadPS, V_QuadPSOutput, V_QuadPSInput input) // Vec2 screen_pos = SV_DispatchThreadID + Vec2(0.5, 0.5); // Vec4 result = Vec4(0.025, 0.025, 0.025, 1); -// Vec2 world_pos = mul(params.xf.screen_to_world, Vec3(screen_pos, 1)); -// Vec2 cell_pos = floor(mul(params.xf.world_to_cell, Vec3(world_pos, 1))); -// Vec2 tile_pos = mul(params.xf.world_to_tile, Vec3(world_pos, 1)); +// Vec2 world_pos = mul(params.af.screen_to_world, Vec3(screen_pos, 1)); +// Vec2 cell_pos = floor(mul(params.af.world_to_cell, Vec3(world_pos, 1))); +// Vec2 tile_pos = mul(params.af.world_to_tile, Vec3(world_pos, 1)); // P_TileKind tile = tiles.Load(Vec3(tile_pos, 0)); // f32 half_thickness = 1; // f32 half_world_bounds_size = P_WorldPitch * 0.5; -// Vec2 world_bounds_screen_p0 = mul(params.xf.world_to_screen, Vec3(-half_world_bounds_size, -half_world_bounds_size, 1)); -// Vec2 world_bounds_screen_p1 = mul(params.xf.world_to_screen, Vec3(half_world_bounds_size, half_world_bounds_size, 1)); +// Vec2 world_bounds_screen_p0 = mul(params.af.world_to_screen, Vec3(-half_world_bounds_size, -half_world_bounds_size, 1)); +// Vec2 world_bounds_screen_p1 = mul(params.af.world_to_screen, Vec3(half_world_bounds_size, half_world_bounds_size, 1)); // b32 is_in_world_bounds = // screen_pos.x > (world_bounds_screen_p0.x - half_thickness) && // screen_pos.y > (world_bounds_screen_p0.y - half_thickness) && @@ -290,7 +290,7 @@ PixelShader(V_QuadPS, V_QuadPSOutput, V_QuadPSInput input) // // // Cells test // // { // // RWTexture2D cells = G_Dereference(params.cells); -// // Vec2 cell_pos = floor(mul(params.xf.world_to_cell, Vec3(world_pos, 1))); +// // Vec2 cell_pos = floor(mul(params.af.world_to_cell, Vec3(world_pos, 1))); // // Vec4 cell = cells.Load(cell_pos); // // if (cell.a != 0) // // { @@ -313,7 +313,7 @@ PixelShader(V_QuadPS, V_QuadPSOutput, V_QuadPSInput input) // // Stains test // // { // // RWTexture2D stains = G_Dereference(params.stains); -// // Vec2 cell_pos = mul(params.xf.world_to_cell, Vec3(world_pos, 1)); +// // Vec2 cell_pos = mul(params.af.world_to_cell, Vec3(world_pos, 1)); // // V_ParticleKind stain = stains.Load(cell_pos); // // if (stain == V_ParticleKind_Test) @@ -419,7 +419,7 @@ ComputeShader(V_SimParticlesCS, 64) particle.emitter_init_num = 0; } - Vec2 cell_pos = floor(mul(params.xf.world_to_cell, Vec3(particle.pos, 1))); + Vec2 cell_pos = floor(mul(params.af.world_to_cell, Vec3(particle.pos, 1))); b32 is_in_world_bounds = cell_pos.x >= 0 && cell_pos.y >= 0 && cell_pos.x < countof(stains).x && cell_pos.y < countof(stains).y; // Simulate @@ -496,9 +496,9 @@ ComputeShader2D(V_ShadeCS, 8, 8) SamplerState wrap_sampler = G_Dereference(params.pt_wrap_sampler); Vec2 shade_pos = SV_DispatchThreadID + Vec2(0.5, 0.5); - Vec2 world_pos = mul(params.xf.shade_to_world, Vec3(shade_pos, 1)); - Vec2 cell_pos = floor(mul(params.xf.world_to_cell, Vec3(world_pos, 1))); - Vec2 tile_pos = mul(params.xf.world_to_tile, Vec3(world_pos, 1)); + Vec2 world_pos = mul(params.af.shade_to_world, Vec3(shade_pos, 1)); + Vec2 cell_pos = floor(mul(params.af.world_to_cell, Vec3(world_pos, 1))); + Vec2 tile_pos = mul(params.af.world_to_tile, Vec3(world_pos, 1)); P_TileKind tile = tiles.Load(Vec3(tile_pos, 0)); @@ -638,15 +638,15 @@ PixelShader(V_CompositePS, V_CompositePSOutput, V_CompositePSInput input) Vec2 screen_pos = input.sv_position.xy; - Vec2 world_pos = mul(params.xf.screen_to_world, Vec3(screen_pos, 1)); - Vec2 tile_pos = mul(params.xf.world_to_tile, Vec3(world_pos, 1)); + Vec2 world_pos = mul(params.af.screen_to_world, Vec3(screen_pos, 1)); + Vec2 tile_pos = mul(params.af.world_to_tile, Vec3(world_pos, 1)); P_TileKind equipped_tile = params.equipped_tile; f32 half_thickness = 1; Vec2 half_world_dims = Vec2(P_WorldPitch, P_WorldPitch) * 0.5; - Vec2 world_bounds_screen_p0 = mul(params.xf.world_to_screen, Vec3(-half_world_dims.xy, 1)); - Vec2 world_bounds_screen_p1 = mul(params.xf.world_to_screen, Vec3(half_world_dims.xy, 1)); + Vec2 world_bounds_screen_p0 = mul(params.af.world_to_screen, Vec3(-half_world_dims.xy, 1)); + Vec2 world_bounds_screen_p1 = mul(params.af.world_to_screen, Vec3(half_world_dims.xy, 1)); b32 is_in_world_bounds = ( screen_pos.x > (world_bounds_screen_p0.x - half_thickness) && screen_pos.y > (world_bounds_screen_p0.y - half_thickness) && @@ -654,7 +654,7 @@ PixelShader(V_CompositePS, V_CompositePSOutput, V_CompositePSInput input) screen_pos.y < (world_bounds_screen_p1.y + half_thickness) ); - Vec2 shade_pos = mul(params.xf.screen_to_shade, Vec3(screen_pos.xy, 1)); + Vec2 shade_pos = mul(params.af.screen_to_shade, Vec3(screen_pos.xy, 1)); //- Shaded color Vec4 shade_color = 0; @@ -677,8 +677,8 @@ PixelShader(V_CompositePS, V_CompositePSOutput, V_CompositePSInput input) Rng2 world_selection = params.world_selection; Rng2 tile_selection; - tile_selection.p0 = floor(mul(params.xf.world_to_tile, Vec3(world_selection.p0, 1))); - tile_selection.p1 = ceil(mul(params.xf.world_to_tile, Vec3(world_selection.p1, 1))); + tile_selection.p0 = floor(mul(params.af.world_to_tile, Vec3(world_selection.p0, 1))); + tile_selection.p1 = ceil(mul(params.af.world_to_tile, Vec3(world_selection.p1, 1))); f32 dist = 100000000; dist = min(dist, screen_pos.x - screen_selection.p0.x); @@ -720,8 +720,8 @@ PixelShader(V_CompositePS, V_CompositePSOutput, V_CompositePSInput input) if (V_ShaderConst_GpuFlags & V_GpuFlag_DebugDraw) { const Vec4 grid_color = LinearFromSrgb(Vec4(1, 1, 1, 0.1)); - Vec2 grid_screen_p0 = mul(params.xf.world_to_screen, Vec3(floor(world_pos), 1)); - Vec2 grid_screen_p1 = mul(params.xf.world_to_screen, Vec3(ceil(world_pos), 1)); + Vec2 grid_screen_p0 = mul(params.af.world_to_screen, Vec3(floor(world_pos), 1)); + Vec2 grid_screen_p1 = mul(params.af.world_to_screen, Vec3(ceil(world_pos), 1)); f32 grid_dist = 100000; grid_dist = min(grid_dist, abs(screen_pos.x - grid_screen_p0.x)); grid_dist = min(grid_dist, abs(screen_pos.x - grid_screen_p1.x)); @@ -739,7 +739,7 @@ PixelShader(V_CompositePS, V_CompositePSOutput, V_CompositePSInput input) const Vec4 x_axis_color = LinearFromSrgb(Vec4(0.75, 0, 0, 1)); const Vec4 y_axis_color = LinearFromSrgb(Vec4(0, 0.75, 0, 1)); - Vec2 zero_screen = mul(params.xf.world_to_screen, Vec3(0, 0, 1)); + Vec2 zero_screen = mul(params.af.world_to_screen, Vec3(0, 0, 1)); f32 x_dist = abs(screen_pos.x - zero_screen.x); f32 y_dist = abs(screen_pos.y - zero_screen.y); if (y_dist <= half_thickness) diff --git a/src/pp/pp_vis/pp_vis_shared.cgh b/src/pp/pp_vis/pp_vis_shared.cgh index 461f1489..f5d53ee1 100644 --- a/src/pp/pp_vis/pp_vis_shared.cgh +++ b/src/pp/pp_vis/pp_vis_shared.cgh @@ -23,27 +23,27 @@ Enum(V_SelectionMode) V_SelectionMode_Tile, }; -Struct(V_Xforms) +Struct(V_Affines) { // World <-> screen - Xform world_to_screen; - Xform screen_to_world; + Affine world_to_screen; + Affine screen_to_world; // World <-> shade - Xform world_to_shade; - Xform shade_to_world; + Affine world_to_shade; + Affine shade_to_world; // Shade <-> screen - Xform shade_to_screen; - Xform screen_to_shade; + Affine shade_to_screen; + Affine screen_to_shade; // World <-> cell - Xform world_to_cell; - Xform cell_to_world; + Affine world_to_cell; + Affine cell_to_world; // World <-> tile - Xform world_to_tile; - Xform tile_to_world; + Affine world_to_tile; + Affine tile_to_world; }; Struct(V_TileDesc) @@ -63,7 +63,7 @@ Struct(V_GpuParams) f32 dt; u64 tick; u64 seed; - V_Xforms xf; + V_Affines af; V_SelectionMode selection_mode; P_TileKind equipped_tile; @@ -182,7 +182,7 @@ Enum(V_QuadFlag) Struct(V_Quad) { V_QuadFlag flags; - Xform to_shade_xf; + Affine to_shade_af; G_Texture2DRef tex; Rng2 uv_rect; };