The issue you're encountering—where collision forces or haptic effects are not applied—is likely due to the explicit zeroing of the tool's force in the SELECTION state. Here's a breakdown of the problem and how to resolve it:
Root Cause
In the SELECTION state, the following line is present:
tool->setDeviceGlobalForce(0.0, 0.0, 0.0);
This overrides any haptic forces computed by tool->computeInteractionForces() (called earlier in the loop). As a result, even if collisions are detected, the haptic device receives no feedback during object manipulation.
Why This Happens
- The
SELECTION state is designed to allow free movement of the object by disabling haptic forces.
- However, if you intend to apply haptic feedback (e.g., collision forces, surface textures, or vibrations) during object manipulation, this line must be removed or modified.
Solution
Option 1: Remove the Zero-Force Line (If You Want Haptic Feedback During Selection)
Remove or comment out the line that sets the force to zero:
// tool->setDeviceGlobalForce(0.0, 0.0, 0.0); // Remove this line
This allows the haptic device to apply forces from collisions even while the object is being moved.
Option 2: Apply Forces Only When Needed (Advanced)
If you want to toggle haptic feedback (e.g., enable it when the object is "grabbed" but disable it during movement), use a flag:
bool applyForces = true; // Set this based on your logic
if (applyForces) {
tool->applyToDevice();
} else {
tool->setDeviceGlobalForce(0.0, 0.0, 0.0);
}
Additional Checks
-
Collision Setup:
- Ensure the haptic point (
tool->m_hapticPoint) is properly configured with collision properties (e.g., setRadius, setIsDynamic, etc.).
- Verify that the object being manipulated has collision geometry enabled.
-
Force Application: