Skip to content

Commit

Permalink
bug fixed: sphere ray intersection
Browse files Browse the repository at this point in the history
  • Loading branch information
denizdiktas committed Aug 15, 2023
1 parent b028dca commit 88b2e91
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions Arrangement_on_surface_2/demo/earth/Main_widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,32 +75,28 @@ void Main_widget::mousePressEvent(QMouseEvent* e)
float ti = -1;
if (abs(d) < std::numeric_limits<float>::epsilon())
{
// single intersection
ti = -b / (2 * a);
qDebug() << "*** NUM INTERSECTIONS= 1, ti = " << ti;
}
else
{
if (d < 0)
{
qDebug() << "* NUM INTERSECTIONS = 0";

// no intersection
return;
}
else
{

// two intersections
auto sd = sqrt(d);
auto t1 = (-b - d) / (2 * a);
auto t2 = (-b + d) / (2 * a);
auto t1 = (-b - sd) / (2 * a);
auto t2 = (-b + sd) / (2 * a);
if (t1 > 0 && t2 > 0)
ti = std::min(t1, t2);
else if (t1 > 0)
ti = t1;
else
ti = t2;

qDebug() << "*** NUM INTERSECTIONS= 2, ti = " << ti;
}
}

Expand Down Expand Up @@ -384,7 +380,7 @@ void Main_widget::init_camera()
m_camera_manip_zoom = std::make_unique<Camera_manip_zoom>(m_camera);

// this makes z-axes point upwards!
//m_model.rotate(-90, 1, 0, 0);
m_model.rotate(-90, 1, 0, 0);

// register the zoom-changed function
Message_manager::add("zoom_changed", [&]
Expand Down

0 comments on commit 88b2e91

Please sign in to comment.