MCPcopy Create free account
hub / github.com/Illation/ETEngine / DrawGrid

Method DrawGrid

Engine/source/EtRendering/Extensions/DebugRenderer.cpp:150–297  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

148}
149
150void DebugRenderer::DrawGrid(Camera const& camera, float pixelSpacingRad)
151{
152#if defined(ET_DEBUG)
153 vec3 camPos = camera.GetPosition();
154
155 //max draw distance of the grid
156 constexpr float falloffAngle = math::radians(75.f);
157 float distLimit = sqrt(pow(camera.GetFarPlane(), 2) - camPos.y*camPos.y);
158 float maxDist = std::min(tan(falloffAngle)*std::abs(camPos.y), distLimit);
159
160 //figure out the spacing of lines
161 static const float unit = 1;
162
163 float spacing = tan((camera.GetFOV() / Viewport::GetCurrentViewport()->GetDimensions().x)*pixelSpacingRad)*std::abs(camPos.y);
164 int32 digitCount = 0;
165 float num = abs(spacing);
166 while (num >= unit)
167 {
168 num /= 10;
169 digitCount++;
170 }
171 int32 spacingLower = 10 ^ (digitCount);
172 int32 spacingHigher = spacingLower * 10;
173
174 //how many lines do we draw?
175 int32 linesDrawn = (int32)(maxDist / (float)spacingLower);
176
177 vec2 floorPos = vec2(camPos.x, camPos.z);//height is 0
178 ivec2 lineIdx = math::vecCast<int32>((floorPos / (float)spacingLower));
179 vec2 basePos = math::vecCast<float>(lineIdx) * (float)spacingLower;
180
181 //Line thickness and alpha
182 constexpr float thicknessHigher = 5;
183 constexpr float thicknessLower = 2;
184
185 float maxAlpha = 0.5f;
186 float fade = (spacing - spacingLower) / (spacingHigher - spacingLower);
187 fade = 1;
188 float thickness = thicknessLower + ((thicknessHigher - thicknessLower)*fade);
189
190 const vec3 greyCol(0.75f);
191 const vec3 redCol(1, 0, 0);
192 const vec3 blueCol(0, 0, 1);
193
194 //Create the lines
195 std::vector<LineVertex> normalLines;
196 std::vector<LineVertex> thickLines;
197
198 //lateral (X)
199 for (int32 i = lineIdx.y - linesDrawn; i < lineIdx.y + linesDrawn; ++i)
200 {
201 vec2 pos = math::vecCast<float>(ivec2(lineIdx.x, i)) * (float)spacingLower;
202 float lineFalloff = 1 - (abs(pos.y - basePos.y) / maxDist);
203 float lineDist = sin(math::PI_DIV2*lineFalloff)*maxDist;
204 vec3 p0 = vec3(pos.x-lineDist, 0, pos.y);
205 vec3 p1 = vec3(pos.x, 0, pos.y);
206 vec3 p2 = vec3(pos.x+lineDist, 0, pos.y);
207

Callers

nothing calls this directly

Calls 8

radiansFunction · 0.85
LineVertexClass · 0.85
insertMethod · 0.80
endMethod · 0.80
beginMethod · 0.80
GetFarPlaneMethod · 0.45
GetFOVMethod · 0.45
GetDimensionsMethod · 0.45

Tested by

no test coverage detected