rename 'xform' -> 'affine'

This commit is contained in:
jacob 2026-01-23 17:37:58 -06:00
parent d5efdab6d9
commit 0ee976cda2
16 changed files with 368 additions and 368 deletions

View File

@ -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 //- Initialization
Xform XformFromPos(Vec2 v) Affine AffineFromPos(Vec2 v)
{ {
Xform xf; Affine af;
xf.bx = VEC2(1, 0); af.bx = VEC2(1, 0);
xf.by = VEC2(0, 1); af.by = VEC2(0, 1);
xf.og = v; af.og = v;
return xf; return af;
} }
Xform XformFromRot(f32 r) Affine AffineFromRot(f32 r)
{ {
Xform result; Affine result;
f32 c = CosF32(r); f32 c = CosF32(r);
f32 s = SinF32(r); f32 s = SinF32(r);
result.bx = VEC2(c, s); result.bx = VEC2(c, s);
@ -828,83 +828,83 @@ Xform XformFromRot(f32 r)
return result; return result;
} }
Xform XformFromScale(Vec2 scale) Affine AffineFromScale(Vec2 scale)
{ {
Xform result; Affine result;
result.bx = VEC2(scale.x, 0); result.bx = VEC2(scale.x, 0);
result.by = VEC2(0, scale.y); result.by = VEC2(0, scale.y);
result.og = VEC2(0, 0); result.og = VEC2(0, 0);
return result; return result;
} }
Xform XformFromTrs(Trs trs) Affine AffineFromTrs(Trs trs)
{ {
Xform xf = XformFromPos(trs.t); Affine af = AffineFromPos(trs.t);
xf = RotateXform(xf, trs.r); af = RotateAffine(af, trs.r);
xf = ScaleXform(xf, trs.s); af = ScaleAffine(af, trs.s);
return xf; return af;
} }
//- Translation //- 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); 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 xf; return af;
} }
Xform WorldTranslateXform(Xform xf, Vec2 v) Affine WorldTranslateAffine(Affine af, Vec2 v)
{ {
xf.og = AddVec2(xf.og, v); af.og = AddVec2(af.og, v);
return xf; return af;
} }
//- Rotation //- 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 diff = r;
f32 c = CosF32(diff); f32 c = CosF32(diff);
f32 s = SinF32(diff); f32 s = SinF32(diff);
xf.bx = VEC2(xf.bx.x * c - xf.bx.y * s, xf.bx.x * s + xf.bx.y * c); af.bx = VEC2(af.bx.x * c - af.bx.y * s, af.bx.x * s + af.bx.y * c);
xf.by = VEC2(xf.by.x * c - xf.by.y * s, xf.by.x * s + xf.by.y * c); af.by = VEC2(af.by.x * c - af.by.y * s, af.by.x * s + af.by.y * c);
return xf; 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 //- Scale
Xform ScaleXform(Xform xf, Vec2 scale) Affine ScaleAffine(Affine af, Vec2 scale)
{ {
xf.bx = MulVec2(xf.bx, scale.x); af.bx = MulVec2(af.bx, scale.x);
xf.by = MulVec2(xf.by, scale.y); af.by = MulVec2(af.by, scale.y);
return xf; return af;
} }
Xform WorldScaleXform(Xform xf, Vec2 scale) Affine WorldScaleAffine(Affine af, Vec2 scale)
{ {
Xform result; Affine result;
result.bx = MulVec2Vec2(xf.bx, scale); result.bx = MulVec2Vec2(af.bx, scale);
result.by = MulVec2Vec2(xf.by, scale); result.by = MulVec2Vec2(af.by, scale);
result.og = MulVec2Vec2(xf.og, scale); result.og = MulVec2Vec2(af.og, scale);
return result; return result;
} }
//- Lerp //- 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.bx = SlerpVec2(a.bx, b.bx, t);
result.by = SlerpVec2(a.by, b.by, t); result.by = SlerpVec2(a.by, b.by, t);
result.og = LerpVec2(a.og, b.og, t); result.og = LerpVec2(a.og, b.og, t);
@ -912,109 +912,109 @@ Xform LerpXform(Xform a, Xform b, f32 t)
} }
//- Invert //- Invert
Xform InvertXform(Xform xf) Affine InvertAffine(Affine af)
{ {
f32 det = DeterminantFromXform(xf); f32 det = DeterminantFromAffine(af);
f32 inv_det = 1.0f / det; f32 inv_det = 1.0f / det;
f32 old_bx_x = xf.bx.x; f32 old_bx_x = af.bx.x;
xf.bx.x = xf.by.y; af.bx.x = af.by.y;
xf.by.y = old_bx_x; af.by.y = old_bx_x;
xf.bx = MulVec2Vec2(xf.bx, VEC2(inv_det, -inv_det)); af.bx = MulVec2Vec2(af.bx, VEC2(inv_det, -inv_det));
xf.by = MulVec2Vec2(xf.by, 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 //- 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.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.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.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.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; return result;
} }
Vec2 MulXformBasisV2(Xform xf, Vec2 v) Vec2 MulAffineBasisV2(Affine af, Vec2 v)
{ {
return VEC2( return VEC2(
xf.bx.x * v.x + xf.by.x * v.y, af.bx.x * v.x + af.by.x * v.y,
xf.bx.y * v.x + xf.by.y * 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); Vec2 result = MulAffineBasisV2(af, v);
result = AddVec2(result, xf.og); result = AddVec2(result, af.og);
return result; return result;
} }
Vec2 InvertXformBasisMulV2(Xform xf, Vec2 v) Vec2 InvertAffineBasisMulV2(Affine af, Vec2 v)
{ {
Xform inv = InvertXform(xf); Affine inv = InvertAffine(af);
Vec2 result = MulXformBasisV2(inv, v); Vec2 result = MulAffineBasisV2(inv, v);
return result; return result;
} }
// TODO: Get rid of this? Just force caller to use invert manually since it's expensive. // 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); Affine inv = InvertAffine(af);
return MulXformV2(inv, v); return MulAffineV2(inv, v);
} }
//- Helpers //- Helpers
Xform BasisFromXform(Xform xf) Affine BasisFromAffine(Affine af)
{ {
Xform result = Zi; Affine result = Zi;
result.bx = xf.bx; result.bx = af.bx;
result.by = xf.by; result.by = af.by;
return result; 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); 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
Mat4x4 Mat4x4FromXform(Xform xf) Mat4x4 Mat4x4FromAffine(Affine af)
{ {
return (Mat4x4) return (Mat4x4)
{ {
.e = { .e = {
{xf.bx.x, xf.bx.y, 0, 0}, {af.bx.x, af.bx.y, 0, 0},
{xf.by.x, xf.by.y, 0, 0}, {af.by.x, af.by.y, 0, 0},
{0, 0, 1, 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; 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 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); return MulMat4x4(projection, view4x4);
} }

View File

@ -147,9 +147,9 @@ Struct(Rng3U64) { Vec3U64 p0, p1; };
#define RNG3U64(p0, p1) (Rng3U64) { (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 bx; // X basis vector (x axis)
Vec2 by; // Y basis vector (y axis) Vec2 by; // Y basis vector (y axis)
@ -436,54 +436,54 @@ Rng2I32 MulRng2I32Vec2I32(Rng2I32 a, Vec2I32 v);
Rng2I32 DivRng2I32Vec2I32(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 //- Initialization
#define XformIdentity (Xform) { .bx = { .x = 1 }, .by = { .y = 1 } } #define AffineIdentity (Affine) { .bx = { .x = 1 }, .by = { .y = 1 } }
#define CompXformIdentity { .bx = { .x = 1 }, .by = { .y = 1 } } #define CompAffineIdentity { .bx = { .x = 1 }, .by = { .y = 1 } }
Xform XformFromPos(Vec2 v); Affine AffineFromPos(Vec2 v);
Xform XformFromRot(f32 r); Affine AffineFromRot(f32 r);
Xform XformFromScale(Vec2 scale); Affine AffineFromScale(Vec2 scale);
Xform XformFromTrs(Trs trs); Affine AffineFromTrs(Trs trs);
//- Translation //- Translation
Xform TranslateXform(Xform xf, Vec2 v); Affine TranslateAffine(Affine af, Vec2 v);
Xform WorldTranslateXform(Xform xf, Vec2 v); Affine WorldTranslateAffine(Affine af, Vec2 v);
//- Rotation //- Rotation
Xform RotateXform(Xform xf, f32 r); Affine RotateAffine(Affine af, f32 r);
Xform WorldRotateXform(Xform xf, f32 r); Affine WorldRotateAffine(Affine af, f32 r);
Xform WorldRotateXformBasis(Xform xf, f32 r); Affine WorldRotateAffineBasis(Affine af, f32 r);
Xform XformWithWorldRotation(Xform xf, f32 r); Affine AffineWithWorldRotation(Affine af, f32 r);
//- Scale //- Scale
Xform ScaleXform(Xform xf, Vec2 scale); Affine ScaleAffine(Affine af, Vec2 scale);
Xform WorldScaleXform(Xform xf, Vec2 scale); Affine WorldScaleAffine(Affine af, Vec2 scale);
//- Lerp //- Lerp
Xform LerpXform(Xform a, Xform b, f32 t); Affine LerpAffine(Affine a, Affine b, f32 t);
//- Invert //- Invert
Xform InvertXform(Xform xf); Affine InvertAffine(Affine af);
//- Mul //- Mul
Vec2 MulXformV2(Xform xf, Vec2 v); Vec2 MulAffineV2(Affine af, Vec2 v);
Xform MulXform(Xform a, Xform b); Affine MulAffine(Affine a, Affine b);
Vec2 MulXformBasisV2(Xform xf, Vec2 v); Vec2 MulAffineBasisV2(Affine af, Vec2 v);
Vec2 InvertXformMulV2(Xform xf, Vec2 v); Vec2 InvertAffineMulV2(Affine af, Vec2 v);
Vec2 InvertXformBasisMulV2(Xform xf, Vec2 v); Vec2 InvertAffineBasisMulV2(Affine af, Vec2 v);
//- Helpers //- Helpers
Xform BasisFromXform(Xform xf); Affine BasisFromAffine(Affine af);
f32 DeterminantFromXform(Xform xf); f32 DeterminantFromAffine(Affine af);
Vec2 RightFromXform(Xform xf); Vec2 RightFromAffine(Affine af);
Vec2 LeftFromXform(Xform xf); Vec2 LeftFromAffine(Affine af);
Vec2 UpFromXform(Xform xf); Vec2 UpFromAffine(Affine af);
Vec2 DownFromXform(Xform xf); Vec2 DownFromAffine(Affine af);
f32 RotationFromXform(Xform xf); f32 RotationFromAffine(Affine af);
Vec2 ScaleFromXform(Xform xf); Vec2 ScaleFromAffine(Affine af);
//- Trs //- Trs
#define TRS(...) ((Trs) { .t = VEC2(0,0), .s = VEC2(1, 1), .r = 0, __VA_ARGS__ }) #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
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 Mat4x4FromOrtho(f32 left, f32 right, f32 bottom, f32 top, f32 near_z, f32 far_z);
Mat4x4 MulMat4x4(Mat4x4 m1, Mat4x4 m2); 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);

View File

@ -14,7 +14,7 @@ typedef int4 Vec4I32;
typedef uint2 Vec2U32; typedef uint2 Vec2U32;
typedef uint3 Vec3U32; typedef uint3 Vec3U32;
typedef uint4 Vec4U32; typedef uint4 Vec4U32;
typedef float2x3 Xform; typedef float2x3 Affine;
typedef float4 Rect; typedef float4 Rect;
typedef float4 ClipRect; typedef float4 ClipRect;
typedef float4 Aabb; typedef float4 Aabb;

View File

@ -28,14 +28,14 @@ CLD_Shape CLD_ShapeFromQuad(Quad quad)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
//~ Menkowski support point //~ 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; Vec2 *points = shape->points;
u32 count = shape->count; u32 count = shape->count;
f32 radius = shape->radius; f32 radius = shape->radius;
dir = RotateVec2(dir, -RotationFromXform(xf)); dir = RotateVec2(dir, -RotationFromAffine(af));
dir = MulVec2Vec2(dir, ScaleFromXform(xf)); dir = MulVec2Vec2(dir, ScaleFromAffine(af));
if (count == 1) if (count == 1)
{ {
@ -69,7 +69,7 @@ CLD_SupportPoint CLD_SupportPointFromDirEx(CLD_Shape *shape, Xform xf, Vec2 dir,
furthest = AddVec2(furthest, dir); furthest = AddVec2(furthest, dir);
} }
furthest = MulXformV2(xf, furthest); furthest = MulAffineV2(af, furthest);
CLD_SupportPoint result; CLD_SupportPoint result;
result.p = furthest; result.p = furthest;
@ -77,16 +77,16 @@ CLD_SupportPoint CLD_SupportPointFromDirEx(CLD_Shape *shape, Xform xf, Vec2 dir,
return result; 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; CLD_MenkowskiPoint result;
result.s0 = CLD_SupportPointFromDir(shape0, xf0, dir); result.s0 = CLD_SupportPointFromDir(shape0, af0, dir);
result.s1 = CLD_SupportPointFromDir(shape1, xf1, NegVec2(dir)); result.s1 = CLD_SupportPointFromDir(shape1, af1, NegVec2(dir));
result.p = SubVec2(result.s0.p, result.s1.p); result.p = SubVec2(result.s0.p, result.s1.p);
return result; return result;
} }
@ -94,13 +94,13 @@ CLD_MenkowskiPoint CLD_MenkowskiPointFromDir(CLD_Shape *shape0, CLD_Shape *shape
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
//~ Aabb //~ Aabb
Aabb CLD_AabbFromShape(CLD_Shape *shape, Xform xf) Aabb CLD_AabbFromShape(CLD_Shape *shape, Affine af)
{ {
Aabb result; Aabb result;
result.p0.x = CLD_SupportPointFromDir(shape, xf, VEC2(-1, 0)).p.x - CLD_CollisionTolerance; result.p0.x = CLD_SupportPointFromDir(shape, af, VEC2(-1, 0)).p.x - CLD_CollisionTolerance;
result.p0.y = CLD_SupportPointFromDir(shape, xf, VEC2(0, -1)).p.y - CLD_CollisionTolerance; result.p0.y = CLD_SupportPointFromDir(shape, af, VEC2(0, -1)).p.y - CLD_CollisionTolerance;
result.p1.x = CLD_SupportPointFromDir(shape, xf, VEC2(1, 0)).p.x + CLD_CollisionTolerance; result.p1.x = CLD_SupportPointFromDir(shape, af, VEC2(1, 0)).p.x + CLD_CollisionTolerance;
result.p1.y = CLD_SupportPointFromDir(shape, xf, VEC2(0, 1)).p.y + CLD_CollisionTolerance; result.p1.y = CLD_SupportPointFromDir(shape, af, VEC2(0, 1)).p.y + CLD_CollisionTolerance;
return result; return result;
} }
@ -138,9 +138,9 @@ b32 CLD_TestAabb(Aabb box0, Aabb box1)
// //
#if COLLIDER_DEBUG #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 #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 #endif
{ {
b32 overlapping = 0; b32 overlapping = 0;
@ -149,9 +149,9 @@ CLD_GjkData CLD_GjkDataFromShapes(CLD_Shape *shape0, CLD_Shape *shape1, Xform xf
CLD_MenkowskiPoint m = Zi; CLD_MenkowskiPoint m = Zi;
// First point is support point in shape's general directions to eachother // 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); 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; s.len = 1;
Vec2 removed_a = Zi; 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); dir = NegVec2(s.a.p);
CLD_DBGSTEP; 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 // Check that new point is far enough away from existing point
if (Vec2LenSq(SubVec2(m.p, s.a.p)) < min_unique_pt_dist_sq) 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; 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 // Check that new point is far enough away from existing points
if ( if (
Vec2LenSq(SubVec2(m.p, s.a.p)) < min_unique_pt_dist_sq || 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 // closest edge when shapes are overlapping
#if COLLIDER_DEBUG #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 #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 #endif
{ {
TempArena scratch = BeginScratchNoConflict(); TempArena scratch = BeginScratchNoConflict();
@ -389,7 +389,7 @@ CLD_EpaData CLD_EpaDataFromShapes(CLD_Shape *shape0, CLD_Shape *shape1, Xform xf
// Find new point in dir // Find new point in dir
Vec2 dir = MulVec2(PerpVec2(vab), winding); 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 #if COLLIDER_DEBUG
{ {
@ -545,7 +545,7 @@ Vec2 CLD_ClipPointToLine(Vec2 a, Vec2 b, Vec2 p, Vec2 normal)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
//~ Collision points //~ 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; CLD_CollisionData result = Zi;
@ -567,19 +567,19 @@ CLD_CollisionData CLD_CollisionDataFromShapes(CLD_Shape *shape0, CLD_Shape *shap
// Run GJK // Run GJK
#if COLLIDER_DEBUG #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; dbg_step = gjk_result.dbg_step;
#else #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 #endif
CLD_DBGSTEP; CLD_DBGSTEP;
// Run EPA // Run EPA
#if COLLIDER_DEBUG #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; dbg_step = epa_result.dbg_step;
#else #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 #endif
normal = epa_result.normal; normal = epa_result.normal;
CLD_DBGSTEP; CLD_DBGSTEP;
@ -639,7 +639,7 @@ CLD_CollisionData CLD_CollisionDataFromShapes(CLD_Shape *shape0, CLD_Shape *shap
{ {
if (shape0->count > 1) if (shape0->count > 1)
{ {
b0 = CLD_SupportPointFromDirEx(shape0, xf0, normal, b0.i); b0 = CLD_SupportPointFromDirEx(shape0, af0, normal, b0.i);
} }
else else
{ {
@ -651,7 +651,7 @@ CLD_CollisionData CLD_CollisionDataFromShapes(CLD_Shape *shape0, CLD_Shape *shap
{ {
if (shape1->count > 1) if (shape1->count > 1)
{ {
b1 = CLD_SupportPointFromDirEx(shape1, xf1, NegVec2(normal), b1.i); b1 = CLD_SupportPointFromDirEx(shape1, af1, NegVec2(normal), b1.i);
} }
else else
{ {
@ -828,7 +828,7 @@ CLD_CollisionData CLD_CollisionDataFromShapes(CLD_Shape *shape0, CLD_Shape *shap
// TODO: De-duplicate code between CLD_ClosestPointDataFromShapes & CLD_CollisionDataFromShapes // 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; CLD_ClosestPointData result = Zi;
@ -851,10 +851,10 @@ CLD_ClosestPointData CLD_ClosestPointDataFromShapes(CLD_Shape *shape0, CLD_Shape
//- Run GJK //- Run GJK
#if COLLIDER_DEBUG #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; dbg_step = gjk_result.dbg_step;
#else #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 #endif
CLD_DBGSTEP; CLD_DBGSTEP;
@ -862,10 +862,10 @@ CLD_ClosestPointData CLD_ClosestPointDataFromShapes(CLD_Shape *shape0, CLD_Shape
//- Run EPA //- Run EPA
#if COLLIDER_DEBUG #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; dbg_step = epa_result.dbg_step;
#else #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 #endif
CLD_DBGSTEP; CLD_DBGSTEP;
@ -919,9 +919,9 @@ CLD_ClosestPointData CLD_ClosestPointDataFromShapes(CLD_Shape *shape0, CLD_Shape
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
//~ Time of impact //~ 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]. // 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 t0 = 0;
f32 t1 = 1; 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;
Vec2 dir_neg; 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) if (closest_points.colliding)
{ {
// Shapes are penetrating at t=0 // 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 p0 = CLD_SupportPointFromDir(c0, af0_t1, dir).p;
Vec2 p1 = CLD_SupportPointFromDir(c1, xf1_t1, dir_neg).p; Vec2 p1 = CLD_SupportPointFromDir(c1, af1_t1, dir_neg).p;
t1_sep = DotVec2(dir, SubVec2(p1, p0)); t1_sep = DotVec2(dir, SubVec2(p1, p0));
if (t1_sep > 0) 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; t = (-t1_sep / m) + t1;
} }
Xform xf0 = LerpXform(xf0_t0, xf0_t1, t); Affine af0 = LerpAffine(af0_t0, af0_t1, t);
Xform xf1 = LerpXform(xf1_t0, xf1_t1, t); Affine af1 = LerpAffine(af1_t0, af1_t1, t);
Vec2 p0 = CLD_SupportPointFromDir(c0, xf0, dir).p; Vec2 p0 = CLD_SupportPointFromDir(c0, af0, dir).p;
Vec2 p1 = CLD_SupportPointFromDir(c1, xf1, dir_neg).p; Vec2 p1 = CLD_SupportPointFromDir(c1, af1, dir_neg).p;
t_sep = DotVec2(dir, SubVec2(p1, p0)); t_sep = DotVec2(dir, SubVec2(p1, p0));
// Update bracket // 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 //~ Point cloud debug
// TODO: Remove this (debugging) // 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) }; Vec2Array result = { .points = ArenaNext(arena, Vec2) };
for (u64 i = 0; i < detail; ++i) for (u64 i = 0; i < detail; ++i)
{ {
f32 angle = ((f32)i / detail) * (2 * Pi); f32 angle = ((f32)i / detail) * (2 * Pi);
Vec2 dir = Vec2FromAngle(angle); 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])) if (result.count == 0 || !MatchVec2(m.p, result.points[result.count - 1]))
{ {
*PushStructNoZero(arena, Vec2) = m.p; *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) // 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 // FIXME: Account for radius
Vec2Array result = { .points = ArenaNext(arena, Vec2) }; 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; u32 count1 = shape1->count;
for (u64 i = 0; i < count0; ++i) 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) 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); *PushStructNoZero(arena, Vec2) = SubVec2(p0, p1);
++result.count; ++result.count;
} }

View File

@ -160,14 +160,14 @@ CLD_Shape CLD_ShapeFromQuad(Quad quad);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
//~ Menkowski //~ Menkowski
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);
CLD_SupportPoint CLD_SupportPointFromDir(CLD_Shape *shape, Xform xf, Vec2 dir); CLD_SupportPoint CLD_SupportPointFromDir(CLD_Shape *shape, Affine af, Vec2 dir);
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);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
//~ Aabb //~ Aabb
Aabb CLD_AabbFromShape(CLD_Shape *shape, Xform xf); Aabb CLD_AabbFromShape(CLD_Shape *shape, Affine af);
Aabb CLD_CombineAabb(Aabb b0, Aabb b1); Aabb CLD_CombineAabb(Aabb b0, Aabb b1);
b32 CLD_TestAabb(Aabb box0, Aabb box1); b32 CLD_TestAabb(Aabb box0, Aabb box1);
@ -175,18 +175,18 @@ b32 CLD_TestAabb(Aabb box0, Aabb box1);
//~ Gjk //~ Gjk
#if COLLIDER_DEBUG #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 #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 #endif
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
//~ Epa //~ Epa
#if COLLIDER_DEBUG #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 #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 #endif
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
@ -198,20 +198,20 @@ Vec2 CLD_ClipPointToLine(Vec2 a, Vec2 b, Vec2 p, Vec2 normal);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
//~ Collision point //~ 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 //~ 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 //~ 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 //~ Point cloud debug
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 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);

View File

@ -16,7 +16,7 @@ void D_DrawMaterial(GPU_RenderSig *sig, D_MaterialParams params)
{ {
GPU_RenderCmdDesc cmd = ZI; GPU_RenderCmdDesc cmd = ZI;
cmd.kind = GP_RENDER_CMD_KIND_DRAW_MATERIAL; 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.texture = params.texture;
cmd.material.clip = params.clip; cmd.material.clip = params.clip;
cmd.material.tint = params.tint; 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); 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(); TempArena scratch = BeginScratchNoConflict();
Vec2Array poly = ZI; 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); poly.points = PushStructsNoZero(scratch.arena, Vec2, shape.count);
for (u32 i = 0; i < shape.count; ++i) 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; 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; f32 angle = ((f32)i / (f32)detail) * Tau;
Vec2 dir = VEC2(CosF32(angle), SinF32(angle)); 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; poly.points[i] = p;
} }
} }
@ -249,7 +249,7 @@ void D_DrawColliderLine(GPU_RenderSig *sig, CLD_Shape shape, Xform shape_xf, f32
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
//~ Grid //~ 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; 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; GPU_RenderCmdDesc cmd = ZI;
cmd.kind = GP_RENDER_CMD_KIND_DRAW_MATERIAL; cmd.kind = GP_RENDER_CMD_KIND_DRAW_MATERIAL;
cmd.material.xf = xf; cmd.material.af = af;
cmd.material.tint = Color_White; cmd.material.tint = Color_White;
cmd.material.grid_cmd_id = grid_id; cmd.material.grid_cmd_id = grid_id;
GPU_PushRenderCmd(sig, &cmd); GPU_PushRenderCmd(sig, &cmd);
@ -281,7 +281,7 @@ void D_DrawUiRect(GPU_RenderSig *sig, D_UiRectParams params)
{ {
GPU_RenderCmdDesc cmd = ZI; GPU_RenderCmdDesc cmd = ZI;
cmd.kind = GP_RENDER_CMD_KIND_DRAW_UI_RECT; 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.texture = params.texture;
cmd.ui_rect.clip = params.clip; cmd.ui_rect.clip = params.clip;
cmd.ui_rect.tint = params.tint; 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]; D_TextGlyph *tg = &line->glyphs[i];
Vec2 pos = VEC2(draw_pos.x + tg->off_x, draw_pos.y + tg->off_y); Vec2 pos = VEC2(draw_pos.x + tg->off_x, draw_pos.y + tg->off_y);
Vec2 size = VEC2(tg->width, tg->height); Vec2 size = VEC2(tg->width, tg->height);
Xform xf = XformFromRect(RectFromVec2(pos, size)); Affine af = AffineFromRect(RectFromVec2(pos, size));
D_DrawUiRect(sig, D_UIRECTPARAMS(.xf = xf, .texture = params.font->texture, .tint = params.color, .clip = tg->clip)); D_DrawUiRect(sig, D_UIRECTPARAMS(.af = af, .texture = params.font->texture, .tint = params.color, .clip = tg->clip));
draw_pos.x += tg->advance; draw_pos.x += tg->advance;
} }

View File

@ -3,7 +3,7 @@
Struct(D_MaterialParams) Struct(D_MaterialParams)
{ {
Xform xf; Affine af;
GPU_Resource *texture; GPU_Resource *texture;
ClipRect clip; ClipRect clip;
u32 tint; u32 tint;
@ -21,7 +21,7 @@ Struct(D_MaterialParams)
Struct(D_UiRectParams) Struct(D_UiRectParams)
{ {
Xform xf; Affine af;
GPU_Resource *texture; GPU_Resource *texture;
ClipRect clip; ClipRect clip;
u32 tint; 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_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_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_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 //~ 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 //~ Ui

View File

@ -100,7 +100,7 @@ void PB_WSP_InitializeWasapi(void)
IAudioClient_Initialize(PB_WSP.client, AUDCLNT_SHAREMODE_SHARED, flags, duration, 0, wfx, 0); 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 // Set up event handler to wait on
PB_WSP.event = CreateEventW(0, 0, 0, 0); PB_WSP.event = CreateEventW(0, 0, 0, 0);

View File

@ -2,7 +2,7 @@ P_Ctx P = Zi;
ThreadLocal P_ThreadLocalCtx P_tl = Zi; ThreadLocal P_ThreadLocalCtx P_tl = Zi;
Readonly P_Ent P_NilEnt = { Readonly P_Ent P_NilEnt = {
.xf = CompXformIdentity, .af = CompAffineIdentity,
.control.look = { 0, -1 }, .control.look = { 0, -1 },
}; };
@ -124,17 +124,17 @@ P_Shape P_ShapeFromDescEx(P_ShapeDesc desc)
return result; return result;
} }
P_Shape P_MulXformShape(Xform xf, P_Shape shape) P_Shape P_MulAffineShape(Affine af, P_Shape shape)
{ {
P_Shape result = shape; P_Shape result = shape;
for (i32 i = 0; i < shape.points_count; ++i) 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.radius *= MaxF32(scale.x, scale.y);
result.centroid = MulXformV2(xf, shape.centroid); result.centroid = MulAffineV2(af, shape.centroid);
result.center_of_mass = MulXformV2(xf, shape.center_of_mass); result.center_of_mass = MulAffineV2(af, shape.center_of_mass);
return result; return result;
} }
@ -193,7 +193,7 @@ P_Shape P_LocalShapeFromEnt(P_Ent *ent)
P_Shape P_WorldShapeFromEnt(P_Ent *ent) P_Shape P_WorldShapeFromEnt(P_Ent *ent)
{ {
P_Shape local = P_LocalShapeFromEnt(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; return world;
} }
@ -231,8 +231,8 @@ P_Anim P_AnimFromEnt(P_Ent *ent, i64 time_ns)
// P_Anim result = Zi; // P_Anim result = Zi;
// // result.slice_to_world_xf = XformIdentity; // // result.slice_to_world_af = AffineIdentity;
// // result.slice_to_world_xf = ent->xf; // // result.slice_to_world_af = ent->af;
// i64 animation_rate_ns = NsFromSeconds(0.100); // 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 // // FIXME: Use origin ray
// { // {
// Vec2 world_dims = DivVec2(sframe.dims, P_CellsPerMeter); // Vec2 world_dims = DivVec2(sframe.dims, P_CellsPerMeter);
// result.body_to_world_xf = XformIdentity; // result.body_to_world_af = AffineIdentity;
// result.body_to_world_xf.og = ent->xf.og; // result.body_to_world_af.og = ent->af.og;
// // result.body_to_world_xf.og = SubVec2(result.body_to_world_xf.og, MulVec2(world_dims, 0.25)); // // result.body_to_world_af.og = SubVec2(result.body_to_world_af.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_af = AffineWithWorldRotation(result.body_to_world_af, AngleFromVec2(ent->control.look));
// result.body_to_world_xf = TranslateXform(result.body_to_world_xf, MulVec2(world_dims, -0.5)); // result.body_to_world_af = TranslateAffine(result.body_to_world_af, MulVec2(world_dims, -0.5));
// result.body_to_world_xf = ScaleXform(result.body_to_world_xf, world_dims); // 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 world_dims = VEC2(0.5, 0.5);
// // Vec2 px_dims = slice.dims; // // Vec2 px_dims = slice.dims;
// // Vec2 world_dims = DivVec2(px_dims, P_CellsPerMeter); // // Vec2 world_dims = DivVec2(px_dims, P_CellsPerMeter);
// // result.slice_to_world_xf = XformIdentity; // // result.slice_to_world_af = AffineIdentity;
// // result.slice_to_world_xf.og = ent->xf.og; // // result.slice_to_world_af.og = ent->af.og;
// // // result.slice_to_world_xf.og = SubVec2(result.slice_to_world_xf.og, MulVec2(world_dims, 0.25)); // // // result.slice_to_world_af.og = SubVec2(result.slice_to_world_af.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_af = AffineWithWorldRotation(result.slice_to_world_af, AngleFromVec2(ent->control.look));
// // result.slice_to_world_xf = TranslateXform(result.slice_to_world_xf, MulVec2(world_dims, -0.5)); // // result.slice_to_world_af = TranslateAffine(result.slice_to_world_af, MulVec2(world_dims, -0.5));
// // result.slice_to_world_xf = ScaleXform(result.slice_to_world_xf, world_dims); // // result.slice_to_world_af = ScaleAffine(result.slice_to_world_af, world_dims);
// // } // // }
// // result.slice = SPR_SliceFromSheet(sheet, // // result.slice = SPR_SliceFromSheet(sheet,
@ -312,8 +312,8 @@ P_Anim P_AnimFromEnt(P_Ent *ent, i64 time_ns)
// P_Anim result = Zi; // P_Anim result = Zi;
// // result.slice_to_world_xf = XformIdentity; // // result.slice_to_world_af = AffineIdentity;
// // result.slice_to_world_xf = ent->xf; // // result.slice_to_world_af = ent->af;
// i64 animation_rate_ns = NsFromSeconds(0.100); // 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 world_dims = VEC2(0.5, 0.5);
// Vec2 px_dims = slice.dims; // Vec2 px_dims = slice.dims;
// Vec2 world_dims = DivVec2(px_dims, P_CellsPerMeter); // Vec2 world_dims = DivVec2(px_dims, P_CellsPerMeter);
// result.slice_to_world_xf = XformIdentity; // result.slice_to_world_af = AffineIdentity;
// result.slice_to_world_xf.og = ent->xf.og; // result.slice_to_world_af.og = ent->af.og;
// // result.slice_to_world_xf.og = SubVec2(result.slice_to_world_xf.og, MulVec2(world_dims, 0.25)); // // result.slice_to_world_af.og = SubVec2(result.slice_to_world_af.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_af = AffineWithWorldRotation(result.slice_to_world_af, AngleFromVec2(ent->control.look));
// result.slice_to_world_xf = TranslateXform(result.slice_to_world_xf, MulVec2(world_dims, -0.5)); // result.slice_to_world_af = TranslateAffine(result.slice_to_world_af, MulVec2(world_dims, -0.5));
// result.slice_to_world_xf = ScaleXform(result.slice_to_world_xf, world_dims); // result.slice_to_world_af = ScaleAffine(result.slice_to_world_af, world_dims);
// } // }
// // result.slice = SPR_SliceFromSheet(sheet, // // 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); Vec4 color = VEC4(0.8, 0.8, 0.8, 1);
Vec2 p0 = world_shape.centroid; 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); 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)) 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; P_Control control = guy->control;
// Xform xf = guy->xf; // Affine af = guy->af;
// Xform desired_xf = xf; // Affine desired_af = af;
// if (!IsVec2Zero(control.look)) // 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); // 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); // Vec2 pos_diff = SubVec2(desired_af.og, af.og);
// f32 angle_diff = UnwindAngleF32(RotationFromXform(desired_xf) - RotationFromXform(xf)); // f32 angle_diff = UnwindAngleF32(RotationFromAffine(desired_af) - RotationFromAffine(af));
// guy->solved_v = pos_diff; // guy->solved_v = pos_diff;
// guy->solved_w = angle_diff; // guy->solved_w = angle_diff;
@ -2405,10 +2405,10 @@ void P_StepFrame(P_Frame *frame)
{ {
if (!is_predicting || ent == local_guy) if (!is_predicting || ent == local_guy)
{ {
Xform xf = ent->xf; Affine af = ent->af;
xf.og = AddVec2(xf.og, MulVec2(ent->solved_v, solver_dt)); af.og = AddVec2(af.og, MulVec2(ent->solved_v, solver_dt));
xf = RotateXform(xf, ent->solved_w * solver_dt); af = RotateAffine(af, ent->solved_w * solver_dt);
ent->xf = xf; ent->af = af;
} }
} }
} }

View File

@ -112,8 +112,8 @@ Struct(P_Ent)
b32 is_dummy; b32 is_dummy;
f32 health; f32 health;
Xform prev_xf; Affine prev_af;
Xform xf; Affine af;
// TODO: Remove this (weapon testing) // TODO: Remove this (weapon testing)
i64 last_fire_ns; i64 last_fire_ns;
@ -481,7 +481,7 @@ String P_NameFromTileKind(P_TileKind kind);
P_Shape P_ShapeFromDescEx(P_ShapeDesc desc); P_Shape P_ShapeFromDescEx(P_ShapeDesc desc);
#define P_ShapeFromDesc(...) P_ShapeFromDescEx((P_ShapeDesc) { __VA_ARGS__ }) #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); Rng2 P_BoundingBoxFromShape(P_Shape shape);
P_Shape P_LocalShapeFromEnt(P_Ent *ent); P_Shape P_LocalShapeFromEnt(P_Ent *ent);

View File

@ -594,7 +594,7 @@ void S_TickForever(WaveLaneCtx *lane)
P_Ent *guy = P_PushTempEnt(frame_arena, &ents); P_Ent *guy = P_PushTempEnt(frame_arena, &ents);
*guy = P_NilEnt; *guy = P_NilEnt;
guy->key = msg->key; guy->key = msg->key;
guy->xf = XformFromPos(msg->pos); guy->af = AffineFromPos(msg->pos);
guy->is_guy = 1; guy->is_guy = 1;
guy->has_weapon = 1; guy->has_weapon = 1;
guy->exists = 1; guy->exists = 1;
@ -604,7 +604,7 @@ void S_TickForever(WaveLaneCtx *lane)
P_Ent *guy = P_PushTempEnt(frame_arena, &ents); P_Ent *guy = P_PushTempEnt(frame_arena, &ents);
*guy = P_NilEnt; *guy = P_NilEnt;
guy->key = P_RandKey(); guy->key = P_RandKey();
guy->xf = XformFromPos(msg->pos); guy->af = AffineFromPos(msg->pos);
guy->is_guy = 1; guy->is_guy = 1;
guy->has_weapon = 1; guy->has_weapon = 1;
guy->exists = 1; guy->exists = 1;
@ -621,7 +621,7 @@ void S_TickForever(WaveLaneCtx *lane)
// P_Ent *ent = P_PushTempEnt(frame_arena, &ents); // P_Ent *ent = P_PushTempEnt(frame_arena, &ents);
// *ent = P_NilEnt; // *ent = P_NilEnt;
// ent->key = msg->key; // ent->key = msg->key;
// ent->xf = XformFromPos(msg->pos); // ent->af = AffineFromPos(msg->pos);
// ent->is_guy = 1; // ent->is_guy = 1;
// ent->is_dummy = 1; // ent->is_dummy = 1;
// ent->has_weapon = 1; // ent->has_weapon = 1;

View File

@ -60,8 +60,8 @@ String P_PackWorld(Arena *arena, P_World *src_world)
} }
} }
result.len += StringF(arena, " }\n").len; result.len += StringF(arena, " }\n").len;
result.len += StringF(arena, " pos: \"%F\"\n", FmtFloat2(ent->xf.og)).len; result.len += StringF(arena, " pos: \"%F\"\n", FmtFloat2(ent->af.og)).len;
result.len += StringF(arena, " rot: \"%F\"\n", FmtFloat2(RightFromXform(ent->xf))).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, " exists: \"%F\"\n", FmtFloat(ent->exists)).len;
result.len += StringF(arena, " look: \"%F\"\n", FmtFloat2(ent->control.look)).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"))) if (MatchString(attr->name, Lit("pos")))
{ {
Vec2 pos = CR_Vec2FromString(attr->value); Vec2 pos = CR_Vec2FromString(attr->value);
ent->xf.og = pos; ent->af.og = pos;
} }
if (MatchString(attr->name, Lit("rot"))) if (MatchString(attr->name, Lit("rot")))
{ {
Vec2 rot = CR_Vec2FromString(attr->value); 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"))) if (MatchString(attr->name, Lit("exists")))
{ {

View File

@ -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); 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))) if (prev_frame->is_editing && (should_zoom || (frame->is_panning && prev_frame->is_panning)))
{ {
Xform prev_frame_edit_to_screen_xf = Zi; Affine prev_frame_edit_to_screen_af = Zi;
Xform edit_to_screen_xf = 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 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); 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_af = AffineFromScale(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_af = TranslateAffine(prev_frame_edit_to_screen_af, 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)); prev_frame_edit_to_screen_af = WorldTranslateAffine(prev_frame_edit_to_screen_af, MulVec2(Vec2FromVec(frame->screen_dims), 0.5));
edit_to_screen_xf = XformFromScale(VEC2(edit_camera_scale, edit_camera_scale)); edit_to_screen_af = AffineFromScale(VEC2(edit_camera_scale, edit_camera_scale));
edit_to_screen_xf = TranslateXform(edit_to_screen_xf, NegVec2(frame->edit_camera_pos)); edit_to_screen_af = TranslateAffine(edit_to_screen_af, NegVec2(frame->edit_camera_pos));
edit_to_screen_xf = WorldTranslateXform(edit_to_screen_xf, MulVec2(Vec2FromVec(frame->screen_dims), 0.5)); 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 prev_target_cursor = MulAffineV2(InvertAffine(prev_frame_edit_to_screen_af), prev_frame->screen_cursor);
Vec2 target_cursor = MulXformV2(InvertXform(edit_to_screen_xf), ui_frame->cursor_pos); Vec2 target_cursor = MulAffineV2(InvertAffine(edit_to_screen_af), ui_frame->cursor_pos);
Vec2 diff = SubVec2(prev_target_cursor, target_cursor); Vec2 diff = SubVec2(prev_target_cursor, target_cursor);
frame->edit_camera_pos = AddVec2(frame->edit_camera_pos, diff); 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); P_Ent *guy = P_EntFromKey(local_world->last_frame, player->guy);
Vec2 guy_center = P_WorldShapeFromEnt(guy).centroid; Vec2 guy_center = P_WorldShapeFromEnt(guy).centroid;
Vec2 screen_center = MulVec2(frame->screen_dims, 0.5); 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 = guy_center;
target_camera_pos = AddVec2(target_camera_pos, MulVec2Vec2(look, look_ratio)); target_camera_pos = AddVec2(target_camera_pos, MulVec2Vec2(look, look_ratio));
target_camera_zoom = 1; target_camera_zoom = 1;
@ -895,66 +895,66 @@ void V_TickForever(WaveLaneCtx *lane)
} }
////////////////////////////// //////////////////////////////
//- Compute frame xforms //- Compute frame Affines
// World <-> screen // World <-> screen
frame->xf.world_to_screen = XformIdentity; frame->af.world_to_screen = AffineIdentity;
frame->xf.screen_to_world = XformIdentity; frame->af.screen_to_world = AffineIdentity;
{ {
f32 camera_scale = frame->screen_dims.x / (meters_per_camera_width * frame->camera_zoom); 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->af.world_to_screen = AffineFromScale(VEC2(camera_scale, camera_scale));
frame->xf.world_to_screen = TranslateXform(frame->xf.world_to_screen, NegVec2(frame->camera_pos)); frame->af.world_to_screen = TranslateAffine(frame->af.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->af.world_to_screen = WorldTranslateAffine(frame->af.world_to_screen, MulVec2(frame->screen_dims, 0.5));
frame->xf.world_to_screen.og = RoundVec2(frame->xf.world_to_screen.og); frame->af.world_to_screen.og = RoundVec2(frame->af.world_to_screen.og);
frame->xf.screen_to_world = InvertXform(frame->xf.world_to_screen); frame->af.screen_to_world = InvertAffine(frame->af.world_to_screen);
} }
// World <-> shade // World <-> shade
frame->xf.world_to_shade = XformIdentity; frame->af.world_to_shade = AffineIdentity;
frame->xf.shade_to_world = XformIdentity; frame->af.shade_to_world = AffineIdentity;
{ {
f32 camera_scale = (frame->shade_dims.x - shade_extra_dims.x) / (meters_per_camera_width * frame->camera_zoom); 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->af.world_to_shade = AffineFromScale(VEC2(camera_scale, camera_scale));
frame->xf.world_to_shade = TranslateXform(frame->xf.world_to_shade, NegVec2(frame->camera_pos)); frame->af.world_to_shade = TranslateAffine(frame->af.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->af.world_to_shade = WorldTranslateAffine(frame->af.world_to_shade, MulVec2(frame->shade_dims, 0.5));
frame->xf.world_to_shade.og = RoundVec2(frame->xf.world_to_shade.og); frame->af.world_to_shade.og = RoundVec2(frame->af.world_to_shade.og);
frame->xf.shade_to_world = InvertXform(frame->xf.world_to_shade); frame->af.shade_to_world = InvertAffine(frame->af.world_to_shade);
} }
// Shade <-> screen // Shade <-> screen
frame->xf.shade_to_screen = XformIdentity; frame->af.shade_to_screen = AffineIdentity;
frame->xf.screen_to_shade = XformIdentity; frame->af.screen_to_shade = AffineIdentity;
{ {
frame->xf.shade_to_screen = MulXform(frame->xf.world_to_screen, frame->xf.shade_to_world); frame->af.shade_to_screen = MulAffine(frame->af.world_to_screen, frame->af.shade_to_world);
frame->xf.screen_to_shade = InvertXform(frame->xf.shade_to_screen); frame->af.screen_to_shade = InvertAffine(frame->af.shade_to_screen);
} }
// World <-> cell // World <-> cell
// TODO: This never changes, should be #defined (so shaders don't need to read it every frame) // TODO: This never changes, should be #defined (so shaders don't need to read it every frame)
frame->xf.world_to_cell = XformIdentity; frame->af.world_to_cell = AffineIdentity;
frame->xf.cell_to_world = XformIdentity; frame->af.cell_to_world = AffineIdentity;
{ {
frame->xf.world_to_cell = ScaleXform(frame->xf.world_to_cell, VEC2(P_CellsPerMeter, P_CellsPerMeter)); frame->af.world_to_cell = ScaleAffine(frame->af.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->af.world_to_cell = TranslateAffine(frame->af.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.cell_to_world = InvertAffine(frame->af.world_to_cell);
} }
// World <-> tile // World <-> tile
// TODO: This never changes, should be #defined (so shaders don't need to read it every frame) // TODO: This never changes, should be #defined (so shaders don't need to read it every frame)
frame->xf.world_to_tile = XformIdentity; frame->af.world_to_tile = AffineIdentity;
frame->xf.tile_to_world = XformIdentity; frame->af.tile_to_world = AffineIdentity;
{ {
frame->xf.world_to_tile = ScaleXform(frame->xf.world_to_tile, VEC2(P_TilesPerMeter, P_TilesPerMeter)); frame->af.world_to_tile = ScaleAffine(frame->af.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->af.world_to_tile = TranslateAffine(frame->af.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.tile_to_world = InvertAffine(frame->af.world_to_tile);
} }
////////////////////////////// //////////////////////////////
//- Update cursors / selection //- Update cursors / selection
frame->screen_cursor = ui_frame->cursor_pos; frame->screen_cursor = ui_frame->cursor_pos;
frame->shade_cursor = MulXformV2(frame->xf.screen_to_shade, frame->screen_cursor); frame->shade_cursor = MulAffineV2(frame->af.screen_to_shade, frame->screen_cursor);
frame->world_cursor = MulXformV2(frame->xf.screen_to_world, frame->screen_cursor); frame->world_cursor = MulAffineV2(frame->af.screen_to_world, frame->screen_cursor);
b32 show_editor_ui = TweakBool("Show editor UI", 1); 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.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->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.p0 = MulAffineV2(frame->af.world_to_screen, frame->world_selection.p0);
frame->screen_selection.p1 = MulXformV2(frame->xf.world_to_screen, frame->world_selection.p1); 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.p0 = MulAffineV2(frame->af.world_to_shade, frame->world_selection.p0);
frame->shade_selection.p1 = MulXformV2(frame->xf.world_to_shade, frame->world_selection.p1); frame->shade_selection.p1 = MulAffineV2(frame->af.world_to_shade, frame->world_selection.p1);
////////////////////////////// //////////////////////////////
//- Place tiles //- Place tiles
@ -1001,8 +1001,8 @@ void V_TickForever(WaveLaneCtx *lane)
{ {
// TODO: Fix clamp when both start & end are outside of world // TODO: Fix clamp when both start & end are outside of world
Rng2I32 tile_range = Zi; Rng2I32 tile_range = Zi;
tile_range.p0 = Vec2I32FromVec(FloorVec2(MulXformV2(frame->xf.world_to_tile, prev_frame->world_selection.p0))); tile_range.p0 = Vec2I32FromVec(FloorVec2(MulAffineV2(frame->af.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.p1 = Vec2I32FromVec(CeilVec2(MulAffineV2(frame->af.world_to_tile, prev_frame->world_selection.p1)));
P_Msg *msg = P_PushMsg(P_MsgKind_TileEdit, Zstr); P_Msg *msg = P_PushMsg(P_MsgKind_TileEdit, Zstr);
msg->tile_kind = prev_frame->equipped_tile; msg->tile_kind = prev_frame->equipped_tile;
@ -1743,7 +1743,7 @@ void V_TickForever(WaveLaneCtx *lane)
// // else // // else
// // { // // {
// // // TODO: Unified blend logic between local world & correct world // // // 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_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); // // 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) if (body_slice.ready)
{ {
Xform body_to_world_xf = XformIdentity; Affine body_to_world_af = AffineIdentity;
{ {
// FIXME: Use origin ray // FIXME: Use origin ray
Vec2 world_dims = DivVec2(body_slice.dims, P_CellsPerMeter); Vec2 world_dims = DivVec2(body_slice.dims, P_CellsPerMeter);
body_to_world_xf.og = ent->xf.og; body_to_world_af.og = ent->af.og;
// body_to_world_xf.og = SubVec2(body_to_world_xf.og, MulVec2(world_dims, 0.25)); // body_to_world_af.og = SubVec2(body_to_world_af.og, MulVec2(world_dims, 0.25));
body_to_world_xf = XformWithWorldRotation(body_to_world_xf, AngleFromVec2(ent->control.look)); body_to_world_af = AffineWithWorldRotation(body_to_world_af, AngleFromVec2(ent->control.look));
body_to_world_xf = TranslateXform(body_to_world_xf, MulVec2(world_dims, -0.5)); body_to_world_af = TranslateAffine(body_to_world_af, MulVec2(world_dims, -0.5));
body_to_world_xf = ScaleXform(body_to_world_xf, world_dims); body_to_world_af = ScaleAffine(body_to_world_af, world_dims);
} }
// Push body quad // Push body quad
{ {
V_Quad *quad = PushStruct(frame->quads_arena, V_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->tex = body_slice.tex;
quad->uv_rect = body_slice.uv_rect; 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); // 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 // // Push weapon quad
// { // {
// V_Quad *quad = PushStruct(frame->quads_arena, V_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; // quad->slice = wep_sframe.slice;
// } // }
} }
@ -1904,8 +1904,8 @@ void V_TickForever(WaveLaneCtx *lane)
{ {
skip = 1; skip = 1;
} }
// V_DrawPoint(MulXformV2(frame->xf.world_to_screen, start), Color_Red); // V_DrawPoint(MulAffineV2(frame->af.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, end), Color_Purple);
end = hit_pos; end = hit_pos;
} }
@ -2147,8 +2147,8 @@ void V_TickForever(WaveLaneCtx *lane)
// { // {
// if (firer->fire_held) // if (firer->fire_held)
// { // {
// Xform firer_xf = firer->xf; // Affine firer_af = firer->af;
// P_Shape firer_world_shape = P_MulXformShape(firer_xf, firer->local_shape); // P_Shape firer_world_shape = P_MulAffineShape(firer_af, firer->local_shape);
// Vec2 ray_start = firer_world_shape.centroid; // Vec2 ray_start = firer_world_shape.centroid;
// Vec2 ray_dir = firer->look; // Vec2 ray_dir = firer->look;
@ -2162,8 +2162,8 @@ void V_TickForever(WaveLaneCtx *lane)
// { // {
// if (victim != firer) // if (victim != firer)
// { // {
// Xform victim_xf = victim->xf; // Affine victim_af = victim->af;
// P_Shape victim_world_shape = P_MulXformShape(victim_xf, victim->local_shape); // P_Shape victim_world_shape = P_MulAffineShape(victim_af, victim->local_shape);
// P_RaycastResult raycast = P_RaycastShape(victim_world_shape, ray_start, ray_dir); // P_RaycastResult raycast = P_RaycastShape(victim_world_shape, ray_start, ray_dir);
// if (raycast.is_intersecting) // if (raycast.is_intersecting)
@ -2295,28 +2295,28 @@ void V_TickForever(WaveLaneCtx *lane)
{ {
case P_DebugDrawKind_Point: 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); V_DrawPoint(ui_p, color);
} break; } break;
case P_DebugDrawKind_Line: case P_DebugDrawKind_Line:
{ {
Vec2 ui_p0 = MulXformV2(frame->xf.world_to_screen, n->line.p0); Vec2 ui_p0 = MulAffineV2(frame->af.world_to_screen, n->line.p0);
Vec2 ui_p1 = MulXformV2(frame->xf.world_to_screen, n->line.p1); Vec2 ui_p1 = MulAffineV2(frame->af.world_to_screen, n->line.p1);
V_DrawLine(ui_p0, ui_p1, color); V_DrawLine(ui_p0, ui_p1, color);
} break; } break;
case P_DebugDrawKind_Rect: case P_DebugDrawKind_Rect:
{ {
Rng2 ui_rect = Zi; Rng2 ui_rect = Zi;
ui_rect.p0 = MulXformV2(frame->xf.world_to_screen, n->rect.p0); ui_rect.p0 = MulAffineV2(frame->af.world_to_screen, n->rect.p0);
ui_rect.p1 = MulXformV2(frame->xf.world_to_screen, n->rect.p1); ui_rect.p1 = MulAffineV2(frame->af.world_to_screen, n->rect.p1);
V_DrawRect(ui_rect, color, V_DrawFlag_Line); V_DrawRect(ui_rect, color, V_DrawFlag_Line);
} break; } break;
case P_DebugDrawKind_Shape: 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); V_DrawShape(ui_shape, color, detail, V_DrawFlag_Line);
} break; } break;
} }
@ -3663,8 +3663,8 @@ void V_TickForever(WaveLaneCtx *lane)
} }
UI_BuildSpacer(UI_PIX(padding, 1), Axis_Y); UI_BuildSpacer(UI_PIX(padding, 1), Axis_Y);
{ {
Vec2 tile_pos = MulXformV2(frame->xf.world_to_tile, frame->world_cursor); Vec2 tile_pos = MulAffineV2(frame->af.world_to_tile, frame->world_cursor);
Vec2 cell_pos = MulXformV2(frame->xf.world_to_cell, frame->world_cursor); Vec2 cell_pos = MulAffineV2(frame->af.world_to_cell, frame->world_cursor);
i32 tile_idx = P_TileIdxFromTilePos(tile_pos); i32 tile_idx = P_TileIdxFromTilePos(tile_pos);
UI_BuildLabelF("Camera pos: %F", FmtFloat2(frame->camera_pos)); UI_BuildLabelF("Camera pos: %F", FmtFloat2(frame->camera_pos));
UI_BuildLabelF("Cursor world pos: %F", FmtFloat2(frame->world_cursor)); UI_BuildLabelF("Cursor world pos: %F", FmtFloat2(frame->world_cursor));
@ -4067,7 +4067,7 @@ void V_TickForever(WaveLaneCtx *lane)
// P_Ent *ent = &cmd->ent; // P_Ent *ent = &cmd->ent;
// *ent = P_NilEnt; // *ent = P_NilEnt;
// ent->key = V.guy_key; // ent->key = V.guy_key;
// ent->xf = XformFromPos(guy_pos); // ent->af = AffineFromPos(guy_pos);
// ent->is_guy = 1; // ent->is_guy = 1;
// ent->has_weapon = 1; // ent->has_weapon = 1;
// ent->exists = 1; // ent->exists = 1;
@ -4208,7 +4208,7 @@ void V_TickForever(WaveLaneCtx *lane)
params.dt = frame->dt; params.dt = frame->dt;
params.tick = frame->tick; params.tick = frame->tick;
params.seed = RandU64FromState(&frame->rand); params.seed = RandU64FromState(&frame->rand);
params.xf = frame->xf; params.af = frame->af;
params.selection_mode = frame->selection_mode; params.selection_mode = frame->selection_mode;
params.equipped_tile = frame->equipped_tile; params.equipped_tile = frame->equipped_tile;

View File

@ -270,8 +270,8 @@ Struct(V_Frame)
Vec2 camera_pos; Vec2 camera_pos;
f32 camera_zoom; f32 camera_zoom;
// Xforms; // Affines;
V_Xforms xf; V_Affines af;
// Cursors // Cursors
Vec2 screen_cursor; Vec2 screen_cursor;

View File

@ -89,7 +89,7 @@ VertexShader(V_QuadVS, V_QuadPSInput)
V_Quad quad = quads[SV_InstanceID]; V_Quad quad = quads[SV_InstanceID];
Vec2 rect_uv = RectUvFromIdx(SV_VertexID); 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 tex_uv = lerp(quad.uv_rect.p0, quad.uv_rect.p1, rect_uv);
// Vec2 shade_pos = lerp(quad.p0, quad.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); // Vec2 screen_pos = SV_DispatchThreadID + Vec2(0.5, 0.5);
// Vec4 result = Vec4(0.025, 0.025, 0.025, 1); // Vec4 result = Vec4(0.025, 0.025, 0.025, 1);
// Vec2 world_pos = mul(params.xf.screen_to_world, Vec3(screen_pos, 1)); // Vec2 world_pos = mul(params.af.screen_to_world, Vec3(screen_pos, 1));
// 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)));
// Vec2 tile_pos = mul(params.xf.world_to_tile, 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)); // P_TileKind tile = tiles.Load(Vec3(tile_pos, 0));
// f32 half_thickness = 1; // f32 half_thickness = 1;
// f32 half_world_bounds_size = P_WorldPitch * 0.5; // 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_p0 = mul(params.af.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_p1 = mul(params.af.world_to_screen, Vec3(half_world_bounds_size, half_world_bounds_size, 1));
// b32 is_in_world_bounds = // b32 is_in_world_bounds =
// screen_pos.x > (world_bounds_screen_p0.x - half_thickness) && // screen_pos.x > (world_bounds_screen_p0.x - half_thickness) &&
// screen_pos.y > (world_bounds_screen_p0.y - 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 // // // Cells test
// // { // // {
// // RWTexture2D<Vec4> cells = G_Dereference<Vec4>(params.cells); // // RWTexture2D<Vec4> cells = G_Dereference<Vec4>(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); // // Vec4 cell = cells.Load(cell_pos);
// // if (cell.a != 0) // // if (cell.a != 0)
// // { // // {
@ -313,7 +313,7 @@ PixelShader(V_QuadPS, V_QuadPSOutput, V_QuadPSInput input)
// // Stains test // // Stains test
// // { // // {
// // RWTexture2D<V_ParticleKind> stains = G_Dereference<V_ParticleKind>(params.stains); // // RWTexture2D<V_ParticleKind> stains = G_Dereference<V_ParticleKind>(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); // // V_ParticleKind stain = stains.Load(cell_pos);
// // if (stain == V_ParticleKind_Test) // // if (stain == V_ParticleKind_Test)
@ -419,7 +419,7 @@ ComputeShader(V_SimParticlesCS, 64)
particle.emitter_init_num = 0; 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; 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 // Simulate
@ -496,9 +496,9 @@ ComputeShader2D(V_ShadeCS, 8, 8)
SamplerState wrap_sampler = G_Dereference(params.pt_wrap_sampler); SamplerState wrap_sampler = G_Dereference(params.pt_wrap_sampler);
Vec2 shade_pos = SV_DispatchThreadID + Vec2(0.5, 0.5); Vec2 shade_pos = SV_DispatchThreadID + Vec2(0.5, 0.5);
Vec2 world_pos = mul(params.xf.shade_to_world, Vec3(shade_pos, 1)); Vec2 world_pos = mul(params.af.shade_to_world, Vec3(shade_pos, 1));
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)));
Vec2 tile_pos = mul(params.xf.world_to_tile, 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)); 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 screen_pos = input.sv_position.xy;
Vec2 world_pos = mul(params.xf.screen_to_world, Vec3(screen_pos, 1)); Vec2 world_pos = mul(params.af.screen_to_world, Vec3(screen_pos, 1));
Vec2 tile_pos = mul(params.xf.world_to_tile, Vec3(world_pos, 1)); Vec2 tile_pos = mul(params.af.world_to_tile, Vec3(world_pos, 1));
P_TileKind equipped_tile = params.equipped_tile; P_TileKind equipped_tile = params.equipped_tile;
f32 half_thickness = 1; f32 half_thickness = 1;
Vec2 half_world_dims = Vec2(P_WorldPitch, P_WorldPitch) * 0.5; 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_p0 = mul(params.af.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_p1 = mul(params.af.world_to_screen, Vec3(half_world_dims.xy, 1));
b32 is_in_world_bounds = ( b32 is_in_world_bounds = (
screen_pos.x > (world_bounds_screen_p0.x - half_thickness) && screen_pos.x > (world_bounds_screen_p0.x - half_thickness) &&
screen_pos.y > (world_bounds_screen_p0.y - 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) 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 //- Shaded color
Vec4 shade_color = 0; Vec4 shade_color = 0;
@ -677,8 +677,8 @@ PixelShader(V_CompositePS, V_CompositePSOutput, V_CompositePSInput input)
Rng2 world_selection = params.world_selection; Rng2 world_selection = params.world_selection;
Rng2 tile_selection; Rng2 tile_selection;
tile_selection.p0 = floor(mul(params.xf.world_to_tile, Vec3(world_selection.p0, 1))); tile_selection.p0 = floor(mul(params.af.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.p1 = ceil(mul(params.af.world_to_tile, Vec3(world_selection.p1, 1)));
f32 dist = 100000000; f32 dist = 100000000;
dist = min(dist, screen_pos.x - screen_selection.p0.x); 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) if (V_ShaderConst_GpuFlags & V_GpuFlag_DebugDraw)
{ {
const Vec4 grid_color = LinearFromSrgb(Vec4(1, 1, 1, 0.1)); 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_p0 = mul(params.af.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_p1 = mul(params.af.world_to_screen, Vec3(ceil(world_pos), 1));
f32 grid_dist = 100000; 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_p0.x));
grid_dist = min(grid_dist, abs(screen_pos.x - grid_screen_p1.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 x_axis_color = LinearFromSrgb(Vec4(0.75, 0, 0, 1));
const Vec4 y_axis_color = LinearFromSrgb(Vec4(0, 0.75, 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 x_dist = abs(screen_pos.x - zero_screen.x);
f32 y_dist = abs(screen_pos.y - zero_screen.y); f32 y_dist = abs(screen_pos.y - zero_screen.y);
if (y_dist <= half_thickness) if (y_dist <= half_thickness)

View File

@ -23,27 +23,27 @@ Enum(V_SelectionMode)
V_SelectionMode_Tile, V_SelectionMode_Tile,
}; };
Struct(V_Xforms) Struct(V_Affines)
{ {
// World <-> screen // World <-> screen
Xform world_to_screen; Affine world_to_screen;
Xform screen_to_world; Affine screen_to_world;
// World <-> shade // World <-> shade
Xform world_to_shade; Affine world_to_shade;
Xform shade_to_world; Affine shade_to_world;
// Shade <-> screen // Shade <-> screen
Xform shade_to_screen; Affine shade_to_screen;
Xform screen_to_shade; Affine screen_to_shade;
// World <-> cell // World <-> cell
Xform world_to_cell; Affine world_to_cell;
Xform cell_to_world; Affine cell_to_world;
// World <-> tile // World <-> tile
Xform world_to_tile; Affine world_to_tile;
Xform tile_to_world; Affine tile_to_world;
}; };
Struct(V_TileDesc) Struct(V_TileDesc)
@ -63,7 +63,7 @@ Struct(V_GpuParams)
f32 dt; f32 dt;
u64 tick; u64 tick;
u64 seed; u64 seed;
V_Xforms xf; V_Affines af;
V_SelectionMode selection_mode; V_SelectionMode selection_mode;
P_TileKind equipped_tile; P_TileKind equipped_tile;
@ -182,7 +182,7 @@ Enum(V_QuadFlag)
Struct(V_Quad) Struct(V_Quad)
{ {
V_QuadFlag flags; V_QuadFlag flags;
Xform to_shade_xf; Affine to_shade_af;
G_Texture2DRef tex; G_Texture2DRef tex;
Rng2 uv_rect; Rng2 uv_rect;
}; };