Update to my previous email.

                float height = (center-control)*normal;
                osg::Vec3d centroid(center - normal*height);

        for(Edges::iterator eitr = edges.begin();
            eitr != edges.end();
            ++eitr)
        {
            if (eitr->second==1) 
            {

                                const Edge& edge = eitr->first;


                           Face face;
                face.name = "baseSide";
                face.plane.set(centroid, edge.first, edge.second);
                face.vertices.push_back(centroid);
                face.vertices.push_back(edge.first);
                face.vertices.push_back(edge.second);
                if (face.plane.distance(center)<0.0) face.plane.flip();
                _faces.push_back(face);
                
                uniqueVertices.insert(edge.first);
                uniqueVertices.insert(edge.second);
            }
        }
                
                float minHeight = -1;
                {
                        Vertices baseVertices;
            for(VertexSet::iterator itr = uniqueVertices.begin();
                itr != uniqueVertices.end();
                ++itr)
            {
                const osg::Vec3d& point = *itr;
                double h_point = point * normal;
                osg::Vec3d newpoint = point - normal * (h_point - minHeight);
                baseVertices.push_back(newpoint);
            }
            
            //compute centroid of the base vertices
            osg::Vec3d center;
            double totalArea = 0;
            for(unsigned int i=0; i<baseVertices.size()-1; ++i)
            {
                const osg::Vec3d& a = baseVertices[i];
                const osg::Vec3d& b = baseVertices[i+1];
                const osg::Vec3d& c = baseVertices[(i+2)%baseVertices.size()];
                double area = ((a-b)^(b-c)).length()*0.5;
                osg::Vec3d localCenter = (a+b+c)/3.0;
                center += localCenter*area;
                totalArea += area;
            }
            center /= totalArea;
            osg::Vec3d normal(center-centroid);
            normal.normalize();

                        osg::Plane basePlane(normal, center);
                        cut(basePlane,"basePlane");
                }


I hope you might find it useful.

Cheers,
MattFranklin

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=13431#13431





_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to