void Entity::pick(const Rayf& ray, PickResult& pickResults) { float dist = bounds().intersectWithRay(ray, NULL); if (Math<float>::isnan(dist)) return; Vec3f hitPoint = ray.pointAtDistance(dist); EntityHit* hit = new EntityHit(*this, hitPoint, dist); pickResults.add(hit); }
Vec3f Grid::moveDeltaForBounds(const Model::Face& face, const BBoxf& bounds, const BBoxf& worldBounds, const Rayf& ray, const Vec3f& position) const { const Planef dragPlane = Planef::alignedOrthogonalDragPlane(position, face.boundary().normal); const Vec3f halfSize = bounds.size() * 0.5f; float offsetLength = halfSize.dot(dragPlane.normal); if (offsetLength < 0.0f) offsetLength *= -1.0f; const Vec3f offset = dragPlane.normal * offsetLength; const float dist = dragPlane.intersectWithRay(ray); const Vec3f newPos = ray.pointAtDistance(dist); Vec3f delta = moveDeltaForPoint(bounds.center(), worldBounds, newPos - (bounds.center() - offset)); Axis::Type a = dragPlane.normal.firstComponent(); if (dragPlane.normal[a] > 0.0f) delta[a] = position[a] - bounds.min[a]; else delta[a] = position[a] - bounds.max[a]; return delta; }
void Brush::pick(const Rayf& ray, PickResult& pickResults) { float dist = bounds().intersectWithRay(ray, NULL); if (Math<float>::isnan(dist)) return; dist = Math<float>::nan(); Side* side = NULL; for (unsigned int i = 0; i < m_geometry->sides.size() && Math<float>::isnan(dist); i++) { side = m_geometry->sides[i]; dist = side->intersectWithRay(ray); } if (!Math<float>::isnan(dist)) { assert(side != NULL); Vec3f hitPoint = ray.pointAtDistance(dist); FaceHit* hit = new FaceHit(*(side->face), hitPoint, dist); pickResults.add(hit); } }