Amerio.Stephane Posted May 19, 2025 Posted May 19, 2025 Hello, I'm trying to draw the tangent vectors along a WorldSpline (2.19) (The world spline is at world origin, with no rotation.) auto pos = path->segment->calcPoint(t); auto dir = path->segment->calcTangent(t); Visualizer::renderDirection(pos, dir, vec4_blue, 0.25f, true, 0, false); But this tangent is not tangent at all... Am I doing something wrong?
silent Posted May 19, 2025 Posted May 19, 2025 Hi Stephane, Is there any screenshot that you can share with us? What do you mean by not tangent? Thanks! How to submit a good bug report --- FTP server for test scenes and user uploads: ftp://files.unigine.com user: upload password: 6xYkd6vLYWjpW6SN
Amerio.Stephane Posted May 19, 2025 Author Posted May 19, 2025 Here the dark blue line should be tangent to the light blue spline (tangent = should be along the flow of the spline 'river')
silent Posted May 20, 2025 Posted May 20, 2025 Hi Stephane, Could you please share a small sample to help us reproduce the issue? So far with that code: Vector<SplineSegmentPtr> segments; wsg_->getSplineSegments(segments); for (const auto &segment : segments) { const float step = 1.0f / 32.0f; for (int i = 0; i < 32; ++i) { float t = step * i; auto pos = segment->calcPoint(t); auto dir = segment->calcTangent(t); Unigine::Visualizer::renderDirection(pos, dir, vec4_blue, 0.25f, true, 0, false); } } The results looks pretty much correct(?): Thanks! How to submit a good bug report --- FTP server for test scenes and user uploads: ftp://files.unigine.com user: upload password: 6xYkd6vLYWjpW6SN
Amerio.Stephane Posted May 20, 2025 Author Posted May 20, 2025 Soooo apparently the real code was a bit less trivial and my excerpt was incomplete here. It appears the worldsplinegraph wsg was not, in fact, at world origin with a zero rotation, and the code tried to compensate incorrectly. For future reference, as this may help others: auto wt = wsg->getWorldTransform(); // This was incorrect pos = wt * path->segment->calcPoint(t); dir = wt * path->segment->calcTangent(t); //< treats a direction as a position, BAD! // This is correct pos = wt * path->segment->calcPoint(t); quat q = wt.getRotate(); dir = q * path->segment->calcTangent(t); Treating a direction as a position is bad when doing matrix multiplication, duh... 1
Recommended Posts