john-chapman / im3d

Immediate mode rendering and 3d gizmos.
MIT License
1.21k stars 63 forks source link

Intersect(Ray, Capsule) #34

Open shadd3 opened 6 years ago

shadd3 commented 6 years ago

hello, thanks for your work.

I embeded your library within a native/android application (Im3d on PC Version / my application runs correcly) but on the android version, the axis selection does not work

due to an issue with Intersect (see t0 & t1 )

bool Context::gizmoAxisTranslation_Behavior(Id _id, const Vec3& _origin, const Vec3& _axis, float _snap, float _worldHeight, float _worldSize, Vec3* _out_)
{
......
        float t0, t1;  <===== here
        bool intersects = Intersect(ray, axisCapsule, t0, t1);  <===== here
        makeHot(_id, t0, intersects);  <===== here
......
}
bool Im3d::Intersect(const Ray& _ray, const Capsule& _capsule, float& t0_, float& t1_ <==== here) 
{
    //IM3D_ASSERT(false); // \todo implement
    return Intersects(_ray, _capsule);
}

t0 & t1 are not initialized & not filled by Intersect but used by makeHot workarround : makeHot => /_depth < m_hotDepth &&/ or Intersect => / t0 = 0.0f; t1 = 1.0f;/

bool Context::makeHot(Id _id, float _depth, bool _intersects)
{
    if (m_activeId == Id_Invalid && /*_depth < m_hotDepth &&*/ <==== here _intersects && !isKeyDown(Action_Select)) {
        m_hotId = _id;
        m_appHotId = m_appId;
        m_hotDepth = _depth;
        return true;
    }
    return false;
}

or

bool Im3d::Intersect(const Ray& _ray, const Capsule& _capsule, float& t0_, float& t1_)
{
    //IM3D_ASSERT(false); // \todo implement
    t0_ = 0.0f;
    t1_ = 1.0f;
    return Intersects(_ray, _capsule);
}

regards

john-chapman commented 6 years ago

Hi - thanks very much for reporting this. As you noted it's a bug in Intersect(ray, capsule) - actually it's just not implemented!

For now I think I'll add your workaround (the second one) as a quick fix; it means that overlapping gizmos with capsule bounds won't work correctly (the hit will be on the first one you test, not the nearest one). I'll leave the issue open and rename it to match the core problem.