root/OpenSceneGraph/trunk/src/osgWrappers/deprecated-dotosg/osgSim/IO_DOFTransform.cpp @ 13041

Revision 13041, 5.4 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#include "osgSim/DOFTransform"
2#include <osg/io_utils>
3
4#include "osgDB/Registry"
5#include "osgDB/Input"
6#include "osgDB/Output"
7
8using namespace osg;
9using namespace osgSim;
10using namespace osgDB;
11using namespace std;
12
13// forward declare functions to use later.
14bool DOFTransform_readLocalData(Object& obj, Input& fr);
15bool DOFTransform_writeLocalData(const Object& obj, Output& fw);
16
17// register the read and write functions with the osgDB::Registry.
18REGISTER_DOTOSGWRAPPER(g_DOFTransformProxy)
19(
20    new osgSim::DOFTransform,
21    "DOFTransform",
22    "Object Node Transform DOFTransform Group",
23    &DOFTransform_readLocalData,
24    &DOFTransform_writeLocalData,
25    DotOsgWrapper::READ_AND_WRITE
26);
27
28bool DOFTransform_readLocalData(Object& obj, Input& fr)
29{
30    bool iteratorAdvanced = false;
31
32    DOFTransform& dof = static_cast<DOFTransform&>(obj);
33
34    if (fr.matchSequence("PutMatrix {"))
35    {
36        fr += 2; // skip over "putMatrix {"
37        iteratorAdvanced = true;
38
39        bool matched = true;
40        for(int k=0;k<16 && matched;++k)
41        {
42            matched = fr[k].isFloat();
43        }
44        if (matched)
45        {
46            osg::Matrix matrix;
47            int k=0;
48            double v;
49            for(int i=0;i<4;++i)
50            {
51                for(int j=0;j<4;++j)
52                {
53                    fr[k].getFloat(v);
54                    matrix(i,j)=v;
55                    k++;
56                }
57            }
58
59            dof.setPutMatrix(matrix);
60            dof.setInversePutMatrix(Matrix::inverse(matrix));
61        }
62
63        fr.advanceToEndOfCurrentBlock();
64    }
65
66
67#define ReadVec3(A,B) {  \
68    if (fr[0].matchWord(B) && \
69        fr[1].getFloat(vec3[0]) && \
70        fr[2].getFloat(vec3[1]) && \
71        fr[3].getFloat(vec3[2])) \
72    { \
73        dof.A(vec3); \
74        fr+=4; \
75        iteratorAdvanced = true; \
76    } \
77}
78
79    Vec3 vec3;
80
81    ReadVec3(setMinHPR,"minHPR")
82    ReadVec3(setMaxHPR,"maxHPR")
83    ReadVec3(setIncrementHPR,"incrementHPR")
84    ReadVec3(setCurrentHPR,"currentHPR")
85
86    ReadVec3(setMinTranslate,"minTranslate")
87    ReadVec3(setMaxTranslate,"maxTranslate")
88    ReadVec3(setIncrementTranslate,"incrementTranslate")
89    ReadVec3(setCurrentTranslate,"currentTranslate")
90
91    ReadVec3(setMinScale,"minScale")
92    ReadVec3(setMaxScale,"maxScale")
93    ReadVec3(setIncrementScale,"incrementScale")
94    ReadVec3(setCurrentScale,"currentScale")
95
96    if (fr[0].matchWord("multOrder"))
97    {
98        if (fr[1].matchWord("PRH")) dof.setHPRMultOrder(DOFTransform::PRH);
99        else if(fr[1].matchWord("PHR")) dof.setHPRMultOrder(DOFTransform::PHR);
100        else if(fr[1].matchWord("HPR")) dof.setHPRMultOrder(DOFTransform::HPR);
101        else if(fr[1].matchWord("HRP")) dof.setHPRMultOrder(DOFTransform::HRP);
102        else if(fr[1].matchWord("RHP")) dof.setHPRMultOrder(DOFTransform::RHP);
103        else if(fr[1].matchWord("RPH")) dof.setHPRMultOrder(DOFTransform::RPH);
104    }
105
106
107    if (fr.matchSequence("limitationFlags %i"))
108    {
109        unsigned int flags;
110        fr[1].getUInt(flags);
111        dof.setLimitationFlags(flags);
112
113        fr += 2;
114        iteratorAdvanced = true;
115
116    }
117
118    if (fr[0].matchWord("animationOn"))
119    {
120
121        if (fr[1].matchWord("TRUE")) dof.setAnimationOn(true);
122        else if (fr[1].matchWord("FALSE")) dof.setAnimationOn(false);
123
124        fr += 2;
125        iteratorAdvanced = true;
126
127    }
128
129#undef ReadVec3
130
131    return iteratorAdvanced;
132}
133
134
135bool DOFTransform_writeLocalData(const Object& obj, Output& fw)
136{
137    const DOFTransform& transform = static_cast<const DOFTransform&>(obj);
138
139    const Matrix& matrix = transform.getPutMatrix();
140    fw.indent()<<"PutMatrix {"<<std::endl;
141    fw.moveIn();
142    fw.indent() << matrix(0,0) << " " << matrix(0,1) << " " << matrix(0,2) << " " << matrix(0,3) << std::endl;
143    fw.indent() << matrix(1,0) << " " << matrix(1,1) << " " << matrix(1,2) << " " << matrix(1,3) << std::endl;
144    fw.indent() << matrix(2,0) << " " << matrix(2,1) << " " << matrix(2,2) << " " << matrix(2,3) << std::endl;
145    fw.indent() << matrix(3,0) << " " << matrix(3,1) << " " << matrix(3,2) << " " << matrix(3,3) << std::endl;
146    fw.indent() << "}" << std::endl;
147    fw.moveOut();
148
149
150    fw.indent()<<"minHPR             "<<transform.getMinHPR()<<std::endl;
151    fw.indent()<<"maxHPR             "<<transform.getMaxHPR()<<std::endl;
152    fw.indent()<<"incrementHPR       "<<transform.getIncrementHPR()<<std::endl;
153    fw.indent()<<"currentHPR         "<<transform.getCurrentHPR()<<std::endl;
154
155    fw.indent()<<"minTranslate       "<<transform.getMinTranslate()<<std::endl;
156    fw.indent()<<"maxTranslate       "<<transform.getMaxTranslate()<<std::endl;
157    fw.indent()<<"incrementTranslate "<<transform.getIncrementTranslate()<<std::endl;
158    fw.indent()<<"currentTranslate   "<<transform.getCurrentTranslate()<<std::endl;
159
160    fw.indent()<<"minScale           "<<transform.getMinScale()<<std::endl;
161    fw.indent()<<"maxScale           "<<transform.getMaxScale()<<std::endl;
162    fw.indent()<<"incrementScale     "<<transform.getIncrementScale()<<std::endl;
163    fw.indent()<<"currentScale       "<<transform.getCurrentScale()<<std::endl;
164
165
166    const char* mOrderStr[] = {"PRH", "PHR", "HPR", "HRP", "RPH", "RHP"};
167    fw.indent()<<"multOrder          "<<mOrderStr[transform.getHPRMultOrder()]<<std::endl;
168
169    fw.indent()<<"limitationFlags    0x"<<hex<<transform.getLimitationFlags()<<dec<<std::endl;
170
171    fw.indent()<<"animationOn        ";
172    if (transform.getAnimationOn()) fw<<"TRUE"<<std::endl;
173    else fw<<"FALSE"<<std::endl;
174
175    return true;
176}
Note: See TracBrowser for help on using the browser.