From: <sv...@ww...> - 2004-08-07 02:10:05
|
Author: mkrose Date: 2004-08-06 19:09:58 -0700 (Fri, 06 Aug 2004) New Revision: 1202 Modified: trunk/CSP/CSPSim/CHANGES.current trunk/CSP/CSPSim/Source/Theater/ElevationCorrection.cpp trunk/CSP/CSPSim/Source/Theater/FeatureQuad.cpp trunk/CSP/CSPSim/Source/Theater/RandomBillboardModel.cpp Log: Fixed a bug in the layout logic for RandomBillboardModel that could cause misplacement and bad elevation corrections. Also minor cleanups of path handling and logging. Browse at: https://www.zerobar.net/viewcvs/viewcvs.cgi?view=rev&rev=1202 Modified: trunk/CSP/CSPSim/CHANGES.current =================================================================== --- trunk/CSP/CSPSim/CHANGES.current 2004-08-07 02:05:39 UTC (rev 1201) +++ trunk/CSP/CSPSim/CHANGES.current 2004-08-07 02:09:58 UTC (rev 1202) @@ -64,6 +64,10 @@ * Reduced the gear damping coefficients slightly. The front gear is now slightly underdamped, which agrees with an F-16 cockpit video I've seen. + * Fixed a bug in the layout logic for RandomBillboardModel that could cause + misplacement and bad elevation corrections. Also minor cleanups of + path handling and logging. + 2004-07-29: onsight * Removed a couple obsolete files from the Makefile, and added InputEvent. Modified: trunk/CSP/CSPSim/Source/Theater/ElevationCorrection.cpp =================================================================== --- trunk/CSP/CSPSim/Source/Theater/ElevationCorrection.cpp 2004-08-07 02:05:39 UTC (rev 1201) +++ trunk/CSP/CSPSim/Source/Theater/ElevationCorrection.cpp 2004-08-07 02:09:58 UTC (rev 1202) @@ -25,6 +25,7 @@ #include "Theater/ElevationCorrection.h" #include "TerrainObject.h" +#include "Log.h" ElevationCorrection::ElevationCorrection(TerrainObject *terrain, float x, float y, float angle): LayoutTransform(x, y, angle) { @@ -34,12 +35,14 @@ osg::Vec3 ElevationCorrection::operator()(osg::Vec3 const &offset) const { osg::Vec3 absolute = LayoutTransform::operator()(offset); float elevation = 0.0; + CSP_LOG(SCENE, DEBUG, "Placing feature at absolute position " << absolute); if (m_Terrain != 0) { TerrainObject::IntersectionHint hint; elevation = m_Terrain->getGroundElevation(absolute.x(), absolute.y(), hint); + CSP_LOG(SCENE, DEBUG, "Feature elevation " << elevation << " m, offset " << offset); + } else { + CSP_LOG(SCENE, ERROR, "No elevation data available for feature!"); } - std::cout << "PLACING FEATURE @ " << absolute << "\n"; - std::cout << "ELEVATION = " << elevation << ", offset = " << offset << "\n"; return offset + osg::Z_AXIS * elevation; } Modified: trunk/CSP/CSPSim/Source/Theater/FeatureQuad.cpp =================================================================== --- trunk/CSP/CSPSim/Source/Theater/FeatureQuad.cpp 2004-08-07 02:05:39 UTC (rev 1201) +++ trunk/CSP/CSPSim/Source/Theater/FeatureQuad.cpp 2004-08-07 02:09:58 UTC (rev 1202) @@ -24,7 +24,10 @@ #include "Theater/FeatureQuad.h" +#include "Config.h" +#include <SimData/FileUtility.h> + #include <osg/Geometry> #include <osg/Texture2D> #include <osg/BlendFunc> @@ -35,12 +38,9 @@ #include <osg/Material> - - SIMDATA_REGISTER_INTERFACE(FeatureQuad) - osg::Geometry *FeatureQuad::makeGeometry() const { float vv[][3] = { { m_Width*(m_OffsetX-0.5), 0.0, m_Height*(m_OffsetY-0.5) }, @@ -82,7 +82,9 @@ osg::StateSet* FeatureQuad::makeStateSet() const { osg::Texture2D* tex = new osg::Texture2D; - osg::Image *image = osgDB::readImageFile("../Data/Images/"+m_Texture.getSource()); + std::string image_path = getDataPath("ImagePath"); + std::string path = simdata::ospath::join(image_path, m_Texture.getSource()); + osg::Image* image = osgDB::readImageFile(path); tex->setImage(image); osg::StateSet *state = new osg::StateSet; state->setTextureAttributeAndModes(0, tex, osg::StateAttribute::ON); Modified: trunk/CSP/CSPSim/Source/Theater/RandomBillboardModel.cpp =================================================================== --- trunk/CSP/CSPSim/Source/Theater/RandomBillboardModel.cpp 2004-08-07 02:05:39 UTC (rev 1201) +++ trunk/CSP/CSPSim/Source/Theater/RandomBillboardModel.cpp 2004-08-07 02:09:58 UTC (rev 1202) @@ -123,7 +123,7 @@ RandomBillboardModel::RandomBillboardModel(): m_Seed(0), - m_IsoContour(new RectangularCurve()) { + m_IsoContour(new RectangularCurve()) { } RandomBillboardModel::~RandomBillboardModel() { @@ -153,7 +153,17 @@ void RandomBillboardModel::addSceneModel(FeatureSceneGroup *group, LayoutTransform const &transform, ElevationCorrection const &correction) { int i, n = m_Models.size(); std::vector<simdata::Vector3>::iterator ofs, end; - FeatureSceneModel *scene_model = new FeatureSceneModel(transform); + + // the drawables in the billboard are already offset to the correct positions + // relative to the root scene group (ie. including all parent transformations), + // so the scene model should not reapply the same transformations. + // alternatively, we could set the transform in the scene model and set the + // x,y offsets of the drawables to be the local offsets. since each drawable + // will generally have a unique z position, the latter doesn't offer any + // obvious advantage. + //FeatureSceneModel *scene_model = new FeatureSceneModel(transform); + FeatureSceneModel *scene_model = new FeatureSceneModel(LayoutTransform()); + for (i = 0; i < n; i++) { osg::Billboard *bb = new osg::Billboard(); bb->setStateSet(m_Models[i]->getStateSet()); @@ -161,13 +171,17 @@ end = m_Offsets[i].end(); osg::Geometry *model = m_Models[i]->getGeometry(); for (; ofs != end; ofs++) { - bb->addDrawable(new osg::Geometry(*model), correction(transform(*ofs))); + // pos has the x, y coordinates of the drawable relative to the root + // FeatureSceneGroup. + osg::Vec3 pos = correction(transform(*ofs)); + bb->addDrawable(new osg::Geometry(*model), pos); } scene_model->addChild(bb); } group->addChild(scene_model); - osgUtil::Optimizer optimizer; - optimizer.optimize(group); + // FIXME this should be done at a higher level when the full FSG is complete + //osgUtil::Optimizer optimizer; + //optimizer.optimize(group); } |