01 // Uses the mouse position to calculate 02 // a 3D dot in the scene 03 void projection(SoQtRenderArea *renderArea, 04 int mouseX, int mouseY, SbVec3f &interface) 05 { 06 // Position of mouse in rendering area: 07 SbVec2s size = renderArea->getSize( 08 float x = float(mouseX) / size[0]; 09 float y = float(size[1] - mouseY) / size[1]; 10 11 // Pointer to camera 12 SoGroup *root = (SoGroup *) renderArea->getSceneGraph(); 13 SoCamera *camera = (SoCamera *) root->getChild(0); 14 15 // Volume visible to camera 16 SbViewVolume cameraVolume; 17 cameraVolume = camera->getViewVolume(); 18 19 // Mouse line vertical to scene 20 // The other endpoint is created by mirroring on the plane 21 SbVec3f p0, p1; 22 cameraVolume.projectDotToLine(SbVec2f(x,y), p0, p1); 23 24 // The center of the line is the position we are looking for 25 // on the surface, which goes through the origin 26 interface = (p0 + p1) / 2.0; 27 }