119 | | #if 0 |
120 | | osgProducer::Viewer* viewer = dynamic_cast<osgProducer::Viewer*>(&aa); |
121 | | osgUtil::IntersectVisitor::HitList hlist; |
122 | | if (viewer->computeIntersections(ea.getX(),ea.getY(), nv->getNodePath().back(), hlist)) |
123 | | { |
124 | | if (!hlist.empty()) |
| 119 | |
| 120 | osgViewer::View* view = dynamic_cast<osgViewer::View*>(&aa); |
| 121 | osg::notify(osg::NOTICE)<<"osgmovie - view = "<<view<<std::endl; |
| 122 | osgUtil::LineSegmentIntersector::Intersections intersections; |
| 123 | if (view && view->computeIntersections(ea.getX(), ea.getY(), nv->getNodePath().back(), intersections)) |
| 124 | { |
| 125 | #if 1 |
| 126 | osg::notify(osg::NOTICE)<<"osgmovie - Vertex interpolation not implemented yet"<<std::endl; |
| 127 | #else |
| 128 | // use the nearest intersection |
| 129 | const osgUtil::LineSegmentIntersector::Intersection& intersection = *(intersections.begin()); |
| 130 | osg::Drawable* drawable = intersection.drawable.get(); |
| 131 | osg::Geometry* geometry = drawable ? drawable->asGeometry() : 0; |
| 132 | osg::Vec3Array* vertices = geometry ? dynamic_cast<osg::Vec3Array*>(geometry->getVertexArray()) : 0; |
| 133 | if (vertices) |
137 | | if (vil.size()==3) |
| 148 | osg::Vec3 p1 = intersection.getLocalLineSegment()->start(); |
| 149 | osg::Vec3 p2 = intersection.getLocalLineSegment()->end(); |
| 150 | |
| 151 | osg::Vec3 p12 = p1-p2; |
| 152 | osg::Vec3 v13 = v1-v3; |
| 153 | osg::Vec3 v23 = v2-v3; |
| 154 | osg::Vec3 p1v3 = p1-v3; |
| 155 | |
| 156 | osg::Matrix matrix(p12.x(), v13.x(), v23.x(), 0.0, |
| 157 | p12.y(), v13.y(), v23.y(), 0.0, |
| 158 | p12.z(), v13.z(), v23.z(), 0.0, |
| 159 | 0.0, 0.0, 0.0, 1.0); |
| 160 | |
| 161 | osg::Matrix inverse; |
| 162 | inverse.invert(matrix); |
| 163 | |
| 164 | osg::Vec3 ratio = inverse*p1v3; |
| 165 | |
| 166 | // extract the baricentric coordinates. |
| 167 | float r1 = ratio.y(); |
| 168 | float r2 = ratio.z(); |
| 169 | float r3 = 1.0f-r1-r2; |
| 170 | |
| 171 | osg::Array* texcoords = (geometry->getNumTexCoordArrays()>0) ? geometry->getTexCoordArray(0) : 0; |
| 172 | osg::Vec2Array* texcoords_Vec2Array = dynamic_cast<osg::Vec2Array*>(texcoords); |
| 173 | if (texcoords_Vec2Array) |
139 | | |
140 | | int i1 = vil[0]; |
141 | | int i2 = vil[1]; |
142 | | int i3 = vil[2]; |
143 | | osg::Vec3 v1 = (*vertices)[i1]; |
144 | | osg::Vec3 v2 = (*vertices)[i2]; |
145 | | osg::Vec3 v3 = (*vertices)[i3]; |
146 | | osg::Vec3 v = hit.getLocalIntersectPoint(); |
147 | | osg::Vec3 p1 = hit.getLocalLineSegment()->start(); |
148 | | osg::Vec3 p2 = hit.getLocalLineSegment()->end(); |
149 | | |
150 | | osg::Vec3 p12 = p1-p2; |
151 | | osg::Vec3 v13 = v1-v3; |
152 | | osg::Vec3 v23 = v2-v3; |
153 | | osg::Vec3 p1v3 = p1-v3; |
154 | | |
155 | | osg::Matrix matrix(p12.x(), v13.x(), v23.x(), 0.0, |
156 | | p12.y(), v13.y(), v23.y(), 0.0, |
157 | | p12.z(), v13.z(), v23.z(), 0.0, |
158 | | 0.0, 0.0, 0.0, 1.0); |
159 | | |
160 | | osg::Matrix inverse; |
161 | | inverse.invert(matrix); |
162 | | |
163 | | osg::Vec3 ratio = inverse*p1v3; |
164 | | |
165 | | // extract the baricentric coordinates. |
166 | | float r1 = ratio.y(); |
167 | | float r2 = ratio.z(); |
168 | | float r3 = 1.0f-r1-r2; |
169 | | |
170 | | osg::Array* texcoords = (geometry->getNumTexCoordArrays()>0) ? geometry->getTexCoordArray(0) : 0; |
171 | | osg::Vec2Array* texcoords_Vec2Array = dynamic_cast<osg::Vec2Array*>(texcoords); |
172 | | if (texcoords_Vec2Array) |
173 | | { |
174 | | // we have tex coord array so now we can compute the final tex coord at the point of intersection. |
175 | | osg::Vec2 tc1 = (*texcoords_Vec2Array)[i1]; |
176 | | osg::Vec2 tc2 = (*texcoords_Vec2Array)[i2]; |
177 | | osg::Vec2 tc3 = (*texcoords_Vec2Array)[i3]; |
178 | | osg::Vec2 tc = tc1*r1 + tc2*r2 + tc3*r3; |
179 | | |
180 | | osg::notify(osg::NOTICE)<<"We hit tex coords "<<tc<<std::endl; |
181 | | |
182 | | } |
183 | | |
184 | | |
| 175 | // we have tex coord array so now we can compute the final tex coord at the point of intersection. |
| 176 | osg::Vec2 tc1 = (*texcoords_Vec2Array)[i1]; |
| 177 | osg::Vec2 tc2 = (*texcoords_Vec2Array)[i2]; |
| 178 | osg::Vec2 tc3 = (*texcoords_Vec2Array)[i3]; |
| 179 | osg::Vec2 tc = tc1*r1 + tc2*r2 + tc3*r3; |
| 180 | |
| 181 | osg::notify(osg::NOTICE)<<"We hit tex coords "<<tc<<std::endl; |
| 182 | |