[Gcblue-commits] gcb_wx/src/graphics tc3DTerrain.cpp,1.14,1.15 tc3DViewer.cpp,1.2,1.3 tc3DWindow.cpp
Status: Alpha
Brought to you by:
ddcforge
|
From: Dewitt C. <ddc...@us...> - 2004-10-21 04:11:16
|
Update of /cvsroot/gcblue/gcb_wx/src/graphics In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9417/src/graphics Modified Files: tc3DTerrain.cpp tc3DViewer.cpp tc3DWindow.cpp tcButton.cpp tcChatBox.cpp tcCreditView.cpp tcDisplaySettingsView.cpp tcGraphicsEngine.cpp tcMapObject.cpp tcMapView.cpp tcNetworkView.cpp tcScenarioSelectView.cpp tcXmlWindow.cpp Log Message: Changes related to GDI+ replacement Index: tcNetworkView.cpp =================================================================== RCS file: /cvsroot/gcblue/gcb_wx/src/graphics/tcNetworkView.cpp,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** tcNetworkView.cpp 2 Oct 2004 22:41:33 -0000 1.2 --- tcNetworkView.cpp 21 Oct 2004 04:10:59 -0000 1.3 *************** *** 224,228 **** if (config) { ! AddXMLControls(); } else --- 224,228 ---- if (config) { ! // AddXMLControls(); } else Index: tc3DTerrain.cpp =================================================================== RCS file: /cvsroot/gcblue/gcb_wx/src/graphics/tc3DTerrain.cpp,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** tc3DTerrain.cpp 26 Jul 2004 01:44:40 -0000 1.14 --- tc3DTerrain.cpp 21 Oct 2004 04:10:59 -0000 1.15 *************** *** 258,262 **** terrainNode->addDrawable(pDrawable); ! terrainNode->setCullingActive(false); // disables small feature and view frustrum culling float detailThreshold = 6.0f; terrain->SetDetailThreshold(detailThreshold); --- 258,262 ---- terrainNode->addDrawable(pDrawable); ! terrainNode->setCullingActive(true); // disables small feature and view frustrum culling float detailThreshold = 6.0f; terrain->SetDetailThreshold(detailThreshold); Index: tcChatBox.cpp =================================================================== RCS file: /cvsroot/gcblue/gcb_wx/src/graphics/tcChatBox.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** tcChatBox.cpp 2 Oct 2004 22:41:33 -0000 1.1 --- tcChatBox.cpp 21 Oct 2004 04:10:59 -0000 1.2 *************** *** 118,122 **** if (config) { ! AddXMLControls(); } else --- 118,122 ---- if (config) { ! // AddXMLControls(); } else Index: tcDisplaySettingsView.cpp =================================================================== RCS file: /cvsroot/gcblue/gcb_wx/src/graphics/tcDisplaySettingsView.cpp,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** tcDisplaySettingsView.cpp 2 Oct 2004 22:41:33 -0000 1.4 --- tcDisplaySettingsView.cpp 21 Oct 2004 04:10:59 -0000 1.5 *************** *** 235,239 **** if (config) { ! AddXMLControls(); } else --- 235,239 ---- if (config) { ! // AddXMLControls(); } else Index: tcMapObject.cpp =================================================================== RCS file: /cvsroot/gcblue/gcb_wx/src/graphics/tcMapObject.cpp,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** tcMapObject.cpp 14 Sep 2004 02:01:46 -0000 1.4 --- tcMapObject.cpp 21 Oct 2004 04:10:59 -0000 1.5 *************** *** 1,6 **** ! /* ! ** tcDirector.cpp ! ** ! ** Copyright (C) 2003 Dewitt Colclough (de...@tw...) ** All rights reserved. --- 1,6 ---- ! /** ! ** @file tcMapObject.cpp ! */ ! /* Copyright (C) 2004 Dewitt Colclough (de...@tw...) ** All rights reserved. *************** *** 19,23 **** ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ ! /// @file tcDirector.cpp source file for tcDirector class --- 19,23 ---- ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ ! *************** *** 26,36 **** #ifndef WX_PRECOMP #include "wx/wx.h" - #ifdef WIN32 - #include "wx/msw/private.h" // for MS Windows specific definitions - #endif // WIN32 #endif // WX_PRECOMP #include "tcMapObject.h" - #include "gdiplus.h" #include "tcMapView.h" #include "math_constants.h" --- 26,32 ---- *************** *** 38,48 **** using MapView::tcMapView; - using Gdiplus::Pen; - using Gdiplus::SolidBrush; - using Gdiplus::Font; tcMapView* tcMapObject::mapView = NULL; ! void tcMapObject::Draw(Gdiplus::Graphics *graphics) { if (!isActive) return; --- 34,41 ---- using MapView::tcMapView; tcMapView* tcMapObject::mapView = NULL; ! void tcMapObject::Draw() { if (!isActive) return; *************** *** 51,61 **** float y = pscreen.y; - Pen* pen = mapView->GetPen(); - pen->SetColor(color); - if (markerEnabled) { ! graphics->DrawLine(pen,x-8,y-8,x+8,y+8); ! graphics->DrawLine(pen,x+8,y-8,x-8,y+8); } } --- 44,51 ---- float y = pscreen.y; if (markerEnabled) { ! mapView->DrawLineR(x-8, y-8, x+8, y+8, color); ! mapView->DrawLineR(x+8, y-8, x-8, y+8, color); } } *************** *** 105,109 **** _y = y * C_PIOVER180; } ! color = 0xFE64FF64; // green default isActive = true; markerEnabled = true; --- 95,99 ---- _y = y * C_PIOVER180; } ! color = osg::Vec4(0.392, 1.0, 0.392, 1.0); // green default isActive = true; markerEnabled = true; *************** *** 117,121 **** /********** tcMapTextObject **************/ ! void tcMapTextObject::Draw(Gdiplus::Graphics *graphics) { if (!isActive) return; --- 107,111 ---- /********** tcMapTextObject **************/ ! void tcMapTextObject::Draw() { if (!isActive) return; *************** *** 124,141 **** float y = pscreen.y; - SolidBrush *brush = mapView->GetBrush(); - Font *font = mapView->GetFont(); - Pen *pen = mapView->GetPen(); - - pen->SetColor(color); - brush->SetColor(color); ! mapView->DrawText(graphics, font, brush, caption.c_str(), ! x+5.0f, y); if (markerEnabled) // avoids parent draw overhead this way { ! graphics->DrawLine(pen,x-8,y-8,x+8,y+8); ! graphics->DrawLine(pen,x+8,y-8,x-8,y+8); } --- 114,125 ---- float y = pscreen.y; ! mapView->DrawTextR(caption.c_str(), x+5.0f, y, ! mapView->GetDefaultFont(), color, 16.0, LEFT_BASE_LINE); if (markerEnabled) // avoids parent draw overhead this way { ! mapView->DrawLineR(x-8, y-8, x+8, y+8, color); ! mapView->DrawLineR(x+8, y-8, x-8, y+8, color); } Index: tcXmlWindow.cpp =================================================================== RCS file: /cvsroot/gcblue/gcb_wx/src/graphics/tcXmlWindow.cpp,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** tcXmlWindow.cpp 7 Oct 2004 22:01:46 -0000 1.3 --- tcXmlWindow.cpp 21 Oct 2004 04:10:59 -0000 1.4 *************** *** 134,137 **** --- 134,142 ---- } + if (config) + { + AddXMLControls(); + } + if (ref_count++ > 0) return; Index: tcCreditView.cpp =================================================================== RCS file: /cvsroot/gcblue/gcb_wx/src/graphics/tcCreditView.cpp,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** tcCreditView.cpp 2 Oct 2004 22:41:33 -0000 1.5 --- tcCreditView.cpp 21 Oct 2004 04:10:59 -0000 1.6 *************** *** 181,185 **** const float height = float(mnHeight); ! float fY = 0.5f*(float)nDeltaTime; float fX = 0.5f*(float)mnWidth; --- 181,185 ---- const float height = float(mnHeight); ! float fY = 0.25f*(float)nDeltaTime; float fX = 0.5f*(float)mnWidth; Index: tcScenarioSelectView.cpp =================================================================== RCS file: /cvsroot/gcblue/gcb_wx/src/graphics/tcScenarioSelectView.cpp,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** tcScenarioSelectView.cpp 2 Oct 2004 22:41:33 -0000 1.4 --- tcScenarioSelectView.cpp 21 Oct 2004 04:10:59 -0000 1.5 *************** *** 482,486 **** if (config) { ! AddXMLControls(); } else --- 482,486 ---- if (config) { ! // AddXMLControls(); } else Index: tcMapView.cpp =================================================================== RCS file: /cvsroot/gcblue/gcb_wx/src/graphics/tcMapView.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** tcMapView.cpp 2 Oct 2004 22:41:33 -0000 1.1 --- tcMapView.cpp 21 Oct 2004 04:10:59 -0000 1.2 *************** *** 1,6 **** ! /* ! ** tcMapView.cpp ! ** ! ** Copyright (C) 2003 Dewitt Colclough (de...@tw...) ** All rights reserved. --- 1,6 ---- ! /** ! ** @file tcMapView.cpp ! */ [...2569 lines suppressed...] terrainView->Maximize(); } else { ! Minimize(); terrainView->Minimize(); } *************** *** 2310,2314 **** if (!terrainView) {wxMessageBox("terrainView init failed\n");} ! tcWindow::MoveToTop(); // so that color elevation map is underneath mnCounter = 0; ClearMapObjects(); --- 2430,2434 ---- if (!terrainView) {wxMessageBox("terrainView init failed\n");} ! MoveToTop(); // so that color elevation map is underneath mnCounter = 0; ClearMapObjects(); Index: tcButton.cpp =================================================================== RCS file: /cvsroot/gcblue/gcb_wx/src/graphics/tcButton.cpp,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** tcButton.cpp 7 Oct 2004 22:01:46 -0000 1.12 --- tcButton.cpp 21 Oct 2004 04:10:59 -0000 1.13 *************** *** 211,215 **** caption = current->Attribute("Caption"); ! TiXmlNode* childNode = config->FirstChild("Image"); if (childNode) --- 211,217 ---- caption = current->Attribute("Caption"); ! SetName(caption.c_str()); ! ! TiXmlNode* childNode = config->FirstChild("Image"); if (childNode) Index: tcGraphicsEngine.cpp =================================================================== RCS file: /cvsroot/gcblue/gcb_wx/src/graphics/tcGraphicsEngine.cpp,v retrieving revision 1.18 retrieving revision 1.19 diff -C2 -d -r1.18 -r1.19 *** tcGraphicsEngine.cpp 14 Sep 2004 02:01:46 -0000 1.18 --- tcGraphicsEngine.cpp 21 Oct 2004 04:10:59 -0000 1.19 *************** *** 323,326 **** --- 323,327 ---- glDisable(GL_ALPHA_TEST); glDisable(GL_DEPTH_TEST); + glDisable(GL_DEPTH_WRITEMASK); glDisable(GL_DITHER); glDisable(GL_FOG); *************** *** 366,369 **** --- 367,371 ---- glClearColor(0.00f, 0.00f, 0.00f, 0.0f); // Black Background glDisable(GL_DEPTH_TEST); + glDisable(GL_DEPTH_WRITEMASK); glDisable(GL_ALPHA_TEST); glDisable(GL_DITHER); Index: tc3DWindow.cpp =================================================================== RCS file: /cvsroot/gcblue/gcb_wx/src/graphics/tc3DWindow.cpp,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** tc3DWindow.cpp 7 Oct 2004 22:01:45 -0000 1.5 --- tc3DWindow.cpp 21 Oct 2004 04:10:59 -0000 1.6 *************** *** 198,201 **** --- 198,203 ---- transform->setMatrix(osg::Matrix::translate(pos.x, pos.y + yOffset, 0)); + + UpdateBackgroundQuadVertices(); } *************** *** 248,251 **** --- 250,254 ---- (*vertices)[3] = osg::Vec3(mnWidth, mnHeight, 0); backgroundQuad->setVertexArray(vertices); + backgroundQuad->dirtyDisplayList(); } *************** *** 267,274 **** --- 270,279 ---- backgroundQuad->setTexCoordArray(0,texcoords); + /* osg::Vec3Array* normals = new osg::Vec3Array(1); (*normals)[0].set(1.0f, 0.0f, 0.0f); backgroundQuad->setNormalArray(normals); backgroundQuad->setNormalBinding(osg::Geometry::BIND_OVERALL); + */ backgroundQuad->addPrimitiveSet(new osg::DrawArrays(GL_QUADS,0,4)); *************** *** 276,286 **** osg::StateSet* stateSet = backgroundQuad->getOrCreateStateSet(); stateSet->setMode(GL_DEPTH_TEST, osg::StateAttribute::OFF); stateSet->setMode(GL_LIGHTING, osg::StateAttribute::OFF); stateSet->setRenderBinDetails(baseRenderBin + backgroundRenderBin, "RenderBin"); osg::Depth* depth = new osg::Depth(osg::Depth::ALWAYS, 1, 1, false); depth->setWriteMask(0); stateSet->setAttribute(depth); ! } --- 281,293 ---- osg::StateSet* stateSet = backgroundQuad->getOrCreateStateSet(); stateSet->setMode(GL_DEPTH_TEST, osg::StateAttribute::OFF); + stateSet->setMode(GL_DEPTH_WRITEMASK, osg::StateAttribute::OFF); stateSet->setMode(GL_LIGHTING, osg::StateAttribute::OFF); stateSet->setRenderBinDetails(baseRenderBin + backgroundRenderBin, "RenderBin"); + /* osg::Depth* depth = new osg::Depth(osg::Depth::ALWAYS, 1, 1, false); depth->setWriteMask(0); stateSet->setAttribute(depth); ! */ } *************** *** 344,348 **** } ! mbActive=abActive; } --- 351,355 ---- } ! mbActive = abActive; } *************** *** 791,796 **** } ! /** --- 798,826 ---- } + /** + * Optimize this later to check for case where geometry is already child + */ + void tc3DWindow::DrawGeometry(osg::Geometry* geometry, float x, float y) + { + osg::MatrixTransform* transform = GetTransformObject(); + transform->setMatrix(osg::Matrix::translate(x, y, 0)); + ! transform->removeChild(0, transform->getNumChildren()); // shouldn't leak with ref ptrs ! ! ! osg::Geode* geode = new osg::Geode; ! geode->addDrawable(geometry); ! ! transform->addChild(geode); ! } ! ! /// workaround method for inverted coordinates ! void tc3DWindow::DrawGeometryR(osg::Geometry* geometry, float x, float y) ! { ! const float h = float(mnHeight); ! ! DrawGeometry(geometry, x, h - y); ! } /** *************** *** 837,841 **** } ! /** --- 867,874 ---- } ! osgText::Font* tc3DWindow::GetDefaultFont() ! { ! return defaultFont.get(); ! } /** *************** *** 913,931 **** osg::Image* tc3DWindow::LoadImage(const char* fileName) { ! /* ! Gdiplus::Image* image; ! std::string path = IMAGE_PATH; ! path += fileName; ! MultiByteToWideChar(CP_ACP, 0, path.c_str(), -1, mzwchar, 255); ! image = new Image(mzwchar,false); ! if (image==NULL) ! { ! std::cerr << "tc3DWindow::LoadImage - " << path << " failed." << std::endl; ! } ! return image; ! */ ! return 0; } --- 946,958 ---- osg::Image* tc3DWindow::LoadImage(const char* fileName) { ! wxString fileWithPath = PrependImagePath(fileName); ! osg::Image* image = osgDB::readImageFile(fileWithPath.c_str()); ! if (!image) ! { ! fprintf(stderr, "Failed to load image: %s\n", fileName); ! } ! return image; } *************** *** 936,947 **** osg::Texture2D* tc3DWindow::LoadTexture(const char* fileName) { ! wxString fileWithPath = PrependImagePath(fileName); ! osg::Image* image = osgDB::readImageFile(fileWithPath.c_str()); ! ! if (!image) ! { ! fprintf(stderr, "Failed to load image: %s\n", fileName); ! return 0; ! } osg::Texture2D* tex = new osg::Texture2D; --- 963,967 ---- osg::Texture2D* tc3DWindow::LoadTexture(const char* fileName) { ! osg::Image* image = LoadImage(fileName); osg::Texture2D* tex = new osg::Texture2D; *************** *** 1036,1039 **** --- 1056,1060 ---- osg::StateSet* stateSet = quad->getOrCreateStateSet(); stateSet->setMode(GL_DEPTH_TEST, osg::StateAttribute::OFF); + stateSet->setMode(GL_DEPTH_WRITEMASK, osg::StateAttribute::OFF); stateSet->setMode(GL_LIGHTING, osg::StateAttribute::OFF); stateSet->setRenderBinDetails(baseRenderBin + imageRenderBin, "RenderBin"); *************** *** 1092,1098 **** --- 1113,1121 ---- osg::StateSet* stateSet = line->getOrCreateStateSet(); stateSet->setMode(GL_DEPTH_TEST, osg::StateAttribute::OFF); + stateSet->setMode(GL_DEPTH_WRITEMASK, osg::StateAttribute::OFF); stateSet->setMode(GL_LIGHTING, osg::StateAttribute::OFF); stateSet->setRenderBinDetails(baseRenderBin + lineRenderBin, "RenderBin"); + /* osg::LineWidth* lw = new osg::LineWidth; *************** *** 1169,1172 **** --- 1192,1196 ---- osg::StateSet* stateSet = rect->getOrCreateStateSet(); stateSet->setMode(GL_DEPTH_TEST, osg::StateAttribute::OFF); + stateSet->setMode(GL_DEPTH_WRITEMASK, osg::StateAttribute::OFF); stateSet->setMode(GL_LIGHTING, osg::StateAttribute::OFF); stateSet->setRenderBinDetails(baseRenderBin + rectRenderBin, "RenderBin"); *************** *** 1217,1220 **** --- 1241,1245 ---- stateSet->setRenderBinDetails(baseRenderBin + textRenderBin, "RenderBin"); stateSet->setMode(GL_DEPTH_TEST, osg::StateAttribute::OFF); + stateSet->setMode(GL_DEPTH_WRITEMASK, osg::StateAttribute::OFF); stateSet->setMode(GL_LIGHTING, osg::StateAttribute::OFF); *************** *** 1235,1240 **** --- 1260,1314 ---- /** + * + */ + osg::MatrixTransform* tc3DWindow::GetTransformObject() + { + size_t nPool = transformPool.size(); + + if (transformIdx < nPool) + { + osg::MatrixTransform* transform = transformPool[transformIdx++].get(); + wxASSERT(transform); + if (transform->getNumParents() == 0) + { + groupRoot->addChild(transform); + } + return transform; + } + else if (transformIdx == nPool) + { + osg::ref_ptr<osg::MatrixTransform> transform = new osg::MatrixTransform; + + transform->setReferenceFrame(osg::MatrixTransform::RELATIVE_TO_PARENTS); + transform->setDataVariance(osg::Object::DYNAMIC); + + wxASSERT(groupRoot.valid()); + groupRoot->addChild(transform.get()); + + transformPool.push_back(transform); + + return transformPool[transformIdx++].get(); + } + else + { + wxASSERT(0); + fprintf(stderr, "tc3DWindow::GetTransformObject - Corrupt transformIdx\n"); + return 0; + } + } + + + /** + * Newer name for HideUnusedObjects, use this for new code + */ + void tc3DWindow::FinishDraw() + { + HideUnusedObjects(); + } + + /** * removes unused (as of last Draw() call) objects from root scenegraph node * This should be called once at the end of Draw() + * Deprecated, use FinishDraw() */ void tc3DWindow::HideUnusedObjects() *************** *** 1269,1272 **** --- 1343,1353 ---- rectIdx = 0; + // transform pool + for (unsigned idx = transformIdx; idx < transformPool.size(); idx++) + { + groupRoot->removeChild(transformPool[idx].get()); + } + transformIdx = 0; + } *************** *** 1287,1290 **** --- 1368,1374 ---- rectPool.clear(); rectIdx = 0; + + transformPool.clear(); + transformIdx = 0; } *************** *** 1347,1350 **** --- 1431,1442 ---- { baseRenderBin = n; + + backgroundQuad->getOrCreateStateSet()-> + setRenderBinDetails(baseRenderBin + backgroundRenderBin, "RenderBin"); + } + + void tc3DWindow::SetName(const char* s) + { + transform->setName(s); } *************** *** 1372,1376 **** iconSize(32), normalPosition(pos, size), ! baseRenderBin(0), backgroundRenderBin(-1), imageRenderBin(0), --- 1464,1468 ---- iconSize(32), normalPosition(pos, size), ! baseRenderBin(10), backgroundRenderBin(-1), imageRenderBin(0), *************** *** 1400,1407 **** root = new osg::Geode; root->setName(name.c_str()); - //root->setCullingActive(false); - osg::StateSet* stateSet = root->getOrCreateStateSet(); stateSet->setMode(GL_DEPTH_TEST, osg::StateAttribute::OFF); //osg::Depth* depth = new osg::Depth(osg::Depth::ALWAYS, 0, 0, false); --- 1492,1507 ---- root = new osg::Geode; root->setName(name.c_str()); osg::StateSet* stateSet = root->getOrCreateStateSet(); stateSet->setMode(GL_DEPTH_TEST, osg::StateAttribute::OFF); + stateSet->setMode(GL_DEPTH_WRITEMASK, osg::StateAttribute::OFF); + stateSet->setMode(GL_LIGHTING, osg::StateAttribute::OFF); + root->setCullingActive(false); + + groupRoot = new osg::Group; + osg::StateSet* groupStateSet = groupRoot->getOrCreateStateSet(); + groupStateSet->setMode(GL_DEPTH_TEST, osg::StateAttribute::OFF); + groupStateSet->setMode(GL_DEPTH_WRITEMASK, osg::StateAttribute::OFF); + groupStateSet->setMode(GL_LIGHTING, osg::StateAttribute::OFF); + //osg::Depth* depth = new osg::Depth(osg::Depth::ALWAYS, 0, 0, false); *************** *** 1410,1413 **** --- 1510,1514 ---- switchNode = new osg::Switch; switchNode->addChild(root.get()); + switchNode->addChild(groupRoot.get()); switchNode->setAllChildrenOff(); *************** *** 1431,1434 **** --- 1532,1537 ---- transform->addChild(switchNode.get()); + SetName(name.c_str()); + wxASSERT(viewer); *************** *** 1488,1494 **** #ifdef _DEBUG fprintf(stdout, "Destroying 3D window %s, %d text obj, %d image quad obj" ! ", line obj %d, rect obj %d\n", wxWindow::GetName().c_str(), textPool.size(), imageQuadPool.size(), ! linePool.size(), rectPool.size()); #endif } --- 1591,1597 ---- #ifdef _DEBUG fprintf(stdout, "Destroying 3D window %s, %d text obj, %d image quad obj" ! ", line obj %d, rect obj %d, transform %d\n", wxWindow::GetName().c_str(), textPool.size(), imageQuadPool.size(), ! linePool.size(), rectPool.size(), transformPool.size()); #endif } Index: tc3DViewer.cpp =================================================================== RCS file: /cvsroot/gcblue/gcb_wx/src/graphics/tc3DViewer.cpp,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** tc3DViewer.cpp 7 Oct 2004 22:01:45 -0000 1.2 --- tc3DViewer.cpp 21 Oct 2004 04:10:59 -0000 1.3 *************** *** 85,88 **** --- 85,208 ---- END_EVENT_TABLE() + namespace osgUtil + { + + class PrintCullVistor : public osgUtil::CullVisitor + { + public: + /* + virtual void apply(Node& node) + { + CullVisitor::apply((Node&)node); + PrintStatus(node); + } + + virtual void apply(osg::Geode& node) + { + CullVisitor::apply((Geode&)node); + PrintStatus(node); + } + */ + CullVisitor::value_type distance(const osg::Vec3& coord,const osg::Matrix& matrix) + { + + //std::cout << "distance("<<coord<<", "<<matrix<<")"<<std::endl; + + return -((CullVisitor::value_type)coord[0]*(CullVisitor::value_type)matrix(0,2)+(CullVisitor::value_type)coord[1]*(CullVisitor::value_type)matrix(1,2)+(CullVisitor::value_type)coord[2]*(CullVisitor::value_type)matrix(2,2)+matrix(3,2)); + } + + void apply(Geode& node) + { + if (isCulled(node)) return; + + // push the node's state. + StateSet* node_state = node.getStateSet(); + if (node_state) pushStateSet(node_state); + + // traverse any call callbacks and traverse any children. + handle_cull_callbacks_and_traverse(node); + + RefMatrix& matrix = getModelViewMatrix(); + for(unsigned int i=0;i<node.getNumDrawables();++i) + { + Drawable* drawable = node.getDrawable(i); + const BoundingBox &bb =drawable->getBound(); + + if( drawable->getCullCallback() ) + { + if( drawable->getCullCallback()->cull( this, drawable, _state.valid()?_state.get():NULL ) == true ) + continue; + } + + //else + { + if (node.isCullingActive() && isCulled(bb)) continue; + } + + + if (_computeNearFar && bb.valid()) + { + if (!updateCalculatedNearFar(matrix,*drawable,false)) continue; + } + + // push the geoset's state on the geostate stack. + StateSet* stateset = drawable->getStateSet(); + if (stateset) pushStateSet(stateset); + + if (bb.valid()) addDrawableAndDepth(drawable,&matrix, distance(bb.center(),matrix)); + else addDrawableAndDepth(drawable,&matrix,0.0f); + + if (stateset) popStateSet(); + + } + + // pop the node's state off the geostate stack. + if (node_state) popStateSet(); + + PrintStatus(node); + + } + + + /* + virtual void apply(osg::ClipNode& node) + { + fprintf(stdout, "cull visitor: %s, %s\n", node.className(), node.getName().c_str()); + CullVisitor::apply((ClipNode&)node); + } + */ + /* + virtual void apply(osg::Group& node) + { + CullVisitor::apply((Group&)node); + PrintStatus(node); + } + virtual void apply(osg::Transform& node) + { + CullVisitor::apply((Transform&)node); + PrintStatus(node); + } + virtual void apply(osg::Projection& node) + { + CullVisitor::apply((Projection&)node); + PrintStatus(node); + } + virtual void apply(osg::Switch& node) + { + CullVisitor::apply((Switch&)node); + PrintStatus(node); + } + */ + void PrintStatus(osg::Node& node) + { + RenderBin* rb = getCurrentRenderBin(); + int binNum = rb->getBinNum(); + fprintf(stdout, "cull : %s, %s, bin %d (%d)\n", node.className(), node.getName().c_str(), + binNum, isCulled(node)); + } + + }; + } + void tc3DViewer::OnChar(wxKeyEvent& event) *************** *** 277,281 **** void tc3DViewer::SetActive(bool b) { ! if (isActive==b) return; isActive = b; --- 397,401 ---- void tc3DViewer::SetActive(bool b) { ! if (isActive == b) return; isActive = b; *************** *** 923,934 **** /** - * @return pointer to MatrixTransform used to display 2D objects like HUD text - */ - osg::MatrixTransform* tc3DViewer::GetDrawMatrixTransform() - { - return hudObjects.get(); - } - - /** * @return object position in world coordinates. */ --- 1043,1046 ---- *************** *** 1002,1005 **** --- 1114,1122 ---- guiView->setUpdateVisitor(guiUpdateVisitor.get()); + //cullVisitor = new osgUtil::PrintCullVistor(); + cullVisitor = new osgUtil::CullVisitor(); + guiView->setCullVisitor(cullVisitor.get()); + + guiObjects = new osg::MatrixTransform; guiObjects->setMatrix(osg::Matrix::identity()); *************** *** 1070,1073 **** --- 1187,1191 ---- updateVisitor->setFrameStamp(frameStamp.get()); sceneView->setUpdateVisitor(updateVisitor.get()); + } /** *************** *** 1473,1476 **** --- 1591,1605 ---- // doesn't work with OSG 0.9.5, should work with 0.9.6 and beyond osg::setNotifyLevel(osg::NOTICE); + /* + ALWAYS=0, + FATAL=1, + WARN=2, + NOTICE=3, + INFO=4, + DEBUG_INFO=5, + DEBUG_FP=6 + */ + #else + osg::setNotifyLevel(osg::DEBUG_FP); #endif |