| | 35 | static Producer::CameraConfig *BuildConfig(void) |
| | 36 | { |
| | 37 | Producer::RenderSurface *rs1 = new Producer::RenderSurface; |
| | 38 | rs1->setScreenNum(0); |
| | 39 | //rs1->useBorder(false); |
| | 40 | rs1->setWindowRect(0,0,640,480); |
| | 41 | Producer::Camera *camera1 = new Producer::Camera; |
| | 42 | camera1->setRenderSurface(rs1); |
| | 43 | camera1->setOffset( 1.0, 0.0 ); |
| | 44 | |
| | 45 | Producer::RenderSurface *rs2 = new Producer::RenderSurface; |
| | 46 | rs2->setScreenNum(0); |
| | 47 | //rs2->useBorder(false); |
| | 48 | rs2->setWindowRect(640,0,640,480); |
| | 49 | Producer::Camera *camera2 = new Producer::Camera; |
| | 50 | camera2->setRenderSurface(rs2); |
| | 51 | camera2->setOffset( -1.0, 0.0 ); |
| | 52 | |
| | 53 | Producer::InputArea *ia = new Producer::InputArea; |
| | 54 | ia->addInputRectangle( rs1, Producer::InputRectangle(0.0,0.5,0.0,1.0)); |
| | 55 | ia->addInputRectangle( rs2, Producer::InputRectangle(0.5,1.0,0.0,1.0)); |
| | 56 | // ia->addInputRectangle( rs1, Producer::InputRectangle(-1.0,0.0,-1.0,1.0)); |
| | 57 | // ia->addInputRectangle( rs2, Producer::InputRectangle(0.0,1.0,-1.0,1.0)); |
| | 58 | |
| | 59 | |
| | 60 | Producer::CameraConfig *cfg = new Producer::CameraConfig; |
| | 61 | cfg->addCamera("Camera 1",camera1); |
| | 62 | cfg->addCamera("Camera 2", camera2); |
| | 63 | cfg->setInputArea(ia); |
| | 64 | return cfg; |
| | 65 | } |
| | 66 | |
| 82 | | float x=ea.getXnormalized(); |
| 83 | | float y=ea.getYnormalized(); |
| 84 | | |
| 85 | | Producer::Camera *cmm=_cg->getCamera(0); |
| 86 | | osg::Matrix vum(osg::Matrix(cmm->getViewMatrix()) * |
| 87 | | osg::Matrix(cmm->getProjectionMatrix())/* * |
| 88 | | osg::Matrix::translate(1.0f,1.0f,1.0f) * |
| 89 | | osg::Matrix::scale(0.5f,0.5f,0.5f)*/); |
| 90 | | |
| 91 | | osgUtil::PickVisitor iv; |
| 92 | | osgUtil::IntersectVisitor::HitList& hlist=iv.getHits(scene, vum, x,y); |
| | 114 | float x=ea.getX(); |
| | 115 | float y=ea.getY(); |
| | 116 | |
| | 117 | |
| | 118 | Producer::KeyboardMouse* km = _viewer->getKeyboardMouse(); |
| | 119 | |
| | 120 | |
| 100 | | //osg::Vec3 ip = hitr->getLocalIntersectPoint(); |
| 101 | | //osg::Vec3 in = hitr->getLocalIntersectNormal(); |
| 102 | | osg::Geode* geode = hitr->_geode.get(); |
| 103 | | // the geodes are identified by name. |
| 104 | | if (geode) |
| | 133 | std::cout << " compute pixel coords "<<pixel_x<<" "<<pixel_y<<std::endl; |
| | 134 | |
| | 135 | int pr_wx, pr_wy; |
| | 136 | unsigned int pr_width, pr_height; |
| | 137 | cmm->getProjectionRect( pr_wx, pr_wy, pr_width, pr_height ); |
| | 138 | |
| | 139 | int rs_wx, rs_wy; |
| | 140 | unsigned int rs_width, rs_height; |
| | 141 | rs->getWindowRect( rs_wx, rs_wy, rs_width, rs_height ); |
| | 142 | |
| | 143 | pr_wx += rs_wx; |
| | 144 | pr_wy += rs_wy; |
| | 145 | |
| | 146 | std::cout << " wx = "<<pr_wx<<" wy = "<<pr_wy<<" width="<<pr_width<<" height="<<pr_height<<std::endl; |
| | 147 | |
| | 148 | |
| | 149 | |
| | 150 | if (pixel_x<(float)pr_wx) break; |
| | 151 | if (pixel_x>(float)(pr_wx+pr_width)) break; |
| | 152 | |
| | 153 | if (pixel_y<(float)pr_wy) break; |
| | 154 | if (pixel_y>(float)(pr_wy+pr_height)) break; |
| | 155 | |
| | 156 | |
| | 157 | float rx = 2.0f*(pixel_x - (float)pr_wx)/(float)pr_width-1.0f; |
| | 158 | float ry = 2.0f*(pixel_y - (float)pr_wy)/(float)pr_height-1.0f; |
| | 159 | |
| | 160 | std::cout << " rx "<<rx<<" "<<ry<<std::endl; |
| | 161 | |
| | 162 | osg::Matrix vum(osg::Matrix(cmm->getViewMatrix()) * |
| | 163 | osg::Matrix(cmm->getProjectionMatrix())/* * |
| | 164 | osg::Matrix::translate(1.0f,1.0f,1.0f) * |
| | 165 | osg::Matrix::scale(0.5f,0.5f,0.5f)*/); |
| | 166 | |
| | 167 | osgUtil::PickVisitor iv; |
| | 168 | osgUtil::IntersectVisitor::HitList& hlist=iv.getHits(scene, vum, rx,ry); |
| | 169 | if (iv.hits()) |