root/OpenSceneGraph/trunk/src/osgPlugins/OpenFlight/Document.cpp @ 10084

Revision 10084, 3.4 kB (checked in by robert, 5 years ago)

Refactored the subsurface PolygonOffset? code so that it uses sensible values and also moves management of the PolygonOffset? and Depth attribute objects into the Document object rather than using static vars.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
RevLine 
[7748]1/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
2 *
3 * This library is open source and may be redistributed and/or modified under 
4 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
5 * (at your option) any later version.  The full license is in LICENSE file
6 * included with this distribution, and on the openscenegraph.org website.
7 *
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 * OpenSceneGraph Public License for more details.
12*/
13
[5038]14//
15// OpenFlight® loader for OpenSceneGraph
16//
[7748]17//  Copyright (C) 2005-2007  Brede Johansen
[5038]18//
19
20#include "Document.h"
21
22using namespace flt;
23
24
25Document::Document() :
[5794]26    _replaceClampWithClampToEdge(false),
[5229]27    _preserveFace(false),
[5528]28    _preserveObject(false),
[5229]29    _defaultDOFAnimationState(false),
30    _useTextureAlphaForTransparancyBinning(true),
[5610]31    _useBillboardCenter(false),
[5229]32    _doUnitsConversion(true),
[7931]33    _readObjectRecordData(false),
[5229]34    _desiredUnits(METERS),
[5038]35    _done(false),
36    _level(0),
37    _subfaceLevel(0),
38    _unitScale(1.0),
[5236]39    _version(0),
40    _colorPoolParent(false),
41    _texturePoolParent(false),
42    _materialPoolParent(false),
[6091]43    _lightSourcePoolParent(false),
[5236]44    _lightPointAppearancePoolParent(false),
[6759]45    _lightPointAnimationPoolParent(false),
[5236]46    _shaderPoolParent(false)
[5038]47{
[10084]48    _subsurfaceDepth = new osg::Depth(osg::Depth::LESS, 0.0, 1.0,false);
[5038]49}
50
51Document::~Document()
52{
53}
54
55void Document::pushLevel()
56{
57    _levelStack.push_back(_currentPrimaryRecord.get());
58    _level++;
59}
60
61void Document::popLevel()
62{
63    _levelStack.pop_back();
64
65    if (!_levelStack.empty())
[7756]66        _currentPrimaryRecord = _levelStack.back();
[5038]67
68    if (--_level<=0)
69        _done = true;
70}
71
72void Document::pushSubface()
73{
74    _subfaceLevel++;
75}
76
77void Document::popSubface()
78{
79    _subfaceLevel--;
80}
81
82void Document::pushExtension()
83{
84    if (!_currentPrimaryRecord.valid())
85    {
86        osg::notify(osg::WARN) << "No current primary in Document::pushExtension()." << std::endl;
87        return;
88    }
89
90    _extensionStack.push_back(_currentPrimaryRecord.get());
91}
92
93void Document::popExtension()
94{
95    _currentPrimaryRecord=_extensionStack.back().get();
96    if (!_currentPrimaryRecord.valid())
97    {
[8563]98        osg::notify(osg::WARN) << "Can't decide primary in Document::popExtension()." << std::endl;
[5038]99        return;
100    }
101
102    _extensionStack.pop_back();
103}
104
105osg::Node* Document::getInstanceDefinition(int no)
106{
107    InstanceDefinitionMap::iterator itr = _instanceDefinitionMap.find(no);
108    if (itr != _instanceDefinitionMap.end())
109        return (*itr).second.get();
110
111    return NULL;
112}
113
[10084]114void Document::setSubSurfacePolygonOffset(int level, osg::PolygonOffset* po)
115{
116    _subsurfacePolygonOffsets[level] = po;
117}
118
119osg::PolygonOffset* Document::getSubSurfacePolygonOffset(int level)
120{
121    osg::notify(osg::DEBUG_INFO)<<"Document::getSubSurfacePolygonOffset("<<level<<")"<<std::endl;
122    osg::ref_ptr<osg::PolygonOffset>& po = _subsurfacePolygonOffsets[level];
123    if (!po)
124    {
125        po = new osg::PolygonOffset(-1.0f*float(level), -1.0f);
126    }
127    return po.get();
128}
129
[5038]130double flt::unitsToMeters(CoordUnits unit)
131{
132    switch (unit)
133    {
134    case METERS:
135        return 1.0;
136    case KILOMETERS:
137        return 1000.0;
138    case FEET:
139        return 0.3048;
140    case INCHES:
141        return 0.02540;
142    case NAUTICAL_MILES:
143        return 1852.0;
144    }
145
146    return 1.0;
147}
Note: See TracBrowser for help on using the browser.