| 1968 | namespace |
| 1969 | { |
| 1970 | void DrawCylinder(Array<DebugTriangle>* list, const Vector3& position, const Quaternion& orientation, float radius, float height, const Color& color, float duration) |
| 1971 | { |
| 1972 | // Setup cache |
| 1973 | PROFILE_MEM(EngineDebug); |
| 1974 | Float3 CylinderCache[DEBUG_DRAW_CYLINDER_VERTICES]; |
| 1975 | const float angleBetweenFacets = TWO_PI / DEBUG_DRAW_CYLINDER_RESOLUTION; |
| 1976 | const float verticalOffset = height * 0.5f; |
| 1977 | int32 index = 0; |
| 1978 | for (int32 i = 0; i < DEBUG_DRAW_CYLINDER_RESOLUTION; i++) |
| 1979 | { |
| 1980 | const float theta = i * angleBetweenFacets; |
| 1981 | const float x = Math::Cos(theta) * radius; |
| 1982 | const float z = Math::Sin(theta) * radius; |
| 1983 | |
| 1984 | // Top cap |
| 1985 | CylinderCache[index++] = Float3(x, verticalOffset, z); |
| 1986 | |
| 1987 | // Top part of body |
| 1988 | CylinderCache[index++] = Float3(x, verticalOffset, z); |
| 1989 | |
| 1990 | // Bottom part of body |
| 1991 | CylinderCache[index++] = Float3(x, -verticalOffset, z); |
| 1992 | |
| 1993 | // Bottom cap |
| 1994 | CylinderCache[index++] = Float3(x, -verticalOffset, z); |
| 1995 | } |
| 1996 | |
| 1997 | DebugTriangle t; |
| 1998 | t.Color = Color32(color); |
| 1999 | t.TimeLeft = duration; |
| 2000 | const Float3 positionF = position - Context->Origin; |
| 2001 | const Matrix world = Matrix::RotationQuaternion(orientation) * Matrix::Translation(positionF); |
| 2002 | |
| 2003 | // Write triangles |
| 2004 | for (uint32 i = 0; i < DEBUG_DRAW_CYLINDER_VERTICES; i += 4) |
| 2005 | { |
| 2006 | // Each iteration, the loop advances to the next vertex column |
| 2007 | // Four triangles per column (except for the four degenerate cap triangles) |
| 2008 | |
| 2009 | // Top cap triangles |
| 2010 | auto nextIndex = (uint16)((i + 4) % DEBUG_DRAW_CYLINDER_VERTICES); |
| 2011 | if (nextIndex != 0) |
| 2012 | { |
| 2013 | Float3::Transform(CylinderCache[i], world, t.V0); |
| 2014 | Float3::Transform(CylinderCache[nextIndex], world, t.V1); |
| 2015 | Float3::Transform(CylinderCache[0], world, t.V2); |
| 2016 | list->Add(t); |
| 2017 | } |
| 2018 | |
| 2019 | // Body triangles |
| 2020 | nextIndex = (uint16)((i + 5) % DEBUG_DRAW_CYLINDER_VERTICES); |
| 2021 | Float3::Transform(CylinderCache[(i + 1)], world, t.V0); |
| 2022 | Float3::Transform(CylinderCache[(i + 2)], world, t.V1); |
| 2023 | Float3::Transform(CylinderCache[nextIndex], world, t.V2); |
| 2024 | list->Add(t); |
| 2025 | |
| 2026 | Float3::Transform(CylinderCache[nextIndex], world, t.V0); |
| 2027 | Float3::Transform(CylinderCache[(i + 2)], world, t.V1); |