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

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

Ran script to remove trailing spaces and tabs

  • Property svn:eol-style set to native
Line 
1/*
2 * This library is open source and may be redistributed and/or modified under
3 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or (at
4 * your option) any later version. The full license is in the LICENSE file
5 * included with this distribution, and on the openscenegraph.org website.
6 *
7 * This library is distributed in the hope that it will be useful, but
8 * WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * OpenSceneGraph Public License for more details.
11*/
12
13//
14// Copyright(c) 2008 Skew Matrix Software LLC.
15//
16
17#include "FltExportVisitor.h"
18#include "DataOutputStream.h"
19#include "Opcodes.h"
20#include <osg/MatrixTransform>
21#include <osg/Notify>
22
23
24namespace flt
25{
26
27
28/** If the DataOutputStream parameter is NULL, write to the _records
29    member variable. Otherwise, write to the specified DataOutputStream.
30    */
31void
32FltExportVisitor::writeComment( const osg::Node& node, DataOutputStream* dos )
33{
34    if (dos==NULL)
35        dos = _records;
36
37    // Write all descriptions as Comment records.
38    unsigned int nd = node.getNumDescriptions();
39    unsigned int idx=0;
40    while( idx < nd )
41    {
42        const std::string& com = node.getDescription( idx );
43        unsigned int iLen = com.length() + 5;
44        if (iLen > 0xffff)
45        {
46            // short overrun
47            std::string warning( "fltexp: writeComment: Descriptions too long, resorts in short overrun. Skipping." );
48            _fltOpt->getWriteResult().warn( warning );
49            OSG_WARN << warning << std::endl;
50            continue;
51        }
52        uint16 length( (uint16)iLen );
53
54        dos->writeInt16( (int16) COMMENT_OP );
55        dos->writeInt16( length );
56        dos->writeString( com );
57
58        idx++;
59    }
60}
61
62/** If the DataOutputStream parameter is NULL, write to the _records
63    member variable. Otherwise, write to the specified DataOutputStream.
64    */
65void
66FltExportVisitor::writeLongID( const std::string& id, DataOutputStream* dos )
67{
68    if (dos==NULL)
69        dos = _records;
70
71    uint16 length( 2 + 2 + id.length() + 1 );  // +1 for terminating '\0'
72
73    dos->writeInt16( (int16) LONG_ID_OP );
74    dos->writeUInt16( length );
75    dos->writeString( id );
76}
77
78void
79FltExportVisitor::writeMatrix( const osg::Referenced* ref )
80{
81    const osg::RefMatrix* rm = dynamic_cast<const osg::RefMatrix*>( ref );
82    if (!rm)
83        return;
84
85    uint16 length( 4 + (16 * sizeof(float32)) );
86
87    _records->writeInt16( (int16) MATRIX_OP );
88    _records->writeUInt16( length );
89
90    int idx, jdx;
91    for (idx=0; idx<4; idx++)
92    {
93        for (jdx=0; jdx<4; jdx++)
94        {
95            _records->writeFloat32( (*rm)( idx, jdx ) );
96        }
97    }
98}
99
100void
101FltExportVisitor::writeContinuationRecord( const unsigned short length )
102{
103    OSG_DEBUG << "fltexp: Continuation record length: " << length+4 << std::endl;
104    _records->writeInt16( (int16) CONTINUATION_OP );
105    _records->writeUInt16( length+4 );
106}
107
108
109}
Note: See TracBrowser for help on using the browser.