Changeset 154 for trunk/VUT/Ogre/src/OgreItemBufferQueryManager.cpp
- Timestamp:
- 07/04/05 17:57:51 (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/VUT/Ogre/src/OgreItemBufferQueryManager.cpp
r153 r154 8 8 //----------------------------------------------------------------------- 9 9 ItemBufferQueryManager::ItemBufferQueryManager(PlatformHierarchyInterface *hierarchyInterface, Viewport *vp): 10 PlatformQueryManager(hierarchyInterface, vp) , mWasInitialised(false)10 PlatformQueryManager(hierarchyInterface, vp) 11 11 { 12 12 } … … 23 23 bool relativeVisibility) 24 24 { 25 // initialise item buffer if necessary25 // initialise item buffer (if not already initialised) 26 26 InitItemBuffer(visibleNodes, visibleGeometry); 27 27 … … 45 45 sm->setOption("UseItemBuffer", &useItemBuffer); 46 46 47 // clear background with black 47 // clear background with black (i.e., not a valid item id) 48 48 ColourValue bg = mViewport->getBackgroundColour(); 49 49 mViewport->setBackgroundColour(ColourValue(0, 0, 0, 0)); … … 70 70 uchar *buf = mViewport->getTarget()->getBufferContents(dimx, dimy); 71 71 72 72 73 // loop through frame buffer & collect visible pixels 73 74 for (int idx = 0; idx < dimy * dimx * 3; idx += 3) 74 75 { 76 // -- decode color code to receive id 75 77 int id = buf[idx] << 16; 76 78 id += buf[idx + 1] << 8; 77 79 id += buf[idx + 2]; 78 80 79 // if valid id <= add visibility 80 if ((id > =0) && (id < (int)visibleGeometry->size()))81 // if valid id <= add visibility (id values start at 1 82 if ((id > 0) && (id < (int)visibleGeometry->size())) 81 83 { 82 84 ((*visibleGeometry)[id]).AddVisibility(1, 1); 83 85 } 84 /* else 85 { 86 std::stringstream d; 87 d << "id: " << id << ", buf 1: " << (int)buf[idx] << ", buf 2: " << (int)buf[idx + 1] << ", buf 3: " << (int)buf[idx + 2]; 88 LogManager::getSingleton().logMessage(d.str()); 89 }*/ 86 /*else { std::stringstream d; 87 d << "adding pixel to geometry with id: " << id << ", buf 1: " << (int)buf[idx] << ", buf 2: " << (int)buf[idx + 1] << ", buf 3: " << (int)buf[idx + 2]; 88 LogManager::getSingleton().logMessage(d.str()); }*/ 90 89 } 91 90 … … 104 103 mWasInitialised = true; 105 104 106 SceneManager::EntityIterator it = dynamic_cast<PlatformHierarchyInterface *>(mHierarchyInterface)-> 105 SceneManager::EntityIterator it = 106 dynamic_cast<PlatformHierarchyInterface *>(mHierarchyInterface)-> 107 107 GetSceneManager()->getEntityIterator(); 108 108 109 109 // TODO: make this more efficient 110 110 visibleGeometry->clear(); 111 visibleNodes->clear(); 111 112 112 113 while (it.hasMoreElements()) … … 115 116 } 116 117 } 117 //-----------------------------------------------------------------------118 void ItemBufferQueryManager::ComputeFromPointVisibility(const Vector3 &point,119 InfoContainer<GtpVisibility::NodeInfo> *visibleNodes,120 InfoContainer<GtpVisibility::MeshInfo> *visibleGeometry,121 bool relativeVisibility)122 {123 SceneManager *sm = dynamic_cast<PlatformHierarchyInterface *>124 (mHierarchyInterface)->GetSceneManager();125 126 Camera *cam = sm->createCamera("PointQueryCam");127 128 //save old camera129 Camera *savedCam = mViewport->getCamera();130 131 // --- initialise new camera132 mViewport->setCamera(cam);133 cam->setPosition(point);134 135 cam->setNearClipDistance(savedCam->getNearClipDistance());136 cam->setFarClipDistance(savedCam->getFarClipDistance());137 138 // set frustum to 45 degrees so all the scene can be captured with 6 shots139 cam->setAspectRatio(1.0);140 cam->setFOVy(Radian(Math::HALF_PI));141 142 int sign = -1;143 144 // ---- capture visibility from all 6 directions145 for (int i=0; i < 6; i++)146 {147 sign *= -1;148 149 // Print camera details150 std::stringstream d;151 d << "Point query camera: " + StringConverter::toString(cam->getDerivedPosition()) +152 " " + "O: " + StringConverter::toString(cam->getDerivedOrientation());153 LogManager::getSingleton().logMessage(d.str());154 155 // prevent from initialising array again156 if (i > 0)157 mWasInitialised = true;158 159 // compute camera visibility for this direction160 ComputeCameraVisibility(*cam, visibleNodes, visibleGeometry, relativeVisibility);161 162 //mViewport->getTarget()->update(); for(int j=0; j<10000000; j++) printf("wait"); // HACK: DISPLAY CAMERA VIEW163 164 // --- permute directions165 Vector3 dir(0,0,0);166 dir[i/2] = sign;167 168 cam->setDirection(dir);169 }170 171 // reset camera172 mViewport->setCamera(savedCam);173 }174 175 118 } // namespace Ogre
Note: See TracChangeset
for help on using the changeset viewer.