base_math refactor
This commit is contained in:
parent
b61cf28266
commit
6776a15141
@ -48,9 +48,9 @@ internal P_WindowSettings default_window_settings(P_Window *window)
|
||||
Vec2 monitor_size = P_GetWindowMonitorSize(window);
|
||||
|
||||
i32 width = 1280;
|
||||
i32 height = math_round_to_int(width / (f32)(DEFAULT_CAMERA_WIDTH / DEFAULT_CAMERA_HEIGHT));
|
||||
i32 x = math_round_to_int(monitor_size.x / 2.f - width / 2);
|
||||
i32 y = math_round_to_int(monitor_size.y / 2.f - height / 2);
|
||||
i32 height = RoundF32ToI32(width / (f32)(DEFAULT_CAMERA_WIDTH / DEFAULT_CAMERA_HEIGHT));
|
||||
i32 x = RoundF32ToI32(monitor_size.x / 2.f - width / 2);
|
||||
i32 y = RoundF32ToI32(monitor_size.y / 2.f - height / 2);
|
||||
|
||||
return (P_WindowSettings) {
|
||||
.title = WINDOW_TITLE,
|
||||
|
||||
@ -960,8 +960,8 @@ Ase_DecodedSheet ase_decode_sheet(Arena *arena, String encoded)
|
||||
/* Assert all data was read */
|
||||
Assert(BB_NumBytesRemaining(&br) == 0);
|
||||
|
||||
res.image_size = V2(image_width, image_height);
|
||||
res.frame_size = V2(frame_width, frame_height);
|
||||
res.image_size = VEC2(image_width, image_height);
|
||||
res.frame_size = VEC2(frame_width, frame_height);
|
||||
res.num_frames = num_frames;
|
||||
res.num_spans = num_spans;
|
||||
res.num_slice_keys = num_slice_keys;
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@ -162,180 +162,176 @@ f64 ClampF64(f64 v, f64 min, f64 max);
|
||||
//~ Rounding ops
|
||||
|
||||
//- Round
|
||||
f32 math_round(f32 f);
|
||||
f64 math_round64(f64 f);
|
||||
i32 math_round_to_int(f32 f);
|
||||
i64 math_round_to_int64(f64 f);
|
||||
f32 RoundF32(f32 f);
|
||||
f64 RoundF64(f64 f);
|
||||
i32 RoundF32ToI32(f32 f);
|
||||
i64 RoundF64ToI64(f64 f);
|
||||
|
||||
//- Floor
|
||||
f32 math_floor(f32 f);
|
||||
f64 math_floor64(f64 f);
|
||||
i32 math_floor_to_int(f32 f);
|
||||
i64 math_floor_to_int64(f64 f);
|
||||
f32 FloorF32(f32 f);
|
||||
f64 FloorF64(f64 f);
|
||||
i32 FloorF32ToI32(f32 f);
|
||||
i64 FloorF64ToI64(f64 f);
|
||||
|
||||
//- Ceil
|
||||
f32 math_ceil(f32 f);
|
||||
f64 math_ceil64(f64 f);
|
||||
i32 math_ceil_to_int(f32 f);
|
||||
i64 math_ceil_to_int64(f64 f);
|
||||
f32 CeilF32(f32 f);
|
||||
f64 CeilF64(f64 f);
|
||||
i32 CeilF32ToI32(f32 f);
|
||||
i64 CeilF64ToI64(f64 f);
|
||||
|
||||
//- Trunc
|
||||
f32 math_trunc(f32 f);
|
||||
f64 math_trunc64(f64 f);
|
||||
f32 TruncF32(f32 f);
|
||||
f64 TruncF64(f64 f);
|
||||
|
||||
////////////////////////////////
|
||||
//~ Fmod
|
||||
|
||||
f32 math_fmod(f32 x, f32 m);
|
||||
f64 math_fmod64(f64 x, f64 m);
|
||||
f32 ModF32(f32 x, f32 m);
|
||||
f64 ModF64(f64 x, f64 m);
|
||||
|
||||
////////////////////////////////
|
||||
//~ Floating point sign
|
||||
//~ Abs
|
||||
|
||||
f32 math_fabs(f32 f);
|
||||
f64 math_fabs64(f64 f);
|
||||
i32 math_fsign(f32 f);
|
||||
i64 math_fsign64(f64 f);
|
||||
|
||||
////////////////////////////////
|
||||
//~ Integer sign
|
||||
|
||||
u32 math_abs_i32(i32 v);
|
||||
u64 math_abs_i64(i64 v);
|
||||
f32 AbsF32(f32 f);
|
||||
f64 AbsF64(f64 f);
|
||||
u32 AbsI32(i32 v);
|
||||
u64 AbsI64(i64 v);
|
||||
i32 SignF32(f32 f);
|
||||
i64 SignF64(f64 f);
|
||||
|
||||
////////////////////////////////
|
||||
//~ Exponential ops
|
||||
|
||||
u64 math_pow_u64(u64 base, u8 exp);
|
||||
f32 math_ln(f32 x);
|
||||
f32 math_exp(f32 x);
|
||||
f32 math_pow(f32 a, f32 b);
|
||||
f32 math_sqrt(f32 x);
|
||||
f64 math_sqrt64(f64 x);
|
||||
f32 math_rsqrt(f32 x);
|
||||
u64 PowU64(u64 base, u8 exp);
|
||||
f32 LnF32(f32 x);
|
||||
f32 ExpF32(f32 x);
|
||||
f32 PowF32(f32 a, f32 b);
|
||||
f32 SqrtF32(f32 x);
|
||||
f64 SqrtF64(f64 x);
|
||||
f32 RSqrtF32(f32 x);
|
||||
|
||||
////////////////////////////////
|
||||
//~ Trig
|
||||
|
||||
f32 math_reduce_positive_to_pio4(f32 x, i32 *octant_out);
|
||||
f32 math_sin_approx(f32 x);
|
||||
f32 math_cos_approx(f32 x);
|
||||
f32 math_sin(f32 x);
|
||||
f32 math_cos(f32 x);
|
||||
f32 math_atan(f32 x);
|
||||
f32 math_atan2(f32 y, f32 x);
|
||||
f32 math_asin(f32 x);
|
||||
f32 math_acos(f32 x);
|
||||
f32 ReduceToPio4(f32 x, i32 *octant_out);
|
||||
f32 SinApproxF32(f32 x);
|
||||
f32 CosApproxF32(f32 x);
|
||||
f32 SinF32(f32 x);
|
||||
f32 CosF32(f32 x);
|
||||
f32 ArcTanF32(f32 x);
|
||||
f32 ArcTan2F32(f32 y, f32 x);
|
||||
f32 ArcSinF32(f32 x);
|
||||
f32 ArcCosF32(f32 x);
|
||||
|
||||
////////////////////////////////
|
||||
//~ Angle unwind
|
||||
|
||||
/* Returns angle in range [-Pi, Pi] */
|
||||
f32 math_unwind_angle(f32 a);
|
||||
f32 UnwindAngleF32(f32 a);
|
||||
|
||||
////////////////////////////////
|
||||
//~ Float lerp
|
||||
|
||||
f32 math_lerp_f32(f32 val0, f32 val1, f32 t);
|
||||
f64 math_lerp_f64(f64 val0, f64 val1, f64 t);
|
||||
f32 math_lerp_angle(f32 a, f32 b, f32 t);
|
||||
f32 LerpF32(f32 val0, f32 val1, f32 t);
|
||||
f64 LerpF64(f64 val0, f64 val1, f64 t);
|
||||
f32 LerpAngleF32(f32 a, f32 b, f32 t);
|
||||
|
||||
////////////////////////////////
|
||||
//~ Int lerp
|
||||
|
||||
i32 math_lerp_i32(i32 val0, i32 val1, f32 t);
|
||||
i64 math_lerp_i64(i64 val0, i64 val1, f64 t);
|
||||
i32 LerpI32(i32 val0, i32 val1, f32 t);
|
||||
i64 LerpI64(i64 val0, i64 val1, f64 t);
|
||||
|
||||
////////////////////////////////
|
||||
//~ Vec2 operations
|
||||
|
||||
#define V2(x, y) CppCompatInitListType(Vec2) { (x), (y) }
|
||||
#define V2FromV2I32(v) V2((v).x, (v).y)
|
||||
#define VEC2(x, y) CppCompatInitListType(Vec2) { (x), (y) }
|
||||
#define Vec2FromVec2I32(v) VEC2((v).x, (v).y)
|
||||
|
||||
b32 v2_is_zero(Vec2 a);
|
||||
b32 v2_eq(Vec2 a, Vec2 b);
|
||||
b32 IsVec2Zero(Vec2 a);
|
||||
b32 EqVec2(Vec2 a, Vec2 b);
|
||||
|
||||
//- Mul
|
||||
Vec2 v2_mul(Vec2 a, f32 s);
|
||||
Vec2 v2_mul_v2(Vec2 a, Vec2 b);
|
||||
Vec2 v2_neg(Vec2 a);
|
||||
Vec2 MulVec2(Vec2 a, f32 s);
|
||||
Vec2 MulVec2Vec2(Vec2 a, Vec2 b);
|
||||
Vec2 NegVec2(Vec2 a);
|
||||
|
||||
//- Div
|
||||
Vec2 v2_div(Vec2 a, f32 s);
|
||||
Vec2 v2_div_v2(Vec2 a, Vec2 b);
|
||||
Vec2 DivVec2(Vec2 a, f32 s);
|
||||
Vec2 DivVec2Vec2(Vec2 a, Vec2 b);
|
||||
|
||||
//- Add
|
||||
Vec2 v2_add(Vec2 a, Vec2 b);
|
||||
Vec2 v2_sub(Vec2 a, Vec2 b);
|
||||
Vec2 AddVec2(Vec2 a, Vec2 b);
|
||||
Vec2 SubVec2(Vec2 a, Vec2 b);
|
||||
|
||||
//- Len
|
||||
f32 v2_len(Vec2 a);
|
||||
f32 v2_len_sq(Vec2 a);
|
||||
Vec2 v2_with_len(Vec2 a, f32 len);
|
||||
Vec2 v2_clamp_len(Vec2 a, f32 max);
|
||||
f32 v2_distance(Vec2 a, Vec2 b);
|
||||
Vec2 v2_norm(Vec2 a);
|
||||
f32 Vec2Len(Vec2 a);
|
||||
f32 Vec2LenSq(Vec2 a);
|
||||
Vec2 Vec2WithLen(Vec2 a, f32 len);
|
||||
Vec2 ClampVec2Len(Vec2 a, f32 max);
|
||||
f32 Vec2Distance(Vec2 a, Vec2 b);
|
||||
Vec2 NormVec2(Vec2 a);
|
||||
|
||||
//- Dot
|
||||
f32 v2_dot(Vec2 a, Vec2 b);
|
||||
f32 v2_wedge(Vec2 a, Vec2 b);
|
||||
Vec2 v2_perp(Vec2 a);
|
||||
Vec2 v2_perp_mul(Vec2 a, f32 s);
|
||||
Vec2 v2_perp_towards_dir(Vec2 v, Vec2 dir);
|
||||
f32 DotVec2(Vec2 a, Vec2 b);
|
||||
f32 WedgeVec2(Vec2 a, Vec2 b);
|
||||
Vec2 PerpVec2(Vec2 a);
|
||||
Vec2 MulPerpVec2(Vec2 a, f32 s);
|
||||
Vec2 PerpVec2TowardsDir(Vec2 v, Vec2 dir);
|
||||
|
||||
//- Round / floor / ceil
|
||||
Vec2 v2_round(Vec2 a);
|
||||
Vec2I32 v2_round_to_int(Vec2 a);
|
||||
Vec2 v2_floor(Vec2 a);
|
||||
Vec2 v2_ceil(Vec2 a);
|
||||
Vec2 RoundVec2(Vec2 a);
|
||||
Vec2I32 RoundVec2ToVec2I32(Vec2 a);
|
||||
Vec2 FloorVec2(Vec2 a);
|
||||
Vec2 CeilVec2(Vec2 a);
|
||||
|
||||
//- Angle
|
||||
i32 v2_winding(Vec2 a, Vec2 b);
|
||||
Vec2 v2_rotated(Vec2 v, f32 a);
|
||||
Vec2 v2_from_angle(f32 a);
|
||||
f32 v2_angle(Vec2 v);
|
||||
f32 v2_angle_from_dirs(Vec2 dir1, Vec2 dir2);
|
||||
f32 v2_angle_from_points(Vec2 pt1, Vec2 pt2);
|
||||
i32 WindingFromVec2(Vec2 a, Vec2 b);
|
||||
Vec2 RotateVec2(Vec2 v, f32 a);
|
||||
Vec2 Vec2FromAngle(f32 a);
|
||||
f32 AngleFromVec2(Vec2 v);
|
||||
f32 AngleFromVec2Dirs(Vec2 dir1, Vec2 dir2);
|
||||
f32 AngleFromVec2Points(Vec2 pt1, Vec2 pt2);
|
||||
|
||||
//- Closest point
|
||||
Vec2 v2_closest_point_ray(Vec2 ray_pos, Vec2 ray_dir_norm, Vec2 p);
|
||||
Vec2 ClosestPointFromRay(Vec2 ray_pos, Vec2 ray_dir_norm, Vec2 p);
|
||||
|
||||
//- Lerp
|
||||
Vec2 v2_lerp(Vec2 val0, Vec2 val1, f32 t);
|
||||
Vec2 v2_slerp(Vec2 val0, Vec2 val1, f32 t);
|
||||
Vec2 LerpVec2(Vec2 val0, Vec2 val1, f32 t);
|
||||
Vec2 SlerpVec2(Vec2 val0, Vec2 val1, f32 t);
|
||||
|
||||
////////////////////////////////
|
||||
//~ Vec3 operations
|
||||
|
||||
#define V3(x, y, z) ((Vec3) { (x), (y), (z) })
|
||||
#define VEC3(x, y, z) ((Vec3) { (x), (y), (z) })
|
||||
|
||||
////////////////////////////////
|
||||
//~ Vec4 operations
|
||||
|
||||
#define V4(x, y, z, w) ((Vec4) { (x), (y), (z), (w) })
|
||||
#define VEC4(x, y, z, w) ((Vec4) { (x), (y), (z), (w) })
|
||||
|
||||
////////////////////////////////
|
||||
//~ Vec2I32 Operations
|
||||
|
||||
#define V2I32(x, y) CppCompatInitListType(Vec2I32) { (x), (y) }
|
||||
b32 v2i32_eq(Vec2I32 a, Vec2I32 b);
|
||||
Vec2I32 v2i32_neg(Vec2I32 a);
|
||||
Vec2I32 v2i32_add(Vec2I32 a, Vec2I32 b);
|
||||
Vec2I32 v2i32_sub(Vec2I32 a, Vec2I32 b);
|
||||
#define VEC2I32(x, y) CppCompatInitListType(Vec2I32) { (x), (y) }
|
||||
b32 EqVec2I32(Vec2I32 a, Vec2I32 b);
|
||||
Vec2I32 NegVec2I32(Vec2I32 a);
|
||||
Vec2I32 AddVec2I32(Vec2I32 a, Vec2I32 b);
|
||||
Vec2I32 SubVec2I32(Vec2I32 a, Vec2I32 b);
|
||||
|
||||
////////////////////////////////
|
||||
//~ Vec3I32 operations
|
||||
|
||||
#define V3I32(x, y, z) CppCompatInitListType(Vec3I32) { (x), (y), (z) }
|
||||
#define VEC3I32(x, y, z) CppCompatInitListType(Vec3I32) { (x), (y), (z) }
|
||||
|
||||
////////////////////////////////
|
||||
//~ Xform operations
|
||||
|
||||
b32 XformEq(Xform xf1, Xform xf2);
|
||||
b32 EqXform(Xform xf1, Xform xf2);
|
||||
|
||||
//- Initialization
|
||||
#define XformIdentity CppCompatInitListType(Xform) { .bx = V2(1, 0), .by = V2(0, 1) }
|
||||
#define XformIdentityNoCast { .bx = V2(1, 0), .by = V2(0, 1) }
|
||||
#define XformIdentity CppCompatInitListType(Xform) { .bx = VEC2(1, 0), .by = VEC2(0, 1) }
|
||||
#define XformIdentityNoCast { .bx = VEC2(1, 0), .by = VEC2(0, 1) }
|
||||
Xform XformFromPos(Vec2 v);
|
||||
Xform XformFromRot(f32 r);
|
||||
Xform XformFromScale(Vec2 scale);
|
||||
@ -371,52 +367,47 @@ Vec2 InvertXformMulV2(Xform xf, Vec2 v);
|
||||
Vec2 InvertXformBasisMulV2(Xform xf, Vec2 v);
|
||||
|
||||
//- Helpers
|
||||
Xform GetXformBasis(Xform xf);
|
||||
f32 GetXformDeterminant(Xform xf);
|
||||
Vec2 GetXformRight(Xform xf);
|
||||
Vec2 GetXformLeft(Xform xf);
|
||||
Vec2 GetXformUp(Xform xf);
|
||||
Vec2 GetXformDown(Xform xf);
|
||||
f32 GetXformRotation(Xform xf);
|
||||
Vec2 GetXformScale(Xform xf);
|
||||
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);
|
||||
|
||||
//- Trs
|
||||
#define TRS(...) ((Trs) { .t = V2(0,0), .s = V2(1, 1), .r = 0, __VA_ARGS__ })
|
||||
#define TRS(...) ((Trs) { .t = VEC2(0,0), .s = VEC2(1, 1), .r = 0, __VA_ARGS__ })
|
||||
|
||||
////////////////////////////////
|
||||
//~ Rect operations
|
||||
|
||||
#define RectFromScalar(_x, _y, _width, _height) (Rect) { .x = (_x), .y = (_y), .width = (_width), .height = (_height) }
|
||||
#define RectFromV2(_pos, _size) (Rect) { .pos = (_pos), .size = (_size) }
|
||||
#define ClipAll ((ClipRect) { { 0.0f, 0.0f }, { 1.0f, 1.0f } })
|
||||
#define RectFromVec2(_pos, _size) (Rect) { .pos = (_pos), .size = (_size) }
|
||||
#define AllClipped ((ClipRect) { { 0.0f, 0.0f }, { 1.0f, 1.0f } })
|
||||
|
||||
////////////////////////////////
|
||||
//~ Quad operations
|
||||
|
||||
#define QuadUnitSquare (Quad) { .p0 = V2(0, 0), .p1 = V2(0, 1), .p2 = V2(1, 1), .p3 = V2(1, 0) }
|
||||
#define QuadUnitSquareCentered (Quad) { .p0 = V2(-0.5f, -0.5f), .p1 = V2(0.5f, -0.5f), .p2 = V2(0.5f, 0.5f), .p3 = V2(-0.5f, 0.5f) }
|
||||
#define UnitSquareQuad (Quad) { .p0 = VEC2(0, 0), .p1 = VEC2(0, 1), .p2 = VEC2(1, 1), .p3 = VEC2(1, 0) }
|
||||
#define CenteredUnitSquareQuad (Quad) { .p0 = VEC2(-0.5f, -0.5f), .p1 = VEC2(0.5f, -0.5f), .p2 = VEC2(0.5f, 0.5f), .p3 = VEC2(-0.5f, 0.5f) }
|
||||
|
||||
Quad quad_from_rect(Rect rect);
|
||||
Quad quad_from_aabb(Aabb aabb);
|
||||
Quad quad_from_line(Vec2 start, Vec2 end, f32 thickness);
|
||||
Quad quad_from_ray(Vec2 pos, Vec2 rel, f32 thickness);
|
||||
Quad quad_scale(Quad q, f32 s);
|
||||
Quad quad_round(Quad quad);
|
||||
Quad quad_floor(Quad quad);
|
||||
|
||||
////////////////////////////////
|
||||
//~ Polygon operations
|
||||
|
||||
Vec2 math_poly_center(V2Array a);
|
||||
Quad QuadFromRect(Rect rect);
|
||||
Quad QuadFromAabb(Aabb aabb);
|
||||
Quad QuadFromLine(Vec2 start, Vec2 end, f32 thickness);
|
||||
Quad QuadFromRay(Vec2 pos, Vec2 rel, f32 thickness);
|
||||
Quad ScaleQuad(Quad q, f32 s);
|
||||
Quad RoundQuad(Quad quad);
|
||||
Quad FloorQuad(Quad quad);
|
||||
|
||||
////////////////////////////////
|
||||
//~ Spring operations
|
||||
|
||||
SoftSpring math_spring_init(f32 hertz, f32 damping_ratio, f32 dt);
|
||||
SoftSpring MakeSpring(f32 hertz, f32 damping_ratio, f32 dt);
|
||||
|
||||
////////////////////////////////
|
||||
//~ Mat4x4 operations
|
||||
|
||||
Mat4x4 mat4x4_from_xform(Xform xf);
|
||||
Mat4x4 mat4x4_from_ortho(f32 left, f32 right, f32 bottom, f32 top, f32 near_z, f32 far_z);
|
||||
Mat4x4 mat4x4_mul(Mat4x4 m1, Mat4x4 m2);
|
||||
Mat4x4 Mat4x4FromXform(Xform xf);
|
||||
Mat4x4 Mat4x4FromOrtho(f32 left, f32 right, f32 bottom, f32 top, f32 near_z, f32 far_z);
|
||||
Mat4x4 MulMat4x4(Mat4x4 m1, Mat4x4 m2);
|
||||
|
||||
@ -109,9 +109,9 @@ String string_from_float(Arena *arena, f64 f, u32 precision)
|
||||
}
|
||||
|
||||
/* Add one half of next precision level to round up */
|
||||
f += 0.5 / (f64)math_pow_u64(10, (u8)precision);
|
||||
f += 0.5 / (f64)PowU64(10, (u8)precision);
|
||||
|
||||
f64 part_whole = math_trunc64(f);
|
||||
f64 part_whole = TruncF64(f);
|
||||
f64 part_decimal = f - part_whole;
|
||||
|
||||
/* Print whole part */
|
||||
@ -120,10 +120,10 @@ String string_from_float(Arena *arena, f64 f, u32 precision)
|
||||
u8 *backwards_text = PushDry(scratch.arena, u8);
|
||||
u64 backwards_text_len = 0;
|
||||
do {
|
||||
u64 digit = (u64)math_round_to_int64(math_fmod64(part_whole, 10.0));
|
||||
u64 digit = (u64)RoundF64ToI64(ModF64(part_whole, 10.0));
|
||||
string_from_char(scratch.arena, INT_CHARS[digit % 10]);
|
||||
++backwards_text_len;
|
||||
part_whole = math_trunc64(part_whole / 10.0);
|
||||
part_whole = TruncF64(part_whole / 10.0);
|
||||
} while (part_whole > 0);
|
||||
|
||||
/* Reverse text into final string */
|
||||
|
||||
@ -32,8 +32,8 @@ internal CLD_SupportPoint collider_get_support_point_internal(CLD_Shape *shape,
|
||||
u32 count = shape->count;
|
||||
f32 radius = shape->radius;
|
||||
|
||||
dir = v2_rotated(dir, -GetXformRotation(xf));
|
||||
dir = v2_mul_v2(dir, GetXformScale(xf));
|
||||
dir = RotateVec2(dir, -RotationFromXform(xf));
|
||||
dir = MulVec2Vec2(dir, ScaleFromXform(xf));
|
||||
|
||||
if (count == 1) {
|
||||
/* Skip 'ignore' on single point colliders */
|
||||
@ -48,7 +48,7 @@ internal CLD_SupportPoint collider_get_support_point_internal(CLD_Shape *shape,
|
||||
continue;
|
||||
}
|
||||
Vec2 p = points[i];
|
||||
f32 dot = v2_dot(dir, p);
|
||||
f32 dot = DotVec2(dir, p);
|
||||
if (dot > furthest_dot) {
|
||||
furthest = p;
|
||||
furthest_dot = dot;
|
||||
@ -57,8 +57,8 @@ internal CLD_SupportPoint collider_get_support_point_internal(CLD_Shape *shape,
|
||||
}
|
||||
|
||||
if (radius > 0.0) {
|
||||
dir = v2_with_len(dir, radius);
|
||||
furthest = v2_add(furthest, dir);
|
||||
dir = Vec2WithLen(dir, radius);
|
||||
furthest = AddVec2(furthest, dir);
|
||||
}
|
||||
|
||||
furthest = MulXformV2(xf, furthest);
|
||||
@ -90,8 +90,8 @@ internal CLD_MenkowskiPoint get_menkowski_point(CLD_Shape *shape0, CLD_Shape *sh
|
||||
{
|
||||
CLD_MenkowskiPoint res;
|
||||
res.s0 = collider_get_support_point(shape0, xf0, dir);
|
||||
res.s1 = collider_get_support_point(shape1, xf1, v2_neg(dir));
|
||||
res.p = v2_sub(res.s0.p, res.s1.p);
|
||||
res.s1 = collider_get_support_point(shape1, xf1, NegVec2(dir));
|
||||
res.p = SubVec2(res.s0.p, res.s1.p);
|
||||
return res;
|
||||
}
|
||||
|
||||
@ -102,10 +102,10 @@ internal CLD_MenkowskiPoint get_menkowski_point(CLD_Shape *shape0, CLD_Shape *sh
|
||||
Aabb collider_aabb_from_collider(CLD_Shape *shape, Xform xf)
|
||||
{
|
||||
Aabb res;
|
||||
res.p0.x = collider_get_support_point(shape, xf, V2(-1, 0)).p.x - COLLISION_TOLERANCE;
|
||||
res.p0.y = collider_get_support_point(shape, xf, V2(0, -1)).p.y - COLLISION_TOLERANCE;
|
||||
res.p1.x = collider_get_support_point(shape, xf, V2(1, 0)).p.x + COLLISION_TOLERANCE;
|
||||
res.p1.y = collider_get_support_point(shape, xf, V2(0, 1)).p.y + COLLISION_TOLERANCE;
|
||||
res.p0.x = collider_get_support_point(shape, xf, VEC2(-1, 0)).p.x - COLLISION_TOLERANCE;
|
||||
res.p0.y = collider_get_support_point(shape, xf, VEC2(0, -1)).p.y - COLLISION_TOLERANCE;
|
||||
res.p1.x = collider_get_support_point(shape, xf, VEC2(1, 0)).p.x + COLLISION_TOLERANCE;
|
||||
res.p1.y = collider_get_support_point(shape, xf, VEC2(0, 1)).p.y + COLLISION_TOLERANCE;
|
||||
return res;
|
||||
}
|
||||
|
||||
@ -167,8 +167,8 @@ internal struct gjk_result gjk_get_simplex(CLD_Shape *shape0, CLD_Shape *shape1,
|
||||
CLD_MenkowskiPoint m = ZI;
|
||||
|
||||
/* First point is support point in shape's general directions to eachother */
|
||||
dir = v2_sub(xf1.og, xf0.og);
|
||||
if (v2_is_zero(dir)) dir = V2(1, 0);
|
||||
dir = SubVec2(xf1.og, xf0.og);
|
||||
if (IsVec2Zero(dir)) dir = VEC2(1, 0);
|
||||
s.a = get_menkowski_point(shape0, shape1, xf0, xf1, dir);
|
||||
s.len = 1;
|
||||
|
||||
@ -178,12 +178,12 @@ internal struct gjk_result gjk_get_simplex(CLD_Shape *shape0, CLD_Shape *shape1,
|
||||
for (;;) {
|
||||
if (s.len == 1) {
|
||||
/* Second point is support point towards origin */
|
||||
dir = v2_neg(s.a.p);
|
||||
dir = NegVec2(s.a.p);
|
||||
|
||||
DBGSTEP;
|
||||
m = get_menkowski_point(shape0, shape1, xf0, xf1, dir);
|
||||
/* Check that new point is far enough away from existing point */
|
||||
if (v2_len_sq(v2_sub(m.p, s.a.p)) < min_unique_pt_dist_sq) {
|
||||
if (Vec2LenSq(SubVec2(m.p, s.a.p)) < min_unique_pt_dist_sq) {
|
||||
overlapping = 0;
|
||||
break;
|
||||
}
|
||||
@ -192,21 +192,21 @@ internal struct gjk_result gjk_get_simplex(CLD_Shape *shape0, CLD_Shape *shape1,
|
||||
s.len = 2;
|
||||
|
||||
/* Third point is support point in direction of line normal towards origin */
|
||||
dir = v2_perp_towards_dir(v2_sub(s.b.p, s.a.p), v2_neg(s.a.p));
|
||||
dir = PerpVec2TowardsDir(SubVec2(s.b.p, s.a.p), NegVec2(s.a.p));
|
||||
}
|
||||
|
||||
{
|
||||
DBGSTEP;
|
||||
m = get_menkowski_point(shape0, shape1, xf0, xf1, dir);
|
||||
/* Check that new point is far enough away from existing points */
|
||||
if (v2_len_sq(v2_sub(m.p, s.a.p)) < min_unique_pt_dist_sq ||
|
||||
v2_len_sq(v2_sub(m.p, s.b.p)) < min_unique_pt_dist_sq ||
|
||||
if (Vec2LenSq(SubVec2(m.p, s.a.p)) < min_unique_pt_dist_sq ||
|
||||
Vec2LenSq(SubVec2(m.p, s.b.p)) < min_unique_pt_dist_sq ||
|
||||
(
|
||||
(num_removed >= 1) && (
|
||||
(v2_len_sq(v2_sub(m.p, removed_a)) < min_unique_pt_dist_sq) ||
|
||||
(num_removed >= 2 && v2_len_sq(v2_sub(m.p, removed_b)) < min_unique_pt_dist_sq))
|
||||
(Vec2LenSq(SubVec2(m.p, removed_a)) < min_unique_pt_dist_sq) ||
|
||||
(num_removed >= 2 && Vec2LenSq(SubVec2(m.p, removed_b)) < min_unique_pt_dist_sq))
|
||||
) ||
|
||||
math_fabs(v2_wedge(v2_sub(s.b.p, s.a.p), v2_sub(m.p, s.a.p))) < min_unique_pt_dist_sq) {
|
||||
AbsF32(WedgeVec2(SubVec2(s.b.p, s.a.p), SubVec2(m.p, s.a.p))) < min_unique_pt_dist_sq) {
|
||||
overlapping = 0;
|
||||
break;
|
||||
}
|
||||
@ -215,9 +215,9 @@ internal struct gjk_result gjk_get_simplex(CLD_Shape *shape0, CLD_Shape *shape1,
|
||||
s.a = m;
|
||||
s.len = 3;
|
||||
|
||||
if ((math_fabs(v2_wedge(v2_sub(s.b.p, s.a.p), v2_neg(s.a.p))) <= min_unique_pt_dist_sq) ||
|
||||
(math_fabs(v2_wedge(v2_sub(s.c.p, s.b.p), v2_neg(s.b.p))) <= min_unique_pt_dist_sq) ||
|
||||
(math_fabs(v2_wedge(v2_sub(s.c.p, s.a.p), v2_neg(s.a.p))) <= min_unique_pt_dist_sq)) {
|
||||
if ((AbsF32(WedgeVec2(SubVec2(s.b.p, s.a.p), NegVec2(s.a.p))) <= min_unique_pt_dist_sq) ||
|
||||
(AbsF32(WedgeVec2(SubVec2(s.c.p, s.b.p), NegVec2(s.b.p))) <= min_unique_pt_dist_sq) ||
|
||||
(AbsF32(WedgeVec2(SubVec2(s.c.p, s.a.p), NegVec2(s.a.p))) <= min_unique_pt_dist_sq)) {
|
||||
/* Simplex lies on origin */
|
||||
overlapping = 1;
|
||||
break;
|
||||
@ -226,21 +226,21 @@ internal struct gjk_result gjk_get_simplex(CLD_Shape *shape0, CLD_Shape *shape1,
|
||||
|
||||
/* Determine region of the simplex in which the origin lies */
|
||||
DBGSTEP;
|
||||
Vec2 vab = v2_sub(s.b.p, s.a.p);
|
||||
Vec2 vac = v2_sub(s.c.p, s.a.p);
|
||||
Vec2 vbc = v2_sub(s.c.p, s.b.p);
|
||||
Vec2 vab = SubVec2(s.b.p, s.a.p);
|
||||
Vec2 vac = SubVec2(s.c.p, s.a.p);
|
||||
Vec2 vbc = SubVec2(s.c.p, s.b.p);
|
||||
|
||||
Vec2 rab_dir = v2_perp_towards_dir(vab, v2_neg(vac));
|
||||
Vec2 rac_dir = v2_perp_towards_dir(vac, v2_neg(vab));
|
||||
Vec2 rbc_dir = v2_perp_towards_dir(vbc, vab);
|
||||
Vec2 rab_dir = PerpVec2TowardsDir(vab, NegVec2(vac));
|
||||
Vec2 rac_dir = PerpVec2TowardsDir(vac, NegVec2(vab));
|
||||
Vec2 rbc_dir = PerpVec2TowardsDir(vbc, vab);
|
||||
|
||||
f32 rab_dot = v2_dot(rab_dir, v2_neg(s.a.p));
|
||||
f32 rac_dot = v2_dot(rac_dir, v2_neg(s.a.p));
|
||||
f32 rbc_dot = v2_dot(rbc_dir, v2_neg(s.b.p));
|
||||
f32 rab_dot = DotVec2(rab_dir, NegVec2(s.a.p));
|
||||
f32 rac_dot = DotVec2(rac_dir, NegVec2(s.a.p));
|
||||
f32 rbc_dot = DotVec2(rbc_dir, NegVec2(s.b.p));
|
||||
|
||||
f32 vab_dot = v2_dot(vab, v2_neg(s.a.p)) / v2_len_sq(vab);
|
||||
f32 vac_dot = v2_dot(vac, v2_neg(s.a.p)) / v2_len_sq(vac);
|
||||
f32 vbc_dot = v2_dot(vbc, v2_neg(s.b.p)) / v2_len_sq(vbc);
|
||||
f32 vab_dot = DotVec2(vab, NegVec2(s.a.p)) / Vec2LenSq(vab);
|
||||
f32 vac_dot = DotVec2(vac, NegVec2(s.a.p)) / Vec2LenSq(vac);
|
||||
f32 vbc_dot = DotVec2(vbc, NegVec2(s.b.p)) / Vec2LenSq(vbc);
|
||||
|
||||
if (rab_dot >= 0 && vab_dot >= 0 && vab_dot <= 1) {
|
||||
/* Region ab, remove c */
|
||||
@ -347,7 +347,7 @@ internal struct epa_result epa_get_normal_from_gjk(CLD_Shape *shape0, CLD_Shape
|
||||
proto_count = 3;
|
||||
}
|
||||
|
||||
i32 winding = v2_winding(v2_sub(s.c.p, s.a.p), v2_sub(s.b.p, s.a.p));
|
||||
i32 winding = WindingFromVec2(SubVec2(s.c.p, s.a.p), SubVec2(s.b.p, s.a.p));
|
||||
|
||||
u32 epa_iterations = 0;
|
||||
for (;;) {
|
||||
@ -365,13 +365,13 @@ internal struct epa_result epa_get_normal_from_gjk(CLD_Shape *shape0, CLD_Shape
|
||||
CLD_MenkowskiPoint a = proto[a_index];
|
||||
CLD_MenkowskiPoint b = proto[b_index];
|
||||
|
||||
Vec2 vab = v2_sub(b.p, a.p);
|
||||
Vec2 vao = v2_neg(a.p);
|
||||
Vec2 vab = SubVec2(b.p, a.p);
|
||||
Vec2 vao = NegVec2(a.p);
|
||||
|
||||
f32 proj_ratio = ClampF32(v2_dot(vao, vab) / v2_len_sq(vab), 0, 1);
|
||||
Vec2 proj = v2_add(a.p, v2_mul(vab, proj_ratio));
|
||||
f32 proj_ratio = ClampF32(DotVec2(vao, vab) / Vec2LenSq(vab), 0, 1);
|
||||
Vec2 proj = AddVec2(a.p, MulVec2(vab, proj_ratio));
|
||||
|
||||
f32 proj_len_sq = v2_len_sq(proj);
|
||||
f32 proj_len_sq = Vec2LenSq(proj);
|
||||
if (proj_len_sq < closest_len_sq - min_unique_pt_dist_sq) {
|
||||
closest_a = a;
|
||||
closest_b = b;
|
||||
@ -379,16 +379,16 @@ internal struct epa_result epa_get_normal_from_gjk(CLD_Shape *shape0, CLD_Shape
|
||||
closest_len_sq = proj_len_sq;
|
||||
}
|
||||
}
|
||||
Vec2 vab = v2_sub(closest_b.p, closest_a.p);
|
||||
Vec2 vab = SubVec2(closest_b.p, closest_a.p);
|
||||
|
||||
/* Find new point in dir */
|
||||
Vec2 dir = v2_mul(v2_perp(vab), winding);
|
||||
Vec2 dir = MulVec2(PerpVec2(vab), winding);
|
||||
CLD_MenkowskiPoint m = get_menkowski_point(shape0, shape1, xf0, xf1, dir);
|
||||
|
||||
#if COLLIDER_DEBUG
|
||||
{
|
||||
/* If debug step count is reached, we still want to inspect the normal at the step */
|
||||
normal = v2_norm(dir);
|
||||
normal = NormVec2(dir);
|
||||
closest_feature.a = closest_a;
|
||||
closest_feature.b = closest_b;
|
||||
closest_feature.len = 2;
|
||||
@ -406,22 +406,22 @@ internal struct epa_result epa_get_normal_from_gjk(CLD_Shape *shape0, CLD_Shape
|
||||
//const f32 validity_epsilon = 0.00000000001f; /* Arbitrary */
|
||||
const f32 validity_epsilon = min_unique_pt_dist_sq; /* Arbitrary */
|
||||
|
||||
Vec2 vam = v2_sub(m.p, closest_a.p);
|
||||
Vec2 vbm = v2_sub(closest_b.p, closest_a.p);
|
||||
Vec2 vam = SubVec2(m.p, closest_a.p);
|
||||
Vec2 vbm = SubVec2(closest_b.p, closest_a.p);
|
||||
|
||||
f32 dot = v2_dot(vab, vam) / v2_len_sq(vab);
|
||||
f32 dot = DotVec2(vab, vam) / Vec2LenSq(vab);
|
||||
|
||||
if (dot >= -validity_epsilon && dot <= 1 - validity_epsilon && (v2_wedge(vab, vam) * -winding) >= -validity_epsilon) {
|
||||
if (dot >= -validity_epsilon && dot <= 1 - validity_epsilon && (WedgeVec2(vab, vam) * -winding) >= -validity_epsilon) {
|
||||
/* New point is not between edge */
|
||||
valid = 0;
|
||||
} else if (v2_len_sq(vam) < min_unique_pt_dist_sq || v2_len_sq(vbm) < min_unique_pt_dist_sq) {
|
||||
} else if (Vec2LenSq(vam) < min_unique_pt_dist_sq || Vec2LenSq(vbm) < min_unique_pt_dist_sq) {
|
||||
/* New point is too close to existing */
|
||||
valid = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (!valid || epa_iterations >= max_iterations) {
|
||||
normal = v2_norm(dir);
|
||||
normal = NormVec2(dir);
|
||||
closest_feature.a = closest_a;
|
||||
closest_feature.b = closest_b;
|
||||
closest_feature.len = 2;
|
||||
@ -444,7 +444,7 @@ internal struct epa_result epa_get_normal_from_gjk(CLD_Shape *shape0, CLD_Shape
|
||||
proto[closest_b_index] = m;
|
||||
}
|
||||
} else {
|
||||
normal = v2_norm(gjk_res.final_dir);
|
||||
normal = NormVec2(gjk_res.final_dir);
|
||||
closest_feature.len = gjk_res.simplex.len;
|
||||
closest_feature.a = gjk_res.simplex.a;
|
||||
closest_feature.b = gjk_res.simplex.b;
|
||||
@ -483,14 +483,14 @@ struct clip_line_to_line_result {
|
||||
|
||||
internal struct clip_line_to_line_result clip_line_to_line(Vec2 a0, Vec2 b0, Vec2 a1, Vec2 b1, Vec2 normal)
|
||||
{
|
||||
Vec2 vab0 = v2_sub(b0, a0);
|
||||
Vec2 vab1 = v2_sub(b1, a1);
|
||||
Vec2 va0a1 = v2_sub(a1, a0);
|
||||
Vec2 vb0b1 = v2_sub(b1, b0);
|
||||
f32 vab0_w = v2_wedge(vab0, normal);
|
||||
f32 vab1_w = v2_wedge(vab1, normal);
|
||||
f32 va0a1_w = v2_wedge(va0a1, normal);
|
||||
f32 vb0b1_w = v2_wedge(vb0b1, normal);
|
||||
Vec2 vab0 = SubVec2(b0, a0);
|
||||
Vec2 vab1 = SubVec2(b1, a1);
|
||||
Vec2 va0a1 = SubVec2(a1, a0);
|
||||
Vec2 vb0b1 = SubVec2(b1, b0);
|
||||
f32 vab0_w = WedgeVec2(vab0, normal);
|
||||
f32 vab1_w = WedgeVec2(vab1, normal);
|
||||
f32 va0a1_w = WedgeVec2(va0a1, normal);
|
||||
f32 vb0b1_w = WedgeVec2(vb0b1, normal);
|
||||
|
||||
/* FIXME: Handle 0 denominator */
|
||||
f32 a0t;
|
||||
@ -509,20 +509,20 @@ internal struct clip_line_to_line_result clip_line_to_line(Vec2 a0, Vec2 b0, Vec
|
||||
}
|
||||
|
||||
struct clip_line_to_line_result res;
|
||||
res.a0_clipped = v2_add(a0, v2_mul(vab0, a0t));
|
||||
res.a1_clipped = v2_add(a1, v2_mul(vab1, a1t));
|
||||
res.b0_clipped = v2_add(b0, v2_mul(vab0, -b0t));
|
||||
res.b1_clipped = v2_add(b1, v2_mul(vab1, -b1t));
|
||||
res.a0_clipped = AddVec2(a0, MulVec2(vab0, a0t));
|
||||
res.a1_clipped = AddVec2(a1, MulVec2(vab1, a1t));
|
||||
res.b0_clipped = AddVec2(b0, MulVec2(vab0, -b0t));
|
||||
res.b1_clipped = AddVec2(b1, MulVec2(vab1, -b1t));
|
||||
return res;
|
||||
}
|
||||
|
||||
internal Vec2 clip_point_to_line(Vec2 a, Vec2 b, Vec2 p, Vec2 normal)
|
||||
{
|
||||
Vec2 vab = v2_sub(b, a);
|
||||
Vec2 vap = v2_sub(p, a);
|
||||
Vec2 vab = SubVec2(b, a);
|
||||
Vec2 vap = SubVec2(p, a);
|
||||
|
||||
f32 vab_w = v2_wedge(vab, normal);
|
||||
f32 vap_w = v2_wedge(vap, normal);
|
||||
f32 vab_w = WedgeVec2(vab, normal);
|
||||
f32 vap_w = WedgeVec2(vap, normal);
|
||||
|
||||
f32 t;
|
||||
{
|
||||
@ -530,7 +530,7 @@ internal Vec2 clip_point_to_line(Vec2 a, Vec2 b, Vec2 p, Vec2 normal)
|
||||
t = ClampF32(vap_w * w, 0, 1);
|
||||
}
|
||||
|
||||
Vec2 res = v2_add(a, v2_mul(vab, t));
|
||||
Vec2 res = AddVec2(a, MulVec2(vab, t));
|
||||
return res;
|
||||
}
|
||||
|
||||
@ -584,18 +584,18 @@ CLD_CollisionResult collider_collision_points(CLD_Shape *shape0, CLD_Shape *shap
|
||||
CLD_MenkowskiFeature f = epa_res.closest_feature;
|
||||
/* Shapes not overlapping, determine if distance between shapes within tolerance */
|
||||
if (f.len == 1) {
|
||||
Vec2 p = v2_neg(f.a.p);
|
||||
if (v2_len_sq(p) <= (tolerance * tolerance)) {
|
||||
Vec2 p = NegVec2(f.a.p);
|
||||
if (Vec2LenSq(p) <= (tolerance * tolerance)) {
|
||||
colliding = 1;
|
||||
}
|
||||
} else {
|
||||
/* Project origin to determine if distance is within tolerance. */
|
||||
Assert(f.len == 2);
|
||||
Vec2 vab = v2_sub(f.b.p, f.a.p);
|
||||
Vec2 vao = v2_neg(f.a.p);
|
||||
f32 ratio = ClampF32(v2_dot(vab, vao) / v2_dot(vab, vab), 0, 1);
|
||||
Vec2 p = v2_add(f.a.p, v2_mul(vab, ratio));
|
||||
if (v2_len_sq(p) <= (tolerance * tolerance)) {
|
||||
Vec2 vab = SubVec2(f.b.p, f.a.p);
|
||||
Vec2 vao = NegVec2(f.a.p);
|
||||
f32 ratio = ClampF32(DotVec2(vab, vao) / DotVec2(vab, vab), 0, 1);
|
||||
Vec2 p = AddVec2(f.a.p, MulVec2(vab, ratio));
|
||||
if (Vec2LenSq(p) <= (tolerance * tolerance)) {
|
||||
colliding = 1;
|
||||
}
|
||||
}
|
||||
@ -628,7 +628,7 @@ CLD_CollisionResult collider_collision_points(CLD_Shape *shape0, CLD_Shape *shap
|
||||
}
|
||||
if (a1.i == b1.i) {
|
||||
if (shape1->count > 1) {
|
||||
b1 = collider_get_support_point_internal(shape1, xf1, v2_neg(normal), b1.i);
|
||||
b1 = collider_get_support_point_internal(shape1, xf1, NegVec2(normal), b1.i);
|
||||
} else {
|
||||
collapse1 = 1;
|
||||
b1 = a1;
|
||||
@ -641,33 +641,33 @@ CLD_CollisionResult collider_collision_points(CLD_Shape *shape0, CLD_Shape *shap
|
||||
b1 = a1;
|
||||
}
|
||||
|
||||
Vec2 vab0 = v2_sub(b0.p, a0.p);
|
||||
Vec2 vab1 = v2_sub(b1.p, a1.p);
|
||||
Vec2 vab0_norm = v2_norm(vab0);
|
||||
Vec2 vab1_norm = v2_norm(vab1);
|
||||
Vec2 vab0 = SubVec2(b0.p, a0.p);
|
||||
Vec2 vab1 = SubVec2(b1.p, a1.p);
|
||||
Vec2 vab0_norm = NormVec2(vab0);
|
||||
Vec2 vab1_norm = NormVec2(vab1);
|
||||
|
||||
/* Swap points based on normal direction for consistent clipping */
|
||||
if (v2_wedge(normal, vab0) < 0) {
|
||||
if (WedgeVec2(normal, vab0) < 0) {
|
||||
CLD_SupportPoint tmp = a0;
|
||||
a0 = b0;
|
||||
b0 = tmp;
|
||||
vab0 = v2_neg(vab0);
|
||||
vab0 = NegVec2(vab0);
|
||||
}
|
||||
if (v2_wedge(normal, vab1) < 0) {
|
||||
if (WedgeVec2(normal, vab1) < 0) {
|
||||
CLD_SupportPoint tmp = a1;
|
||||
a1 = b1;
|
||||
b1 = tmp;
|
||||
vab1 = v2_neg(vab1);
|
||||
vab1 = NegVec2(vab1);
|
||||
}
|
||||
|
||||
/* Collapse lines that are too far in the direction of the normal to be accurately clipped */
|
||||
f32 collapse_epsilon = 0.05f;
|
||||
collapse0 = collapse0 || math_fabs(v2_wedge(normal, vab0_norm)) < collapse_epsilon;
|
||||
collapse1 = collapse1 || math_fabs(v2_wedge(normal, vab1_norm)) < collapse_epsilon;
|
||||
collapse0 = collapse0 || AbsF32(WedgeVec2(normal, vab0_norm)) < collapse_epsilon;
|
||||
collapse1 = collapse1 || AbsF32(WedgeVec2(normal, vab1_norm)) < collapse_epsilon;
|
||||
|
||||
/* Collapse lines into deepest point */
|
||||
if (collapse0) {
|
||||
if (v2_dot(normal, vab0) > 0) {
|
||||
if (DotVec2(normal, vab0) > 0) {
|
||||
a0 = b0;
|
||||
} else {
|
||||
/* TODO: Remove this (debugging) */
|
||||
@ -675,7 +675,7 @@ CLD_CollisionResult collider_collision_points(CLD_Shape *shape0, CLD_Shape *shap
|
||||
}
|
||||
}
|
||||
if (collapse1) {
|
||||
if (v2_dot(normal, vab1) < 0) {
|
||||
if (DotVec2(normal, vab1) < 0) {
|
||||
a1 = b1;
|
||||
} else {
|
||||
/* TODO: Remove this (debugging) */
|
||||
@ -697,16 +697,16 @@ CLD_CollisionResult collider_collision_points(CLD_Shape *shape0, CLD_Shape *shap
|
||||
Vec2 b0_clipped = clip_res.b0_clipped;
|
||||
Vec2 b1_clipped = clip_res.b1_clipped;
|
||||
/* Calc midpoint between clipped a & b */
|
||||
Vec2 va0a1_clipped = v2_sub(a1_clipped, a0_clipped);
|
||||
Vec2 vb0b1_clipped = v2_sub(b1_clipped, b0_clipped);
|
||||
a_sep = v2_dot(va0a1_clipped, normal);
|
||||
b_sep = v2_dot(vb0b1_clipped, normal);
|
||||
a_midpoint = v2_add(a0_clipped, v2_mul(va0a1_clipped, 0.5f));
|
||||
b_midpoint = v2_add(b0_clipped, v2_mul(vb0b1_clipped, 0.5f));
|
||||
Vec2 va0a1_clipped = SubVec2(a1_clipped, a0_clipped);
|
||||
Vec2 vb0b1_clipped = SubVec2(b1_clipped, b0_clipped);
|
||||
a_sep = DotVec2(va0a1_clipped, normal);
|
||||
b_sep = DotVec2(vb0b1_clipped, normal);
|
||||
a_midpoint = AddVec2(a0_clipped, MulVec2(va0a1_clipped, 0.5f));
|
||||
b_midpoint = AddVec2(b0_clipped, MulVec2(vb0b1_clipped, 0.5f));
|
||||
ignore_a = 0;
|
||||
ignore_b = 0;
|
||||
Vec2 vfin = v2_sub(b_midpoint, a_midpoint);
|
||||
if (v2_len_sq(vfin) < (0.005 * 0.005)) {
|
||||
Vec2 vfin = SubVec2(b_midpoint, a_midpoint);
|
||||
if (Vec2LenSq(vfin) < (0.005 * 0.005)) {
|
||||
if (a_sep > b_sep) {
|
||||
ignore_a = 1;
|
||||
} else {
|
||||
@ -730,9 +730,9 @@ CLD_CollisionResult collider_collision_points(CLD_Shape *shape0, CLD_Shape *shap
|
||||
p1 = clip_point_to_line(a1.p, b1.p, a0.p, normal);
|
||||
}
|
||||
/* Calc midpoint */
|
||||
Vec2 vsep = v2_sub(p1, p0);
|
||||
a_midpoint = v2_add(p0, v2_mul(vsep, 0.5f));
|
||||
a_sep = v2_dot(normal, p1) - v2_dot(normal, p0);
|
||||
Vec2 vsep = SubVec2(p1, p0);
|
||||
a_midpoint = AddVec2(p0, MulVec2(vsep, 0.5f));
|
||||
a_sep = DotVec2(normal, p1) - DotVec2(normal, p0);
|
||||
ignore_a = 0;
|
||||
res.a0_clipped = p0;
|
||||
res.a1_clipped = p1;
|
||||
@ -827,26 +827,26 @@ CLD_ClosestResult collider_closest_points(CLD_Shape *shape0, CLD_Shape *shape1,
|
||||
if (f.len == 1) {
|
||||
p0 = f.a.s0.p;
|
||||
p1 = f.a.s1.p;
|
||||
colliding = gjk_res.overlapping || v2_len_sq(v2_neg(f.a.p)) <= (tolerance * tolerance);
|
||||
colliding = gjk_res.overlapping || Vec2LenSq(NegVec2(f.a.p)) <= (tolerance * tolerance);
|
||||
} else {
|
||||
Assert(f.len == 2);
|
||||
/* FIXME: Winding order dependent? */
|
||||
f32 ratio;
|
||||
{
|
||||
/* Determine ratio between edge a & b that projected origin lies */
|
||||
Vec2 vab = v2_sub(f.b.p, f.a.p);
|
||||
Vec2 vao = v2_neg(f.a.p);
|
||||
ratio = ClampF32(v2_dot(vab, vao) / v2_dot(vab, vab), 0, 1);
|
||||
Vec2 vab = SubVec2(f.b.p, f.a.p);
|
||||
Vec2 vao = NegVec2(f.a.p);
|
||||
ratio = ClampF32(DotVec2(vab, vao) / DotVec2(vab, vab), 0, 1);
|
||||
}
|
||||
/* Shape 0 */
|
||||
p0 = v2_sub(f.b.s0.p, f.a.s0.p);
|
||||
p0 = v2_mul(p0, ratio);
|
||||
p0 = v2_add(p0, f.a.s0.p);
|
||||
p0 = SubVec2(f.b.s0.p, f.a.s0.p);
|
||||
p0 = MulVec2(p0, ratio);
|
||||
p0 = AddVec2(p0, f.a.s0.p);
|
||||
/* Shape 1 */
|
||||
p1 = v2_sub(f.b.s1.p, f.a.s1.p);
|
||||
p1 = v2_mul(p1, ratio);
|
||||
p1 = v2_add(p1, f.a.s1.p);
|
||||
colliding = gjk_res.overlapping || v2_len_sq(v2_sub(p1, p0)) <= (tolerance * tolerance);
|
||||
p1 = SubVec2(f.b.s1.p, f.a.s1.p);
|
||||
p1 = MulVec2(p1, ratio);
|
||||
p1 = AddVec2(p1, f.a.s1.p);
|
||||
colliding = gjk_res.overlapping || Vec2LenSq(SubVec2(p1, p0)) <= (tolerance * tolerance);
|
||||
}
|
||||
|
||||
#if COLLIDER_DEBUG
|
||||
@ -890,16 +890,16 @@ f32 collider_time_of_impact(CLD_Shape *c0, CLD_Shape *c1,
|
||||
/* Shapes are penetrating at t=0 */
|
||||
return 0;
|
||||
}
|
||||
dir = v2_sub(closest_points_res.p1, closest_points_res.p0);
|
||||
t0_sep = v2_len(dir);
|
||||
dir = v2_div(dir, t0_sep); /* Normalize */
|
||||
dir_neg = v2_neg(dir);
|
||||
dir = SubVec2(closest_points_res.p1, closest_points_res.p0);
|
||||
t0_sep = Vec2Len(dir);
|
||||
dir = DivVec2(dir, t0_sep); /* Normalize */
|
||||
dir_neg = NegVec2(dir);
|
||||
}
|
||||
|
||||
{
|
||||
Vec2 p0 = collider_get_support_point(c0, xf0_t1, dir).p;
|
||||
Vec2 p1 = collider_get_support_point(c1, xf1_t1, dir_neg).p;
|
||||
t1_sep = v2_dot(dir, v2_sub(p1, p0));
|
||||
t1_sep = DotVec2(dir, SubVec2(p1, p0));
|
||||
if (t1_sep > 0) {
|
||||
/* Shapes are not penetrating at t=1 */
|
||||
return 1;
|
||||
@ -907,7 +907,7 @@ f32 collider_time_of_impact(CLD_Shape *c0, CLD_Shape *c1,
|
||||
}
|
||||
|
||||
u32 iteration = 0;
|
||||
while (math_fabs(t_sep) > tolerance && iteration < max_iterations) {
|
||||
while (AbsF32(t_sep) > tolerance && iteration < max_iterations) {
|
||||
/* Use mix of bisection & 0 position method to find root
|
||||
* (as described in https://box2d.org/files/ErinCatto_ContinuousCollision_GDC2013.pdf) */
|
||||
if (iteration & 1) {
|
||||
@ -924,7 +924,7 @@ f32 collider_time_of_impact(CLD_Shape *c0, CLD_Shape *c1,
|
||||
|
||||
Vec2 p0 = collider_get_support_point(c0, xf0, dir).p;
|
||||
Vec2 p1 = collider_get_support_point(c1, xf1, dir_neg).p;
|
||||
t_sep = v2_dot(dir, v2_sub(p1, p0));
|
||||
t_sep = DotVec2(dir, SubVec2(p1, p0));
|
||||
|
||||
/* Update bracket */
|
||||
if (t_sep > 0) {
|
||||
@ -952,9 +952,9 @@ V2Array menkowski(Arena *arena, CLD_Shape *shape0, CLD_Shape *shape1, Xform xf0,
|
||||
V2Array res = { .points = PushDry(arena, Vec2) };
|
||||
for (u64 i = 0; i < detail; ++i) {
|
||||
f32 angle = ((f32)i / detail) * (2 * Pi);
|
||||
Vec2 dir = v2_from_angle(angle);
|
||||
Vec2 dir = Vec2FromAngle(angle);
|
||||
CLD_MenkowskiPoint m = get_menkowski_point(shape0, shape1, xf0, xf1, dir);
|
||||
if (res.count == 0 || !v2_eq(m.p, res.points[res.count - 1])) {
|
||||
if (res.count == 0 || !EqVec2(m.p, res.points[res.count - 1])) {
|
||||
*PushStructNoZero(arena, Vec2) = m.p;
|
||||
++res.count;
|
||||
}
|
||||
@ -975,7 +975,7 @@ V2Array cloud(Arena *arena, CLD_Shape *shape0, CLD_Shape *shape1, Xform xf0, Xfo
|
||||
Vec2 p0 = MulXformV2(xf0, points0[i]);
|
||||
for (u64 j = 0; j < count1; ++j) {
|
||||
Vec2 p1 = MulXformV2(xf1, points1[j]);
|
||||
*PushStructNoZero(arena, Vec2) = v2_sub(p0, p1);
|
||||
*PushStructNoZero(arena, Vec2) = SubVec2(p0, p1);
|
||||
++res.count;
|
||||
}
|
||||
}
|
||||
@ -995,21 +995,21 @@ b32 collider_collision_boolean(CLD_Shape *shape0, CLD_Shape *shape1)
|
||||
Vec2 dir, p;
|
||||
|
||||
/* First point is support point in shape's general directions to eachother */
|
||||
dir = v2_sub(starting_point(shape1), starting_point(shape0));
|
||||
if (v2_is_zero(dir)) dir = V2(1, 0);
|
||||
dir = SubVec2(starting_point(shape1), starting_point(shape0));
|
||||
if (IsVec2Zero(dir)) dir = VEC2(1, 0);
|
||||
s.a = get_menkowski_point(shape0, shape1, dir);
|
||||
|
||||
/* Second point is support point towards origin */
|
||||
dir = v2_neg(s.a);
|
||||
dir = NegVec2(s.a);
|
||||
p = get_menkowski_point(shape0, shape1, dir);
|
||||
if (v2_dot(dir, p) >= 0) {
|
||||
if (DotVec2(dir, p) >= 0) {
|
||||
s.b = s.a;
|
||||
s.a = p;
|
||||
for (;;) {
|
||||
/* Third point is support point in direction of line normal towards origin */
|
||||
dir = v2_perp_towards_dir(v2_sub(s.b, s.a), v2_neg(s.a));
|
||||
dir = PerpVec2TowardsDir(SubVec2(s.b, s.a), NegVec2(s.a));
|
||||
p = get_menkowski_point(shape0, shape1, dir);
|
||||
if (v2_dot(dir, p) < 0) {
|
||||
if (DotVec2(dir, p) < 0) {
|
||||
/* New point did not cross origin, collision impossible */
|
||||
break;
|
||||
}
|
||||
@ -1018,17 +1018,17 @@ b32 collider_collision_boolean(CLD_Shape *shape0, CLD_Shape *shape1)
|
||||
s.b = s.a;
|
||||
s.a = p;
|
||||
|
||||
Vec2 vab = v2_sub(s.b, s.a);
|
||||
Vec2 vac = v2_sub(s.c, s.a);
|
||||
Vec2 a_to_origin = v2_neg(s.a);
|
||||
Vec2 vab = SubVec2(s.b, s.a);
|
||||
Vec2 vac = SubVec2(s.c, s.a);
|
||||
Vec2 a_to_origin = NegVec2(s.a);
|
||||
|
||||
dir = v2_perp_towards_dir(vab, v2_neg(vac)); /* Normal of ab pointing away from c */
|
||||
if (v2_dot(dir, a_to_origin) >= 0) {
|
||||
dir = PerpVec2TowardsDir(vab, NegVec2(vac)); /* Normal of ab pointing away from c */
|
||||
if (DotVec2(dir, a_to_origin) >= 0) {
|
||||
/* Point is in region ab, remove c from simplex (will happen automatically next iteration) */
|
||||
} else {
|
||||
/* Point is not in region ab */
|
||||
dir = v2_perp_towards_dir(vac, v2_neg(vab)); /* Normal of ac pointing away from b */
|
||||
if (v2_dot(dir, a_to_origin) >= 0) {
|
||||
dir = PerpVec2TowardsDir(vac, NegVec2(vab)); /* Normal of ac pointing away from b */
|
||||
if (DotVec2(dir, a_to_origin) >= 0) {
|
||||
/* Point is in region ac, remove b from simplex */
|
||||
s.b = s.c;
|
||||
} else {
|
||||
|
||||
@ -11,7 +11,7 @@ D_StartupReceipt draw_startup(F_StartupReceipt *font_sr)
|
||||
__prof;
|
||||
(UNUSED)font_sr;
|
||||
u32 pixel_white = 0xFFFFFFFF;
|
||||
G.solid_white_texture = gp_texture_alloc(GP_TEXTURE_FORMAT_R8G8B8A8_UNORM, 0, V2I32(1, 1), &pixel_white);
|
||||
G.solid_white_texture = gp_texture_alloc(GP_TEXTURE_FORMAT_R8G8B8A8_UNORM, 0, VEC2I32(1, 1), &pixel_white);
|
||||
return (D_StartupReceipt) { 0 };
|
||||
}
|
||||
|
||||
@ -80,11 +80,11 @@ void draw_circle(G_RenderSig *sig, Vec2 pos, f32 radius, u32 color, u32 detail)
|
||||
Vec2 *points = PushArrayNoZero(scratch.arena, Vec2, detail);
|
||||
for (u32 i = 0; i < detail; ++i) {
|
||||
f32 angle = ((f32)i / (f32)detail) * Tau;
|
||||
Vec2 p = V2(
|
||||
radius * math_cos(angle),
|
||||
radius * math_sin(angle)
|
||||
Vec2 p = VEC2(
|
||||
radius * CosF32(angle),
|
||||
radius * SinF32(angle)
|
||||
);
|
||||
points[i] = v2_add(pos, p);
|
||||
points[i] = AddVec2(pos, p);
|
||||
}
|
||||
|
||||
V2Array vertices = {
|
||||
@ -114,25 +114,25 @@ void draw_quad(G_RenderSig *sig, Quad quad, u32 color)
|
||||
void draw_gradient_line(G_RenderSig *sig, Vec2 start, Vec2 end, f32 thickness, u32 start_color, u32 end_color)
|
||||
{
|
||||
#if 0
|
||||
Quad quad = quad_from_line(start, end, thickness);
|
||||
Quad quad = QuadFromLine(start, end, thickness);
|
||||
draw_material(sig, DRAW_MATERIAL_PARAMS(.texture = G.solid_white_texture, .tint0 = start_color, .tint1 = end_color, .quad = quad));
|
||||
#else
|
||||
/* Placeholder */
|
||||
(UNUSED)end_color;
|
||||
Quad quad = quad_from_line(start, end, thickness);
|
||||
Quad quad = QuadFromLine(start, end, thickness);
|
||||
draw_quad(sig, quad, start_color);
|
||||
#endif
|
||||
}
|
||||
|
||||
void draw_line(G_RenderSig *sig, Vec2 start, Vec2 end, f32 thickness, u32 color)
|
||||
{
|
||||
Quad quad = quad_from_line(start, end, thickness);
|
||||
Quad quad = QuadFromLine(start, end, thickness);
|
||||
draw_quad(sig, quad, color);
|
||||
}
|
||||
|
||||
void draw_ray(G_RenderSig *sig, Vec2 pos, Vec2 rel, f32 thickness, u32 color)
|
||||
{
|
||||
Quad quad = quad_from_ray(pos, rel, thickness);
|
||||
Quad quad = QuadFromRay(pos, rel, thickness);
|
||||
draw_quad(sig, quad, color);
|
||||
}
|
||||
|
||||
@ -142,13 +142,13 @@ void draw_poly_line(G_RenderSig *sig, V2Array points, b32 loop, f32 thickness, u
|
||||
for (u64 i = 1; i < points.count; ++i) {
|
||||
Vec2 p1 = points.points[i - 1];
|
||||
Vec2 p2 = points.points[i];
|
||||
Quad q = quad_from_line(p1, p2, thickness);
|
||||
Quad q = QuadFromLine(p1, p2, thickness);
|
||||
draw_quad(sig, q, color);
|
||||
}
|
||||
if (loop && points.count > 2) {
|
||||
Vec2 p1 = points.points[points.count - 1];
|
||||
Vec2 p2 = points.points[0];
|
||||
Quad q = quad_from_line(p1, p2, thickness);
|
||||
Quad q = QuadFromLine(p1, p2, thickness);
|
||||
draw_quad(sig, q, color);
|
||||
}
|
||||
}
|
||||
@ -161,11 +161,11 @@ void draw_circle_line(G_RenderSig *sig, Vec2 pos, f32 radius, f32 thickness, u32
|
||||
Vec2 *points = PushArrayNoZero(scratch.arena, Vec2, detail);
|
||||
for (u32 i = 0; i < detail; ++i) {
|
||||
f32 angle = ((f32)i / (f32)detail) * Tau;
|
||||
Vec2 p = V2(
|
||||
radius * math_cos(angle),
|
||||
radius * math_sin(angle)
|
||||
Vec2 p = VEC2(
|
||||
radius * CosF32(angle),
|
||||
radius * SinF32(angle)
|
||||
);
|
||||
points[i] = v2_add(pos, p);
|
||||
points[i] = AddVec2(pos, p);
|
||||
}
|
||||
|
||||
V2Array a = {
|
||||
@ -189,19 +189,19 @@ void draw_arrow_line(G_RenderSig *sig, Vec2 start, Vec2 end, f32 thickness, f32
|
||||
const f32 head_width_ratio = 0.5f; /* Width of arrowhead relative to its length */
|
||||
|
||||
const f32 max_height_to_line_ratio = 0.9f; /* Maximum length of arrowhead relative to total line length */
|
||||
arrowhead_height = MinF32(arrowhead_height, v2_len(v2_sub(end, start)) * max_height_to_line_ratio);
|
||||
arrowhead_height = MinF32(arrowhead_height, Vec2Len(SubVec2(end, start)) * max_height_to_line_ratio);
|
||||
|
||||
Vec2 head_start_dir = v2_sub(start, end);
|
||||
head_start_dir = v2_norm(head_start_dir);
|
||||
head_start_dir = v2_mul(head_start_dir, arrowhead_height);
|
||||
Vec2 head_start_dir = SubVec2(start, end);
|
||||
head_start_dir = NormVec2(head_start_dir);
|
||||
head_start_dir = MulVec2(head_start_dir, arrowhead_height);
|
||||
|
||||
Vec2 head_start = v2_add(end, head_start_dir);
|
||||
Vec2 head_start = AddVec2(end, head_start_dir);
|
||||
|
||||
Vec2 head_p1_dir = v2_perp_mul(head_start_dir, head_width_ratio);
|
||||
Vec2 head_p2_dir = v2_neg(head_p1_dir);
|
||||
Vec2 head_p1_dir = MulPerpVec2(head_start_dir, head_width_ratio);
|
||||
Vec2 head_p2_dir = NegVec2(head_p1_dir);
|
||||
|
||||
Vec2 head_p1 = v2_add(head_start, head_p1_dir);
|
||||
Vec2 head_p2 = v2_add(head_start, head_p2_dir);
|
||||
Vec2 head_p1 = AddVec2(head_start, head_p1_dir);
|
||||
Vec2 head_p2 = AddVec2(head_start, head_p2_dir);
|
||||
|
||||
Vec2 head_points[] = { end, head_p1, head_p2 };
|
||||
V2Array head_points_v2_array = {
|
||||
@ -210,13 +210,13 @@ void draw_arrow_line(G_RenderSig *sig, Vec2 start, Vec2 end, f32 thickness, f32
|
||||
};
|
||||
draw_poly(sig, head_points_v2_array, color);
|
||||
|
||||
Quad line_quad = quad_from_line(start, head_start, thickness);
|
||||
Quad line_quad = QuadFromLine(start, head_start, thickness);
|
||||
draw_quad(sig, line_quad, color);
|
||||
}
|
||||
|
||||
void draw_arrow_ray(G_RenderSig *sig, Vec2 pos, Vec2 rel, f32 thickness, f32 arrowhead_height, u32 color)
|
||||
{
|
||||
Vec2 end = v2_add(pos, rel);
|
||||
Vec2 end = AddVec2(pos, rel);
|
||||
draw_arrow_line(sig, pos, end, thickness, arrowhead_height, color);
|
||||
}
|
||||
|
||||
@ -236,7 +236,7 @@ void draw_collider_line(G_RenderSig *sig, CLD_Shape shape, Xform shape_xf, f32 t
|
||||
poly.points = PushArrayNoZero(scratch.arena, Vec2, detail);
|
||||
for (u32 i = 0; i < detail; ++i) {
|
||||
f32 angle = ((f32)i / (f32)detail) * Tau;
|
||||
Vec2 dir = V2(math_cos(angle), math_sin(angle));
|
||||
Vec2 dir = VEC2(CosF32(angle), SinF32(angle));
|
||||
Vec2 p = collider_get_support_point(&shape, shape_xf, dir).p;
|
||||
poly.points[i] = p;
|
||||
}
|
||||
@ -459,9 +459,9 @@ Rect draw_text(G_RenderSig *sig, D_TextParams params)
|
||||
/* Draw glyphs */
|
||||
for (u64 i = 0; i < line->num_glyphs; ++i) {
|
||||
struct drawable_glyph *tg = &line->glyphs[i];
|
||||
Vec2 pos = V2(draw_pos.x + tg->off_x, draw_pos.y + tg->off_y);
|
||||
Vec2 size = V2(tg->width, tg->height);
|
||||
Xform xf = XformFromRect(RectFromV2(pos, size));
|
||||
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));
|
||||
draw_ui_rect(sig, DRAW_UI_RECT_PARAMS(.xf = xf, .texture = params.font->texture, .tint = params.color, .clip = tg->clip));
|
||||
draw_pos.x += tg->advance;
|
||||
|
||||
|
||||
@ -7,7 +7,7 @@ D_StartupReceipt draw_startup(F_StartupReceipt *font_sr);
|
||||
|
||||
#define DRAW_MATERIAL_PARAMS(...) ((D_MaterialParams) { \
|
||||
.tint = ColorWhite, \
|
||||
.clip = ClipAll, \
|
||||
.clip = AllClipped, \
|
||||
__VA_ARGS__ \
|
||||
})
|
||||
|
||||
@ -68,7 +68,7 @@ void draw_grid(G_RenderSig *sig, Xform xf, u32 bg0_color, u32 bg1_color, u32 lin
|
||||
|
||||
#define DRAW_UI_RECT_PARAMS(...) ((D_UiRectParams) { \
|
||||
.tint = ColorWhite, \
|
||||
.clip = ClipAll, \
|
||||
.clip = AllClipped, \
|
||||
__VA_ARGS__ \
|
||||
})
|
||||
|
||||
|
||||
@ -100,7 +100,7 @@ internal P_JobDef(font_load_asset_job, job)
|
||||
resource_close(&res);
|
||||
|
||||
/* Send texture to GPU */
|
||||
G_Resource *texture = gp_texture_alloc(GP_TEXTURE_FORMAT_R8G8B8A8_UNORM, 0, V2I32(result.image_width, result.image_height), result.image_pixels);
|
||||
G_Resource *texture = gp_texture_alloc(GP_TEXTURE_FORMAT_R8G8B8A8_UNORM, 0, VEC2I32(result.image_width, result.image_height), result.image_pixels);
|
||||
|
||||
/* Allocate store memory */
|
||||
F_Font *font = 0;
|
||||
|
||||
@ -2495,9 +2495,9 @@ internal struct dx12_resource *gbuff_alloc(DXGI_FORMAT format, Vec2I32 size, D3D
|
||||
/* Calculate the view projection matrix */
|
||||
Inline Mat4x4 calculate_vp(Xform view, f32 viewport_width, f32 viewport_height)
|
||||
{
|
||||
Mat4x4 projection = mat4x4_from_ortho(0.0, viewport_width, viewport_height, 0.0, -1.0, 1.0);
|
||||
Mat4x4 view4x4 = mat4x4_from_xform(view);
|
||||
return mat4x4_mul(projection, view4x4);
|
||||
Mat4x4 projection = Mat4x4FromOrtho(0.0, viewport_width, viewport_height, 0.0, -1.0, 1.0);
|
||||
Mat4x4 view4x4 = Mat4x4FromXform(view);
|
||||
return MulMat4x4(projection, view4x4);
|
||||
}
|
||||
|
||||
internal D3D12_GPU_DESCRIPTOR_HANDLE gpu_handle_from_descriptor(struct descriptor *descriptor, struct command_descriptor_heap *cdh)
|
||||
@ -2695,17 +2695,17 @@ G_Resource *gp_run_render(G_RenderSig *gp_render_sig, G_RenderParams params)
|
||||
struct render_sig *rsig = (struct render_sig *)gp_render_sig;
|
||||
++rsig->frame_index;
|
||||
|
||||
Vec2I32 ui_size = V2I32(MaxI32(params.ui_size.x, 1), MaxI32(params.ui_size.y, 1));
|
||||
Vec2I32 render_size = V2I32(MaxI32(params.render_size.x, 1), MaxI32(params.render_size.y, 1));
|
||||
Vec2I32 ui_size = VEC2I32(MaxI32(params.ui_size.x, 1), MaxI32(params.ui_size.y, 1));
|
||||
Vec2I32 render_size = VEC2I32(MaxI32(params.render_size.x, 1), MaxI32(params.render_size.y, 1));
|
||||
Xform world_to_render_xf = params.world_to_render_xf;
|
||||
Xform render_to_ui_xf = params.render_to_ui_xf;
|
||||
|
||||
Rect ui_viewport = RectFromV2(V2(0, 0), V2(ui_size.x, ui_size.y));
|
||||
Rect render_viewport = RectFromV2(V2(0, 0), V2(render_size.x, render_size.y));
|
||||
Rect ui_viewport = RectFromVec2(VEC2(0, 0), VEC2(ui_size.x, ui_size.y));
|
||||
Rect render_viewport = RectFromVec2(VEC2(0, 0), VEC2(render_size.x, render_size.y));
|
||||
|
||||
|
||||
/* Allocate render buffers */
|
||||
if (rsig->shade_target && !v2i32_eq(render_size, rsig->shade_target->texture_size)) {
|
||||
if (rsig->shade_target && !EqVec2I32(render_size, rsig->shade_target->texture_size)) {
|
||||
__profn("Release sig resources");
|
||||
fenced_release(rsig->albedo, FENCED_RELEASE_KIND_RESOURCE);
|
||||
fenced_release(rsig->emittance, FENCED_RELEASE_KIND_RESOURCE);
|
||||
@ -2726,7 +2726,7 @@ G_Resource *gp_run_render(G_RenderSig *gp_render_sig, G_RenderParams params)
|
||||
}
|
||||
|
||||
/* Allocate ui buffers */
|
||||
if (rsig->ui_target && !v2i32_eq(ui_size, rsig->ui_target->texture_size)) {
|
||||
if (rsig->ui_target && !EqVec2I32(ui_size, rsig->ui_target->texture_size)) {
|
||||
fenced_release(rsig->ui_target, FENCED_RELEASE_KIND_RESOURCE);
|
||||
rsig->ui_target = 0;
|
||||
}
|
||||
@ -2751,8 +2751,8 @@ G_Resource *gp_run_render(G_RenderSig *gp_render_sig, G_RenderParams params)
|
||||
Mat4x4 blit_vp_matrix = ZI;
|
||||
{
|
||||
Xform xf = render_to_ui_xf;
|
||||
xf = ScaleXform(xf, V2(render_size.x, render_size.y));
|
||||
xf = TranslateXform(xf, V2(0.5, 0.5));
|
||||
xf = ScaleXform(xf, VEC2(render_size.x, render_size.y));
|
||||
xf = TranslateXform(xf, VEC2(0.5, 0.5));
|
||||
blit_vp_matrix = calculate_vp(xf, ui_viewport.width, ui_viewport.height);
|
||||
}
|
||||
|
||||
@ -3287,7 +3287,7 @@ internal struct swapchain_buffer *update_swapchain(struct swapchain *swapchain,
|
||||
__prof;
|
||||
resolution.x = MaxI32(resolution.x, 1);
|
||||
resolution.y = MaxI32(resolution.y, 1);
|
||||
b32 should_rebuild = !v2i32_eq(swapchain->resolution, resolution);
|
||||
b32 should_rebuild = !EqVec2I32(swapchain->resolution, resolution);
|
||||
if (should_rebuild) {
|
||||
HRESULT hr = 0;
|
||||
struct command_queue *cq = G.command_queues[DX12_QUEUE_DIRECT];
|
||||
@ -3360,15 +3360,15 @@ internal void present_blit(struct swapchain_buffer *dst, struct dx12_resource *s
|
||||
ID3D12DescriptorHeap *heaps[] = { descriptor_heap->heap };
|
||||
ID3D12GraphicsCommandList_SetDescriptorHeaps(cl->cl, countof(heaps), heaps);
|
||||
|
||||
Rect viewport_rect = RectFromV2(V2(0, 0), V2(swapchain->resolution.x, swapchain->resolution.y));
|
||||
Rect viewport_rect = RectFromVec2(VEC2(0, 0), VEC2(swapchain->resolution.x, swapchain->resolution.y));
|
||||
D3D12_VIEWPORT viewport = viewport_from_rect(viewport_rect);
|
||||
D3D12_RECT scissor = scissor_from_rect(viewport_rect);
|
||||
|
||||
Mat4x4 vp_matrix = ZI;
|
||||
{
|
||||
Xform xf = src_xf;
|
||||
xf = ScaleXform(xf, V2(src->texture_size.x, src->texture_size.y));
|
||||
xf = TranslateXform(xf, V2(0.5, 0.5));
|
||||
xf = ScaleXform(xf, VEC2(src->texture_size.x, src->texture_size.y));
|
||||
xf = TranslateXform(xf, VEC2(0.5, 0.5));
|
||||
vp_matrix = calculate_vp(xf, viewport.Width, viewport.Height);
|
||||
}
|
||||
|
||||
|
||||
@ -481,7 +481,7 @@ internal f64 interpret_number(String src)
|
||||
while (pos <= whole_right) {
|
||||
u8 digit = MinU8(src.text[pos] - 48, 9);
|
||||
u64 exp = whole_right - pos;
|
||||
res += digit * math_pow_u64(10, exp);
|
||||
res += digit * PowU64(10, exp);
|
||||
++pos;
|
||||
}
|
||||
res *= whole_sign;
|
||||
@ -494,11 +494,11 @@ internal f64 interpret_number(String src)
|
||||
while (pos <= fraction_right) {
|
||||
u8 digit = MinU8(src.text[pos] - 48, 9);
|
||||
u64 exp = fraction_right - pos;
|
||||
frac_whole += digit * math_pow_u64(10, exp);
|
||||
frac_whole += digit * PowU64(10, exp);
|
||||
++pos;
|
||||
}
|
||||
|
||||
res += (f64)frac_whole / math_pow_u64(10, (fraction_right - fraction_left + 1));
|
||||
res += (f64)frac_whole / PowU64(10, (fraction_right - fraction_left + 1));
|
||||
}
|
||||
|
||||
/* Process exponent part */
|
||||
@ -508,14 +508,14 @@ internal f64 interpret_number(String src)
|
||||
while (pos <= exponent_right) {
|
||||
u8 digit = MinU8(src.text[pos] - 48, 9);
|
||||
u64 exp = exponent_right - pos;
|
||||
exponent_whole += digit * math_pow_u64(10, exp);
|
||||
exponent_whole += digit * PowU64(10, exp);
|
||||
++pos;
|
||||
}
|
||||
|
||||
if (exponent_sign >= 0) {
|
||||
res *= math_pow_u64(10, exponent_whole);
|
||||
res *= PowU64(10, exponent_whole);
|
||||
} else {
|
||||
res /= math_pow_u64(10, exponent_whole);
|
||||
res /= PowU64(10, exponent_whole);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -67,8 +67,8 @@ M_StartupReceipt mixer_startup(void)
|
||||
{
|
||||
__prof;
|
||||
G.track_arena = AllocArena(Gibi(64));
|
||||
G.listener_pos = V2(0, 0);
|
||||
G.listener_dir = V2(0, -1);
|
||||
G.listener_pos = VEC2(0, 0);
|
||||
G.listener_dir = VEC2(0, -1);
|
||||
return (M_StartupReceipt) { 0 };
|
||||
}
|
||||
|
||||
@ -236,7 +236,7 @@ void mixer_set_listener(Vec2 pos, Vec2 dir)
|
||||
P_Lock lock = P_LockE(&G.mutex);
|
||||
{
|
||||
G.listener_pos = pos;
|
||||
G.listener_dir = v2_norm(dir);
|
||||
G.listener_dir = NormVec2(dir);
|
||||
}
|
||||
P_Unlock(&lock);
|
||||
}
|
||||
@ -267,8 +267,8 @@ M_PcmF32 mixer_update(Arena *arena, u64 frame_count)
|
||||
res.count = frame_count * 2;
|
||||
res.samples = PushArray(arena, f32, res.count);
|
||||
|
||||
Vec2 listener_pos = V2(0, 0);
|
||||
Vec2 listener_dir = V2(0, 0);
|
||||
Vec2 listener_pos = VEC2(0, 0);
|
||||
Vec2 listener_dir = VEC2(0, 0);
|
||||
|
||||
/* Create temp array of mixes */
|
||||
struct mix **mixes = 0;
|
||||
@ -312,12 +312,12 @@ M_PcmF32 mixer_update(Arena *arena, u64 frame_count)
|
||||
if (source_is_stereo) {
|
||||
source_samples_count = frame_count * 2;
|
||||
/* Round <samples_count * speed> to nearest frame boundary (nearest multiple of 2) */
|
||||
source_samples_count = (u64)math_ceil_to_int((f32)source_samples_count * speed);
|
||||
source_samples_count = (u64)CeilF32ToI32((f32)source_samples_count * speed);
|
||||
source_samples_count &= ~1;
|
||||
} else {
|
||||
source_samples_count = frame_count;
|
||||
/* Round <samples_count * speed> to nearest sample */
|
||||
source_samples_count = (u64)math_round_to_int((f32)source_samples_count * speed);
|
||||
source_samples_count = (u64)RoundF32ToI32((f32)source_samples_count * speed);
|
||||
}
|
||||
|
||||
u64 source_sample_pos_start = mix->source_pos;
|
||||
@ -357,8 +357,8 @@ M_PcmF32 mixer_update(Arena *arena, u64 frame_count)
|
||||
/* 16 bit Stereo -> 32 bit Stereo */
|
||||
for (u64 out_frame_pos = 0; out_frame_pos < out_frames_count; ++out_frame_pos) {
|
||||
f32 in_frame_pos_exact = source_frame_pos_start + (((f32)out_frame_pos / (f32)out_frames_count) * (f32)source_frames_count);
|
||||
u32 in_frame_pos_prev = math_floor_to_int(in_frame_pos_exact);
|
||||
u32 in_frame_pos_next = math_ceil_to_int(in_frame_pos_exact);
|
||||
u32 in_frame_pos_prev = FloorF32ToI32(in_frame_pos_exact);
|
||||
u32 in_frame_pos_next = CeilF32ToI32(in_frame_pos_exact);
|
||||
|
||||
/* Sample source */
|
||||
f32 sample1_prev = sample_sound(source, (in_frame_pos_prev * 2) + 0, desc.looping) * (1.f / 32768.f);
|
||||
@ -368,8 +368,8 @@ M_PcmF32 mixer_update(Arena *arena, u64 frame_count)
|
||||
|
||||
/* Lerp */
|
||||
f32 t = in_frame_pos_exact - (f32)in_frame_pos_prev;
|
||||
f32 sample1 = math_lerp_f32(sample1_prev, sample1_next, t);
|
||||
f32 sample2 = math_lerp_f32(sample2_prev, sample2_next, t);
|
||||
f32 sample1 = LerpF32(sample1_prev, sample1_next, t);
|
||||
f32 sample2 = LerpF32(sample2_prev, sample2_next, t);
|
||||
|
||||
out_samples[(out_frame_pos * 2) + 0] += sample1;
|
||||
out_samples[(out_frame_pos * 2) + 1] += sample2;
|
||||
@ -378,8 +378,8 @@ M_PcmF32 mixer_update(Arena *arena, u64 frame_count)
|
||||
/* 16 bit Mono -> 32 bit Stereo */
|
||||
for (u64 out_frame_pos = 0; out_frame_pos < out_frames_count; ++out_frame_pos) {
|
||||
f32 in_frame_pos_exact = source_frame_pos_start + (((f32)out_frame_pos / (f32)out_frames_count) * (f32)source_frames_count);
|
||||
u32 in_frame_pos_prev = math_floor_to_int(in_frame_pos_exact);
|
||||
u32 in_frame_pos_next = math_ceil_to_int(in_frame_pos_exact);
|
||||
u32 in_frame_pos_prev = FloorF32ToI32(in_frame_pos_exact);
|
||||
u32 in_frame_pos_next = CeilF32ToI32(in_frame_pos_exact);
|
||||
|
||||
/* Sample source */
|
||||
f32 sample_prev = sample_sound(source, in_frame_pos_prev, desc.looping) * (1.f / 32768.f);
|
||||
@ -387,7 +387,7 @@ M_PcmF32 mixer_update(Arena *arena, u64 frame_count)
|
||||
|
||||
/* Lerp */
|
||||
f32 t = (f32)in_frame_pos_exact - in_frame_pos_prev;
|
||||
f32 sample = math_lerp_f32(sample_prev, sample_next, t);
|
||||
f32 sample = LerpF32(sample_prev, sample_next, t);
|
||||
|
||||
out_samples[(out_frame_pos * 2) + 0] += sample;
|
||||
out_samples[(out_frame_pos * 2) + 1] += sample;
|
||||
@ -410,11 +410,11 @@ M_PcmF32 mixer_update(Arena *arena, u64 frame_count)
|
||||
Vec2 pos = desc.pos;
|
||||
|
||||
/* If sound pos = listener pos, pretend sound is close in front of listener. */
|
||||
if (v2_eq(listener_pos, pos)) {
|
||||
pos = v2_add(listener_pos, v2_mul(listener_dir, 0.001f));
|
||||
if (EqVec2(listener_pos, pos)) {
|
||||
pos = AddVec2(listener_pos, MulVec2(listener_dir, 0.001f));
|
||||
}
|
||||
Vec2 sound_rel = v2_sub(pos, listener_pos);
|
||||
Vec2 sound_rel_dir = v2_norm(sound_rel);
|
||||
Vec2 sound_rel = SubVec2(pos, listener_pos);
|
||||
Vec2 sound_rel_dir = NormVec2(sound_rel);
|
||||
|
||||
/* Calculate volume */
|
||||
f32 volume_start = effect_data->spatial_volume;
|
||||
@ -424,7 +424,7 @@ M_PcmF32 mixer_update(Arena *arena, u64 frame_count)
|
||||
* h = `rolloff_height`
|
||||
* s = `rolloff_scale`
|
||||
*/
|
||||
f32 dist = v2_len(sound_rel);
|
||||
f32 dist = Vec2Len(sound_rel);
|
||||
f32 v = (dist / rolloff_scale) + 1.0f;
|
||||
volume_end = rolloff_height * (1.0f / (v * v));
|
||||
}
|
||||
@ -432,14 +432,14 @@ M_PcmF32 mixer_update(Arena *arena, u64 frame_count)
|
||||
|
||||
/* Calculate pan */
|
||||
f32 pan_start = effect_data->spatial_pan;
|
||||
f32 pan_end = v2_wedge(listener_dir, sound_rel_dir) * pan_scale;
|
||||
f32 pan_end = WedgeVec2(listener_dir, sound_rel_dir) * pan_scale;
|
||||
effect_data->spatial_pan = pan_end;
|
||||
|
||||
/* Spatialize samples */
|
||||
for (u64 frame_pos = 0; frame_pos < frame_count; ++frame_pos) {
|
||||
f32 t = (f32)frame_pos / (f32)(frame_count - 1);
|
||||
f32 volume = math_lerp_f32(volume_start, volume_end, t);
|
||||
f32 pan = math_lerp_f32(pan_start, pan_end, t);
|
||||
f32 volume = LerpF32(volume_start, volume_end, t);
|
||||
f32 pan = LerpF32(pan_start, pan_end, t);
|
||||
|
||||
u64 sample1_index = frame_pos * 2;
|
||||
u64 sample2_index = sample1_index + 1;
|
||||
|
||||
@ -8,7 +8,7 @@
|
||||
.speed = 1.0, \
|
||||
.looping = 0, \
|
||||
\
|
||||
.pos = V2(0, 0), \
|
||||
.pos = VEC2(0, 0), \
|
||||
\
|
||||
__VA_ARGS__ \
|
||||
})
|
||||
|
||||
@ -144,7 +144,7 @@ b32 P_W32_TryReleaseThread(P_W32_Thread *thread, f32 timeout_seconds)
|
||||
if (handle)
|
||||
{
|
||||
/* Wait for thread to stop */
|
||||
DWORD timeout_ms = (timeout_seconds > 10000000) ? INFINITE : math_round_to_int(timeout_seconds * 1000);
|
||||
DWORD timeout_ms = (timeout_seconds > 10000000) ? INFINITE : RoundF32ToI32(timeout_seconds * 1000);
|
||||
DWORD wait_res = WaitForSingleObject(handle, timeout_ms);
|
||||
if (wait_res == WAIT_OBJECT_0)
|
||||
{
|
||||
@ -1161,7 +1161,7 @@ P_W32_ThreadDef(P_W32_JobSchedulerEntryFunc, _)
|
||||
periods_sum_ns += (f64)periods[i];
|
||||
}
|
||||
f64 mean_ns = periods_sum_ns / (f64)countof(periods);
|
||||
Atomic64FetchSet(&g->current_scheduler_cycle_period_ns.v, math_round_to_int64(mean_ns));
|
||||
Atomic64FetchSet(&g->current_scheduler_cycle_period_ns.v, RoundF64ToI64(mean_ns));
|
||||
}
|
||||
|
||||
{
|
||||
@ -1552,10 +1552,10 @@ LRESULT CALLBACK P_W32_Win32WindowProc(HWND hwnd, UINT msg, WPARAM wparam, LPARA
|
||||
/* Clip cursor in window window */
|
||||
if (cursor_flags & P_W32_CursorFlag_EnableClip)
|
||||
{
|
||||
i32 left = window->x + math_round_to_int(window->cursor_clip_bounds.x);
|
||||
i32 right = left + math_round_to_int(window->cursor_clip_bounds.width);
|
||||
i32 top = window->y + math_round_to_int(window->cursor_clip_bounds.y);
|
||||
i32 bottom = top + math_round_to_int(window->cursor_clip_bounds.height);
|
||||
i32 left = window->x + RoundF32ToI32(window->cursor_clip_bounds.x);
|
||||
i32 right = left + RoundF32ToI32(window->cursor_clip_bounds.width);
|
||||
i32 top = window->y + RoundF32ToI32(window->cursor_clip_bounds.y);
|
||||
i32 bottom = top + RoundF32ToI32(window->cursor_clip_bounds.height);
|
||||
RECT clip = {
|
||||
.left = ClampI32(left, window->x, window->x + window->width),
|
||||
.right = ClampI32(right, window->x, window->x + window->width),
|
||||
@ -1789,7 +1789,7 @@ LRESULT CALLBACK P_W32_Win32WindowProc(HWND hwnd, UINT msg, WPARAM wparam, LPARA
|
||||
(P_WindowEvent)
|
||||
{
|
||||
.kind = P_WindowEventKind_CursorMove,
|
||||
.cursor_position = V2(x, y)
|
||||
.cursor_position = VEC2(x, y)
|
||||
}
|
||||
);
|
||||
} break;
|
||||
@ -1815,7 +1815,7 @@ LRESULT CALLBACK P_W32_Win32WindowProc(HWND hwnd, UINT msg, WPARAM wparam, LPARA
|
||||
{
|
||||
i32 x = raw.data.mouse.lLastX;
|
||||
i32 y = raw.data.mouse.lLastY;
|
||||
Vec2 delta = V2(x, y);
|
||||
Vec2 delta = VEC2(x, y);
|
||||
P_W32_ProcessWindowEvent(
|
||||
window,
|
||||
(P_WindowEvent)
|
||||
@ -1963,7 +1963,7 @@ void P_Wait(volatile void *addr, void *cmp, u32 size, i64 timeout_ns)
|
||||
else if (timeout_ns != 0)
|
||||
{
|
||||
timeout_ms = timeout_ns / 1000000;
|
||||
timeout_ms += (timeout_ms == 0) * math_fsign(timeout_ns);
|
||||
timeout_ms += (timeout_ms == 0) * SignF32(timeout_ns);
|
||||
}
|
||||
if (addr == 0)
|
||||
{
|
||||
@ -2748,13 +2748,13 @@ void P_ToggleWindowTopmost(P_Window *p_window)
|
||||
Vec2 P_GetWindowSize(P_Window *p_window)
|
||||
{
|
||||
P_W32_Window *window = (P_W32_Window *)p_window;
|
||||
return V2((f32)window->width, (f32)window->height);
|
||||
return VEC2((f32)window->width, (f32)window->height);
|
||||
}
|
||||
|
||||
Vec2 P_GetWindowMonitorSize(P_Window *p_window)
|
||||
{
|
||||
P_W32_Window *window = (P_W32_Window *)p_window;
|
||||
return V2((f32)window->monitor_width, (f32)window->monitor_height);
|
||||
return VEC2((f32)window->monitor_width, (f32)window->monitor_height);
|
||||
}
|
||||
|
||||
u64 P_GetInternalWindowHandle(P_Window *p_window)
|
||||
|
||||
@ -97,28 +97,28 @@ P_WindowSettings *settings_deserialize(Arena *arena, String src, String *error_o
|
||||
error = LIT("Expected number for \"x\"");
|
||||
goto abort;
|
||||
}
|
||||
settings->floating_x = math_round_to_int(child->value.number);
|
||||
settings->floating_x = RoundF32ToI32(child->value.number);
|
||||
found_x = 1;
|
||||
} else if (string_eq(key, LIT("y"))) {
|
||||
if (child->type != JSON_TYPE_NUMBER) {
|
||||
error = LIT("Expected number for \"y\"");
|
||||
goto abort;
|
||||
}
|
||||
settings->floating_y = math_round_to_int(child->value.number);
|
||||
settings->floating_y = RoundF32ToI32(child->value.number);
|
||||
found_y = 1;
|
||||
} else if (string_eq(key, LIT("width"))) {
|
||||
if (child->type != JSON_TYPE_NUMBER) {
|
||||
error = LIT("Expected number for \"width\"");
|
||||
goto abort;
|
||||
}
|
||||
settings->floating_width = math_round_to_int(child->value.number);
|
||||
settings->floating_width = RoundF32ToI32(child->value.number);
|
||||
found_width = 1;
|
||||
} else if (string_eq(key, LIT("height"))) {
|
||||
if (child->type != JSON_TYPE_NUMBER) {
|
||||
error = LIT("Expected number for \"height\"");
|
||||
goto abort;
|
||||
}
|
||||
settings->floating_height = math_round_to_int(child->value.number);
|
||||
settings->floating_height = RoundF32ToI32(child->value.number);
|
||||
found_height = 1;
|
||||
}
|
||||
}
|
||||
|
||||
@ -542,7 +542,7 @@ Snapshot *sim_snapshot_from_closest_tick_gte(Client *client, u64 tick)
|
||||
|
||||
Vec2I32 sim_world_tile_index_from_pos(Vec2 pos)
|
||||
{
|
||||
Vec2I32 res = V2I32(pos.x * SIM_TILES_PER_UNIT_SQRT, pos.y * SIM_TILES_PER_UNIT_SQRT);
|
||||
Vec2I32 res = VEC2I32(pos.x * SIM_TILES_PER_UNIT_SQRT, pos.y * SIM_TILES_PER_UNIT_SQRT);
|
||||
res.x -= pos.x < 0;
|
||||
res.y -= pos.y < 0;
|
||||
return res;
|
||||
@ -621,7 +621,7 @@ Snapshot *sim_snapshot_alloc_from_lerp(Client *client, Snapshot *ss0, Snapshot *
|
||||
b32 should_blend = 1;
|
||||
if (ss0->continuity_gen == ss1->continuity_gen && 0 < blend && blend < 1) {
|
||||
ss = sim_snapshot_alloc(client, ss0, ss0->tick);
|
||||
} else if (math_round_to_int64(blend) <= 0) {
|
||||
} else if (RoundF64ToI64(blend) <= 0) {
|
||||
ss = sim_snapshot_alloc(client, ss0, ss0->tick);
|
||||
should_blend = 0;
|
||||
} else {
|
||||
@ -637,8 +637,8 @@ Snapshot *sim_snapshot_alloc_from_lerp(Client *client, Snapshot *ss0, Snapshot *
|
||||
|
||||
if (should_blend) {
|
||||
/* Blend time */
|
||||
ss->sim_dt_ns = math_lerp_i64(ss0->sim_dt_ns, ss1->sim_dt_ns, blend);
|
||||
ss->sim_time_ns = math_lerp_i64(ss0->sim_time_ns, ss1->sim_time_ns, blend);
|
||||
ss->sim_dt_ns = LerpI64(ss0->sim_dt_ns, ss1->sim_dt_ns, blend);
|
||||
ss->sim_time_ns = LerpI64(ss0->sim_time_ns, ss1->sim_time_ns, blend);
|
||||
|
||||
/* Blend entities */
|
||||
{
|
||||
|
||||
@ -462,7 +462,7 @@ Xform sim_ent_get_local_xform(Ent *ent)
|
||||
|
||||
void sim_ent_set_xform(Ent *ent, Xform xf)
|
||||
{
|
||||
if (!XformEq(xf, ent->_xform)) {
|
||||
if (!EqXform(xf, ent->_xform)) {
|
||||
Snapshot *ss = ent->ss;
|
||||
/* Update local xform */
|
||||
if (ent->is_top) {
|
||||
@ -480,7 +480,7 @@ void sim_ent_set_xform(Ent *ent, Xform xf)
|
||||
|
||||
void sim_ent_set_local_xform(Ent *ent, Xform xf)
|
||||
{
|
||||
if (!XformEq(xf, ent->_local_xform)) {
|
||||
if (!EqXform(xf, ent->_local_xform)) {
|
||||
ent->_local_xform = xf;
|
||||
ent->_is_xform_dirty = 1;
|
||||
sim_ent_mark_child_xforms_dirty(ent->ss, ent);
|
||||
@ -494,7 +494,7 @@ void sim_ent_set_local_xform(Ent *ent, Xform xf)
|
||||
void sim_ent_set_linear_velocity(Ent *ent, Vec2 velocity)
|
||||
{
|
||||
if (sim_ent_has_prop(ent, SEPROP_KINEMATIC) || sim_ent_has_prop(ent, SEPROP_DYNAMIC)) {
|
||||
ent->linear_velocity = v2_clamp_len(velocity, SIM_MAX_LINEAR_VELOCITY);
|
||||
ent->linear_velocity = ClampVec2Len(velocity, SIM_MAX_LINEAR_VELOCITY);
|
||||
}
|
||||
}
|
||||
|
||||
@ -510,13 +510,13 @@ void sim_ent_apply_linear_impulse(Ent *ent, Vec2 impulse, Vec2 point)
|
||||
if (sim_ent_has_prop(ent, SEPROP_DYNAMIC)) {
|
||||
Xform xf = sim_ent_get_xform(ent);
|
||||
Vec2 center = xf.og;
|
||||
f32 scale = math_fabs(GetXformDeterminant(xf));
|
||||
f32 scale = AbsF32(DeterminantFromXform(xf));
|
||||
f32 inv_mass = 1.f / (ent->mass_unscaled * scale);
|
||||
f32 inv_inertia = 1.f / (ent->inertia_unscaled * scale);
|
||||
|
||||
Vec2 vcp = v2_sub(point, center);
|
||||
sim_ent_set_linear_velocity(ent, v2_add(ent->linear_velocity, v2_mul(impulse, inv_mass)));
|
||||
sim_ent_set_angular_velocity(ent, v2_wedge(vcp, impulse) * inv_inertia);
|
||||
Vec2 vcp = SubVec2(point, center);
|
||||
sim_ent_set_linear_velocity(ent, AddVec2(ent->linear_velocity, MulVec2(impulse, inv_mass)));
|
||||
sim_ent_set_angular_velocity(ent, WedgeVec2(vcp, impulse) * inv_inertia);
|
||||
}
|
||||
}
|
||||
|
||||
@ -524,17 +524,17 @@ void sim_ent_apply_linear_impulse_to_center(Ent *ent, Vec2 impulse)
|
||||
{
|
||||
if (sim_ent_has_prop(ent, SEPROP_DYNAMIC)) {
|
||||
Xform xf = sim_ent_get_xform(ent);
|
||||
f32 scale = math_fabs(GetXformDeterminant(xf));
|
||||
f32 scale = AbsF32(DeterminantFromXform(xf));
|
||||
f32 inv_mass = 1.f / (ent->mass_unscaled * scale);
|
||||
|
||||
sim_ent_set_linear_velocity(ent, v2_add(ent->linear_velocity, v2_mul(impulse, inv_mass)));
|
||||
sim_ent_set_linear_velocity(ent, AddVec2(ent->linear_velocity, MulVec2(impulse, inv_mass)));
|
||||
}
|
||||
}
|
||||
|
||||
void sim_ent_apply_force_to_center(Ent *ent, Vec2 force)
|
||||
{
|
||||
if (sim_ent_has_prop(ent, SEPROP_DYNAMIC)) {
|
||||
ent->force = v2_add(ent->force, force);
|
||||
ent->force = AddVec2(ent->force, force);
|
||||
}
|
||||
}
|
||||
|
||||
@ -542,7 +542,7 @@ void sim_ent_apply_angular_impulse(Ent *ent, f32 impulse)
|
||||
{
|
||||
if (sim_ent_has_prop(ent, SEPROP_DYNAMIC)) {
|
||||
Xform xf = sim_ent_get_xform(ent);
|
||||
f32 scale = math_fabs(GetXformDeterminant(xf));
|
||||
f32 scale = AbsF32(DeterminantFromXform(xf));
|
||||
f32 inv_inertia = 1.f / (ent->inertia_unscaled * scale);
|
||||
sim_ent_set_angular_velocity(ent, ent->angular_velocity + impulse * inv_inertia);
|
||||
}
|
||||
@ -597,25 +597,25 @@ void sim_ent_lerp(Ent *e, Ent *e0, Ent *e1, f64 blend)
|
||||
sim_ent_set_xform(e, LerpXform(e0_xf, e1_xf, blend));
|
||||
}
|
||||
|
||||
e->control_force = math_lerp_f32(e0->control_force, e1->control_force, blend);
|
||||
e->control_torque = math_lerp_f32(e0->control_torque, e1->control_torque, blend);
|
||||
e->control_force = LerpF32(e0->control_force, e1->control_force, blend);
|
||||
e->control_torque = LerpF32(e0->control_torque, e1->control_torque, blend);
|
||||
|
||||
e->linear_velocity = v2_lerp(e0->linear_velocity, e1->linear_velocity, blend);
|
||||
e->angular_velocity = math_lerp_angle(e0->angular_velocity, e1->angular_velocity, blend);
|
||||
e->linear_velocity = LerpVec2(e0->linear_velocity, e1->linear_velocity, blend);
|
||||
e->angular_velocity = LerpAngleF32(e0->angular_velocity, e1->angular_velocity, blend);
|
||||
|
||||
e->control.move = v2_lerp(e0->control.move, e1->control.move, blend);
|
||||
e->control.focus = v2_lerp(e0->control.focus, e1->control.focus, blend);
|
||||
e->control.move = LerpVec2(e0->control.move, e1->control.move, blend);
|
||||
e->control.focus = LerpVec2(e0->control.focus, e1->control.focus, blend);
|
||||
|
||||
e->sprite_local_xform = LerpXform(e0->sprite_local_xform, e1->sprite_local_xform, blend);
|
||||
e->animation_last_frame_change_time_ns = math_lerp_i64(e0->animation_last_frame_change_time_ns, e1->animation_last_frame_change_time_ns, (f64)blend);
|
||||
e->animation_frame = (u32)math_round_to_int(math_lerp_f32(e0->animation_frame, e1->animation_frame, blend));
|
||||
e->animation_last_frame_change_time_ns = LerpI64(e0->animation_last_frame_change_time_ns, e1->animation_last_frame_change_time_ns, (f64)blend);
|
||||
e->animation_frame = (u32)RoundF32ToI32(LerpF32(e0->animation_frame, e1->animation_frame, blend));
|
||||
|
||||
e->camera_quad_xform = LerpXform(e0->camera_quad_xform, e1->camera_quad_xform, blend);
|
||||
e->camera_xform_target = LerpXform(e0->camera_xform_target, e1->camera_xform_target, blend);
|
||||
e->shake = math_lerp_f32(e0->shake, e1->shake, blend);
|
||||
e->shake = LerpF32(e0->shake, e1->shake, blend);
|
||||
|
||||
e->tracer_gradient_start = v2_lerp(e0->tracer_gradient_start, e1->tracer_gradient_start, blend);
|
||||
e->tracer_gradient_end = v2_lerp(e0->tracer_gradient_end, e1->tracer_gradient_end, blend);
|
||||
e->tracer_gradient_start = LerpVec2(e0->tracer_gradient_start, e1->tracer_gradient_start, blend);
|
||||
e->tracer_gradient_end = LerpVec2(e0->tracer_gradient_end, e1->tracer_gradient_end, blend);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -107,7 +107,7 @@ void phys_create_and_update_contacts(PhysStepCtx *ctx, f32 elapsed_dt, u64 phys_
|
||||
}
|
||||
constraint = &constraint_ent->contact_constraint_data;
|
||||
constraint->normal = collider_res.normal;
|
||||
constraint->friction = math_sqrt(e0->friction * e1->friction);
|
||||
constraint->friction = SqrtF32(e0->friction * e1->friction);
|
||||
|
||||
/* Delete old contacts that are no longer present */
|
||||
for (u32 i = 0; i < constraint->num_points; ++i) {
|
||||
@ -151,8 +151,8 @@ void phys_create_and_update_contacts(PhysStepCtx *ctx, f32 elapsed_dt, u64 phys_
|
||||
}
|
||||
|
||||
/* Update points & separation */
|
||||
contact->vcp0 = v2_sub(point, e0_xf.og);
|
||||
contact->vcp1 = v2_sub(point, e1_xf.og);
|
||||
contact->vcp0 = SubVec2(point, e0_xf.og);
|
||||
contact->vcp1 = SubVec2(point, e1_xf.og);
|
||||
contact->starting_separation = sep;
|
||||
|
||||
#if DeveloperIsEnabled
|
||||
@ -167,11 +167,11 @@ void phys_create_and_update_contacts(PhysStepCtx *ctx, f32 elapsed_dt, u64 phys_
|
||||
Vec2 dir1 = e1->collision_dir;
|
||||
f32 threshold = 0.5;
|
||||
b32 is_wrong_dir = 0;
|
||||
if (!v2_is_zero(dir0)) {
|
||||
is_wrong_dir = v2_dot(dir0, normal) <= threshold;
|
||||
if (!IsVec2Zero(dir0)) {
|
||||
is_wrong_dir = DotVec2(dir0, normal) <= threshold;
|
||||
}
|
||||
if (!v2_is_zero(dir1) && !is_wrong_dir) {
|
||||
is_wrong_dir = v2_dot(dir1, v2_neg(normal)) <= threshold;
|
||||
if (!IsVec2Zero(dir1) && !is_wrong_dir) {
|
||||
is_wrong_dir = DotVec2(dir1, NegVec2(normal)) <= threshold;
|
||||
}
|
||||
constraint->wrong_dir = is_wrong_dir;
|
||||
}
|
||||
@ -188,7 +188,7 @@ void phys_create_and_update_contacts(PhysStepCtx *ctx, f32 elapsed_dt, u64 phys_
|
||||
/* Calculate point */
|
||||
Vec2 midpoint = collider_res.points[0].point;
|
||||
if (collider_res.num_points > 1) {
|
||||
midpoint = v2_add(midpoint, v2_mul(v2_sub(collider_res.points[1].point, midpoint), 0.5f));
|
||||
midpoint = AddVec2(midpoint, MulVec2(SubVec2(collider_res.points[1].point, midpoint), 0.5f));
|
||||
}
|
||||
data.point = midpoint;
|
||||
|
||||
@ -199,11 +199,11 @@ void phys_create_and_update_contacts(PhysStepCtx *ctx, f32 elapsed_dt, u64 phys_
|
||||
Vec2 v1 = e1->linear_velocity;
|
||||
f32 w0 = e0->angular_velocity;
|
||||
f32 w1 = e1->angular_velocity;
|
||||
Vec2 vcp1 = v2_sub(midpoint, e1_xf.og);
|
||||
Vec2 vcp0 = v2_sub(midpoint, e0_xf.og);
|
||||
Vec2 vel0 = v2_add(v0, v2_perp_mul(vcp0, w0));
|
||||
Vec2 vel1 = v2_add(v1, v2_perp_mul(vcp1, w1));
|
||||
vrel = v2_sub(vel0, vel1);
|
||||
Vec2 vcp1 = SubVec2(midpoint, e1_xf.og);
|
||||
Vec2 vcp0 = SubVec2(midpoint, e0_xf.og);
|
||||
Vec2 vel0 = AddVec2(v0, MulPerpVec2(vcp0, w0));
|
||||
Vec2 vel1 = AddVec2(v1, MulPerpVec2(vcp1, w1));
|
||||
vrel = SubVec2(vel0, vel1);
|
||||
}
|
||||
data.vrel = vrel;
|
||||
|
||||
@ -211,8 +211,8 @@ void phys_create_and_update_contacts(PhysStepCtx *ctx, f32 elapsed_dt, u64 phys_
|
||||
CollisionData data_inverted = data;
|
||||
data_inverted.e0 = data.e1;
|
||||
data_inverted.e1 = data.e0;
|
||||
data_inverted.normal = v2_neg(data.normal);
|
||||
data_inverted.vrel = v2_neg(data.vrel);
|
||||
data_inverted.normal = NegVec2(data.normal);
|
||||
data_inverted.vrel = NegVec2(data.vrel);
|
||||
|
||||
/* Run callback twice for both e0 & e1 */
|
||||
b32 skip_solve0 = collision_callback(&data, sim_step_ctx);
|
||||
@ -282,7 +282,7 @@ void phys_prepare_contacts(PhysStepCtx *ctx, u64 phys_iteration)
|
||||
Ent *e1 = sim_ent_from_id(ss, constraint->e1);
|
||||
if (constraint->last_phys_iteration >= phys_iteration && num_points > 0 && sim_ent_is_valid_and_active(e0) && sim_ent_is_valid_and_active(e1)) {
|
||||
Vec2 normal = constraint->normal;
|
||||
Vec2 tangent = v2_perp(normal);
|
||||
Vec2 tangent = PerpVec2(normal);
|
||||
|
||||
Xform e0_xf = sim_ent_get_xform(e0);
|
||||
Xform e1_xf = sim_ent_get_xform(e1);
|
||||
@ -296,14 +296,14 @@ void phys_prepare_contacts(PhysStepCtx *ctx, u64 phys_iteration)
|
||||
{
|
||||
/* If not simulated locally or ent is not dynamic, pretend contact mass is infinite */
|
||||
if (sim_ent_should_simulate(e0) && sim_ent_has_prop(e0, SEPROP_DYNAMIC)) {
|
||||
f32 scale = math_fabs(GetXformDeterminant(e0_xf));
|
||||
f32 scale = AbsF32(DeterminantFromXform(e0_xf));
|
||||
f32 scaled_mass = e0->mass_unscaled * scale;
|
||||
f32 scaled_inertia = e0->inertia_unscaled * scale;
|
||||
inv_m0 = 1.f / scaled_mass;
|
||||
inv_i0 = 1.f / scaled_inertia;
|
||||
}
|
||||
if (sim_ent_should_simulate(e1) && sim_ent_has_prop(e1, SEPROP_DYNAMIC)) {
|
||||
f32 scale = math_fabs(GetXformDeterminant(e1_xf));
|
||||
f32 scale = AbsF32(DeterminantFromXform(e1_xf));
|
||||
f32 scaled_mass = e1->mass_unscaled * scale;
|
||||
f32 scaled_inertia = e1->inertia_unscaled * scale;
|
||||
inv_m1 = 1.f / scaled_mass;
|
||||
@ -324,16 +324,16 @@ void phys_prepare_contacts(PhysStepCtx *ctx, u64 phys_iteration)
|
||||
|
||||
/* Normal mass */
|
||||
{
|
||||
f32 vcp0_wedge = v2_wedge(vcp0, normal);
|
||||
f32 vcp1_wedge = v2_wedge(vcp1, normal);
|
||||
f32 vcp0_wedge = WedgeVec2(vcp0, normal);
|
||||
f32 vcp1_wedge = WedgeVec2(vcp1, normal);
|
||||
f32 k = (inv_m0 + inv_m1) + (inv_i0 * vcp0_wedge * vcp0_wedge) + (inv_i1 * vcp1_wedge * vcp1_wedge);
|
||||
contact->inv_normal_mass = k > 0.0f ? 1.0f / k : 0.0f;
|
||||
}
|
||||
|
||||
/* Tangent mass */
|
||||
{
|
||||
f32 vcp0_wedge = v2_wedge(vcp0, tangent);
|
||||
f32 vcp1_wedge = v2_wedge(vcp1, tangent);
|
||||
f32 vcp0_wedge = WedgeVec2(vcp0, tangent);
|
||||
f32 vcp1_wedge = WedgeVec2(vcp1, tangent);
|
||||
f32 k = (inv_m0 + inv_m1) + (inv_i0 * vcp0_wedge * vcp0_wedge) + (inv_i1 * vcp1_wedge * vcp1_wedge);
|
||||
contact->inv_tangent_mass = k > 0.0f ? 1.0f / k : 0.0f;
|
||||
}
|
||||
@ -403,20 +403,20 @@ void phys_warm_start_contacts(PhysStepCtx *ctx)
|
||||
|
||||
/* Warm start */
|
||||
Vec2 normal = constraint->normal;
|
||||
Vec2 tangent = v2_perp(normal);
|
||||
Vec2 tangent = PerpVec2(normal);
|
||||
f32 inv_num_points = 1.f / num_points;
|
||||
for (u32 i = 0; i < num_points; ++i) {
|
||||
ContactPoint *point = &constraint->points[i];
|
||||
Vec2 vcp0 = point->vcp0;
|
||||
Vec2 vcp1 = point->vcp1;
|
||||
|
||||
Vec2 impulse = v2_add(v2_mul(normal, point->normal_impulse), v2_mul(tangent, point->tangent_impulse));
|
||||
impulse = v2_mul(impulse, inv_num_points);
|
||||
Vec2 impulse = AddVec2(MulVec2(normal, point->normal_impulse), MulVec2(tangent, point->tangent_impulse));
|
||||
impulse = MulVec2(impulse, inv_num_points);
|
||||
|
||||
v0 = v2_sub(v0, v2_mul(impulse, inv_m0));
|
||||
v1 = v2_add(v1, v2_mul(impulse, inv_m1));
|
||||
w0 -= v2_wedge(vcp0, impulse) * inv_i0;
|
||||
w1 += v2_wedge(vcp1, impulse) * inv_i1;
|
||||
v0 = SubVec2(v0, MulVec2(impulse, inv_m0));
|
||||
v1 = AddVec2(v1, MulVec2(impulse, inv_m1));
|
||||
w0 -= WedgeVec2(vcp0, impulse) * inv_i0;
|
||||
w1 += WedgeVec2(vcp1, impulse) * inv_i1;
|
||||
}
|
||||
|
||||
sim_ent_set_linear_velocity(e0, v0);
|
||||
@ -462,11 +462,11 @@ void phys_solve_contacts(PhysStepCtx *ctx, f32 dt, b32 apply_bias)
|
||||
ContactPoint *point = &constraint->points[point_index];
|
||||
Vec2 vcp0 = point->vcp0;
|
||||
Vec2 vcp1 = point->vcp1;
|
||||
Vec2 p0 = v2_add(e0_xf.og, vcp0);
|
||||
Vec2 p1 = v2_add(e1_xf.og, vcp1);
|
||||
Vec2 p0 = AddVec2(e0_xf.og, vcp0);
|
||||
Vec2 p1 = AddVec2(e1_xf.og, vcp1);
|
||||
|
||||
/* FIXME: Should separation use the rotated contact points? */
|
||||
f32 separation = v2_dot(v2_sub(p1, p0), normal) + point->starting_separation;
|
||||
f32 separation = DotVec2(SubVec2(p1, p0), normal) + point->starting_separation;
|
||||
|
||||
f32 velocity_bias = 0.0f;
|
||||
f32 mass_scale = 1.0f;
|
||||
@ -477,21 +477,21 @@ void phys_solve_contacts(PhysStepCtx *ctx, f32 dt, b32 apply_bias)
|
||||
velocity_bias = separation / dt;
|
||||
} else if (apply_bias) {
|
||||
/* Soft constraint */
|
||||
SoftSpring softness = math_spring_init(CONTACT_SPRING_HZ, CONTACT_SPRING_DAMP, dt);
|
||||
SoftSpring softness = MakeSpring(CONTACT_SPRING_HZ, CONTACT_SPRING_DAMP, dt);
|
||||
f32 pushout_velocity = constraint->pushout_velocity;
|
||||
mass_scale = softness.mass_scale;
|
||||
impulse_scale = softness.impulse_scale;
|
||||
velocity_bias = MaxF32(softness.bias_rate * separation, -pushout_velocity);
|
||||
}
|
||||
|
||||
Vec2 vel0 = v2_add(v0, v2_perp_mul(vcp0, w0));
|
||||
Vec2 vel1 = v2_add(v1, v2_perp_mul(vcp1, w1));
|
||||
Vec2 vrel = v2_sub(vel0, vel1);
|
||||
Vec2 vel0 = AddVec2(v0, MulPerpVec2(vcp0, w0));
|
||||
Vec2 vel1 = AddVec2(v1, MulPerpVec2(vcp1, w1));
|
||||
Vec2 vrel = SubVec2(vel0, vel1);
|
||||
|
||||
f32 k = point->inv_normal_mass;
|
||||
|
||||
/* (to be applied along n) */
|
||||
f32 vn = v2_dot(vrel, normal);
|
||||
f32 vn = DotVec2(vrel, normal);
|
||||
f32 j = ((k * mass_scale) * (vn - velocity_bias)) - (point->normal_impulse * impulse_scale);
|
||||
|
||||
f32 old_impulse = point->normal_impulse;
|
||||
@ -499,28 +499,28 @@ void phys_solve_contacts(PhysStepCtx *ctx, f32 dt, b32 apply_bias)
|
||||
f32 delta = new_impulse - old_impulse;
|
||||
point->normal_impulse = new_impulse;
|
||||
|
||||
Vec2 impulse = v2_mul(normal, delta);
|
||||
v0 = v2_sub(v0, v2_mul(impulse, inv_m0));
|
||||
v1 = v2_add(v1, v2_mul(impulse, inv_m1));
|
||||
w0 -= v2_wedge(vcp0, impulse) * inv_i0;
|
||||
w1 += v2_wedge(vcp1, impulse) * inv_i1;
|
||||
Vec2 impulse = MulVec2(normal, delta);
|
||||
v0 = SubVec2(v0, MulVec2(impulse, inv_m0));
|
||||
v1 = AddVec2(v1, MulVec2(impulse, inv_m1));
|
||||
w0 -= WedgeVec2(vcp0, impulse) * inv_i0;
|
||||
w1 += WedgeVec2(vcp1, impulse) * inv_i1;
|
||||
}
|
||||
|
||||
/* Tangent impulse */
|
||||
Vec2 tangent = v2_perp(normal);
|
||||
Vec2 tangent = PerpVec2(normal);
|
||||
for (u32 point_index = 0; point_index < num_points; ++point_index) {
|
||||
ContactPoint *point = &constraint->points[point_index];
|
||||
Vec2 vcp0 = point->vcp0;
|
||||
Vec2 vcp1 = point->vcp1;
|
||||
|
||||
Vec2 vel0 = v2_add(v0, v2_perp_mul(vcp0, w0));
|
||||
Vec2 vel1 = v2_add(v1, v2_perp_mul(vcp1, w1));
|
||||
Vec2 vrel = v2_sub(vel0, vel1);
|
||||
Vec2 vel0 = AddVec2(v0, MulPerpVec2(vcp0, w0));
|
||||
Vec2 vel1 = AddVec2(v1, MulPerpVec2(vcp1, w1));
|
||||
Vec2 vrel = SubVec2(vel0, vel1);
|
||||
|
||||
f32 k = point->inv_tangent_mass;
|
||||
|
||||
/* (to be applied along t) */
|
||||
f32 vt = v2_dot(vrel, tangent);
|
||||
f32 vt = DotVec2(vrel, tangent);
|
||||
f32 j = vt * k;
|
||||
|
||||
f32 max_friction = constraint->friction * point->normal_impulse;
|
||||
@ -529,11 +529,11 @@ void phys_solve_contacts(PhysStepCtx *ctx, f32 dt, b32 apply_bias)
|
||||
f32 delta = new_impulse - old_impulse;
|
||||
point->tangent_impulse = new_impulse;
|
||||
|
||||
Vec2 impulse = v2_mul(tangent, delta);
|
||||
v0 = v2_sub(v0, v2_mul(impulse, inv_m0));
|
||||
v1 = v2_add(v1, v2_mul(impulse, inv_m1));
|
||||
w0 -= v2_wedge(vcp0, impulse) * inv_i0;
|
||||
w1 += v2_wedge(vcp1, impulse) * inv_i1;
|
||||
Vec2 impulse = MulVec2(tangent, delta);
|
||||
v0 = SubVec2(v0, MulVec2(impulse, inv_m0));
|
||||
v1 = AddVec2(v1, MulVec2(impulse, inv_m1));
|
||||
w0 -= WedgeVec2(vcp0, impulse) * inv_i0;
|
||||
w1 += WedgeVec2(vcp1, impulse) * inv_i1;
|
||||
}
|
||||
|
||||
sim_ent_set_linear_velocity(e0, v0);
|
||||
@ -590,8 +590,8 @@ void phys_prepare_motor_joints(PhysStepCtx *ctx)
|
||||
f32 inv_i0;
|
||||
f32 inv_i1;
|
||||
{
|
||||
f32 scale0 = math_fabs(GetXformDeterminant(e0_xf));
|
||||
f32 scale1 = math_fabs(GetXformDeterminant(e1_xf));
|
||||
f32 scale0 = AbsF32(DeterminantFromXform(e0_xf));
|
||||
f32 scale1 = AbsF32(DeterminantFromXform(e1_xf));
|
||||
inv_m0 = 1.f / (e0->mass_unscaled * scale0);
|
||||
inv_m1 = 1.f / (e1->mass_unscaled * scale1);
|
||||
inv_i0 = 1.f / (e0->inertia_unscaled * scale0);
|
||||
@ -602,11 +602,11 @@ void phys_prepare_motor_joints(PhysStepCtx *ctx)
|
||||
joint->inv_i0 = inv_i0;
|
||||
joint->inv_i1 = inv_i1;
|
||||
|
||||
joint->point_local_e0 = V2(0, 0);
|
||||
joint->point_local_e1 = V2(0, 0);
|
||||
joint->point_local_e0 = VEC2(0, 0);
|
||||
joint->point_local_e1 = VEC2(0, 0);
|
||||
|
||||
Vec2 vcp0 = v2_sub(MulXformV2(e0_xf, joint->point_local_e0), e0_xf.og);
|
||||
Vec2 vcp1 = v2_sub(MulXformV2(e1_xf, joint->point_local_e1), e1_xf.og);
|
||||
Vec2 vcp0 = SubVec2(MulXformV2(e0_xf, joint->point_local_e0), e0_xf.og);
|
||||
Vec2 vcp1 = SubVec2(MulXformV2(e1_xf, joint->point_local_e1), e1_xf.og);
|
||||
|
||||
Xform linear_mass_xf = ZI;
|
||||
linear_mass_xf.bx.x = inv_m0 + inv_m1 + vcp0.y * vcp0.y * inv_i0 + vcp1.y * vcp1.y * inv_i1;
|
||||
@ -618,7 +618,7 @@ void phys_prepare_motor_joints(PhysStepCtx *ctx)
|
||||
joint->angular_mass = 1.f / (inv_i0 + inv_i1);
|
||||
|
||||
#if !SIM_PHYSICS_ENABLE_WARM_STARTING
|
||||
joint->linear_impulse = V2(0, 0);
|
||||
joint->linear_impulse = VEC2(0, 0);
|
||||
joint->angular_impulse = 0;
|
||||
#endif
|
||||
} else {
|
||||
@ -651,13 +651,13 @@ void phys_warm_start_motor_joints(PhysStepCtx *ctx)
|
||||
f32 inv_i0 = joint->inv_i0;
|
||||
f32 inv_i1 = joint->inv_i1;
|
||||
|
||||
Vec2 vcp0 = v2_sub(MulXformV2(e0_xf, joint->point_local_e0), e0_xf.og);
|
||||
Vec2 vcp1 = v2_sub(MulXformV2(e1_xf, joint->point_local_e1), e1_xf.og);
|
||||
Vec2 vcp0 = SubVec2(MulXformV2(e0_xf, joint->point_local_e0), e0_xf.og);
|
||||
Vec2 vcp1 = SubVec2(MulXformV2(e1_xf, joint->point_local_e1), e1_xf.og);
|
||||
|
||||
sim_ent_set_linear_velocity(e0, v2_sub(e0->linear_velocity, v2_mul(joint->linear_impulse, inv_m0)));
|
||||
sim_ent_set_linear_velocity(e1, v2_add(e1->linear_velocity, v2_mul(joint->linear_impulse, inv_m1)));
|
||||
e0->angular_velocity -= (v2_wedge(vcp0, joint->linear_impulse) + joint->angular_impulse) * inv_i0;
|
||||
e1->angular_velocity += (v2_wedge(vcp1, joint->linear_impulse) + joint->angular_impulse) * inv_i1;
|
||||
sim_ent_set_linear_velocity(e0, SubVec2(e0->linear_velocity, MulVec2(joint->linear_impulse, inv_m0)));
|
||||
sim_ent_set_linear_velocity(e1, AddVec2(e1->linear_velocity, MulVec2(joint->linear_impulse, inv_m1)));
|
||||
e0->angular_velocity -= (WedgeVec2(vcp0, joint->linear_impulse) + joint->angular_impulse) * inv_i0;
|
||||
e1->angular_velocity += (WedgeVec2(vcp1, joint->linear_impulse) + joint->angular_impulse) * inv_i1;
|
||||
}
|
||||
}
|
||||
|
||||
@ -694,7 +694,7 @@ void phys_solve_motor_joints(PhysStepCtx *ctx, f32 dt)
|
||||
/* Angular constraint */
|
||||
{
|
||||
f32 max_impulse = joint->max_torque * dt;
|
||||
f32 angular_separation = math_unwind_angle(GetXformRotation(e1_xf) - GetXformRotation(e0_xf));
|
||||
f32 angular_separation = UnwindAngleF32(RotationFromXform(e1_xf) - RotationFromXform(e0_xf));
|
||||
|
||||
f32 angular_bias = angular_separation * correction_rate * inv_dt;
|
||||
|
||||
@ -709,26 +709,26 @@ void phys_solve_motor_joints(PhysStepCtx *ctx, f32 dt)
|
||||
|
||||
/* Linear constraint */
|
||||
{
|
||||
Vec2 vcp0 = v2_sub(MulXformV2(e0_xf, joint->point_local_e0), e0_xf.og);
|
||||
Vec2 vcp1 = v2_sub(MulXformV2(e1_xf, joint->point_local_e1), e1_xf.og);
|
||||
Vec2 vcp0 = SubVec2(MulXformV2(e0_xf, joint->point_local_e0), e0_xf.og);
|
||||
Vec2 vcp1 = SubVec2(MulXformV2(e1_xf, joint->point_local_e1), e1_xf.og);
|
||||
|
||||
f32 max_impulse = joint->max_force * dt;
|
||||
|
||||
Vec2 linear_separation = v2_sub(v2_add(e1_xf.og, vcp1), v2_add(e0_xf.og, vcp0));
|
||||
Vec2 linear_bias = v2_mul(linear_separation, correction_rate * inv_dt);
|
||||
Vec2 linear_separation = SubVec2(AddVec2(e1_xf.og, vcp1), AddVec2(e0_xf.og, vcp0));
|
||||
Vec2 linear_bias = MulVec2(linear_separation, correction_rate * inv_dt);
|
||||
|
||||
Vec2 vrel = v2_sub(v2_add(v1, v2_perp_mul(vcp1, w1)), v2_add(v0, v2_perp_mul(vcp0, w0)));
|
||||
Vec2 impulse = v2_neg(MulXformBasisV2(joint->linear_mass_xf, v2_add(vrel, linear_bias)));
|
||||
Vec2 vrel = SubVec2(AddVec2(v1, MulPerpVec2(vcp1, w1)), AddVec2(v0, MulPerpVec2(vcp0, w0)));
|
||||
Vec2 impulse = NegVec2(MulXformBasisV2(joint->linear_mass_xf, AddVec2(vrel, linear_bias)));
|
||||
|
||||
Vec2 old_impulse = joint->linear_impulse;
|
||||
Vec2 new_impulse = v2_clamp_len(v2_add(old_impulse, impulse), max_impulse);
|
||||
Vec2 new_impulse = ClampVec2Len(AddVec2(old_impulse, impulse), max_impulse);
|
||||
joint->linear_impulse = new_impulse;
|
||||
|
||||
Vec2 delta = v2_sub(new_impulse, old_impulse);
|
||||
v0 = v2_sub(v0, v2_mul(delta, inv_m0));
|
||||
v1 = v2_add(v1, v2_mul(delta, inv_m1));
|
||||
w0 -= v2_wedge(vcp0, delta) * inv_i0;
|
||||
w1 += v2_wedge(vcp1, delta) * inv_i1;
|
||||
Vec2 delta = SubVec2(new_impulse, old_impulse);
|
||||
v0 = SubVec2(v0, MulVec2(delta, inv_m0));
|
||||
v1 = AddVec2(v1, MulVec2(delta, inv_m1));
|
||||
w0 -= WedgeVec2(vcp0, delta) * inv_i0;
|
||||
w1 += WedgeVec2(vcp1, delta) * inv_i1;
|
||||
}
|
||||
|
||||
sim_ent_set_linear_velocity(e0, v0);
|
||||
@ -786,14 +786,14 @@ void phys_prepare_mouse_joints(PhysStepCtx *ctx)
|
||||
f32 inv_m;
|
||||
f32 inv_i;
|
||||
{
|
||||
f32 scale = math_fabs(GetXformDeterminant(xf));
|
||||
f32 scale = AbsF32(DeterminantFromXform(xf));
|
||||
inv_m = 1.f / (ent->mass_unscaled * scale);
|
||||
inv_i = 1.f / (ent->inertia_unscaled * scale);
|
||||
}
|
||||
joint->inv_m = inv_m;
|
||||
joint->inv_i = inv_i;
|
||||
|
||||
Vec2 vcp = v2_sub(MulXformV2(xf, joint->point_local_start), xf.og);
|
||||
Vec2 vcp = SubVec2(MulXformV2(xf, joint->point_local_start), xf.og);
|
||||
|
||||
Xform linear_mass_xf = ZI;
|
||||
linear_mass_xf.bx.x = inv_m + inv_i * vcp.y * vcp.y;
|
||||
@ -803,7 +803,7 @@ void phys_prepare_mouse_joints(PhysStepCtx *ctx)
|
||||
joint->linear_mass_xf = InvertXform(linear_mass_xf);
|
||||
|
||||
#if !SIM_PHYSICS_ENABLE_WARM_STARTING
|
||||
joint->linear_impulse = V2(0, 0);
|
||||
joint->linear_impulse = VEC2(0, 0);
|
||||
joint->angular_impulse = 0;
|
||||
#endif
|
||||
} else {
|
||||
@ -829,9 +829,9 @@ void phys_warm_start_mouse_joints(PhysStepCtx *ctx)
|
||||
f32 inv_m = joint->inv_m;
|
||||
f32 inv_i = joint->inv_i;
|
||||
Xform xf = sim_ent_get_xform(ent);
|
||||
Vec2 vcp = v2_sub(MulXformV2(xf, joint->point_local_start), xf.og);
|
||||
sim_ent_set_linear_velocity(ent, v2_add(ent->linear_velocity, v2_mul(joint->linear_impulse, inv_m)));
|
||||
sim_ent_set_angular_velocity(ent, ent->angular_velocity + ((v2_wedge(vcp, joint->linear_impulse) + joint->angular_impulse) * inv_i));
|
||||
Vec2 vcp = SubVec2(MulXformV2(xf, joint->point_local_start), xf.og);
|
||||
sim_ent_set_linear_velocity(ent, AddVec2(ent->linear_velocity, MulVec2(joint->linear_impulse, inv_m)));
|
||||
sim_ent_set_angular_velocity(ent, ent->angular_velocity + ((WedgeVec2(vcp, joint->linear_impulse) + joint->angular_impulse) * inv_i));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -856,7 +856,7 @@ void phys_solve_mouse_joints(PhysStepCtx *ctx, f32 dt)
|
||||
|
||||
/* Angular impulse */
|
||||
{
|
||||
SoftSpring softness = math_spring_init(joint->angular_spring_hz, joint->angular_spring_damp, dt);
|
||||
SoftSpring softness = MakeSpring(joint->angular_spring_hz, joint->angular_spring_damp, dt);
|
||||
f32 mass_scale = softness.mass_scale;
|
||||
f32 impulse_scale = softness.impulse_scale;
|
||||
f32 impulse = mass_scale * (-w / inv_i) - impulse_scale * joint->angular_impulse;
|
||||
@ -873,30 +873,30 @@ void phys_solve_mouse_joints(PhysStepCtx *ctx, f32 dt)
|
||||
Vec2 point_start = MulXformV2(xf, joint->point_local_start);
|
||||
Vec2 point_end = joint->point_end;
|
||||
|
||||
Vec2 vcp = v2_sub(point_start, xf.og);
|
||||
Vec2 separation = v2_sub(point_start, point_end);
|
||||
Vec2 vcp = SubVec2(point_start, xf.og);
|
||||
Vec2 separation = SubVec2(point_start, point_end);
|
||||
|
||||
SoftSpring softness = math_spring_init(joint->linear_spring_hz, joint->linear_spring_damp, dt);
|
||||
SoftSpring softness = MakeSpring(joint->linear_spring_hz, joint->linear_spring_damp, dt);
|
||||
f32 bias_rate = softness.bias_rate;
|
||||
f32 mass_scale = softness.mass_scale;
|
||||
f32 impulse_scale = softness.impulse_scale;
|
||||
|
||||
Vec2 bias = v2_mul(separation, bias_rate);
|
||||
Vec2 vel = v2_add(v, v2_perp_mul(vcp, w));
|
||||
Vec2 b = MulXformBasisV2(joint->linear_mass_xf, v2_add(vel, bias));
|
||||
Vec2 bias = MulVec2(separation, bias_rate);
|
||||
Vec2 vel = AddVec2(v, MulPerpVec2(vcp, w));
|
||||
Vec2 b = MulXformBasisV2(joint->linear_mass_xf, AddVec2(vel, bias));
|
||||
|
||||
Vec2 impulse = v2_mul(b, -mass_scale);
|
||||
impulse = v2_sub(impulse, v2_mul(joint->linear_impulse, impulse_scale));
|
||||
Vec2 impulse = MulVec2(b, -mass_scale);
|
||||
impulse = SubVec2(impulse, MulVec2(joint->linear_impulse, impulse_scale));
|
||||
|
||||
Vec2 old_impulse = joint->linear_impulse;
|
||||
joint->linear_impulse = v2_add(joint->linear_impulse, impulse);
|
||||
joint->linear_impulse = AddVec2(joint->linear_impulse, impulse);
|
||||
|
||||
joint->linear_impulse = v2_clamp_len(joint->linear_impulse, max_impulse);
|
||||
joint->linear_impulse = ClampVec2Len(joint->linear_impulse, max_impulse);
|
||||
|
||||
impulse = v2_sub(joint->linear_impulse, old_impulse);
|
||||
impulse = SubVec2(joint->linear_impulse, old_impulse);
|
||||
|
||||
v = v2_add(v, v2_mul(impulse, inv_m));
|
||||
w += v2_wedge(vcp, impulse) * inv_i;
|
||||
v = AddVec2(v, MulVec2(impulse, inv_m));
|
||||
w += WedgeVec2(vcp, impulse) * inv_i;
|
||||
}
|
||||
|
||||
sim_ent_set_linear_velocity(ent, v);
|
||||
@ -955,8 +955,8 @@ void phys_prepare_weld_joints(PhysStepCtx *ctx)
|
||||
f32 inv_i0;
|
||||
f32 inv_i1;
|
||||
{
|
||||
f32 scale0 = math_fabs(GetXformDeterminant(e0_xf));
|
||||
f32 scale1 = math_fabs(GetXformDeterminant(e1_xf));
|
||||
f32 scale0 = AbsF32(DeterminantFromXform(e0_xf));
|
||||
f32 scale1 = AbsF32(DeterminantFromXform(e1_xf));
|
||||
inv_m0 = 1.f / (e0->mass_unscaled * scale0);
|
||||
inv_m1 = 1.f / (e1->mass_unscaled * scale1);
|
||||
inv_i0 = 1.f / (e0->inertia_unscaled * scale0);
|
||||
@ -968,8 +968,8 @@ void phys_prepare_weld_joints(PhysStepCtx *ctx)
|
||||
joint->inv_i1 = inv_i1;
|
||||
|
||||
#if !SIM_PHYSICS_ENABLE_WARM_STARTING
|
||||
joint->linear_impulse0 = V2(0, 0);
|
||||
joint->linear_impulse1 = V2(0, 0);
|
||||
joint->linear_impulse0 = VEC2(0, 0);
|
||||
joint->linear_impulse1 = VEC2(0, 0);
|
||||
joint->angular_impulse0 = 0;
|
||||
joint->angular_impulse1 = 0;
|
||||
#endif
|
||||
@ -998,9 +998,9 @@ void phys_warm_start_weld_joints(PhysStepCtx *ctx)
|
||||
f32 inv_m = joint->inv_m0;
|
||||
f32 inv_i = joint->inv_i0;
|
||||
Xform xf = sim_ent_get_xform(e1);
|
||||
Vec2 vcp = v2_sub(MulXformV2(xf, joint->point_local_start), xf.og);
|
||||
sim_ent_set_linear_velocity(ent, v2_add(ent->linear_velocity, v2_mul(joint->linear_impulse, inv_m)));
|
||||
ent->angular_velocity += (v2_wedge(vcp, joint->linear_impulse) + joint->angular_impulse) * inv_i;
|
||||
Vec2 vcp = SubVec2(MulXformV2(xf, joint->point_local_start), xf.og);
|
||||
sim_ent_set_linear_velocity(ent, AddVec2(ent->linear_velocity, MulVec2(joint->linear_impulse, inv_m)));
|
||||
ent->angular_velocity += (WedgeVec2(vcp, joint->linear_impulse) + joint->angular_impulse) * inv_i;
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -1009,7 +1009,7 @@ void phys_warm_start_weld_joints(PhysStepCtx *ctx)
|
||||
if (sim_ent_should_simulate(e1)) {
|
||||
f32 inv_m = joint->inv_m1;
|
||||
f32 inv_i = joint->inv_i1;
|
||||
sim_ent_set_linear_velocity(e1, v2_add(e1->linear_velocity, v2_mul(joint->linear_impulse1, inv_m)));
|
||||
sim_ent_set_linear_velocity(e1, AddVec2(e1->linear_velocity, MulVec2(joint->linear_impulse1, inv_m)));
|
||||
sim_ent_set_angular_velocity(e1, e1->angular_velocity + joint->angular_impulse1 * inv_i);
|
||||
}
|
||||
#else
|
||||
@ -1041,10 +1041,10 @@ void phys_solve_weld_joints(PhysStepCtx *ctx, f32 dt)
|
||||
|
||||
/* Angular constraint */
|
||||
{
|
||||
SoftSpring softness = math_spring_init(joint->angular_spring_hz, joint->angular_spring_damp, dt);
|
||||
SoftSpring softness = MakeSpring(joint->angular_spring_hz, joint->angular_spring_damp, dt);
|
||||
f32 inv_i1 = joint->inv_i1;
|
||||
f32 k = 1 / inv_i1;
|
||||
f32 separation = math_unwind_angle(GetXformRotation(target_xf1) - GetXformRotation(xf1));
|
||||
f32 separation = UnwindAngleF32(RotationFromXform(target_xf1) - RotationFromXform(xf1));
|
||||
f32 bias = -separation * softness.bias_rate;
|
||||
f32 b = (w1 + bias) * k;
|
||||
f32 impulse = -softness.mass_scale * b - joint->angular_impulse1 * softness.impulse_scale;
|
||||
@ -1054,25 +1054,25 @@ void phys_solve_weld_joints(PhysStepCtx *ctx, f32 dt)
|
||||
|
||||
/* Linear constraint */
|
||||
{
|
||||
SoftSpring softness = math_spring_init(joint->linear_spring_hz, joint->linear_spring_damp, dt);
|
||||
SoftSpring softness = MakeSpring(joint->linear_spring_hz, joint->linear_spring_damp, dt);
|
||||
f32 inv_m1 = joint->inv_m1;
|
||||
|
||||
Vec2 separation = v2_sub(xf1.og, target_xf1.og);
|
||||
Vec2 separation = SubVec2(xf1.og, target_xf1.og);
|
||||
|
||||
f32 k = 1 / inv_m1;
|
||||
|
||||
Vec2 bias = v2_mul(separation, softness.bias_rate);
|
||||
Vec2 b = v2_mul(v2_add(v1, bias), k);
|
||||
Vec2 bias = MulVec2(separation, softness.bias_rate);
|
||||
Vec2 b = MulVec2(AddVec2(v1, bias), k);
|
||||
|
||||
Vec2 impulse = v2_mul(b, -softness.mass_scale);
|
||||
impulse = v2_sub(impulse, v2_mul(joint->linear_impulse1, softness.impulse_scale));
|
||||
Vec2 impulse = MulVec2(b, -softness.mass_scale);
|
||||
impulse = SubVec2(impulse, MulVec2(joint->linear_impulse1, softness.impulse_scale));
|
||||
|
||||
Vec2 old_impulse = joint->linear_impulse1;
|
||||
joint->linear_impulse1 = v2_add(joint->linear_impulse1, impulse);
|
||||
joint->linear_impulse1 = AddVec2(joint->linear_impulse1, impulse);
|
||||
|
||||
impulse = v2_sub(joint->linear_impulse1, old_impulse);
|
||||
impulse = SubVec2(joint->linear_impulse1, old_impulse);
|
||||
|
||||
v1 = v2_add(v1, v2_mul(impulse, inv_m1));
|
||||
v1 = AddVec2(v1, MulVec2(impulse, inv_m1));
|
||||
}
|
||||
|
||||
|
||||
@ -1090,10 +1090,10 @@ internal Xform get_derived_xform(Ent *ent, f32 dt)
|
||||
{
|
||||
Xform xf = sim_ent_get_xform(ent);
|
||||
|
||||
Vec2 step_linear_velocity = v2_mul(ent->linear_velocity, dt);
|
||||
Vec2 step_linear_velocity = MulVec2(ent->linear_velocity, dt);
|
||||
f32 step_angular_velocity = ent->angular_velocity * dt;
|
||||
|
||||
xf.og = v2_add(xf.og, step_linear_velocity);
|
||||
xf.og = AddVec2(xf.og, step_linear_velocity);
|
||||
xf = WorldRotateXformBasis(xf, step_angular_velocity);
|
||||
return xf;
|
||||
}
|
||||
@ -1117,23 +1117,23 @@ void phys_integrate_forces(PhysStepCtx *ctx, f32 dt)
|
||||
/* Integrate forces */
|
||||
if (is_dynamic) {
|
||||
Xform xf = sim_ent_get_xform(ent);
|
||||
f32 det_abs = math_fabs(GetXformDeterminant(xf));
|
||||
f32 det_abs = AbsF32(DeterminantFromXform(xf));
|
||||
f32 mass = ent->mass_unscaled * det_abs;
|
||||
f32 inertia = ent->inertia_unscaled * det_abs;
|
||||
Vec2 force_accel = v2_mul(v2_div(ent->force, mass), dt);
|
||||
Vec2 force_accel = MulVec2(DivVec2(ent->force, mass), dt);
|
||||
f32 torque_accel = (ent->torque / inertia) * dt;
|
||||
linear_velocity = v2_add(linear_velocity, force_accel);
|
||||
linear_velocity = AddVec2(linear_velocity, force_accel);
|
||||
angular_velocity += torque_accel;
|
||||
}
|
||||
|
||||
/* Apply damping */
|
||||
linear_velocity = v2_mul(linear_velocity, linear_damping_factor);
|
||||
linear_velocity = MulVec2(linear_velocity, linear_damping_factor);
|
||||
angular_velocity *= angular_damping_factor;
|
||||
|
||||
/* Update entity */
|
||||
sim_ent_set_linear_velocity(ent, linear_velocity);
|
||||
sim_ent_set_angular_velocity(ent, angular_velocity);
|
||||
ent->force = V2(0, 0);
|
||||
ent->force = VEC2(0, 0);
|
||||
ent->torque = 0;
|
||||
}
|
||||
|
||||
|
||||
@ -188,7 +188,7 @@ struct WeldJointDesc {
|
||||
EntId e1;
|
||||
|
||||
/* The xform that transforms a point in e0's space into the desired e1 space
|
||||
* (IE `xf` * V2(0, 0) should evaluate to the local point that e1's origin will lie) */
|
||||
* (IE `xf` * VEC2(0, 0) should evaluate to the local point that e1's origin will lie) */
|
||||
Xform xf;
|
||||
|
||||
f32 linear_spring_hz;
|
||||
|
||||
@ -75,7 +75,7 @@ internal Vec2I32 world_to_cell_coords(f32 cell_size, Vec2 world_pos)
|
||||
f32 y = world_pos.y;
|
||||
x = (x + ((x >= 0) - (x < 0)) * cell_size) / cell_size;
|
||||
y = (y + ((y >= 0) - (y < 0)) * cell_size) / cell_size;
|
||||
return V2I32((i32)x, (i32)y);
|
||||
return VEC2I32((i32)x, (i32)y);
|
||||
}
|
||||
|
||||
internal i32 cell_coords_to_bin_index(Space *space, Vec2I32 cell_pos)
|
||||
@ -106,7 +106,7 @@ SpaceCell *space_get_cell(Space *space, Vec2I32 cell_pos)
|
||||
SpaceCellBin *bin = &space->bins[bin_index];
|
||||
SpaceCell *res = space_cell_nil();
|
||||
for (SpaceCell *n = bin->first_cell; n; n = n->next_in_bin) {
|
||||
if (v2i32_eq(n->pos, cell_pos)) {
|
||||
if (EqVec2I32(n->pos, cell_pos)) {
|
||||
res = n;
|
||||
break;
|
||||
}
|
||||
@ -123,7 +123,7 @@ internal void space_cell_node_alloc(Vec2I32 cell_pos, SpaceEntry *entry)
|
||||
/* Find existing cell */
|
||||
SpaceCell *cell = 0;
|
||||
for (SpaceCell *n = bin->first_cell; n; n = n->next_in_bin) {
|
||||
if (v2i32_eq(n->pos, cell_pos)) {
|
||||
if (EqVec2I32(n->pos, cell_pos)) {
|
||||
cell = n;
|
||||
break;
|
||||
}
|
||||
@ -311,8 +311,8 @@ void space_entry_update_aabb(SpaceEntry *entry, Aabb new_aabb)
|
||||
Space *space = space_from_entry(entry);
|
||||
f32 cell_size = space->cell_size;
|
||||
|
||||
Vec2I32 old_cell_p0 = V2I32(0, 0);
|
||||
Vec2I32 old_cell_p1 = V2I32(0, 0);
|
||||
Vec2I32 old_cell_p0 = VEC2I32(0, 0);
|
||||
Vec2I32 old_cell_p1 = VEC2I32(0, 0);
|
||||
if (entry->first_node) {
|
||||
Aabb old_aabb = entry->aabb;
|
||||
old_cell_p0 = world_to_cell_coords(cell_size, old_aabb.p0);
|
||||
@ -342,7 +342,7 @@ void space_entry_update_aabb(SpaceEntry *entry, Aabb new_aabb)
|
||||
for (i32 x = new_cell_p0.x; x <= new_cell_p1.x; ++x) {
|
||||
if (x != 0 && y != 0 && (x < old_cell_p0.x || x > old_cell_p1.x || y < old_cell_p0.y || y > old_cell_p1.y)) {
|
||||
/* Cell is outside of old AABB */
|
||||
space_cell_node_alloc(V2I32(x, y), entry);
|
||||
space_cell_node_alloc(VEC2I32(x, y), entry);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -90,7 +90,7 @@ internal Ent *test_spawn_chucker(Ent *parent)
|
||||
sim_ent_enable_prop(zone, SEPROP_SENSOR);
|
||||
CLD_Shape collider = ZI;
|
||||
collider.count = 2;
|
||||
collider.points[1] = V2(0, -0.5);
|
||||
collider.points[1] = VEC2(0, -0.5);
|
||||
collider.radius = 0.1f;
|
||||
zone->local_collider = collider;
|
||||
|
||||
@ -108,11 +108,11 @@ internal Ent *test_spawn_employee(Ent *parent)
|
||||
|
||||
Ent *e = sim_ent_alloc_sync_src(parent);
|
||||
|
||||
Vec2 pos = V2(1, -1);
|
||||
Vec2 pos = VEC2(1, -1);
|
||||
|
||||
//Vec2 size = V2(0.5, 0.5);
|
||||
//Vec2 size = V2(0.5, 0.25);
|
||||
Vec2 size = V2(1.0, 1.0);
|
||||
//Vec2 size = VEC2(0.5, 0.5);
|
||||
//Vec2 size = VEC2(0.5, 0.25);
|
||||
Vec2 size = VEC2(1.0, 1.0);
|
||||
|
||||
//f32 r = Pi / 4;
|
||||
f32 r = 0;
|
||||
@ -130,7 +130,7 @@ internal Ent *test_spawn_employee(Ent *parent)
|
||||
e->sprite_span_name = LIT("idle.two_handed");
|
||||
e->layer = SIM_LAYER_SHOULDERS;
|
||||
|
||||
e->local_collider.points[0] = V2(0, 0);
|
||||
e->local_collider.points[0] = VEC2(0, 0);
|
||||
e->local_collider.count = 1;
|
||||
e->local_collider.radius = 0.25f;
|
||||
|
||||
@ -148,7 +148,7 @@ internal Ent *test_spawn_employee(Ent *parent)
|
||||
|
||||
|
||||
sim_ent_enable_prop(e, SEPROP_LIGHT_TEST);
|
||||
e->sprite_emittance = V3(1, 1, 1);
|
||||
e->sprite_emittance = VEC3(1, 1, 1);
|
||||
|
||||
|
||||
|
||||
@ -178,7 +178,7 @@ internal Ent *test_spawn_employee(Ent *parent)
|
||||
employee->equipped = e->id;
|
||||
|
||||
sim_ent_enable_prop(e, SEPROP_LIGHT_TEST);
|
||||
e->sprite_emittance = V3(1, 1, 1);
|
||||
e->sprite_emittance = VEC3(1, 1, 1);
|
||||
}
|
||||
|
||||
return employee;
|
||||
@ -197,7 +197,7 @@ internal Ent *test_spawn_camera(Ent *parent, Ent *follow)
|
||||
|
||||
f32 width = (f32)DEFAULT_CAMERA_WIDTH;
|
||||
f32 height = (f32)DEFAULT_CAMERA_HEIGHT;
|
||||
camera_ent->camera_quad_xform = XformFromTrs(TRS(.s = V2(width, height)));
|
||||
camera_ent->camera_quad_xform = XformFromTrs(TRS(.s = VEC2(width, height)));
|
||||
}
|
||||
|
||||
return camera_ent;
|
||||
@ -251,7 +251,7 @@ internal void test_spawn_entities2(Ent *parent, Vec2 pos)
|
||||
Ent *e = sim_ent_alloc_sync_src(parent);
|
||||
|
||||
f32 rot = 0;
|
||||
Vec2 size = V2(0.125, 0.125);
|
||||
Vec2 size = VEC2(0.125, 0.125);
|
||||
Xform xf = XformFromTrs(TRS(.t = pos, .r = rot, .s = size));
|
||||
sim_ent_set_xform(e, xf);
|
||||
|
||||
@ -262,7 +262,7 @@ internal void test_spawn_entities2(Ent *parent, Vec2 pos)
|
||||
//e->sprite_tint = Alpha32F(ColorWhite, 1);
|
||||
|
||||
sim_ent_enable_prop(e, SEPROP_SOLID);
|
||||
Quad collider_quad = quad_from_rect(RectFromScalar(-0.5, -0.5, 1, 1));
|
||||
Quad collider_quad = QuadFromRect(RectFromScalar(-0.5, -0.5, 1, 1));
|
||||
e->local_collider = collider_from_quad(collider_quad);
|
||||
|
||||
sim_ent_enable_prop(e, SEPROP_LIGHT_TEST);
|
||||
@ -273,7 +273,7 @@ internal void test_spawn_entities2(Ent *parent, Vec2 pos)
|
||||
f32 r = rand_f64_from_state(&rand, 1, 5);
|
||||
f32 g = rand_f64_from_state(&rand, 1, 5);
|
||||
f32 b = rand_f64_from_state(&rand, 1, 5);
|
||||
e->sprite_emittance = V3(r, g, b);
|
||||
e->sprite_emittance = VEC3(r, g, b);
|
||||
e->sprite_tint = Rgba32F(r / 5, g / 5, b / 5, 1);
|
||||
}
|
||||
|
||||
@ -293,7 +293,7 @@ internal void test_spawn_entities2(Ent *parent, Vec2 pos)
|
||||
Ent *e = sim_ent_alloc_sync_src(parent);
|
||||
|
||||
f32 r = Pi / 4;
|
||||
Vec2 size = V2(0.5, 0.25);
|
||||
Vec2 size = VEC2(0.5, 0.25);
|
||||
Xform xf = XformFromTrs(.t = pos, .r = r, .s = size);
|
||||
sim_ent_set_xform(e, xf);
|
||||
|
||||
@ -321,7 +321,7 @@ internal void test_spawn_entities3(Ent *parent, Vec2 pos)
|
||||
Ent *e = sim_ent_alloc_sync_src(parent);
|
||||
|
||||
f32 r = 0;
|
||||
Vec2 size = V2(1, 1);
|
||||
Vec2 size = VEC2(1, 1);
|
||||
Xform xf = XformFromTrs(TRS(.t = pos, .r = r, .s = size));
|
||||
sim_ent_set_xform(e, xf);
|
||||
|
||||
@ -331,7 +331,7 @@ internal void test_spawn_entities3(Ent *parent, Vec2 pos)
|
||||
e->sprite_tint = ColorRed;
|
||||
|
||||
sim_ent_enable_prop(e, SEPROP_SOLID);
|
||||
Quad collider_quad = quad_from_rect(RectFromScalar(-0.5, -0.5, 1, 1));
|
||||
Quad collider_quad = QuadFromRect(RectFromScalar(-0.5, -0.5, 1, 1));
|
||||
e->local_collider = collider_from_quad(collider_quad);
|
||||
}
|
||||
}
|
||||
@ -344,7 +344,7 @@ internal void test_spawn_entities4(Ent *parent, Vec2 pos)
|
||||
Ent *e = sim_ent_alloc_sync_src(parent);
|
||||
|
||||
f32 r = 0;
|
||||
Vec2 size = V2(2, 1);
|
||||
Vec2 size = VEC2(2, 1);
|
||||
Xform xf = XformFromTrs(TRS(.t = pos, .r = r, .s = size));
|
||||
sim_ent_set_xform(e, xf);
|
||||
|
||||
@ -353,7 +353,7 @@ internal void test_spawn_entities4(Ent *parent, Vec2 pos)
|
||||
e->layer = SIM_LAYER_SHOULDERS;
|
||||
|
||||
sim_ent_enable_prop(e, SEPROP_LIGHT_TEST);
|
||||
e->sprite_emittance = V3(2, 2, 2);
|
||||
e->sprite_emittance = VEC3(2, 2, 2);
|
||||
|
||||
e->sprite_tint = Rgb32F(1, 1, 1);
|
||||
}
|
||||
@ -365,14 +365,14 @@ internal void test_spawn_tile(Snapshot *world, Vec2 world_pos)
|
||||
|
||||
i32 sign_x = (world_pos.x >= 0) - (world_pos.x < 0);
|
||||
i32 sign_y = (world_pos.y >= 0) - (world_pos.y < 0);
|
||||
Vec2I32 tile_index = V2I32(world_pos.x * SIM_TILES_PER_UNIT_SQRT, world_pos.y * SIM_TILES_PER_UNIT_SQRT);
|
||||
Vec2I32 tile_index = VEC2I32(world_pos.x * SIM_TILES_PER_UNIT_SQRT, world_pos.y * SIM_TILES_PER_UNIT_SQRT);
|
||||
world_pos.x -= sign_x < 0;
|
||||
world_pos.y -= sign_y < 0;
|
||||
|
||||
Vec2 tile_size = V2(1.f / SIM_TILES_PER_UNIT_SQRT, 1.f / SIM_TILES_PER_UNIT_SQRT);
|
||||
Vec2 tile_size = VEC2(1.f / SIM_TILES_PER_UNIT_SQRT, 1.f / SIM_TILES_PER_UNIT_SQRT);
|
||||
|
||||
Vec2 pos = V2((f32)tile_index.x / SIM_TILES_PER_UNIT_SQRT, (f32)tile_index.y / SIM_TILES_PER_UNIT_SQRT);
|
||||
pos = v2_add(pos, v2_mul(V2(tile_size.x * sign_x, tile_size.y * sign_y), 0.5));
|
||||
Vec2 pos = VEC2((f32)tile_index.x / SIM_TILES_PER_UNIT_SQRT, (f32)tile_index.y / SIM_TILES_PER_UNIT_SQRT);
|
||||
pos = AddVec2(pos, MulVec2(VEC2(tile_size.x * sign_x, tile_size.y * sign_y), 0.5));
|
||||
|
||||
Xform xf = XformFromTrs(.t = pos);
|
||||
sim_ent_set_xform(e, xf);
|
||||
@ -384,12 +384,12 @@ internal void test_spawn_tile(Snapshot *world, Vec2 world_pos)
|
||||
{
|
||||
S_Scope *scope = sprite_scope_begin();
|
||||
S_Sheet *sheet = sprite_sheet_from_tag_await(scope, e->sprite);
|
||||
e->sprite_local_xform = XformFromTrs(.s = v2_div(sheet->frame_size, PIXELS_PER_UNIT));
|
||||
e->sprite_local_xform = XformFromTrs(.s = DivVec2(sheet->frame_size, PIXELS_PER_UNIT));
|
||||
sprite_scope_end(scope);
|
||||
}
|
||||
|
||||
sim_ent_enable_prop(e, SEPROP_SOLID);
|
||||
Quad collider_quad = quad_from_rect(RectFromScalar(-tile_size.x / 2, -tile_size.y / 2, tile_size.y, tile_size.y));
|
||||
Quad collider_quad = QuadFromRect(RectFromScalar(-tile_size.x / 2, -tile_size.y / 2, tile_size.y, tile_size.y));
|
||||
e->local_collider = collider_from_quad(collider_quad);
|
||||
#else
|
||||
Vec2I32 tile_index = sim_world_tile_index_from_pos(world_pos);
|
||||
@ -484,8 +484,8 @@ internal void test_generate_walls(Snapshot *world)
|
||||
for (u64 sorted_index = 0; sorted_index < sorted_tile_chunks_count; ++sorted_index) {
|
||||
Ent *chunk = x_sorted_tile_chunks[sorted_index];
|
||||
Vec2I32 chunk_index = chunk->tile_chunk_index;
|
||||
Ent *top_chunk = sim_tile_chunk_from_chunk_index(world, V2I32(chunk_index.x, chunk_index.y - 1));
|
||||
Ent *bottom_chunk = sim_tile_chunk_from_chunk_index(world, V2I32(chunk_index.x, chunk_index.y + 1));
|
||||
Ent *top_chunk = sim_tile_chunk_from_chunk_index(world, VEC2I32(chunk_index.x, chunk_index.y - 1));
|
||||
Ent *bottom_chunk = sim_tile_chunk_from_chunk_index(world, VEC2I32(chunk_index.x, chunk_index.y + 1));
|
||||
/* If there's no chunk below this one, then do an extra iteration (since walls are created at the top of each tile) */
|
||||
i32 y_iterations = SIM_TILES_PER_CHUNK_SQRT + !bottom_chunk->valid;
|
||||
i32 x_iterations = SIM_TILES_PER_CHUNK_SQRT + 1;
|
||||
@ -497,17 +497,17 @@ internal void test_generate_walls(Snapshot *world)
|
||||
i32 desired_wall_dir = -1;
|
||||
TileKind tile = SIM_TILE_KIND_NONE;
|
||||
if (tile_x < SIM_TILES_PER_CHUNK_SQRT && tile_y < SIM_TILES_PER_CHUNK_SQRT) {
|
||||
tile = sim_get_chunk_tile(chunk, V2I32(tile_x, tile_y));
|
||||
tile = sim_get_chunk_tile(chunk, VEC2I32(tile_x, tile_y));
|
||||
}
|
||||
if (tile_x < SIM_TILES_PER_CHUNK_SQRT) {
|
||||
TileKind top_tile = SIM_TILE_KIND_NONE;
|
||||
if (tile_y == 0) {
|
||||
if (top_chunk->valid) {
|
||||
Vec2I32 top_tile_local_index = V2I32(tile_x, SIM_TILES_PER_CHUNK_SQRT - 1);
|
||||
Vec2I32 top_tile_local_index = VEC2I32(tile_x, SIM_TILES_PER_CHUNK_SQRT - 1);
|
||||
top_tile = sim_get_chunk_tile(top_chunk, top_tile_local_index);
|
||||
}
|
||||
} else {
|
||||
top_tile = sim_get_chunk_tile(chunk, V2I32(tile_x, tile_y - 1));
|
||||
top_tile = sim_get_chunk_tile(chunk, VEC2I32(tile_x, tile_y - 1));
|
||||
}
|
||||
if (tile == SIM_TILE_KIND_WALL) {
|
||||
/* Process wall tile */
|
||||
@ -524,8 +524,8 @@ internal void test_generate_walls(Snapshot *world)
|
||||
|
||||
/* Stop wall */
|
||||
if (wall_dir >= 0 && desired_wall_dir != wall_dir) {
|
||||
Vec2I32 start = sim_world_tile_index_from_local_tile_index(chunk_index, V2I32(wall_start, tile_y));
|
||||
Vec2I32 end = sim_world_tile_index_from_local_tile_index(chunk_index, V2I32(wall_end, tile_y));
|
||||
Vec2I32 start = sim_world_tile_index_from_local_tile_index(chunk_index, VEC2I32(wall_start, tile_y));
|
||||
Vec2I32 end = sim_world_tile_index_from_local_tile_index(chunk_index, VEC2I32(wall_end, tile_y));
|
||||
struct wall_node *node = 0;
|
||||
if (wall_start == 0) {
|
||||
u64 start_hash = rand_u64_from_seed(*(u64 *)&start);
|
||||
@ -573,8 +573,8 @@ internal void test_generate_walls(Snapshot *world)
|
||||
for (u64 sorted_index = 0; sorted_index < sorted_tile_chunks_count; ++sorted_index) {
|
||||
Ent *chunk = y_sorted_tile_chunks[sorted_index];
|
||||
Vec2I32 chunk_index = chunk->tile_chunk_index;
|
||||
Ent *left_chunk = sim_tile_chunk_from_chunk_index(world, V2I32(chunk_index.x - 1, chunk_index.y));
|
||||
Ent *right_chunk = sim_tile_chunk_from_chunk_index(world, V2I32(chunk_index.x + 1, chunk_index.y));
|
||||
Ent *left_chunk = sim_tile_chunk_from_chunk_index(world, VEC2I32(chunk_index.x - 1, chunk_index.y));
|
||||
Ent *right_chunk = sim_tile_chunk_from_chunk_index(world, VEC2I32(chunk_index.x + 1, chunk_index.y));
|
||||
/* If there's no chunk to the right of this one, then do an extra iteration (since walls are created on the left of each tile) */
|
||||
i32 y_iterations = SIM_TILES_PER_CHUNK_SQRT + 1;
|
||||
i32 x_iterations = SIM_TILES_PER_CHUNK_SQRT + !right_chunk->valid;
|
||||
@ -586,18 +586,18 @@ internal void test_generate_walls(Snapshot *world)
|
||||
i32 desired_wall_dir = -1;
|
||||
TileKind tile = SIM_TILE_KIND_NONE;
|
||||
if (tile_x < SIM_TILES_PER_CHUNK_SQRT && tile_y < SIM_TILES_PER_CHUNK_SQRT) {
|
||||
tile = sim_get_chunk_tile(chunk, V2I32(tile_x, tile_y));
|
||||
tile = sim_get_chunk_tile(chunk, VEC2I32(tile_x, tile_y));
|
||||
}
|
||||
|
||||
if (tile_y < SIM_TILES_PER_CHUNK_SQRT) {
|
||||
TileKind left_tile = SIM_TILE_KIND_NONE;
|
||||
if (tile_x == 0) {
|
||||
if (left_chunk->valid) {
|
||||
Vec2I32 left_tile_local_index = V2I32(SIM_TILES_PER_CHUNK_SQRT - 1, tile_y);
|
||||
Vec2I32 left_tile_local_index = VEC2I32(SIM_TILES_PER_CHUNK_SQRT - 1, tile_y);
|
||||
left_tile = sim_get_chunk_tile(left_chunk, left_tile_local_index);
|
||||
}
|
||||
} else {
|
||||
left_tile = sim_get_chunk_tile(chunk, V2I32(tile_x - 1, tile_y));
|
||||
left_tile = sim_get_chunk_tile(chunk, VEC2I32(tile_x - 1, tile_y));
|
||||
}
|
||||
if (tile == SIM_TILE_KIND_WALL) {
|
||||
/* Process wall tile */
|
||||
@ -614,8 +614,8 @@ internal void test_generate_walls(Snapshot *world)
|
||||
|
||||
/* Stop wall */
|
||||
if (wall_dir >= 0 && desired_wall_dir != wall_dir) {
|
||||
Vec2I32 start = sim_world_tile_index_from_local_tile_index(chunk_index, V2I32(tile_x, wall_start));
|
||||
Vec2I32 end = sim_world_tile_index_from_local_tile_index(chunk_index, V2I32(tile_x, wall_end));
|
||||
Vec2I32 start = sim_world_tile_index_from_local_tile_index(chunk_index, VEC2I32(tile_x, wall_start));
|
||||
Vec2I32 end = sim_world_tile_index_from_local_tile_index(chunk_index, VEC2I32(tile_x, wall_end));
|
||||
struct wall_node *node = 0;
|
||||
if (wall_start == 0) {
|
||||
u64 start_hash = rand_u64_from_seed(*(u64 *)&start);
|
||||
@ -672,9 +672,9 @@ internal void test_generate_walls(Snapshot *world)
|
||||
|
||||
sim_ent_enable_prop(wall_ent, SEPROP_SOLID);
|
||||
wall_ent->local_collider.count = 2;
|
||||
wall_ent->local_collider.points[1] = v2_sub(end, start);
|
||||
wall_ent->local_collider.points[1] = SubVec2(end, start);
|
||||
|
||||
Vec2 dirs[4] = { V2(0, -1), V2(1, 0), V2(0, 1), V2(-1, 0) };
|
||||
Vec2 dirs[4] = { VEC2(0, -1), VEC2(1, 0), VEC2(0, 1), VEC2(-1, 0) };
|
||||
Assert(node->wall_dir >= 0 && (u32)node->wall_dir < countof(dirs));
|
||||
wall_ent->collision_dir = dirs[node->wall_dir];
|
||||
|
||||
@ -738,11 +738,11 @@ internal PHYS_COLLISION_CALLBACK_FUNC_DEF(on_collision, data, step_ctx)
|
||||
Xform xf = sim_ent_get_xform(tracer);
|
||||
xf.og = point;
|
||||
sim_ent_set_xform(tracer, xf);
|
||||
sim_ent_set_linear_velocity(tracer, V2(0, 0));
|
||||
sim_ent_set_linear_velocity(tracer, VEC2(0, 0));
|
||||
}
|
||||
|
||||
/* Update target */
|
||||
Vec2 knockback = v2_mul(v2_norm(vrel), bullet->bullet_knockback);
|
||||
Vec2 knockback = MulVec2(NormVec2(vrel), bullet->bullet_knockback);
|
||||
sim_ent_apply_linear_impulse(target, knockback, point);
|
||||
|
||||
/* Create test blood */
|
||||
@ -756,8 +756,8 @@ internal PHYS_COLLISION_CALLBACK_FUNC_DEF(on_collision, data, step_ctx)
|
||||
sim_ent_set_xform(decal, xf);
|
||||
|
||||
f32 perp_range = 0.5;
|
||||
Vec2 linear_velocity = v2_mul(normal, 0.5);
|
||||
linear_velocity = v2_add(linear_velocity, v2_mul(v2_perp(normal), rand_f64_from_state(&step_ctx->rand, -perp_range, perp_range)));
|
||||
Vec2 linear_velocity = MulVec2(normal, 0.5);
|
||||
linear_velocity = AddVec2(linear_velocity, MulVec2(PerpVec2(normal), rand_f64_from_state(&step_ctx->rand, -perp_range, perp_range)));
|
||||
|
||||
f32 angular_velocity_range = 5;
|
||||
f32 angular_velocity = rand_f64_from_state(&step_ctx->rand, -angular_velocity_range, angular_velocity_range);
|
||||
@ -793,17 +793,17 @@ internal PHYS_COLLISION_CALLBACK_FUNC_DEF(on_collision, data, step_ctx)
|
||||
|
||||
Xform victim_xf = sim_ent_get_xform(victim);
|
||||
CLD_ClosestResult closest_points = collider_closest_points(&origin_collider, &victim->local_collider, xf, victim_xf);
|
||||
Vec2 dir = v2_sub(closest_points.p1, closest_points.p0);
|
||||
Vec2 dir = SubVec2(closest_points.p1, closest_points.p0);
|
||||
Vec2 point = closest_points.p1;
|
||||
f32 distance = v2_len(dir);
|
||||
f32 distance = Vec2Len(dir);
|
||||
#if 0
|
||||
if (closest_points.colliding) {
|
||||
dir = v2_neg(dir);
|
||||
dir = NegVec2(dir);
|
||||
//distance = 0;
|
||||
}
|
||||
#else
|
||||
if (v2_dot(data->normal, dir) < 0) {
|
||||
dir = v2_neg(dir);
|
||||
if (DotVec2(data->normal, dir) < 0) {
|
||||
dir = NegVec2(dir);
|
||||
point = xf.og;
|
||||
distance = 0;
|
||||
}
|
||||
@ -814,8 +814,8 @@ internal PHYS_COLLISION_CALLBACK_FUNC_DEF(on_collision, data, step_ctx)
|
||||
f32 strength_center = exp->explosion_strength;
|
||||
if (distance < radius) {
|
||||
const f32 falloff_curve = 3; /* Cubic falloff */
|
||||
f32 strength_factor = math_pow(1 - distance/radius, falloff_curve);
|
||||
Vec2 impulse = v2_with_len(dir, strength_center * strength_factor);
|
||||
f32 strength_factor = PowF32(1 - distance/radius, falloff_curve);
|
||||
Vec2 impulse = Vec2WithLen(dir, strength_center * strength_factor);
|
||||
sim_ent_apply_linear_impulse(victim, impulse, point);
|
||||
}
|
||||
}
|
||||
@ -1003,8 +1003,8 @@ void sim_step(SimStepCtx *ctx)
|
||||
player->player_dbg_drag_stop = 0;
|
||||
|
||||
/* Cap movement vector magnitude */
|
||||
if (v2_len_sq(control->move) > 1) {
|
||||
control->move = v2_norm(control->move);
|
||||
if (Vec2LenSq(control->move) > 1) {
|
||||
control->move = NormVec2(control->move);
|
||||
}
|
||||
|
||||
/* Debug cmds */
|
||||
@ -1206,15 +1206,15 @@ void sim_step(SimStepCtx *ctx)
|
||||
/* Update sprite local xform */
|
||||
{
|
||||
S_SheetSlice slice = sprite_sheet_get_slice(sheet, LIT("pivot"), ent->animation_frame);
|
||||
Vec2 sprite_size = v2_div(sheet->frame_size, (f32)PIXELS_PER_UNIT);
|
||||
Vec2 sprite_size = DivVec2(sheet->frame_size, (f32)PIXELS_PER_UNIT);
|
||||
|
||||
Vec2 dir = v2_mul_v2(sprite_size, slice.dir);
|
||||
f32 rot = v2_angle(dir) + Pi / 2;
|
||||
Vec2 dir = MulVec2Vec2(sprite_size, slice.dir);
|
||||
f32 rot = AngleFromVec2(dir) + Pi / 2;
|
||||
|
||||
Xform xf = XformIdentity;
|
||||
xf = RotateXform(xf, -rot);
|
||||
xf = ScaleXform(xf, sprite_size);
|
||||
xf = TranslateXform(xf, v2_neg(slice.center));
|
||||
xf = TranslateXform(xf, NegVec2(slice.center));
|
||||
ent->sprite_local_xform = xf;
|
||||
}
|
||||
#endif
|
||||
@ -1224,7 +1224,7 @@ void sim_step(SimStepCtx *ctx)
|
||||
Xform cxf = ent->sprite_local_xform;
|
||||
|
||||
S_SheetSlice slice = sprite_sheet_get_slice(sheet, ent->sprite_collider_slice, ent->animation_frame);
|
||||
ent->local_collider = collider_from_quad(MulXformQuad(cxf, quad_from_rect(slice.rect)));
|
||||
ent->local_collider = collider_from_quad(MulXformQuad(cxf, QuadFromRect(slice.rect)));
|
||||
}
|
||||
|
||||
/* Test collider */
|
||||
@ -1232,28 +1232,28 @@ void sim_step(SimStepCtx *ctx)
|
||||
if (sim_ent_has_prop(ent, SEPROP_TEST)) {
|
||||
//if ((1)) {
|
||||
#if 0
|
||||
ent->local_collider.points[0] = V2(0, 0);
|
||||
ent->local_collider.points[0] = VEC2(0, 0);
|
||||
ent->local_collider.count = 1;
|
||||
ent->local_collider.radius = 0.5;
|
||||
#elif 0
|
||||
ent->local_collider.points[0] = v2_with_len(V2(0.08f, 0.17f), 0.15f);
|
||||
ent->local_collider.points[1] = v2_with_len(V2(-0.07f, -0.2f), 0.15f);
|
||||
ent->local_collider.points[0] = Vec2WithLen(VEC2(0.08f, 0.17f), 0.15f);
|
||||
ent->local_collider.points[1] = Vec2WithLen(VEC2(-0.07f, -0.2f), 0.15f);
|
||||
ent->local_collider.count = 2;
|
||||
ent->local_collider.radius = 0.075f;
|
||||
#elif 1
|
||||
#if 0
|
||||
/* "Bad" winding order */
|
||||
ent->local_collider.points[0] = V2(-0.15, 0.15);
|
||||
ent->local_collider.points[1] = V2(0.15, 0.15);
|
||||
ent->local_collider.points[2] = V2(0, -0.15);
|
||||
ent->local_collider.points[0] = VEC2(-0.15, 0.15);
|
||||
ent->local_collider.points[1] = VEC2(0.15, 0.15);
|
||||
ent->local_collider.points[2] = VEC2(0, -0.15);
|
||||
#else
|
||||
ent->local_collider.points[0] = V2(0, -0.15);
|
||||
ent->local_collider.points[1] = V2(0.15, 0.15);
|
||||
ent->local_collider.points[2] = V2(-0.15, 0.15);
|
||||
ent->local_collider.points[0] = VEC2(0, -0.15);
|
||||
ent->local_collider.points[1] = VEC2(0.15, 0.15);
|
||||
ent->local_collider.points[2] = VEC2(-0.15, 0.15);
|
||||
#endif
|
||||
ent->local_collider.count = 3;
|
||||
ent->local_collider.radius = 0.25;
|
||||
//ent->local_collider.radius = math_fabs(math_sin(ctx->tick.time) / 3);
|
||||
//ent->local_collider.radius = AbsF32(SinF32(ctx->tick.time) / 3);
|
||||
#else
|
||||
//ent->local_collider.radius = 0.5;
|
||||
ent->local_collider.radius = 0.25;
|
||||
@ -1284,7 +1284,7 @@ void sim_step(SimStepCtx *ctx)
|
||||
|
||||
Xform xf = sim_ent_get_local_xform(ent);
|
||||
xf.og = attach_pos;
|
||||
xf = XformWIthWorldRotation(xf, v2_angle(attach_dir) + Pi / 2);
|
||||
xf = XformWIthWorldRotation(xf, AngleFromVec2(attach_dir) + Pi / 2);
|
||||
sim_ent_set_local_xform(ent, xf);
|
||||
}
|
||||
|
||||
@ -1374,7 +1374,7 @@ void sim_step(SimStepCtx *ctx)
|
||||
|
||||
#if 1
|
||||
/* Point collider */
|
||||
bullet->local_collider.points[0] = V2(0, 0);
|
||||
bullet->local_collider.points[0] = VEC2(0, 0);
|
||||
bullet->local_collider.count = 1;
|
||||
#else
|
||||
bullet->sprite = sprite_tag_from_path(LIT("sprite/bullet.ase"));
|
||||
@ -1422,7 +1422,7 @@ void sim_step(SimStepCtx *ctx)
|
||||
bullet->layer = SIM_LAYER_BULLETS;
|
||||
|
||||
/* Point collider */
|
||||
bullet->local_collider.points[0] = V2(0, 0);
|
||||
bullet->local_collider.points[0] = VEC2(0, 0);
|
||||
bullet->local_collider.count = 1;
|
||||
bullet->local_collider.radius = 0.05f;
|
||||
|
||||
@ -1509,7 +1509,7 @@ void sim_step(SimStepCtx *ctx)
|
||||
|
||||
if (sim_ent_should_simulate(joint_ent)) {
|
||||
sim_ent_set_xform(joint_ent, XformIdentity); /* Reset joint ent position */
|
||||
sim_ent_set_linear_velocity(joint_ent, v2_mul(v2_clamp_len(ent->control.move, 1), ent->control_force_max_speed));
|
||||
sim_ent_set_linear_velocity(joint_ent, MulVec2(ClampVec2Len(ent->control.move, 1), ent->control_force_max_speed));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1556,7 +1556,7 @@ void sim_step(SimStepCtx *ctx)
|
||||
f32 new_angle;
|
||||
{
|
||||
Vec2 ent_pos = xf.og;
|
||||
Vec2 focus_pos = v2_add(ent_pos, ent->control.focus);
|
||||
Vec2 focus_pos = AddVec2(ent_pos, ent->control.focus);
|
||||
|
||||
Vec2 sprite_hold_pos;
|
||||
Vec2 sprite_hold_dir;
|
||||
@ -1569,9 +1569,9 @@ void sim_step(SimStepCtx *ctx)
|
||||
|
||||
Vec2 hold_dir = MulXformBasisV2(sprite_xf, sprite_hold_dir);
|
||||
Vec2 hold_pos = MulXformV2(sprite_xf, sprite_hold_pos);
|
||||
if (v2_eq(hold_pos, ent_pos)) {
|
||||
if (EqVec2(hold_pos, ent_pos)) {
|
||||
/* If hold pos is same as origin (E.G if pivot is being used as hold pos), then move hold pos forward a tad to avoid issue */
|
||||
sprite_hold_pos = v2_add(sprite_hold_pos, V2(0, -1));
|
||||
sprite_hold_pos = AddVec2(sprite_hold_pos, VEC2(0, -1));
|
||||
hold_pos = MulXformV2(sprite_xf, sprite_hold_pos);
|
||||
}
|
||||
|
||||
@ -1579,28 +1579,28 @@ void sim_step(SimStepCtx *ctx)
|
||||
{
|
||||
Xform xf_unrotated = XformWIthWorldRotation(xf, 0);
|
||||
Vec2 hold_pos_unrotated = MulXformV2(xf_unrotated, MulXformV2(ent->sprite_local_xform, sprite_hold_pos));
|
||||
forward_hold_angle_offset = v2_angle_from_dirs(V2(0, -1), v2_sub(hold_pos_unrotated, xf_unrotated.og));
|
||||
forward_hold_angle_offset = AngleFromVec2Dirs(VEC2(0, -1), SubVec2(hold_pos_unrotated, xf_unrotated.og));
|
||||
}
|
||||
|
||||
Vec2 hold_ent_dir = v2_sub(ent_pos, hold_pos);
|
||||
Vec2 focus_ent_dir = v2_sub(ent_pos, focus_pos);
|
||||
Vec2 hold_ent_dir = SubVec2(ent_pos, hold_pos);
|
||||
Vec2 focus_ent_dir = SubVec2(ent_pos, focus_pos);
|
||||
|
||||
f32 hold_ent_len = v2_len(hold_ent_dir);
|
||||
f32 focus_ent_len = v2_len(focus_ent_dir);
|
||||
f32 hold_ent_len = Vec2Len(hold_ent_dir);
|
||||
f32 focus_ent_len = Vec2Len(focus_ent_dir);
|
||||
|
||||
f32 final_hold_angle_btw_ent_and_focus = v2_angle_from_dirs(hold_ent_dir, hold_dir);
|
||||
f32 final_focus_angle_btw_ent_and_hold = math_asin((math_sin(final_hold_angle_btw_ent_and_focus) * hold_ent_len) / focus_ent_len);
|
||||
f32 final_hold_angle_btw_ent_and_focus = AngleFromVec2Dirs(hold_ent_dir, hold_dir);
|
||||
f32 final_focus_angle_btw_ent_and_hold = ArcSinF32((SinF32(final_hold_angle_btw_ent_and_focus) * hold_ent_len) / focus_ent_len);
|
||||
f32 final_ent_angle_btw_focus_and_hold = Pi - (final_focus_angle_btw_ent_and_hold + final_hold_angle_btw_ent_and_focus);
|
||||
|
||||
new_angle = math_unwind_angle(v2_angle_from_dirs(V2(0, -1), v2_sub(focus_pos, ent_pos)) + final_ent_angle_btw_focus_and_hold - forward_hold_angle_offset);
|
||||
new_angle = UnwindAngleF32(AngleFromVec2Dirs(VEC2(0, -1), SubVec2(focus_pos, ent_pos)) + final_ent_angle_btw_focus_and_hold - forward_hold_angle_offset);
|
||||
}
|
||||
|
||||
f32 new_vel = 0;
|
||||
if (!IsF32Nan(new_angle)) {
|
||||
const f32 angle_error_allowed = 0.001f;
|
||||
Xform joint_xf = sim_ent_get_xform(joint_ent);
|
||||
f32 diff = math_unwind_angle(new_angle - GetXformRotation(joint_xf));
|
||||
if (math_fabs(diff) > angle_error_allowed) {
|
||||
f32 diff = UnwindAngleF32(new_angle - RotationFromXform(joint_xf));
|
||||
if (AbsF32(diff) > angle_error_allowed) {
|
||||
/* Instantly snap joint ent to new angle */
|
||||
new_vel = diff / sim_dt;
|
||||
}
|
||||
@ -1733,11 +1733,11 @@ void sim_step(SimStepCtx *ctx)
|
||||
|
||||
Vec2 end = sim_ent_get_xform(ent).og;
|
||||
|
||||
Vec2 tick_velocity = v2_mul(ent->tracer_start_velocity, sim_dt);
|
||||
Vec2 gradient_start = v2_add(ent->tracer_gradient_start, tick_velocity);
|
||||
Vec2 gradient_end = v2_add(ent->tracer_gradient_end, tick_velocity);
|
||||
Vec2 tick_velocity = MulVec2(ent->tracer_start_velocity, sim_dt);
|
||||
Vec2 gradient_start = AddVec2(ent->tracer_gradient_start, tick_velocity);
|
||||
Vec2 gradient_end = AddVec2(ent->tracer_gradient_end, tick_velocity);
|
||||
|
||||
if (v2_dot(tick_velocity, v2_sub(gradient_start, end)) > 0) {
|
||||
if (DotVec2(tick_velocity, SubVec2(gradient_start, end)) > 0) {
|
||||
/* Tracer has disappeared */
|
||||
sim_ent_enable_prop(ent, SEPROP_RELEASE);
|
||||
}
|
||||
@ -1765,18 +1765,18 @@ void sim_step(SimStepCtx *ctx)
|
||||
|
||||
Vec2 pos = MulXformV2(src_xf, ent->bullet_src_pos);
|
||||
Vec2 vel = MulXformBasisV2(src_xf, ent->bullet_src_dir);
|
||||
vel = v2_with_len(vel, ent->bullet_launch_velocity);
|
||||
vel = Vec2WithLen(vel, ent->bullet_launch_velocity);
|
||||
|
||||
#if 0
|
||||
/* Add shooter velocity to bullet */
|
||||
{
|
||||
/* TODO: Add angular velocity as well? */
|
||||
Ent *top = sim_ent_from_id(ss_blended, src->top);
|
||||
impulse = v2_add(impulse, v2_mul(top->linear_velocity, dt));
|
||||
impulse = AddVec2(impulse, MulVec2(top->linear_velocity, dt));
|
||||
}
|
||||
#endif
|
||||
|
||||
Xform xf = XformFromTrs(TRS(.t = pos, .r = v2_angle(vel) + Pi / 2));
|
||||
Xform xf = XformFromTrs(TRS(.t = pos, .r = AngleFromVec2(vel) + Pi / 2));
|
||||
sim_ent_set_xform(ent, xf);
|
||||
|
||||
sim_ent_enable_prop(ent, SEPROP_KINEMATIC);
|
||||
@ -1791,7 +1791,7 @@ void sim_step(SimStepCtx *ctx)
|
||||
tracer->tracer_start = pos;
|
||||
tracer->tracer_start_velocity = ent->linear_velocity;
|
||||
tracer->tracer_gradient_end = pos;
|
||||
tracer->tracer_gradient_start = v2_sub(pos, v2_mul(ent->linear_velocity, tracer->tracer_fade_duration));
|
||||
tracer->tracer_gradient_start = SubVec2(pos, MulVec2(ent->linear_velocity, tracer->tracer_fade_duration));
|
||||
}
|
||||
|
||||
/* Spawn quake */
|
||||
@ -1823,21 +1823,21 @@ void sim_step(SimStepCtx *ctx)
|
||||
f32 aspect_ratio = 1.0;
|
||||
{
|
||||
Xform quad_xf = MulXform(sim_ent_get_xform(ent), ent->camera_quad_xform);
|
||||
Vec2 camera_size = GetXformScale(quad_xf);
|
||||
if (!v2_is_zero(camera_size)) {
|
||||
Vec2 camera_size = ScaleFromXform(quad_xf);
|
||||
if (!IsVec2Zero(camera_size)) {
|
||||
aspect_ratio = camera_size.x / camera_size.y;
|
||||
}
|
||||
}
|
||||
f32 ratio_y = 0.33f;
|
||||
f32 ratio_x = ratio_y / aspect_ratio;
|
||||
Vec2 camera_focus_dir = v2_mul_v2(follow->control.focus, V2(ratio_x, ratio_y));
|
||||
Vec2 camera_focus_pos = v2_add(sim_ent_get_xform(follow).og, camera_focus_dir);
|
||||
Vec2 camera_focus_dir = MulVec2Vec2(follow->control.focus, VEC2(ratio_x, ratio_y));
|
||||
Vec2 camera_focus_pos = AddVec2(sim_ent_get_xform(follow).og, camera_focus_dir);
|
||||
ent->camera_xform_target = xf;
|
||||
ent->camera_xform_target.og = camera_focus_pos;
|
||||
|
||||
/* Lerp camera */
|
||||
if (ent->camera_applied_lerp_continuity_gen_plus_one == ent->camera_lerp_continuity_gen + 1) {
|
||||
f32 t = 1 - math_pow(2.f, -20.f * (f32)sim_dt);
|
||||
f32 t = 1 - PowF32(2.f, -20.f * (f32)sim_dt);
|
||||
xf = LerpXform(xf, ent->camera_xform_target, t);
|
||||
} else {
|
||||
/* Skip lerp */
|
||||
|
||||
@ -206,19 +206,19 @@ S_StartupReceipt sprite_startup(void)
|
||||
u32 width = 64;
|
||||
u32 height = 64;
|
||||
u32 *pixels = generate_purple_black_image(scratch.arena, width, height);
|
||||
G.nil_texture->gp_texture = gp_texture_alloc(GP_TEXTURE_FORMAT_R8G8B8A8_UNORM, 0, V2I32(width, height), pixels);
|
||||
G.nil_texture->gp_texture = gp_texture_alloc(GP_TEXTURE_FORMAT_R8G8B8A8_UNORM, 0, VEC2I32(width, height), pixels);
|
||||
EndScratch(scratch);
|
||||
}
|
||||
|
||||
/* Init loading sheet */
|
||||
G.loading_sheet = PushStruct(G.perm_arena, S_Sheet);
|
||||
G.loading_sheet->image_size = V2(PIXELS_PER_UNIT, PIXELS_PER_UNIT);
|
||||
G.loading_sheet->frame_size = V2(PIXELS_PER_UNIT, PIXELS_PER_UNIT);
|
||||
G.loading_sheet->image_size = VEC2(PIXELS_PER_UNIT, PIXELS_PER_UNIT);
|
||||
G.loading_sheet->frame_size = VEC2(PIXELS_PER_UNIT, PIXELS_PER_UNIT);
|
||||
|
||||
/* Init nil sheet */
|
||||
G.nil_sheet = PushStruct(G.perm_arena, S_Sheet);
|
||||
G.nil_sheet->image_size = V2(PIXELS_PER_UNIT, PIXELS_PER_UNIT);
|
||||
G.nil_sheet->frame_size = V2(PIXELS_PER_UNIT, PIXELS_PER_UNIT);
|
||||
G.nil_sheet->image_size = VEC2(PIXELS_PER_UNIT, PIXELS_PER_UNIT);
|
||||
G.nil_sheet->frame_size = VEC2(PIXELS_PER_UNIT, PIXELS_PER_UNIT);
|
||||
G.nil_sheet->loaded = 1;
|
||||
}
|
||||
SetArenaReadonly(G.perm_arena);
|
||||
@ -353,7 +353,7 @@ internal void cache_entry_load_texture(struct cache_ref ref, S_Tag tag)
|
||||
e->texture->height = decoded.height;
|
||||
e->texture->valid = 1;
|
||||
e->texture->loaded = 1;
|
||||
e->texture->gp_texture = gp_texture_alloc(GP_TEXTURE_FORMAT_R8G8B8A8_UNORM_SRGB, 0, V2I32(decoded.width, decoded.height), decoded.pixels);
|
||||
e->texture->gp_texture = gp_texture_alloc(GP_TEXTURE_FORMAT_R8G8B8A8_UNORM_SRGB, 0, VEC2I32(decoded.width, decoded.height), decoded.pixels);
|
||||
/* TODO: Query gpu for more accurate texture size in VRAM */
|
||||
memory_size += (decoded.width * decoded.height) * sizeof(*decoded.pixels);
|
||||
success = 1;
|
||||
@ -398,7 +398,7 @@ internal S_Sheet init_sheet_from_ase_result(Arena *arena, Ase_DecodedSheet ase)
|
||||
Assert(ase.num_frames >= 1);
|
||||
|
||||
Vec2 frame_size = ase.frame_size;
|
||||
Vec2 frame_center = v2_mul(ase.frame_size, 0.5f);
|
||||
Vec2 frame_center = MulVec2(ase.frame_size, 0.5f);
|
||||
|
||||
/* Init frames */
|
||||
{
|
||||
@ -533,11 +533,11 @@ internal S_Sheet init_sheet_from_ase_result(Arena *arena, Ase_DecodedSheet ase)
|
||||
Rect rect_px = RectFromScalar(x1_px, y1_px, width_px, height_px);
|
||||
Rect rect = RectFromScalar(x1, y1, width, height);
|
||||
/* Center */
|
||||
Vec2 center_px = V2(x1_px + (width_px * 0.5f), y1_px + (height_px * 0.5f));
|
||||
Vec2 center = V2(x1 + (width * 0.5f), y1 + (height * 0.5f));
|
||||
Vec2 center_px = VEC2(x1_px + (width_px * 0.5f), y1_px + (height_px * 0.5f));
|
||||
Vec2 center = VEC2(x1 + (width * 0.5f), y1 + (height * 0.5f));
|
||||
/* Dir */
|
||||
Vec2 dir_px = V2(center_px.x, -1);
|
||||
Vec2 dir = V2(0, -1);
|
||||
Vec2 dir_px = VEC2(center_px.x, -1);
|
||||
Vec2 dir = VEC2(0, -1);
|
||||
|
||||
slice->rect_px = rect_px;
|
||||
slice->center_px = center_px;
|
||||
@ -620,8 +620,8 @@ internal S_Sheet init_sheet_from_ase_result(Arena *arena, Ase_DecodedSheet ase)
|
||||
/* Apply to each point slice in point group */
|
||||
for (u32 j = 0; j < point_slices_per_frame; ++j) {
|
||||
S_SheetSlice *point_slice = &point_slice_group->frame_slices[(i * point_slices_per_frame) + j];
|
||||
point_slice->dir_px = v2_sub(ray_end, point_slice->center_px);
|
||||
point_slice->dir = v2_sub(ray_end_norm, point_slice->center);
|
||||
point_slice->dir_px = SubVec2(ray_end, point_slice->center_px);
|
||||
point_slice->dir = SubVec2(ray_end_norm, point_slice->center);
|
||||
point_slice->has_ray = 1;
|
||||
}
|
||||
}
|
||||
@ -1047,7 +1047,7 @@ S_SheetFrame sprite_sheet_get_frame(S_Sheet *sheet, u32 index)
|
||||
S_SheetFrame res = ZI;
|
||||
res.index = 0;
|
||||
res.duration = 0.1;
|
||||
res.clip = ClipAll;
|
||||
res.clip = AllClipped;
|
||||
return res;
|
||||
}
|
||||
|
||||
@ -1078,10 +1078,10 @@ S_SheetSlice sprite_sheet_get_slice(S_Sheet *sheet, String name, u32 frame_index
|
||||
S_SheetSlice res = ZI;
|
||||
if (string_eq(name, LIT("pivot"))) {
|
||||
/* 'pivot' slice does not exist, return center */
|
||||
res.center = V2(0, 0);
|
||||
res.center_px = v2_mul(sheet->frame_size, 0.5f);
|
||||
res.dir_px = V2(res.center_px.x, 0);
|
||||
res.dir = V2(0, -0.5);
|
||||
res.center = VEC2(0, 0);
|
||||
res.center_px = MulVec2(sheet->frame_size, 0.5f);
|
||||
res.dir_px = VEC2(res.center_px.x, 0);
|
||||
res.dir = VEC2(0, -0.5);
|
||||
} else {
|
||||
res = sprite_sheet_get_slice(sheet, LIT("pivot"), frame_index);
|
||||
}
|
||||
|
||||
@ -229,7 +229,7 @@ struct user_startup_receipt user_startup(F_StartupReceipt *font_sr,
|
||||
P_RegisterLogCallback(debug_console_log_callback, P_LogLevel_Debug);
|
||||
|
||||
G.window = P_AllocWindow();
|
||||
G.swapchain = gp_swapchain_alloc(G.window, V2I32(100, 100));
|
||||
G.swapchain = gp_swapchain_alloc(G.window, VEC2I32(100, 100));
|
||||
P_ShowWindow(G.window);
|
||||
|
||||
/* Start jobs */
|
||||
@ -259,19 +259,19 @@ internal void debug_draw_xform(Xform xf, u32 color_x, u32 color_y)
|
||||
f32 arrowhead_len = 15.f;
|
||||
|
||||
Vec2 pos = MulXformV2(G.world_to_ui_xf, xf.og);
|
||||
Vec2 x_ray = MulXformBasisV2(G.world_to_ui_xf, GetXformRight(xf));
|
||||
Vec2 y_ray = MulXformBasisV2(G.world_to_ui_xf, GetXformUp(xf));
|
||||
Vec2 x_ray = MulXformBasisV2(G.world_to_ui_xf, RightFromXform(xf));
|
||||
Vec2 y_ray = MulXformBasisV2(G.world_to_ui_xf, UpFromXform(xf));
|
||||
|
||||
f32 ray_scale = 1;
|
||||
x_ray = v2_mul(x_ray, ray_scale);
|
||||
y_ray = v2_mul(y_ray, ray_scale);
|
||||
x_ray = MulVec2(x_ray, ray_scale);
|
||||
y_ray = MulVec2(y_ray, ray_scale);
|
||||
|
||||
draw_arrow_ray(G.render_sig, pos, x_ray, thickness, arrowhead_len, color_x);
|
||||
draw_arrow_ray(G.render_sig, pos, y_ray, thickness, arrowhead_len, color_y);
|
||||
|
||||
//u32 color_quad = Rgba32F(0, 1, 1, 0.3);
|
||||
//Quad quad = quad_from_rect(RectFromScalar(0, 0, 1, -1));
|
||||
//quad = MulXformQuad(xf, quad_scale(quad, 0.075f));
|
||||
//Quad quad = QuadFromRect(RectFromScalar(0, 0, 1, -1));
|
||||
//quad = MulXformQuad(xf, ScaleQuad(quad, 0.075f));
|
||||
//draw_quad(G.render_sig, quad, color);
|
||||
}
|
||||
|
||||
@ -288,7 +288,7 @@ internal void debug_draw_movement(Ent *ent)
|
||||
Vec2 pos = MulXformV2(G.world_to_ui_xf, xf.og);
|
||||
Vec2 vel_ray = MulXformBasisV2(G.world_to_ui_xf, velocity);
|
||||
|
||||
if (v2_len(vel_ray) > 0.00001) {
|
||||
if (Vec2Len(vel_ray) > 0.00001) {
|
||||
draw_arrow_ray(G.render_sig, pos, vel_ray, thickness, arrow_len, color_vel);
|
||||
}
|
||||
}
|
||||
@ -416,7 +416,7 @@ internal void draw_debug_console(i32 level, b32 minimized)
|
||||
__prof;
|
||||
TempArena scratch = BeginScratchNoConflict();
|
||||
|
||||
Vec2 desired_start_pos = V2(10, minimized ? 100 : 600);
|
||||
Vec2 desired_start_pos = VEC2(10, minimized ? 100 : 600);
|
||||
i64 fade_time_ns = NsFromSeconds(10);
|
||||
f32 fade_curve = 0.5;
|
||||
f32 spacing = 0;
|
||||
@ -455,13 +455,13 @@ internal void draw_debug_console(i32 level, b32 minimized)
|
||||
f32 opacity = 0.75;
|
||||
if (minimized) {
|
||||
f32 lin = 1.0 - ClampF64((f64)(now_ns - log->time_ns) / (f64)fade_time_ns, 0, 1);
|
||||
opacity *= math_pow(lin, fade_curve);
|
||||
opacity *= PowF32(lin, fade_curve);
|
||||
}
|
||||
if (draw_pos.y > -desired_start_pos.y && opacity > 0) {
|
||||
if (log->level <= level) {
|
||||
/* Draw background */
|
||||
u32 color = colors[log->level][log->color_index];
|
||||
draw_quad(G.render_sig, quad_from_rect(log->bounds), Alpha32F(color, opacity));
|
||||
draw_quad(G.render_sig, QuadFromRect(log->bounds), Alpha32F(color, opacity));
|
||||
|
||||
/* Draw text */
|
||||
String text = log->msg;
|
||||
@ -755,7 +755,7 @@ internal void user_update(P_Window *window)
|
||||
{
|
||||
Xform mouse_xf = XformFromPos(G.world_cursor);
|
||||
CLD_Shape mouse_shape = ZI;
|
||||
mouse_shape.points[0] = V2(0, 0);
|
||||
mouse_shape.points[0] = VEC2(0, 0);
|
||||
mouse_shape.count = 1;
|
||||
mouse_shape.radius = 0.01f;
|
||||
for (u64 ent_index = 0; ent_index < G.ss_blended->num_ents_reserved; ++ent_index) {
|
||||
@ -849,16 +849,16 @@ internal void user_update(P_Window *window)
|
||||
f32 angle0 = rand_f64_from_seed(angle_seed0, 0, Tau);
|
||||
f32 angle1 = rand_f64_from_seed(angle_seed1, 0, Tau);
|
||||
|
||||
Vec2 vec0 = v2_with_len(v2_from_angle(angle0), shake);
|
||||
Vec2 vec0 = Vec2WithLen(Vec2FromAngle(angle0), shake);
|
||||
/* NOTE: vec1 not completely accurate since shake can change between frames, it's just a prediction */
|
||||
Vec2 vec1 = v2_with_len(v2_from_angle(angle1), shake);
|
||||
Vec2 vec1 = Vec2WithLen(Vec2FromAngle(angle1), shake);
|
||||
|
||||
/* TODO: Cubic interp? */
|
||||
f32 blend = (f32)(G.ss_blended->sim_time_ns % frequency_ns) / (f32)frequency_ns;
|
||||
Vec2 vec = v2_lerp(vec0, vec1, blend);
|
||||
Vec2 vec = LerpVec2(vec0, vec1, blend);
|
||||
|
||||
Xform xf = sim_ent_get_xform(ent);
|
||||
xf.og = v2_add(xf.og, v2_mul(vec, shake));
|
||||
xf.og = AddVec2(xf.og, MulVec2(vec, shake));
|
||||
sim_ent_set_xform(ent, xf);
|
||||
}
|
||||
}
|
||||
@ -870,14 +870,14 @@ internal void user_update(P_Window *window)
|
||||
if (G.debug_camera) {
|
||||
G.ui_size = G.screen_size;
|
||||
G.ui_to_screen_xf = XformIdentity;
|
||||
G.ui_to_screen_xf.og = v2_round(G.ui_to_screen_xf.og);
|
||||
G.ui_to_screen_xf.og = RoundVec2(G.ui_to_screen_xf.og);
|
||||
} else {
|
||||
/* Determine ui size by camera & window dimensions */
|
||||
f32 aspect_ratio = (f32)(DEFAULT_CAMERA_WIDTH / DEFAULT_CAMERA_HEIGHT);
|
||||
if (local_camera->valid) {
|
||||
Xform quad_xf = MulXform(sim_ent_get_xform(local_camera), local_camera->camera_quad_xform);
|
||||
Vec2 camera_size = GetXformScale(quad_xf);
|
||||
if (!v2_is_zero(camera_size)) {
|
||||
Vec2 camera_size = ScaleFromXform(quad_xf);
|
||||
if (!IsVec2Zero(camera_size)) {
|
||||
aspect_ratio = camera_size.x / camera_size.y;
|
||||
}
|
||||
}
|
||||
@ -886,15 +886,15 @@ internal void user_update(P_Window *window)
|
||||
if (width / height > aspect_ratio) {
|
||||
width = height * aspect_ratio;
|
||||
} else {
|
||||
height = math_ceil(width / aspect_ratio);
|
||||
height = CeilF32(width / aspect_ratio);
|
||||
}
|
||||
G.ui_size = V2(width, height);
|
||||
G.ui_size = VEC2(width, height);
|
||||
|
||||
/* Center ui in window */
|
||||
f32 x = math_round(G.screen_size.x / 2 - width / 2);
|
||||
f32 y = math_round(G.screen_size.y / 2 - height / 2);
|
||||
G.ui_to_screen_xf = XformFromTrs(TRS(.t = V2(x, y)));
|
||||
G.ui_to_screen_xf.og = v2_round(G.ui_to_screen_xf.og);
|
||||
f32 x = RoundF32(G.screen_size.x / 2 - width / 2);
|
||||
f32 y = RoundF32(G.screen_size.y / 2 - height / 2);
|
||||
G.ui_to_screen_xf = XformFromTrs(TRS(.t = VEC2(x, y)));
|
||||
G.ui_to_screen_xf.og = RoundVec2(G.ui_to_screen_xf.og);
|
||||
}
|
||||
|
||||
G.ui_cursor = MulXformV2(InvertXform(G.ui_to_screen_xf), G.screen_cursor);
|
||||
@ -914,7 +914,7 @@ internal void user_update(P_Window *window)
|
||||
G.debug_camera_pan_start = world_cursor;
|
||||
G.debug_camera_panning = 1;
|
||||
}
|
||||
Vec2 offset = v2_neg(v2_sub(G.debug_camera_pan_start, world_cursor));
|
||||
Vec2 offset = NegVec2(SubVec2(G.debug_camera_pan_start, world_cursor));
|
||||
G.world_to_ui_xf = TranslateXform(G.world_to_ui_xf, offset);
|
||||
world_cursor = InvertXformMulV2(G.world_to_ui_xf, G.ui_cursor);
|
||||
G.debug_camera_pan_start = world_cursor;
|
||||
@ -927,40 +927,40 @@ internal void user_update(P_Window *window)
|
||||
if (input_zooms != 0) {
|
||||
/* Zoom to cursor */
|
||||
f32 zoom_rate = 2;
|
||||
f32 zoom = math_pow(zoom_rate, input_zooms);
|
||||
f32 zoom = PowF32(zoom_rate, input_zooms);
|
||||
G.world_to_ui_xf = TranslateXform(G.world_to_ui_xf, world_cursor);
|
||||
G.world_to_ui_xf = ScaleXform(G.world_to_ui_xf, V2(zoom, zoom));
|
||||
G.world_to_ui_xf = TranslateXform(G.world_to_ui_xf, v2_neg(world_cursor));
|
||||
G.world_to_ui_xf = ScaleXform(G.world_to_ui_xf, VEC2(zoom, zoom));
|
||||
G.world_to_ui_xf = TranslateXform(G.world_to_ui_xf, NegVec2(world_cursor));
|
||||
}
|
||||
G.world_to_ui_xf.og = v2_round(G.world_to_ui_xf.og);
|
||||
G.world_to_ui_xf.og = RoundVec2(G.world_to_ui_xf.og);
|
||||
} else {
|
||||
Xform xf = sim_ent_get_xform(local_camera);
|
||||
|
||||
Vec2 world_center = xf.og;
|
||||
f32 rot = GetXformRotation(xf);
|
||||
f32 rot = RotationFromXform(xf);
|
||||
|
||||
/* Scale view into viewport based on camera size */
|
||||
Vec2 scale = G.ui_size;
|
||||
{
|
||||
Xform quad_xf = MulXform(xf, local_camera->camera_quad_xform);
|
||||
Vec2 camera_size = GetXformScale(quad_xf);
|
||||
if (!v2_is_zero(camera_size)) {
|
||||
scale = v2_div_v2(G.ui_size, camera_size);
|
||||
Vec2 camera_size = ScaleFromXform(quad_xf);
|
||||
if (!IsVec2Zero(camera_size)) {
|
||||
scale = DivVec2Vec2(G.ui_size, camera_size);
|
||||
}
|
||||
}
|
||||
scale.x = MinF32(scale.x, scale.y);
|
||||
scale.y = scale.x;
|
||||
|
||||
Vec2 ui_center = v2_mul(G.ui_size, 0.5);
|
||||
Trs trs = TRS(.t = v2_sub(ui_center, world_center), .r = rot, .s = scale);
|
||||
Vec2 ui_center = MulVec2(G.ui_size, 0.5);
|
||||
Trs trs = TRS(.t = SubVec2(ui_center, world_center), .r = rot, .s = scale);
|
||||
Vec2 pivot = world_center;
|
||||
G.world_to_ui_xf = XformIdentity;
|
||||
G.world_to_ui_xf = TranslateXform(G.world_to_ui_xf, pivot);
|
||||
G.world_to_ui_xf = TranslateXform(G.world_to_ui_xf, trs.t);
|
||||
G.world_to_ui_xf = RotateXform(G.world_to_ui_xf, trs.r);
|
||||
G.world_to_ui_xf = ScaleXform(G.world_to_ui_xf, trs.s);
|
||||
G.world_to_ui_xf = TranslateXform(G.world_to_ui_xf, v2_neg(pivot));
|
||||
G.world_to_ui_xf.og = v2_round(G.world_to_ui_xf.og);
|
||||
G.world_to_ui_xf = TranslateXform(G.world_to_ui_xf, NegVec2(pivot));
|
||||
G.world_to_ui_xf.og = RoundVec2(G.world_to_ui_xf.og);
|
||||
}
|
||||
|
||||
G.world_cursor = InvertXformMulV2(G.world_to_ui_xf, G.ui_cursor);
|
||||
@ -970,7 +970,7 @@ internal void user_update(P_Window *window)
|
||||
* ========================== */
|
||||
|
||||
b32 effects_disabled = 0;
|
||||
G.render_size = v2_round(V2(RENDER_WIDTH, RENDER_HEIGHT));
|
||||
G.render_size = RoundVec2(VEC2(RENDER_WIDTH, RENDER_HEIGHT));
|
||||
|
||||
if (G.debug_camera) {
|
||||
G.render_size = G.ui_size;
|
||||
@ -978,17 +978,17 @@ internal void user_update(P_Window *window)
|
||||
G.world_to_render_xf = G.world_to_ui_xf;
|
||||
} else {
|
||||
Xform ui_to_world_xf = InvertXform(G.world_to_ui_xf);
|
||||
Vec2 world_center = MulXformV2(ui_to_world_xf, v2_mul(G.ui_size, 0.5));
|
||||
Vec2 world_center = MulXformV2(ui_to_world_xf, MulVec2(G.ui_size, 0.5));
|
||||
|
||||
Vec2 scale = V2(PIXELS_PER_UNIT, PIXELS_PER_UNIT);
|
||||
Vec2 scale = VEC2(PIXELS_PER_UNIT, PIXELS_PER_UNIT);
|
||||
|
||||
Xform xf = XformIdentity;
|
||||
|
||||
xf = TranslateXform(xf, v2_mul(G.render_size, 0.5));
|
||||
xf = TranslateXform(xf, MulVec2(G.render_size, 0.5));
|
||||
|
||||
xf = ScaleXform(xf, scale);
|
||||
xf = TranslateXform(xf, v2_mul(world_center, -1));
|
||||
xf.og = v2_round(xf.og);
|
||||
xf = TranslateXform(xf, MulVec2(world_center, -1));
|
||||
xf.og = RoundVec2(xf.og);
|
||||
|
||||
G.world_to_render_xf = xf;
|
||||
}
|
||||
@ -1010,10 +1010,10 @@ internal void user_update(P_Window *window)
|
||||
* ========================== */
|
||||
|
||||
{
|
||||
Vec2 up = V2(0, -1);
|
||||
Vec2 ui_center = v2_mul(G.ui_size, 0.5f);
|
||||
Vec2 up = VEC2(0, -1);
|
||||
Vec2 ui_center = MulVec2(G.ui_size, 0.5f);
|
||||
Vec2 listener_pos = InvertXformMulV2(G.world_to_ui_xf, ui_center);
|
||||
Vec2 listener_dir = v2_norm(InvertXformBasisMulV2(G.world_to_ui_xf, up));
|
||||
Vec2 listener_dir = NormVec2(InvertXformBasisMulV2(G.world_to_ui_xf, up));
|
||||
mixer_set_listener(listener_pos, listener_dir);
|
||||
}
|
||||
|
||||
@ -1024,14 +1024,14 @@ internal void user_update(P_Window *window)
|
||||
{
|
||||
f32 thickness = 2;
|
||||
|
||||
Vec2 offset = v2_neg(MulXformV2(G.world_to_render_xf, V2(0, 0)));
|
||||
f32 spacing = GetXformScale(G.world_to_render_xf).x;
|
||||
Vec2 offset = NegVec2(MulXformV2(G.world_to_render_xf, VEC2(0, 0)));
|
||||
f32 spacing = ScaleFromXform(G.world_to_render_xf).x;
|
||||
|
||||
Vec2 pos = InvertXformMulV2(G.world_to_render_xf, V2(0, 0));
|
||||
Vec2 pos = InvertXformMulV2(G.world_to_render_xf, VEC2(0, 0));
|
||||
Vec2 size = InvertXformBasisMulV2(G.world_to_render_xf, G.render_size);
|
||||
u32 color0 = Rgba32F(0.17f, 0.17f, 0.17f, 1.f);
|
||||
u32 color1 = Rgba32F(0.15f, 0.15f, 0.15f, 1.f);
|
||||
draw_grid(G.render_sig, XformFromRect(RectFromV2(pos, size)), color0, color1, Rgba32(0x3f, 0x3f, 0x3f, 0xFF), ColorRed, ColorGreen, thickness, spacing, offset);
|
||||
draw_grid(G.render_sig, XformFromRect(RectFromVec2(pos, size)), color0, color1, Rgba32(0x3f, 0x3f, 0x3f, 0xFF), ColorRed, ColorGreen, thickness, spacing, offset);
|
||||
}
|
||||
|
||||
#if 0
|
||||
@ -1104,14 +1104,14 @@ internal void user_update(P_Window *window)
|
||||
* [L ] X [R ]
|
||||
* [BL] [B] [BR]
|
||||
*/
|
||||
Vec2I32 chunk_pos_tl = V2I32(chunk_pos.x - 1, chunk_pos.y - 1);
|
||||
Vec2I32 chunk_pos_t = V2I32(chunk_pos.x, chunk_pos.y - 1);
|
||||
Vec2I32 chunk_pos_tr = V2I32(chunk_pos.x + 1, chunk_pos.y - 1);
|
||||
Vec2I32 chunk_pos_l = V2I32(chunk_pos.x - 1, chunk_pos.y);
|
||||
Vec2I32 chunk_pos_r = V2I32(chunk_pos.x + 1, chunk_pos.y);
|
||||
Vec2I32 chunk_pos_bl = V2I32(chunk_pos.x - 1, chunk_pos.y + 1);
|
||||
Vec2I32 chunk_pos_b = V2I32(chunk_pos.x, chunk_pos.y + 1);
|
||||
Vec2I32 chunk_pos_br = V2I32(chunk_pos.x + 1, chunk_pos.y + 1);
|
||||
Vec2I32 chunk_pos_tl = VEC2I32(chunk_pos.x - 1, chunk_pos.y - 1);
|
||||
Vec2I32 chunk_pos_t = VEC2I32(chunk_pos.x, chunk_pos.y - 1);
|
||||
Vec2I32 chunk_pos_tr = VEC2I32(chunk_pos.x + 1, chunk_pos.y - 1);
|
||||
Vec2I32 chunk_pos_l = VEC2I32(chunk_pos.x - 1, chunk_pos.y);
|
||||
Vec2I32 chunk_pos_r = VEC2I32(chunk_pos.x + 1, chunk_pos.y);
|
||||
Vec2I32 chunk_pos_bl = VEC2I32(chunk_pos.x - 1, chunk_pos.y + 1);
|
||||
Vec2I32 chunk_pos_b = VEC2I32(chunk_pos.x, chunk_pos.y + 1);
|
||||
Vec2I32 chunk_pos_br = VEC2I32(chunk_pos.x + 1, chunk_pos.y + 1);
|
||||
Ent *chunk_ent_tl = sim_ent_from_chunk_pos(chunk_pos_tl);
|
||||
Ent *chunk_ent_t = sim_ent_from_chunk_pos(chunk_pos_t);
|
||||
Ent *chunk_ent_tr = sim_ent_from_chunk_pos(chunk_pos_tr);
|
||||
@ -1192,22 +1192,22 @@ internal void user_update(P_Window *window)
|
||||
Vec2 c = ent->tracer_gradient_start;
|
||||
Vec2 d = ent->tracer_gradient_end;
|
||||
|
||||
Vec2 vcd = v2_sub(d, c);
|
||||
Vec2 vca = v2_sub(a, c);
|
||||
Vec2 vdb = v2_sub(b, d);
|
||||
Vec2 vdc = v2_neg(vcd);
|
||||
Vec2 vcd = SubVec2(d, c);
|
||||
Vec2 vca = SubVec2(a, c);
|
||||
Vec2 vdb = SubVec2(b, d);
|
||||
Vec2 vdc = NegVec2(vcd);
|
||||
|
||||
f32 opacity_a = 1;
|
||||
f32 opacity_b = 1;
|
||||
if (v2_len_sq(vcd) != 0) {
|
||||
if (v2_dot(velocity, vca) <= 0) {
|
||||
if (Vec2LenSq(vcd) != 0) {
|
||||
if (DotVec2(velocity, vca) <= 0) {
|
||||
a = c;
|
||||
opacity_a = 0;
|
||||
} else {
|
||||
opacity_a = v2_dot(vcd, vca) / v2_len_sq(vcd);
|
||||
opacity_a = DotVec2(vcd, vca) / Vec2LenSq(vcd);
|
||||
}
|
||||
opacity_a = ClampF32(opacity_a, 0, 1);
|
||||
opacity_b = ClampF32(1.f - (v2_dot(vdc, vdb) / v2_len_sq(vdc)), 0, 1);
|
||||
opacity_b = ClampF32(1.f - (DotVec2(vdc, vdb) / Vec2LenSq(vdc)), 0, 1);
|
||||
}
|
||||
|
||||
f32 thickness = 0.01f;
|
||||
@ -1247,14 +1247,14 @@ internal void user_update(P_Window *window)
|
||||
f32 tile_size = 1.f / SIM_TILES_PER_UNIT_SQRT;
|
||||
for (i32 tile_y = 0; tile_y < SIM_TILES_PER_CHUNK_SQRT; ++tile_y) {
|
||||
for (i32 tile_x = 0; tile_x < SIM_TILES_PER_CHUNK_SQRT; ++tile_x) {
|
||||
Vec2I32 local_tile_index = V2I32(tile_x, tile_y);
|
||||
Vec2I32 local_tile_index = VEC2I32(tile_x, tile_y);
|
||||
TileKind tile = ent->tile_chunk_tiles[local_tile_index.x + (local_tile_index.y * SIM_TILES_PER_CHUNK_SQRT)];
|
||||
//if (tile > -1) {
|
||||
if (tile == SIM_TILE_KIND_WALL) {
|
||||
Vec2I32 world_tile_index = sim_world_tile_index_from_local_tile_index(chunk_index, local_tile_index);
|
||||
Vec2 pos = sim_pos_from_world_tile_index(world_tile_index);
|
||||
Xform tile_xf = XformFromRect(RectFromV2(pos, V2(tile_size, tile_size)));
|
||||
D_MaterialParams params = DRAW_MATERIAL_PARAMS(.xf = tile_xf, .texture = tile_texture->gp_texture, .is_light = 1, .light_emittance = V3(0, 0, 0));
|
||||
Xform tile_xf = XformFromRect(RectFromVec2(pos, VEC2(tile_size, tile_size)));
|
||||
D_MaterialParams params = DRAW_MATERIAL_PARAMS(.xf = tile_xf, .texture = tile_texture->gp_texture, .is_light = 1, .light_emittance = VEC3(0, 0, 0));
|
||||
draw_material(G.render_sig, params);
|
||||
}
|
||||
}
|
||||
@ -1282,7 +1282,7 @@ internal void user_update(P_Window *window)
|
||||
Aabb aabb = collider_aabb_from_collider(&ent->local_collider, xf);
|
||||
f32 thickness = 1;
|
||||
u32 color = Rgba32F(1, 0, 1, 0.5);
|
||||
Quad quad = quad_from_aabb(aabb);
|
||||
Quad quad = QuadFromAabb(aabb);
|
||||
quad = MulXformQuad(G.world_to_ui_xf, quad);
|
||||
draw_quad_line(G.render_sig, quad, thickness, color);
|
||||
}
|
||||
@ -1293,7 +1293,7 @@ internal void user_update(P_Window *window)
|
||||
S_SheetSlice slice = sprite_sheet_get_slice(sheet, LIT("attach.wep"), ent->animation_frame);
|
||||
Vec2 start = MulXformV2(sprite_xform, slice.center);
|
||||
start = MulXformV2(G.world_to_ui_xf, start);
|
||||
Vec2 end = v2_add(xf.og, ent->control.focus);
|
||||
Vec2 end = AddVec2(xf.og, ent->control.focus);
|
||||
end = MulXformV2(G.world_to_ui_xf, end);
|
||||
draw_arrow_line(G.render_sig, start, end, 3, 10, Rgba32F(1, 1, 1, 0.5));
|
||||
}
|
||||
@ -1318,7 +1318,7 @@ internal void user_update(P_Window *window)
|
||||
center = MulXformV2(G.world_to_ui_xf, center);
|
||||
|
||||
if (!slice.has_ray) {
|
||||
Quad quad = quad_from_rect(slice.rect);
|
||||
Quad quad = QuadFromRect(slice.rect);
|
||||
quad = MulXformQuad(sprite_xform, quad);
|
||||
quad = MulXformQuad(G.world_to_ui_xf, quad);
|
||||
draw_quad_line(G.render_sig, quad, 2, quad_color);
|
||||
@ -1329,7 +1329,7 @@ internal void user_update(P_Window *window)
|
||||
if (slice.has_ray) {
|
||||
Vec2 ray = MulXformBasisV2(sprite_xform, slice.dir);
|
||||
ray = MulXformBasisV2(G.world_to_ui_xf, ray);
|
||||
ray = v2_with_len(ray, 25);
|
||||
ray = Vec2WithLen(ray, 25);
|
||||
draw_arrow_ray(G.render_sig, center, ray, 2, 10, ray_color);
|
||||
}
|
||||
}
|
||||
@ -1387,7 +1387,7 @@ internal void user_update(P_Window *window)
|
||||
if (collider.count == 1 && collider.radius > 0) {
|
||||
/* Draw upwards line for circle */
|
||||
Vec2 start = xf.og;
|
||||
Vec2 end = collider_get_support_point(&collider, xf, v2_neg(xf.by)).p;
|
||||
Vec2 end = collider_get_support_point(&collider, xf, NegVec2(xf.by)).p;
|
||||
start = MulXformV2(G.world_to_ui_xf, start);
|
||||
end = MulXformV2(G.world_to_ui_xf, end);
|
||||
draw_line(G.render_sig, start, end, thickness, color);
|
||||
@ -1430,7 +1430,7 @@ internal void user_update(P_Window *window)
|
||||
f32 arrow_thickness = 2;
|
||||
f32 arrow_height = 5;
|
||||
Vec2 start = MulXformV2(G.world_to_ui_xf, dbg_pt);
|
||||
Vec2 end = MulXformV2(G.world_to_ui_xf, v2_add(dbg_pt, v2_mul(v2_norm(data->normal), len)));
|
||||
Vec2 end = MulXformV2(G.world_to_ui_xf, AddVec2(dbg_pt, MulVec2(NormVec2(data->normal), len)));
|
||||
draw_arrow_line(G.render_sig, start, end, arrow_thickness, arrow_height, color);
|
||||
}
|
||||
#if 0
|
||||
@ -1461,7 +1461,7 @@ internal void user_update(P_Window *window)
|
||||
FMT_UINT(data->num_points));
|
||||
|
||||
|
||||
draw_text(G.render_sig, disp_font, v2_add(v2_round(MulXformV2(G.world_to_ui_xf, dbg_pt)), V2(0, offset_px)), text);
|
||||
draw_text(G.render_sig, disp_font, AddVec2(RoundVec2(MulXformV2(G.world_to_ui_xf, dbg_pt)), VEC2(0, offset_px)), text);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@ -1564,12 +1564,12 @@ internal void user_update(P_Window *window)
|
||||
);
|
||||
String text = string_format(temp.arena, fmt,
|
||||
FMT_FLOAT_P(e0_xf.og.x, 24), FMT_FLOAT_P(e0_xf.og.y, 24),
|
||||
FMT_FLOAT_P(GetXformRotation(e0_xf), 24),
|
||||
FMT_FLOAT_P(RotationFromXform(e0_xf), 24),
|
||||
FMT_FLOAT_P(e1_xf.og.x, 24), FMT_FLOAT_P(e1_xf.og.y, 24),
|
||||
FMT_FLOAT_P(GetXformRotation(e1_xf), 24));
|
||||
FMT_FLOAT_P(RotationFromXform(e1_xf), 24));
|
||||
|
||||
|
||||
draw_text(G.render_sig, disp_font, v2_add(v2_round(MulXformV2(G.world_to_ui_xf, V2(0, 0))), V2(0, offset_px)), text);
|
||||
draw_text(G.render_sig, disp_font, AddVec2(RoundVec2(MulXformV2(G.world_to_ui_xf, VEC2(0, 0))), VEC2(0, offset_px)), text);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@ -1652,8 +1652,8 @@ internal void user_update(P_Window *window)
|
||||
f32 len = 0.1f;
|
||||
f32 arrow_thickness = 4;
|
||||
f32 arrowhead_height = 10;
|
||||
Vec2 start = MulXformV2(G.world_to_ui_xf, V2(0, 0));
|
||||
Vec2 end = MulXformV2(G.world_to_ui_xf, v2_mul(v2_norm(collider_res.normal), len));
|
||||
Vec2 start = MulXformV2(G.world_to_ui_xf, VEC2(0, 0));
|
||||
Vec2 end = MulXformV2(G.world_to_ui_xf, MulVec2(NormVec2(collider_res.normal), len));
|
||||
draw_arrow_line(G.render_sig, start, end, arrow_thickness, arrowhead_height, color);
|
||||
}
|
||||
}
|
||||
@ -1678,7 +1678,7 @@ internal void user_update(P_Window *window)
|
||||
f32 thickness = 3;
|
||||
|
||||
Xform quad_xf = MulXform(xf, ent->camera_quad_xform);
|
||||
Quad quad = MulXformQuad(quad_xf, QuadUnitSquareCentered);
|
||||
Quad quad = MulXformQuad(quad_xf, CenteredUnitSquareQuad);
|
||||
quad = MulXformQuad(G.world_to_ui_xf, quad);
|
||||
|
||||
draw_quad_line(G.render_sig, quad, thickness, color);
|
||||
@ -1695,7 +1695,7 @@ internal void user_update(P_Window *window)
|
||||
Vec2 crosshair_pos = G.ui_cursor;
|
||||
S_Tag crosshair = sprite_tag_from_path(LIT("sprite/crosshair.ase"));
|
||||
S_Texture *t = sprite_texture_from_tag_async(sprite_frame_scope, crosshair);
|
||||
Vec2 size = V2(t->width, t->height);
|
||||
Vec2 size = VEC2(t->width, t->height);
|
||||
Xform xf = XformFromTrs(TRS(.t = crosshair_pos, .s = size));
|
||||
draw_ui_rect(G.render_sig, DRAW_UI_RECT_PARAMS(.xf = xf, .texture = t->gp_texture));
|
||||
}
|
||||
@ -1709,11 +1709,11 @@ internal void user_update(P_Window *window)
|
||||
P_ShowWindowCursor(G.window);
|
||||
} else {
|
||||
S_Texture *t = sprite_texture_from_tag_async(sprite_frame_scope, sprite_tag_from_path(LIT("sprite/crosshair.ase")));
|
||||
Vec2 size = V2(t->width, t->height);
|
||||
Rect cursor_clip = RectFromV2(G.ui_screen_offset, G.ui_size);
|
||||
cursor_clip.pos = v2_add(cursor_clip.pos, v2_mul(size, 0.5f));
|
||||
cursor_clip.pos = v2_add(cursor_clip.pos, V2(1, 1));
|
||||
cursor_clip.size = v2_sub(cursor_clip.size, size);
|
||||
Vec2 size = VEC2(t->width, t->height);
|
||||
Rect cursor_clip = RectFromVec2(G.ui_screen_offset, G.ui_size);
|
||||
cursor_clip.pos = AddVec2(cursor_clip.pos, MulVec2(size, 0.5f));
|
||||
cursor_clip.pos = AddVec2(cursor_clip.pos, VEC2(1, 1));
|
||||
cursor_clip.size = SubVec2(cursor_clip.size, size);
|
||||
P_HideWindowCursor(G.window);
|
||||
P_EnableWindoweCursorClip(G.window, cursor_clip);
|
||||
}
|
||||
@ -1770,11 +1770,11 @@ internal void user_update(P_Window *window)
|
||||
}
|
||||
|
||||
input_move_dir = InvertXformBasisMulV2(G.world_to_ui_xf, input_move_dir); /* Make move dir relative to world view */
|
||||
input_move_dir = v2_mul(v2_norm(input_move_dir), move_speed);
|
||||
input_move_dir = MulVec2(NormVec2(input_move_dir), move_speed);
|
||||
}
|
||||
|
||||
if (!G.debug_camera) {
|
||||
G.focus_send = v2_sub(G.world_cursor, sim_ent_get_xform(local_control).og);
|
||||
G.focus_send = SubVec2(G.world_cursor, sim_ent_get_xform(local_control).og);
|
||||
}
|
||||
Vec2 input_aim_dir = G.focus_send;
|
||||
|
||||
@ -1901,7 +1901,7 @@ internal void user_update(P_Window *window)
|
||||
if (G.debug_draw && hovered_ent->valid) {
|
||||
Ent *ent = hovered_ent;
|
||||
|
||||
Vec2 pos = v2_add(G.ui_cursor, V2(15, 15));
|
||||
Vec2 pos = AddVec2(G.ui_cursor, VEC2(15, 15));
|
||||
F_Font *font = font_load_async(LIT("font/fixedsys.ttf"), 12.0f);
|
||||
if (font) {
|
||||
TempArena temp = BeginTempArena(scratch.arena);
|
||||
@ -2027,7 +2027,7 @@ internal void user_update(P_Window *window)
|
||||
//draw_text(G.render_sig, font, pos, string_format(temp.arena, LIT("blended world entities: %F/%F"), FMT_UINT(G.ss_blended->num_ents_allocated), FMT_UINT(G.ss_blended->num_ents_reserved)));
|
||||
//draw_text(G.render_sig, font, pos, text);
|
||||
|
||||
Vec2 pos = V2(10, G.ui_size.y);
|
||||
Vec2 pos = VEC2(10, G.ui_size.y);
|
||||
D_TextOffsetY offset_y = DRAW_TEXT_OFFSET_Y_BOTTOM;
|
||||
draw_text(G.render_sig, DRAW_TEXT_PARAMS(.font = font, .pos = pos, .str = text, .offset_y = offset_y, .color = ColorWhite));
|
||||
EndTempArena(temp);
|
||||
@ -2052,9 +2052,9 @@ internal void user_update(P_Window *window)
|
||||
|
||||
{
|
||||
__profn("Render");
|
||||
Vec2I32 world_resolution = v2_round_to_int(G.render_size);
|
||||
Vec2I32 user_resolution = v2_round_to_int(G.ui_size);
|
||||
Vec2I32 backbuffer_resolution = v2_round_to_int(G.screen_size);
|
||||
Vec2I32 world_resolution = RoundVec2ToVec2I32(G.render_size);
|
||||
Vec2I32 user_resolution = RoundVec2ToVec2I32(G.ui_size);
|
||||
Vec2I32 backbuffer_resolution = RoundVec2ToVec2I32(G.screen_size);
|
||||
|
||||
/* Draw world to user texture */
|
||||
G_Resource *render_texture = 0;
|
||||
@ -2649,7 +2649,7 @@ internal P_JobDef(local_sim_job, _)
|
||||
/* Cmds are too far from master time, snap step end tick */
|
||||
i64 rtt_ns = master_client->last_rtt_ns;
|
||||
f64 rtt_tick_ratio = (f64)(rtt_ns + (step_dt_ns - 1)) / (f64)step_dt_ns;
|
||||
i64 num_predict_ticks = math_round_to_int64(rtt_tick_ratio) + 5;
|
||||
i64 num_predict_ticks = RoundF64ToI64(rtt_tick_ratio) + 5;
|
||||
step_end_tick = master_client->last_tick + num_predict_ticks;
|
||||
compute_timescale = 1.1;
|
||||
} else if (cmds_ahead_on_master > 2) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user