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

Method PickPoints

GTE/Graphics/Picker.cpp:445–501  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

443}
444
445void Picker::PickPoints(std::shared_ptr<Visual> const& visual, char const* positions,
446 uint32_t vstride, IndexBuffer* ibuffer, Line3<float> const& line)
447{
448 // Compute distances from the model-space points to the line.
449 uint32_t const firstPoint = ibuffer->GetFirstPrimitive();
450 uint32_t const numPoints = ibuffer->GetNumActivePrimitives();
451 bool isIndexed = ibuffer->IsIndexed();
452 for (uint32_t i = firstPoint; i < firstPoint + numPoints; ++i)
453 {
454 // Get the vertex index for the point.
455 uint32_t v;
456 if (isIndexed)
457 {
458 ibuffer->GetPoint(i, v);
459 }
460 else
461 {
462 v = i;
463 }
464
465 // Get the vertex position.
466 auto p = *reinterpret_cast<Vector3<float> const*>(positions + static_cast<size_t>(v) * vstride);
467
468 // Compute point-line distance.
469 DCPQuery<float, Vector3<float>, Line3<float>> query;
470 auto result = query(p, line);
471 if (result.distance <= mMaxDistance && mTMin <= result.parameter && result.parameter <= mTMax)
472 {
473 PickRecord record;
474 record.visual = visual;
475 record.primitiveType = IP_POLYPOINT;
476 record.primitiveIndex = i;
477 record.vertexIndex[0] = static_cast<int32_t>(v);
478 record.vertexIndex[1] = -1;
479 record.vertexIndex[2] = -1;
480 record.t = result.parameter;
481 record.bary[0] = 1.0f;
482 record.bary[1] = 0.0f;
483 record.bary[2] = 0.0f;
484 record.linePoint = HLift(result.closest[1], 1.0f);
485 record.primitivePoint = HLift(p, 1.0f);
486
487#if defined (GTE_USE_VEC_MAT)
488 record.linePoint = record.linePoint * visual->worldTransform;
489 record.primitivePoint = record.primitivePoint * visual->worldTransform;
490#else
491 record.linePoint = visual->worldTransform * record.linePoint;
492 record.primitivePoint = visual->worldTransform * record.primitivePoint;
493#endif
494 record.distanceToLinePoint = Length(record.linePoint - mOrigin);
495 record.distanceToPrimitivePoint = Length(record.primitivePoint - mOrigin);
496 record.distanceBetweenLinePrimitive = Length(record.linePoint - record.primitivePoint);
497
498 records.push_back(record);
499 }
500 }
501}
502

Callers

nothing calls this directly

Calls 6

GetFirstPrimitiveMethod · 0.80
IsIndexedMethod · 0.80
GetPointMethod · 0.80
HLiftFunction · 0.50
LengthFunction · 0.50

Tested by

no test coverage detected