| 105 | } |
| 106 | |
| 107 | void DebugLine::add_cone(const Vector3 &base_center, const Vector3 &tip, f32 radius, const Color4 &color, u32 segments, u32 rays) |
| 108 | { |
| 109 | Vector3 normal = tip - base_center; |
| 110 | normalize(normal); |
| 111 | const Vector3 arr[] = |
| 112 | { |
| 113 | { normal.z, normal.z, -normal.x - normal.y }, |
| 114 | { -normal.y - normal.z, normal.x, normal.x } |
| 115 | }; |
| 116 | const int idx = ((normal.z != 0.0f) && (-normal.x != normal.y)); |
| 117 | Vector3 right = arr[idx]; |
| 118 | normalize(right); |
| 119 | |
| 120 | const Vector3 x = right * radius; |
| 121 | const Vector3 y = cross(right, normal) * radius; |
| 122 | Vector3 from; |
| 123 | |
| 124 | // Draw base. |
| 125 | const f32 base_step = PI_TWO / (f32)(segments > 3 ? segments : 3); |
| 126 | from = base_center - y; |
| 127 | for (u32 i = 0; i <= segments; ++i) { |
| 128 | const f32 t = base_step * i - PI_HALF; |
| 129 | const Vector3 to = base_center + x*fcos(t) + y*fsin(t); |
| 130 | add_line(from, to, color); |
| 131 | from = to; |
| 132 | } |
| 133 | |
| 134 | // Draw rays. |
| 135 | const f32 ray_step = PI_TWO / (f32)(rays > 1 ? rays : 1); |
| 136 | from = base_center - y; |
| 137 | for (u32 i = 0; i <= rays; ++i) { |
| 138 | const f32 t = ray_step * i - PI_HALF; |
| 139 | const Vector3 to = base_center + x*fcos(t) + y*fsin(t); |
| 140 | add_line(from, tip, color); |
| 141 | from = to; |
| 142 | } |
| 143 | } |
| 144 | |
| 145 | void DebugLine::add_sphere(const Vector3 ¢er, const f32 radius, const Color4 &color, u32 segments) |
| 146 | { |
no test coverage detected