MCPcopy Create free account
hub / github.com/davideberly/GeometricTools / GetModelSpacePlanes

Method GetModelSpacePlanes

GTE/Graphics/PlanarReflectionEffect.cpp:259–310  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

257}
258
259void PlanarReflectionEffect::GetModelSpacePlanes()
260{
261 for (size_t i = 0; i < mPlaneVisuals.size(); ++i)
262 {
263 auto const& visual = mPlaneVisuals[i];
264 auto const& vbuffer = visual->GetVertexBuffer();
265 auto const& vformat = vbuffer->GetFormat();
266
267 // Verify the vertex format satisfies the constraints.
268 int32_t index = vformat.GetIndex(VASemantic::POSITION, 0);
269 LogAssert(
270 index >= 0,
271 "The POSITION semantic must occur with unit 0.");
272
273 DFType posType = vformat.GetType(index);
274 LogAssert(
275 posType == DF_R32G32B32_FLOAT || posType == DF_R32G32B32A32_FLOAT,
276 "The POSITION must be 3-tuple or 4-tuple float-valued.");
277
278 uint32_t offset = vformat.GetOffset(index);
279 LogAssert(
280 offset == 0,
281 "The POSITION must occur first in the vertex format.");
282
283 // Get the first triangle's vertex indices.
284 auto const& ibuffer = visual->GetIndexBuffer();
285 IPType primitiveType = ibuffer->GetPrimitiveType();
286 LogAssert(
287 primitiveType == IPType::IP_TRIMESH,
288 "The visual must have TRIMESH topology (for now).");
289
290 // Get the first triangle's vertex indices. Get the model-space
291 // vertices from the vertex buffer.
292 std::array<uint32_t, 3> v{};
293 ibuffer->GetTriangle(0, v[0], v[1], v[2]);
294 char const* rawData = vbuffer->GetData();
295 size_t const stride = static_cast<size_t>(vformat.GetVertexSize());
296 std::array<Vector4<float>, 3> p{};
297 for (size_t j = 0; j < 3; ++j)
298 {
299 auto vertices = reinterpret_cast<Vector3<float> const*>(
300 rawData + v[j] * stride);
301 p[j] = HLift(*vertices, 1.0f);
302 }
303
304 mPlaneOrigins[i] = p[0];
305 mPlaneNormals[i] = UnitCross(p[2] - p[0], p[1] - p[0]);
306
307 // The planar reflection effect is responsible for drawing the planes.
308 visual->culling = CullingMode::ALWAYS;
309 }
310}
311
312

Callers

nothing calls this directly

Calls 12

UnitCrossFunction · 0.85
GetPrimitiveTypeMethod · 0.80
GetVertexSizeMethod · 0.80
HLiftFunction · 0.50
GetVertexBufferMethod · 0.45
GetFormatMethod · 0.45
GetIndexMethod · 0.45
GetTypeMethod · 0.45
GetOffsetMethod · 0.45
GetIndexBufferMethod · 0.45
GetTriangleMethod · 0.45
GetDataMethod · 0.45

Tested by

no test coverage detected