Thank you for the answers and the contributed code. Very appreciated.

I'll try it out now,

Josef Grunig

On Thu, Jun 4, 2009 at 9:22 AM, Marcus Lindblom <[email protected]> wrote:
> Dirk Reiners wrote:
>>       Hi Josef,
>>
>> Carsten Neumann wrote:
>>> from the TriangleIterator you should be able to get the texture
>>> coordinates and positions of the three triangle vertices and then
>>> interpolate those to find the tex coords for the intersection point.
>>
>> In other words: no, there is no way to get it out of OpenSG right now. ;)
>>
>> The Line::intersect functions calculates them to test for intersection, but 
>> it
>> doesn't return them. If you need it you can just copy the code out of it.
>>
>> Hope it helps
>
> Here's our code that does this, we added it a few weeks ago:
>
> void ControlPanel::onTriangleHit(OSG::Node* node, OSG::Pnt3f pnt,
> OSG::Vec3f normal, OSG::Int32 triangle)
> {
>         OSG::GeometryRefPtr geom =
> dynamic_cast<OSG::Geometry*>(node->getCore());
>
>         // get the triangle that was hit
>         OSG::TriangleIterator iter = geom->beginTriangles();
>         iter.seek(triangle);
>
>         ///// calculate the texture coordinates at the hit point /////
>
>         // local hit point
>         OSG::Matrix m;
>         node->getToWorld().inverse(m);
>         OSG::Pnt3f local_pnt;
>         m.mult(pnt, local_pnt);
>
>         // get useful data
>         OSG::Pnt3f p0 = iter.getPosition(0);
>         OSG::Pnt3f p1 = iter.getPosition(1);
>         OSG::Pnt3f p2 = iter.getPosition(2);
>
>         // compute normal
>         OSG::Vec3f v1 = p1 - p0;
>         OSG::Vec3f v2 = p2 - p0;
>         OSG::Vec3f n = v1.cross(v2);
>         n.normalize();
>
>         // Compute barycentric coordinates a,b,c
>         float areaABC = n.dot(v1.cross(v2));
>         float areaPBC = n.dot((p1 - local_pnt).cross(p2 - local_pnt));
>         float a = areaPBC / areaABC;
>         float areaPCA = n.dot((p2 - local_pnt).cross(p0 - local_pnt));
>         float b = areaPCA / areaABC;
>         float c = 1.0f - a - b;
>
>         // check for correctness
>         //OSG::Vec3f pp = OSG::Vec3f(a*p0) + OSG::Vec3f(b*p1) +
> OSG::Vec3f(c*p2);
>         //OSG::Vec3f zero = pp - OSG::Vec3f(local_pnt);
>         //ORZ_RUNTIME_ASSERT(zero.length() < 1e-4);
>
>         // compute texture coordinate
>         OSG::Vec2f tc = iter.getTexCoords(0) * a + iter.getTexCoords(1)
> * b + iter.getTexCoords(2) * c;
>
>        dostuff(tc);
> }
>
>
> Hope it helps.
>
>
> ------------------------------------------------------------------------------
> OpenSolaris 2009.06 is a cutting edge operating system for enterprises
> looking to deploy the next generation of Solaris that includes the latest
> innovations from Sun and the OpenSource community. Download a copy and
> enjoy capabilities such as Networking, Storage and Virtualization.
> Go to: http://p.sf.net/sfu/opensolaris-get
> _______________________________________________
> Opensg-users mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/opensg-users
>



-- 
Josef

------------------------------------------------------------------------------
OpenSolaris 2009.06 is a cutting edge operating system for enterprises 
looking to deploy the next generation of Solaris that includes the latest 
innovations from Sun and the OpenSource community. Download a copy and 
enjoy capabilities such as Networking, Storage and Virtualization. 
Go to: http://p.sf.net/sfu/opensolaris-get
_______________________________________________
Opensg-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/opensg-users

Reply via email to