How would I calculate the actual world positions, not distances, of the camera and the vertices?
CD hybr wrote: > Hi, Conan > > gl_ModelViewMatrix * gl_Vertex is position of vertex in camera space > If your view matrix dont have scale component, you dont need anything else to > calculate distance (by distance i mean vector length) > In general case you can use: > osg_ViewMatrixInverse * gl_ModelViewMatrix * gl_Vertex <- this is world space > vector from camera to vertex > > Cheers, > Sergey. > > 13.09.2011, 18:19, "Conan Doyle" <>: > > > Hi, > > > > I want to calculate the distance between my final render cameras position > > and the vertices of each object rendered. I want to pass the world > > position of the camera into a shader and then use gl_Vertex position to > > perform the calculation. In search the OSG website, the net and this forum > > (as I understand a good OSG newbie should) I found the following > > > > http://www.openscenegraph.org/projects/osg/wiki/Support/Tutorials/CameraControlFindingWorldCoordinates > > > > > > > "Where in the world am I? > > > To compute where a particular node is the scene graph is, in world > > > coordinates, you need to acquire the accumulated 4x4 matrix from the root > > > of the scene graph down to your node. osg::Node contains a convenience > > > method, Node::getWorldMatrices(..), that walks the parental chain from > > > your node to the root(s) of your scene graph, returning a list of > > > matrices. A list of matrices is returned rather than a single matrix as > > > the OpenSceneGraph supports sharing of nodes, so they may have multiple > > > parents, and if the parent chain has separate transforms in them the > > > different paths will result in different matrices - in this case you node > > > is effectively in more than one place at once! Multiple parents would be > > > typical in cases such as a wheel subgraph that is reused four times on a > > > car, each with a transform above it to place it in the appropriate place. > > > To use this feature use code such as: > > > > > > osg::MatrixList worldMatrices = myNode->getWorldMatrices(); > > > > > > for(osg::MatrixList::iterator itr = worldMatrices.begin(); > > > itr != worldMatrices.end(); > > > ++itr) > > > { > > > osg::Matrix& matrix = *itr; > > > osg::Vec3 center = myNode->getBound().center() * matrix; > > > std::cout<<"Node "<<myNode->getName()<<" center = "<<center<<" > > > worldMatrix = "<<matrix<<std::end; > > > } > > > " > > > > > > > I am wondering if this is what I need to do... with myNode being my viewer > > camera node, and then getting the worldMatrix for it.... If so, how do I > > get the position from the worldMatrix? > > > > Conan > > > > Thank you! > > > > Cheers, > > Conan > > > > ------------------ > > Read this topic online here: > > http://forum.openscenegraph.org/viewtopic.php?p=42702#42702 > > > > _______________________________________________ > > osg-users mailing list > > > > http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org > > > _______________________________________________ > osg-users mailing list > > http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org > > ------------------ > Post generated by Mail2Forum ------------------ Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=42716#42716 _______________________________________________ osg-users mailing list [email protected] http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

