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

Revision 13041, 3.4 kB (checked in by robert, 3 years ago)

Ran script to remove trailing spaces and tabs

  • 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    _replaceDoubleSidedPolys(false),
30    _defaultDOFAnimationState(false),
31    _useTextureAlphaForTransparancyBinning(true),
32    _useBillboardCenter(false),
33    _doUnitsConversion(true),
34    _readObjectRecordData(false),
35    _desiredUnits(METERS),
36    _done(false),
37    _level(0),
38    _subfaceLevel(0),
39    _unitScale(1.0),
40    _version(0),
41    _colorPoolParent(false),
42    _texturePoolParent(false),
43    _materialPoolParent(false),
44    _lightSourcePoolParent(false),
45    _lightPointAppearancePoolParent(false),
46    _lightPointAnimationPoolParent(false),
47    _shaderPoolParent(false)
48{
49    _subsurfaceDepth = new osg::Depth(osg::Depth::LESS, 0.0, 1.0,false);
50}
51
52Document::~Document()
53{
54}
55
56void Document::pushLevel()
57{
58    _levelStack.push_back(_currentPrimaryRecord.get());
59    _level++;
60}
61
62void Document::popLevel()
63{
64    _levelStack.pop_back();
65
66    if (!_levelStack.empty())
67        _currentPrimaryRecord = _levelStack.back();
68
69    if (--_level<=0)
70        _done = true;
71}
72
73void Document::pushSubface()
74{
75    _subfaceLevel++;
76}
77
78void Document::popSubface()
79{
80    _subfaceLevel--;
81}
82
83void Document::pushExtension()
84{
85    if (!_currentPrimaryRecord.valid())
86    {
87        OSG_WARN << "No current primary in Document::pushExtension()." << std::endl;
88        return;
89    }
90
91    _extensionStack.push_back(_currentPrimaryRecord.get());
92}
93
94void Document::popExtension()
95{
96    _currentPrimaryRecord=_extensionStack.back().get();
97    if (!_currentPrimaryRecord.valid())
98    {
99        OSG_WARN << "Can't decide primary in Document::popExtension()." << std::endl;
100        return;
101    }
102
103    _extensionStack.pop_back();
104}
105
106osg::Node* Document::getInstanceDefinition(int no)
107{
108    InstanceDefinitionMap::iterator itr = _instanceDefinitionMap.find(no);
109    if (itr != _instanceDefinitionMap.end())
110        return (*itr).second.get();
111
112    return NULL;
113}
114
115void Document::setSubSurfacePolygonOffset(int level, osg::PolygonOffset* po)
116{
117    _subsurfacePolygonOffsets[level] = po;
118}
119
120osg::PolygonOffset* Document::getSubSurfacePolygonOffset(int level)
121{
122    OSG_DEBUG<<"Document::getSubSurfacePolygonOffset("<<level<<")"<<std::endl;
123    osg::ref_ptr<osg::PolygonOffset>& po = _subsurfacePolygonOffsets[level];
124    if (!po)
125    {
126        po = new osg::PolygonOffset(-1.0f*float(level), -1.0f);
127    }
128    return po.get();
129}
130
131double flt::unitsToMeters(CoordUnits unit)
132{
133    switch (unit)
134    {
135    case METERS:
136        return 1.0;
137    case KILOMETERS:
138        return 1000.0;
139    case FEET:
140        return 0.3048;
141    case INCHES:
142        return 0.02540;
143    case NAUTICAL_MILES:
144        return 1852.0;
145    }
146
147    return 1.0;
148}
Note: See TracBrowser for help on using the browser.