Files
HelloVulkan/App/scripts/ScriptDebug.h
T
atdunbg 36b1fc0566 新增调试绘制体系:DebugDraw 服务 + 物理调试 pass + 脚本侧力学线
通用图元(线/箭头四翼头/球/胶囊/盒)瞬时+持久双缓冲聚合;
物理 pass 画刚体速度/重力/接触反力;角色 collider 与力学
线归位(引擎只画资产、脚本画行为);线宽按设备上限钳制
2026-10-08 17:02:27 +08:00

53 lines
2.2 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
//
// ScriptDebug.h:脚本侧力学调试封装(Unity Gizmos/Debug.DrawRay 的
// 游戏内同位物)。把调试惯例固化成默认值,脚本不用记参数序:
// - width = 像素(≥1),默认 3px
// - duration 恒 0(OnUpdate 每帧重画,事件类需求再裸调 Debug::)
// - depthTest 恒 false(跟角色跑的线被模型遮挡就失去意义)
// - headSize = 世界单位(箭头翼头空间尺寸),默认 0.08
//
#pragma once
#include <Engine/Debug/DebugDraw.h>
#include <glm/glm.hpp>
namespace ScriptDbg {
// 基础箭头:colorHex 语义色见下(重力红/支撑黄/意图蓝/真实绿)
inline void Arrow(const glm::vec3& from, const glm::vec3& to,
Engine::u32 colorHex, float width = 3.0f) {
Engine::Debug::Arrow(from, to, Engine::Debug::Rgb(colorHex),
/*headSize*/ 0.08f, /*width*/ width,
/*duration*/ 0.0f, /*depthTest*/ false);
}
// 重力:anchor=脚底,len=视觉长度。建议 ∝ gravityScale,且与支撑
// 力同长——静置时红(下)黄(上)等长 = 力平衡,一眼可读
inline void Gravity(const glm::vec3& anchor, float len) {
Arrow(anchor, anchor - glm::vec3(0.0f, len, 0.0f), 0xDC3C3C);
}
// 接触反力(法向支撑):只在有接触时存在——空中传 len=0 内部直接
// 不画(力学语义:离地即失支撑)
inline void Support(const glm::vec3& anchor, float len) {
if (len > 1e-3f) {
Arrow(anchor, anchor + glm::vec3(0.0f, len, 0.0f), 0xD9C33C);
}
}
// 加速度(深橙):脚本侧差分出的测量加速度(F=ma 的 a)。scale =
// m/s² → 世界长度换算;mag 低于 minMag 视为静置/匀速("没有线"=
// 没有加速度,本身就是信息),len 钳到 maxLen 防冲击尖峰爆屏
inline void Accel(const glm::vec3& anchor, const glm::vec3& accel,
float scale = 0.05f, float maxLen = 2.0f) {
const float mag = glm::length(accel);
if (mag > 0.1f) {
const float len = glm::min(mag * scale, maxLen);
Arrow(anchor, anchor + (accel / mag) * len, 0xE0640A);
}
}
} // namespace ScriptDbg