root/OpenSceneGraph/trunk/src/osgPlugins/ive/AutoTransform.cpp @ 4992

Revision 4992, 2.4 kB (checked in by robert, 8 years ago)

From Nathan Monteleone, addition of AutoTransform? support.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1/**********************************************************************
2 *
3 *    FILE:           AutoTransform.cpp
4 *
5 *    DESCRIPTION:    Read/Write osg::AutoTransform in binary format to disk.
6 *
7 *    CREATED BY:     Nathan Monteleone, based on PositionAttitudeTransform.cpp
8 *
9 *    HISTORY:        Created 02.3.2006
10 *
11 *    Copyright 2003 VR-C
12 **********************************************************************/
13
14#include "Exception.h"
15#include "AutoTransform.h"
16#include "Transform.h"
17
18using namespace ive;
19
20void AutoTransform::write(DataOutputStream* out){
21    // Write AutoTransform's identification.
22    out->writeInt(IVEAUTOTRANSFORM);
23    // If the osg class is inherited by any other class we should also write this to file.
24    osg::Transform*  trans = dynamic_cast<osg::Transform*>(this);
25    if(trans){
26        ((ive::Transform*)(trans))->write(out);
27    }
28    else
29        throw Exception("AutoTransform::write(): Could not cast this osg::AutoTransform to an osg::Transform.");
30    // Write AutoTransform's properties.
31
32    out->writeVec3(getPosition());
33    out->writeVec3(getPivotPoint());
34    out->writeFloat(getAutoUpdateEyeMovementTolerance());
35   
36    out->writeInt(getAutoRotateMode());
37
38    out->writeBool(getAutoScaleToScreen());
39
40    out->writeQuat(getRotation());
41    out->writeVec3(getScale());
42}
43
44void AutoTransform::read(DataInputStream* in){
45    // Peek on AutoTransform's identification.
46    int id = in->peekInt();
47    if(id == IVEAUTOTRANSFORM){
48        // Read AutoTransform's identification.
49        id = in->readInt();
50        // If the osg class is inherited by any other class we should also read this from file.
51        osg::Transform*  trans = dynamic_cast<osg::Transform*>(this);
52        if(trans){
53            ((ive::Transform*)(trans))->read(in);
54        }
55        else
56            throw Exception("AutoTransform::read(): Could not cast this osg::AutoTransform to an osg::Transform.");
57        // Read AutoTransform's properties
58
59        setPosition(in->readVec3());
60        setPivotPoint(in->readVec3());
61        setAutoUpdateEyeMovementTolerance(in->readFloat());
62
63        setAutoRotateMode(osg::AutoTransform::AutoRotateMode(in->readInt()));
64
65        setAutoScaleToScreen(in->readBool());
66
67        setRotation(in->readQuat());
68        setScale(in->readVec3());
69    }
70    else{
71        throw Exception("AutoTransform::read(): Expected AutoTransform identification.");
72    }
73}
Note: See TracBrowser for help on using the browser.