root/OpenSceneGraph/trunk/src/osgWrappers/deprecated-dotosg/osg/Light.cpp @ 13041

Revision 13041, 3.2 kB (checked in by robert, 2 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#if defined(_MSC_VER)
2    #pragma warning( disable : 4786 )
3#endif
4
5#include "osg/Light"
6#include <osg/io_utils>
7
8#include "osgDB/Registry"
9#include "osgDB/Input"
10#include "osgDB/Output"
11
12using namespace osg;
13using namespace osgDB;
14
15// forward declare functions to use later.
16bool Light_readLocalData(Object& obj, Input& fr);
17bool Light_writeLocalData(const Object& obj, Output& fw);
18
19// register the read and write functions with the osgDB::Registry.
20REGISTER_DOTOSGWRAPPER(Light)
21(
22    new osg::Light,
23    "Light",
24    "Object StateAttribute Light",
25    &Light_readLocalData,
26    &Light_writeLocalData
27);
28
29
30bool Light_readLocalData(Object& obj, Input& fr)
31{
32    bool iteratorAdvanced = false;
33
34    Light& light = static_cast<Light&>(obj);
35
36    if (fr[0].matchWord("light_num"))
37    {
38        int lightnum=0;
39        if (fr[1].getInt(lightnum))
40        {
41            light.setLightNum(lightnum);
42            fr += 2;
43            iteratorAdvanced = true;
44        }
45    }
46
47#define ReadVec4(A,B) {  \
48    if (fr[0].matchWord(B) && \
49        fr[1].getFloat(vec4[0]) && \
50        fr[2].getFloat(vec4[1]) && \
51        fr[3].getFloat(vec4[2]) && \
52        fr[4].getFloat(vec4[3])) \
53    { \
54        light.A(vec4); \
55        fr+=5; \
56        iteratorAdvanced = true; \
57    } \
58}
59
60#define ReadVec3(A,B) {  \
61    if (fr[0].matchWord(B) && \
62        fr[1].getFloat(vec3[0]) && \
63        fr[2].getFloat(vec3[1]) && \
64        fr[3].getFloat(vec3[2])) \
65    { \
66        light.A(vec3); \
67        fr+=4; \
68        iteratorAdvanced = true; \
69    } \
70}
71
72#define ReadFloat(A,B) {  \
73    if (fr[0].matchWord(B) && \
74        fr[1].getFloat(value)) \
75    { \
76        light.A(value); \
77        fr+=2; \
78        iteratorAdvanced = true; \
79    } \
80}
81
82    Vec4 vec4;
83    ReadVec4(setAmbient,"ambient")
84    ReadVec4(setDiffuse,"diffuse")
85    ReadVec4(setSpecular,"specular")
86    ReadVec4(setPosition,"position")
87
88    Vec3 vec3;
89    ReadVec3(setDirection,"direction")
90
91    float value;
92    ReadFloat(setConstantAttenuation,"constant_attenuation")
93    ReadFloat(setLinearAttenuation,"linear_attenuation")
94    ReadFloat(setQuadraticAttenuation,"quadratic_attenuation")
95    ReadFloat(setSpotExponent,"spot_exponent")
96    ReadFloat(setSpotCutoff,"spot_cutoff")
97
98#undef ReadVec4
99#undef ReadVec3
100#undef ReadFloat
101
102    return iteratorAdvanced;
103}
104
105
106bool Light_writeLocalData(const Object& obj,Output& fw)
107{
108    const Light& light = static_cast<const Light&>(obj);
109
110    fw.indent() << "light_num " << light.getLightNum() << std::endl;
111
112    // Vec4's
113    fw.indent() << "ambient " << light.getAmbient() << std::endl;
114    fw.indent() << "diffuse " << light.getDiffuse() << std::endl;
115    fw.indent() << "specular " << light.getSpecular() << std::endl;
116    fw.indent() << "position " << light.getPosition() << std::endl;
117
118    // Vec3's
119    fw.indent() << "direction " << light.getDirection() << std::endl;
120
121    // float's
122    fw.indent() << "constant_attenuation " << light.getConstantAttenuation() << std::endl;
123    fw.indent() << "linear_attenuation " << light.getLinearAttenuation () << std::endl;
124    fw.indent() << "quadratic_attenuation " << light.getQuadraticAttenuation() << std::endl;
125    fw.indent() << "spot_exponent " << light.getSpotExponent() << std::endl;
126    fw.indent() << "spot_cutoff " << light.getSpotCutoff() << std::endl;
127
128    return true;
129}
Note: See TracBrowser for help on using the browser.