root/OpenSceneGraph/branches/OpenSceneGraph-2.8/src/osgPlugins/OpenFlight/Document.cpp @ 11264

Revision 10086, 3.4 kB (checked in by robert, 9 years ago)

Fix to handling of subsurface layers so that more appropriate PolygonOffset? values are chosen. Merged from svn/trunk using:

svn merge -r 10083:10084 http://www.openscenegraph.org/svn/osg/OpenSceneGraph/trunk/src/osgPlugins/OpenFlight/

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
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
14//
15// OpenFlight® loader for OpenSceneGraph
16//
17//  Copyright (C) 2005-2007  Brede Johansen
18//
19
20#include "Document.h"
21
22using namespace flt;
23
24
25Document::Document() :
26    _replaceClampWithClampToEdge(false),
27    _preserveFace(false),
28    _preserveObject(false),
29    _defaultDOFAnimationState(false),
30    _useTextureAlphaForTransparancyBinning(true),
31    _useBillboardCenter(false),
32    _doUnitsConversion(true),
33    _readObjectRecordData(false),
34    _desiredUnits(METERS),
35    _done(false),
36    _level(0),
37    _subfaceLevel(0),
38    _unitScale(1.0),
39    _version(0),
40    _colorPoolParent(false),
41    _texturePoolParent(false),
42    _materialPoolParent(false),
43    _lightSourcePoolParent(false),
44    _lightPointAppearancePoolParent(false),
45    _lightPointAnimationPoolParent(false),
46    _shaderPoolParent(false)
47{
48    _subsurfaceDepth = new osg::Depth(osg::Depth::LESS, 0.0, 1.0,false);
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())
66        _currentPrimaryRecord = _levelStack.back();
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    {
98        osg::notify(osg::WARN) << "Can't decide primary in Document::popExtension()." << std::endl;
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
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
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.