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

Method CreateNode

GTE/Samples/SceneGraphs/BspNodes/BspNodesWindow3.cpp:330–384  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

328}
329
330std::shared_ptr<BspNode> BspNodesWindow3::CreateNode(int32_t i,
331 Vector2<float> const& v0, Vector2<float> const& v1,
332 Vector4<float> const& color)
333{
334 // Create the model-space separating plane.
335 Vector2<float> dir = v1 - v0;
336 Vector3<float> normal{ dir[1], -dir[0], 0.0f };
337 Normalize(normal);
338 float constant = normal[0] * v0[0] + normal[1] * v0[1];
339 Plane3<float> modelPlane(normal, constant);
340
341 // Create the BSP node.
342 std::shared_ptr<BspNode> bsp = std::make_shared<BspNode>(modelPlane);
343
344 struct Vertex
345 {
346 Vector3<float> position;
347 Vector4<float> color;
348 };
349 VertexFormat vformat;
350 vformat.Bind(VASemantic::POSITION, DF_R32G32B32_FLOAT, 0);
351 vformat.Bind(VASemantic::COLOR, DF_R32G32B32A32_FLOAT, 0);
352 MeshFactory mf;
353 mf.SetVertexFormat(vformat);
354
355 // Create the rectangle representation of the model plane and set the
356 // vertex colors to the specified color.
357 float xExtent = 0.5f * Length(dir);
358 float yExtent = 0.125f;
359 mRectangle[i] = mf.CreateRectangle(2, 2, xExtent, yExtent);
360 auto vbuffer = mRectangle[i]->GetVertexBuffer().get();
361 Vertex* vertex = vbuffer->Get<Vertex>();
362 for (int32_t j = 0; j < 4; ++j)
363 {
364 vertex[j].color = color;
365 }
366 mRectangle[i]->SetEffect(mVCEffect[i]);
367
368 // Set the position and orientation for the world-space plane.
369 Vector3<float> trn{ 0.5f*(v0[0] + v1[0]), 0.5f*(v0[1] + v1[1]), yExtent + 0.001f };
370
371 Matrix4x4<float> zRotate = Rotation<4, float>(AxisAngle<4, float>(
372 Vector4<float>::Unit(2), std::atan2(dir[1], dir[0])));
373
374 Matrix4x4<float> xRotate = Rotation<4, float>(AxisAngle<4, float>(
375 Vector4<float>::Unit(0), (float)GTE_C_HALF_PI));
376
377 Matrix4x4<float> rotate = DoTransform(zRotate, xRotate);
378
379 mRectangle[i]->localTransform.SetTranslation(trn);
380 mRectangle[i]->localTransform.SetRotation(rotate);
381
382 bsp->AttachCoplanarChild(mRectangle[i]);
383 return bsp;
384}
385
386

Callers

nothing calls this directly

Calls 12

SetVertexFormatMethod · 0.80
CreateRectangleMethod · 0.80
SetEffectMethod · 0.80
SetTranslationMethod · 0.80
SetRotationMethod · 0.80
AttachCoplanarChildMethod · 0.80
NormalizeFunction · 0.50
LengthFunction · 0.50
atan2Function · 0.50
DoTransformFunction · 0.50
BindMethod · 0.45
GetVertexBufferMethod · 0.45

Tested by

no test coverage detected