Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 28 additions & 28 deletions apps/editor/editor_app.cc
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ asset::Mesh MakeTurntable(f32 radius, f32 half_height, asset::AssetId id,
const u32 top_ring = static_cast<u32>(lod.vertices.size());
for (u32 i = 0; i <= kSegments; ++i) {
const f32 angle = static_cast<f32>(i) / kSegments * 6.28318530718f;
const f32 x = ::cos(angle), z = ::sin(angle);
const f32 x = ::cosf(angle), z = ::sinf(angle);
lod.vertices.push_back(vertex({x * radius, half_height, z * radius},
{0, 1, 0}, x * 0.5f + 0.5f,
z * 0.5f + 0.5f));
Expand All @@ -92,15 +92,15 @@ asset::Mesh MakeTurntable(f32 radius, f32 half_height, asset::AssetId id,
const u32 bottom_ring = static_cast<u32>(lod.vertices.size());
for (u32 i = 0; i <= kSegments; ++i) {
const f32 angle = static_cast<f32>(i) / kSegments * 6.28318530718f;
const f32 x = ::cos(angle), z = ::sin(angle);
const f32 x = ::cosf(angle), z = ::sinf(angle);
lod.vertices.push_back(vertex({x * radius, -half_height, z * radius},
{0, -1, 0}, x * 0.5f + 0.5f,
z * 0.5f + 0.5f));
}
const u32 side_ring = static_cast<u32>(lod.vertices.size());
for (u32 i = 0; i <= kSegments; ++i) {
const f32 angle = static_cast<f32>(i) / kSegments * 6.28318530718f;
const f32 x = ::cos(angle), z = ::sin(angle);
const f32 x = ::cosf(angle), z = ::sinf(angle);
lod.vertices.push_back(
vertex({x * radius, half_height, z * radius}, {x, 0, z},
static_cast<f32>(i) / kSegments, 0));
Expand All @@ -125,7 +125,7 @@ asset::Mesh MakeTurntable(f32 radius, f32 half_height, asset::AssetId id,
}
lod.submeshes.push_back(
{0, static_cast<u32>(lod.indices.size()), material});
mesh.bounds_radius = ::sqrt(radius * radius + half_height * half_height);
mesh.bounds_radius = ::sqrtf(radius * radius + half_height * half_height);
return mesh;
}
} // namespace
Expand Down Expand Up @@ -157,8 +157,8 @@ bool Editor::OnInitialize(app::Services &s) {

camera_.set_position({6.0f, 4.5f, 6.0f});
Vec3 d = Normalize(Vec3{0, 1.0f, 0} - camera_.position());
camera_.set_yaw_pitch(::atan2(d.x, -d.z),
::asin(rx::Clamp(d.y, -1.0f, 1.0f)));
camera_.set_yaw_pitch(::atan2f(d.x, -d.z),
::asinf(rx::Clamp(d.y, -1.0f, 1.0f)));

// Load a scene or authoring model passed on argv.
if (!open_path_.empty()) {
Expand Down Expand Up @@ -579,7 +579,7 @@ bool Editor::LoadModelDocument(const base::String &path) {
.y);
}
}
if (!::isfinite(floor_y))
if (!isfinite(floor_y))
floor_y = center.y - radius;
constexpr f32 kPlateHalfHeight = 0.055f;
const f32 surface_y =
Expand Down Expand Up @@ -629,8 +629,8 @@ bool Editor::LoadModelDocument(const base::String &path) {
camera_.set_position(center +
Vec3{radius * 1.4f, radius * 0.75f, radius * 1.8f});
Vec3 direction = Normalize(center - camera_.position());
camera_.set_yaw_pitch(::atan2(direction.x, -direction.z),
::asin(rx::Clamp(direction.y, -1.0f, 1.0f)));
camera_.set_yaw_pitch(::atan2f(direction.x, -direction.z),
::asinf(rx::Clamp(direction.y, -1.0f, 1.0f)));
status_message_ = "Imported " + base::String(fs::Filename(path)) + ": " +
rx::ToString(imported_scene.meshes.size()) + " meshes, " +
rx::ToString(region_count) + " jiggle regions" +
Expand Down Expand Up @@ -660,7 +660,7 @@ void Editor::UpdateImportedModels(f32 dt) {
model.active_walk_style = anim::WalkStyleKind::kMarch;
walk_style = march;
} else {
const f32 cycle = ::fmod(model.preview_time, 12.0f);
const f32 cycle = ::fmodf(model.preview_time, 12.0f);
if (cycle < 5.0f) {
model.active_walk_style = anim::WalkStyleKind::kHipSway;
walk_style = hip_sway;
Expand Down Expand Up @@ -737,14 +737,14 @@ void Editor::UpdateImportedModels(f32 dt) {
anim::BodyDynamicsFrame frame;
if (playing_) {
frame.linear_acceleration = {
::sin(model.preview_time * 2.7f) * 7.0f,
::sin(model.preview_time * 5.4f) * 5.5f,
::cos(model.preview_time * 2.1f) * 6.0f,
::sinf(model.preview_time * 2.7f) * 7.0f,
::sinf(model.preview_time * 5.4f) * 5.5f,
::cosf(model.preview_time * 2.1f) * 6.0f,
};
frame.angular_acceleration = {
::sin(model.preview_time * 2.3f) * 2.8f,
::cos(model.preview_time * 1.7f) * 3.5f,
::sin(model.preview_time * 3.2f) * 3.0f,
::sinf(model.preview_time * 2.3f) * 2.8f,
::cosf(model.preview_time * 1.7f) * 3.5f,
::sinf(model.preview_time * 3.2f) * 3.0f,
};
if (fire_event) {
if (event_kind == 0)
Expand Down Expand Up @@ -917,8 +917,8 @@ void Editor::FocusSelection() {
Vec3 eye = center - camera_.forward() * 4.0f;
camera_.set_position(eye);
Vec3 d = Normalize(center - eye);
camera_.set_yaw_pitch(::atan2(d.x, -d.z),
::asin(rx::Clamp(d.y, -1.0f, 1.0f)));
camera_.set_yaw_pitch(::atan2f(d.x, -d.z),
::asinf(rx::Clamp(d.y, -1.0f, 1.0f)));
}

// Picking. The engine GPU path (DrawItem::pick_id + Renderer::RequestPick /
Expand Down Expand Up @@ -966,7 +966,7 @@ bool RayTriangle(const Vec3 &o, const Vec3 &d, const Vec3 &a, const Vec3 &b,
Vec3 e1 = b - a, e2 = c - a;
Vec3 p = Cross(d, e2);
f32 det = Dot(e1, p);
if (::fabs(det) < 1e-8f)
if (::fabsf(det) < 1e-8f)
return false;
f32 inv = 1.0f / det;
Vec3 tv = o - a;
Expand Down Expand Up @@ -1052,7 +1052,7 @@ Vec2 Editor::ProjectToScreen(const Vec3 &world, bool *in_front) const {
f32 w = vp.m[3] * world.x + vp.m[7] * world.y + vp.m[11] * world.z + vp.m[15];
if (in_front)
*in_front = w > 1e-4f;
if (::fabs(w) < 1e-6f)
if (::fabsf(w) < 1e-6f)
w = 1e-6f;
f32 ndc_x = x / w, ndc_y = y / w;
return {(ndc_x * 0.5f + 0.5f) * window_->width(),
Expand Down Expand Up @@ -1112,7 +1112,7 @@ void Editor::UpdateGizmo(f32 mx, f32 my, bool lmb_down, bool lmb_edge) {
// distance from cursor to the handle tip. The tolerance is authored at
// 1x and both operands are pixels, so it scales with the buffer or the
// handle gets relatively harder to grab the denser the display.
f32 d = ::hypot(mx - s1.x, my - s1.y);
f32 d = ::hypotf(mx - s1.x, my - s1.y);
if (d < 14.0f * window_->pixel_density()) {
gizmo_drag_.active = true;
gizmo_drag_.axis = a;
Expand All @@ -1121,7 +1121,7 @@ void Editor::UpdateGizmo(f32 mx, f32 my, bool lmb_down, bool lmb_edge) {
gizmo_drag_.grab_mouse_x = mx;
gizmo_drag_.grab_mouse_y = my;
Vec2 sd{s1.x - s0.x, s1.y - s0.y};
f32 sl = rx::Max(1.0f, ::hypot(sd.x, sd.y));
f32 sl = rx::Max(1.0f, ::hypotf(sd.x, sd.y));
gizmo_drag_.axis_screen_dir = {sd.x / sl, sd.y / sl};
gizmo_drag_.world_per_pixel = len / sl;
undo_.BeginGroup("Move");
Expand Down Expand Up @@ -1585,7 +1585,7 @@ void Editor::RunAutopilot() {
scene::Transform *t = world_->Get<scene::Transform>(find_named("Cube"));
RX_INFO("autopilot: undo -> cube z={:.2f} expected 0 -> {}",
t ? t->position[2] : -99.f,
(t && ::fabs(t->position[2]) < 1e-3f) ? "PASS" : "FAIL");
(t && ::fabsf(t->position[2]) < 1e-3f) ? "PASS" : "FAIL");
MarkDirty();
break;
}
Expand All @@ -1594,7 +1594,7 @@ void Editor::RunAutopilot() {
scene::Transform *t = world_->Get<scene::Transform>(find_named("Cube"));
RX_INFO("autopilot: redo -> cube z={:.2f} expected 2 -> {}",
t ? t->position[2] : -99.f,
(t && ::fabs(t->position[2] - 2.0f) < 1e-3f) ? "PASS" : "FAIL");
(t && ::fabsf(t->position[2] - 2.0f) < 1e-3f) ? "PASS" : "FAIL");
MarkDirty();
break;
}
Expand Down Expand Up @@ -1628,15 +1628,15 @@ void Editor::RunAutopilot() {
const f32 height = terrain_.SampleHeight(0, 0).value_or(-99.0f);
RX_INFO("autopilot: terrain undo height={:.3f} expected {:.3f} -> {}",
height, terrain_before,
::fabs(height - terrain_before) < 1e-4f ? "PASS" : "FAIL");
::fabsf(height - terrain_before) < 1e-4f ? "PASS" : "FAIL");
break;
}
case 520: {
PerformRedo();
const f32 height = terrain_.SampleHeight(0, 0).value_or(-99.0f);
RX_INFO("autopilot: terrain redo height={:.3f} expected {:.3f} -> {}",
height, terrain_after,
::fabs(height - terrain_after) < 1e-4f ? "PASS" : "FAIL");
::fabsf(height - terrain_after) < 1e-4f ? "PASS" : "FAIL");
break;
}
case 530:
Expand All @@ -1661,10 +1661,10 @@ void Editor::RunAutopilot() {
scene::Transform *t = e ? world_->Get<scene::Transform>(e) : nullptr;
RX_INFO("autopilot: after load cube z={:.2f} expected 2 -> {}",
t ? t->position[2] : -99.f,
(t && ::fabs(t->position[2] - 2.0f) < 1e-3f) ? "PASS" : "FAIL");
(t && ::fabsf(t->position[2] - 2.0f) < 1e-3f) ? "PASS" : "FAIL");
const f32 height = terrain_.SampleHeight(0, 0).value_or(-99.0f);
const bool sidecar_pass = fs::Exists("scene_saved.rxterrain") &&
::fabs(height - terrain_after) < 2e-3f;
::fabsf(height - terrain_after) < 2e-3f;
RX_INFO("autopilot: terrain sidecar height={:.3f} expected {:.3f} -> {}",
height, terrain_after, sidecar_pass ? "PASS" : "FAIL");
break;
Expand Down
18 changes: 9 additions & 9 deletions apps/editor/editor_terrain.cc
Original file line number Diff line number Diff line change
Expand Up @@ -121,14 +121,14 @@ void Editor::SetupDefaultTerrain() {
const i32 grid_z = tile_z * static_cast<i32>(quads) + static_cast<i32>(z);
const f32 world_x = grid_x * spacing;
const f32 world_z = grid_z * spacing;
const f32 broad = 0.46f * ::sin(world_x * 0.22f) * ::cos(world_z * 0.18f);
const f32 detail = 0.17f * ::sin((world_x + world_z) * 0.48f) +
0.10f * ::cos((world_x - world_z) * 0.61f);
const f32 knoll = 0.30f * ::exp(-(world_x * world_x + world_z * world_z) / 95.0f);
const f32 broad = 0.46f * ::sinf(world_x * 0.22f) * ::cosf(world_z * 0.18f);
const f32 detail = 0.17f * ::sinf((world_x + world_z) * 0.48f) +
0.10f * ::cosf((world_x - world_z) * 0.61f);
const f32 knoll = 0.30f * ::expf(-(world_x * world_x + world_z * world_z) / 95.0f);
const size_t sample = static_cast<size_t>(z) * side + x;
heights[sample] = broad + detail + knoll;

const f32 patch = ::sin(world_x * 0.31f) * ::cos(world_z * 0.27f);
const f32 patch = ::sinf(world_x * 0.31f) * ::cosf(world_z * 0.27f);
if (heights[sample] > 0.62f) {
weights[sample].rgba = {40, 25, 190, 0};
} else if (heights[sample] < -0.25f) {
Expand Down Expand Up @@ -235,7 +235,7 @@ base::Pair<Vec3, Vec3> Editor::ViewportCameraRay(f32 mx, f32 my) const {
const f32 height = static_cast<f32>(window_->height());
const f32 ndc_x = 2.0f * mx / width - 1.0f;
const f32 ndc_y = 1.0f - 2.0f * my / height;
const f32 tan_half_fov = ::tan(1.0472f * 0.5f);
const f32 tan_half_fov = ::tanf(1.0472f * 0.5f);
const Vec3 forward = camera_.forward();
const Vec3 right = Normalize(Cross(forward, {0, 1, 0}));
const Vec3 up = Cross(right, forward);
Expand Down Expand Up @@ -425,7 +425,7 @@ void Editor::UpdateModeInteraction(bool lmb_down, bool lmb_edge) {
if (terrain_cursor_hit_) {
position = terrain_cursor_hit_->position;
} else {
const f32 plane_t = ::fabs(direction.y) > 1e-5f ? -origin.y / direction.y : -1.0f;
const f32 plane_t = ::fabsf(direction.y) > 1e-5f ? -origin.y / direction.y : -1.0f;
position = plane_t > 0 ? origin + direction * plane_t : origin + direction * 5.0f;
}
position.y += vertical_offset;
Expand Down Expand Up @@ -516,8 +516,8 @@ void Editor::AppendInteractionPreview(base::Vector<render::DebugLine>* lines) co
Vec3 previous;
for (int i = 0; i <= kSegments; ++i) {
const f32 angle = static_cast<f32>(i) * 6.2831853f / kSegments;
Vec3 point{center.x + ::cos(angle) * radius, center.y + 0.035f,
center.z + ::sin(angle) * radius};
Vec3 point{center.x + ::cosf(angle) * radius, center.y + 0.035f,
center.z + ::sinf(angle) * radius};
if (editor_mode_ == EditorMode::kTerrain) {
if (base::Optional<f32> y = terrain_.SampleHeight(point.x, point.z)) point.y = *y + 0.035f;
}
Expand Down
12 changes: 6 additions & 6 deletions apps/editor/editor_ui.cc
Original file line number Diff line number Diff line change
Expand Up @@ -107,23 +107,23 @@ base::String EscapeUguiString(base::StringRef value) {
void QuatToEuler(const Quat &q, f32 out_deg[3]) {
f32 sinr = 2 * (q.w * q.x + q.y * q.z);
f32 cosr = 1 - 2 * (q.x * q.x + q.y * q.y);
f32 x = ::atan2(sinr, cosr);
f32 x = ::atan2f(sinr, cosr);
f32 sinp = 2 * (q.w * q.y - q.z * q.x);
f32 y =
::fabs(sinp) >= 1 ? ::copysign(1.5707963f, sinp) : ::asin(sinp);
::fabsf(sinp) >= 1 ? ::copysignf(1.5707963f, sinp) : ::asinf(sinp);
f32 siny = 2 * (q.w * q.z + q.x * q.y);
f32 cosy = 1 - 2 * (q.y * q.y + q.z * q.z);
f32 z = ::atan2(siny, cosy);
f32 z = ::atan2f(siny, cosy);
const f32 r2d = 57.29578f;
out_deg[0] = x * r2d;
out_deg[1] = y * r2d;
out_deg[2] = z * r2d;
}
Quat EulerToQuat(const f32 deg[3]) {
const f32 d2r = 0.0174533f;
f32 cx = ::cos(deg[0] * d2r * 0.5f), sx = ::sin(deg[0] * d2r * 0.5f);
f32 cy = ::cos(deg[1] * d2r * 0.5f), sy = ::sin(deg[1] * d2r * 0.5f);
f32 cz = ::cos(deg[2] * d2r * 0.5f), sz = ::sin(deg[2] * d2r * 0.5f);
f32 cx = ::cosf(deg[0] * d2r * 0.5f), sx = ::sinf(deg[0] * d2r * 0.5f);
f32 cy = ::cosf(deg[1] * d2r * 0.5f), sy = ::sinf(deg[1] * d2r * 0.5f);
f32 cz = ::cosf(deg[2] * d2r * 0.5f), sz = ::sinf(deg[2] * d2r * 0.5f);
return Normalize(
Quat{sx * cy * cz - cx * sy * sz, cx * sy * cz + sx * cy * sz,
cx * cy * sz - sx * sy * cz, cx * cy * cz + sx * sy * sz});
Expand Down
6 changes: 3 additions & 3 deletions apps/editor/fly_camera.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
namespace rx {

Vec3 FlyCamera::forward() const {
return {::cos(pitch_) * ::sin(yaw_), ::sin(pitch_), -::cos(pitch_) * ::cos(yaw_)};
return {::cosf(pitch_) * ::sinf(yaw_), ::sinf(pitch_), -::cosf(pitch_) * ::cosf(yaw_)};
}

void FlyCamera::Update(const InputState& input, const ActionState& actions, bool allow_mouse,
Expand All @@ -17,7 +17,7 @@ void FlyCamera::Update(const InputState& input, const ActionState& actions, bool
yaw_ += input.mouse_dx * sensitivity;
pitch_ -= input.mouse_dy * sensitivity;
if (input.wheel != 0) {
speed *= ::pow(1.2f, input.wheel);
speed *= ::powf(1.2f, input.wheel);
speed = rx::Clamp(speed, 0.1f, 200.0f);
}
}
Expand All @@ -39,7 +39,7 @@ void FlyCamera::Update(const InputState& input, const ActionState& actions, bool
if (actions.down(Action::kCamUp) || actions.down(Action::kJump)) move += Vec3{0, 1, 0};
if (actions.down(Action::kCamDown) || actions.down(Action::kSneak)) move += Vec3{0, -1, 0};

f32 length = ::sqrt(Dot(move, move));
f32 length = ::sqrtf(Dot(move, move));
if (length > 0) {
f32 boost = actions.down(Action::kSprint) ? 4.0f : 1.0f;
position_ += move * (speed * boost * dt / length);
Expand Down
3 changes: 3 additions & 0 deletions cmake/mingw-shims/WinSock2.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Case shim for the mingw cross build: zetanet includes <WinSock2.h>, mingw
// ships lowercase <winsock2.h> on a case-sensitive fs.
#include <winsock2.h>
12 changes: 6 additions & 6 deletions engine/anim/anim_graph.cc
Original file line number Diff line number Diff line change
Expand Up @@ -100,27 +100,27 @@ kinema::OwnedClip BakeGait(const kinema::Skeleton& sk, u32 frames, f32 rate, con
for (u32 fr = 0; fr < frames; ++fr) {
const f32 phase = static_cast<f32>(fr) / static_cast<f32>(frames - 1); // 0..1, wraps
const f32 theta = phase * kTwoPi;
const f32 leg = ::sin(theta);
const f32 leg = ::sinf(theta);

for (u32 bone = 0; bone < bones; ++bone) {
kinema::Quat rot = sk.bind_rotation[bone];
auto is = [&](int idx) { return idx >= 0 && static_cast<u32>(idx) == bone; };
if (is(j.l_thigh)) rot = Compose(rot, x, amp.thigh * leg);
else if (is(j.r_thigh)) rot = Compose(rot, x, -amp.thigh * leg);
else if (is(j.l_calf))
rot = Compose(rot, x, -amp.knee * Clamp01(-::sin(theta - 0.6f)));
rot = Compose(rot, x, -amp.knee * Clamp01(-::sinf(theta - 0.6f)));
else if (is(j.r_calf))
rot = Compose(rot, x, -amp.knee * Clamp01(-::sin(theta + kPi - 0.6f)));
rot = Compose(rot, x, -amp.knee * Clamp01(-::sinf(theta + kPi - 0.6f)));
else if (is(j.l_arm)) rot = Compose(rot, x, -amp.arm * leg);
else if (is(j.r_arm)) rot = Compose(rot, x, amp.arm * leg);
else if (is(j.spine1)) rot = Compose(rot, z, amp.spine * ::cos(theta));
else if (is(j.spine1)) rot = Compose(rot, z, amp.spine * ::cosf(theta));
else if (is(j.spine)) rot = Compose(rot, x, amp.lean); // constant forward lean
b.SetSample(fr, bone, sk.bind_translation[bone], rot, sk.bind_scale[bone]);
}
if (curve >= 0) {
// Two intensity pulses per cycle, peaking at the footfalls.
f32 pL = ::exp(-::pow((phase - 0.25f) * 6.0f, 2.0f));
f32 pR = ::exp(-::pow((phase - 0.75f) * 6.0f, 2.0f));
f32 pL = ::expf(-::powf((phase - 0.25f) * 6.0f, 2.0f));
f32 pR = ::expf(-::powf((phase - 0.75f) * 6.0f, 2.0f));
b.SetCurveSample(fr, static_cast<u32>(curve), rx::Max(pL, pR));
}
}
Expand Down
Loading