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

Revision 13041, 3.5 kB (checked in by robert, 2 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 "LightSourcePaletteManager.h"
18#include "DataOutputStream.h"
19#include "Opcodes.h"
20#include <osg/Notify>
21#include <osg/Light>
22#include <osg/Vec4f>
23#include <cassert>
24#include <sstream>
25#include <stdio.h>
26
27namespace flt
28{
29
30
31LightSourcePaletteManager::LightSourcePaletteManager( ExportOptions& fltOpt )
32  : _currIndex( -1 ),
33    _fltOpt( fltOpt )
34
35{
36    // TODO: Pay attention to the version here(?)
37}
38
39
40int LightSourcePaletteManager::add(osg::Light const* light)
41{
42    int index = -1;
43    if (light == NULL) return -1;
44
45
46    // If this light has already been cached, set 'index' to the cached value
47    LightPalette::const_iterator it = _lightPalette.find(light);
48    if ( it != _lightPalette.end() )
49    {
50        index = it->second.Index;
51    }
52
53    // New light? Add it to the cache...
54    else
55    {
56        index = ++_currIndex;
57        _lightPalette.insert(std::make_pair(light,
58                                               LightRecord(light, index) ) );
59    }
60
61    return index;
62}
63
64void
65LightSourcePaletteManager::write( DataOutputStream& dos ) const
66{
67    using osg::Vec4f;
68
69    static int const INFINITE_LIGHT = 0;
70    static int const LOCAL_LIGHT    = 1;
71    static int const SPOT_LIGHT     = 2;
72
73    LightPalette::const_iterator it = _lightPalette.begin();
74    for ( ; it != _lightPalette.end(); ++it)
75    {
76        LightRecord m = it->second;
77
78        static char lightName[64];
79        sprintf(lightName, "Light%02d", m.Light->getLightNum() );
80
81        int lightType = INFINITE_LIGHT;
82        Vec4f const& lightPos = m.Light->getPosition();
83        if (lightPos.w() != 0)
84        {
85            if (m.Light->getSpotCutoff() < 180)
86                lightType = SPOT_LIGHT;
87            else
88                lightType = LOCAL_LIGHT;
89        }
90
91        dos.writeInt16( (int16) LIGHT_SOURCE_PALETTE_OP );
92        dos.writeInt16( 240 );
93        dos.writeInt32( m.Index );
94        dos.writeFill(2*4, '\0');                     // Reserved
95        dos.writeString( lightName, 20 );
96        dos.writeFill(4, '\0');                       // Reserved
97
98        dos.writeVec4f(m.Light->getAmbient() );
99        dos.writeVec4f(m.Light->getDiffuse() );
100        dos.writeVec4f(m.Light->getSpecular() );
101        dos.writeInt32(lightType);
102        dos.writeFill(4*10, '\0');                     // Reserved
103        dos.writeFloat32(m.Light->getSpotExponent() );
104        dos.writeFloat32(m.Light->getSpotCutoff() );
105        dos.writeFloat32(0);                           // Yaw (N/A)
106        dos.writeFloat32(0);                           // Pitch (N/A)
107        dos.writeFloat32(m.Light->getConstantAttenuation() );
108        dos.writeFloat32(m.Light->getLinearAttenuation() );
109        dos.writeFloat32(m.Light->getQuadraticAttenuation() );
110        dos.writeInt32(0);                             // Modeling flag (N/A)
111        dos.writeFill(4*19, '\0');                     // Reserved
112
113    }
114}
115
116
117
118// End namespace fltexp
Note: See TracBrowser for help on using the browser.