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

Revision 7968, 2.8 kB (checked in by robert, 6 years ago)

To osg::AutoTransform? added support for MinimumScale?, MaximumScale? and AutoScaleTransitionWidth? parameters
and a new scheme for computing the scaling when using autoscale that introduces smooth
transitions to the scaling of the subgraph so that it looks more natural.

  • 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    if ( out->getVersion() >= VERSION_0025 )
41    {
42        out->writeFloat(getMinimumScale());
43        out->writeFloat(getMaximumScale());
44        out->writeFloat(getAutoScaleTransistionWidthRatio());
45    }
46
47    out->writeQuat(getRotation());
48    out->writeVec3(getScale());
49   
50}
51
52void AutoTransform::read(DataInputStream* in){
53    // Peek on AutoTransform's identification.
54    int id = in->peekInt();
55    if(id == IVEAUTOTRANSFORM){
56        // Read AutoTransform's identification.
57        id = in->readInt();
58        // If the osg class is inherited by any other class we should also read this from file.
59        osg::Transform*  trans = dynamic_cast<osg::Transform*>(this);
60        if(trans){
61            ((ive::Transform*)(trans))->read(in);
62        }
63        else
64            throw Exception("AutoTransform::read(): Could not cast this osg::AutoTransform to an osg::Transform.");
65        // Read AutoTransform's properties
66
67        setPosition(in->readVec3());
68        setPivotPoint(in->readVec3());
69        setAutoUpdateEyeMovementTolerance(in->readFloat());
70
71        setAutoRotateMode(osg::AutoTransform::AutoRotateMode(in->readInt()));
72
73        setAutoScaleToScreen(in->readBool());
74
75        if ( in->getVersion() >= VERSION_0025 )
76        {
77            setMinimumScale(in->readFloat());
78            setMaximumScale(in->readFloat());
79            setAutoScaleTransistionWidthRatio(in->readFloat());
80        }
81
82        setRotation(in->readQuat());
83        setScale(in->readVec3());
84
85
86    }
87    else{
88        throw Exception("AutoTransform::read(): Expected AutoTransform identification.");
89    }
90}
Note: See TracBrowser for help on using the browser.