1 /*---------------------------------------------------------------------------*\
5 * Copyright (C) 2000-2006 by the OpenSG Forum *
9 * contact: dirk@opensg.org, gerrit.voss@vossg.org, jbehr@zgdv.de *
11 \*---------------------------------------------------------------------------*/
12 /*---------------------------------------------------------------------------*\
15 * This library is free software; you can redistribute it and/or modify it *
16 * under the terms of the GNU Library General Public License as published *
17 * by the Free Software Foundation, version 2. *
19 * This library is distributed in the hope that it will be useful, but *
20 * WITHOUT ANY WARRANTY; without even the implied warranty of *
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
22 * Library General Public License for more details. *
24 * You should have received a copy of the GNU Library General Public *
25 * License along with this library; if not, write to the Free Software *
26 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *
28 \*---------------------------------------------------------------------------*/
29 /*---------------------------------------------------------------------------*\
37 \*---------------------------------------------------------------------------*/
39 //---------------------------------------------------------------------------
41 //---------------------------------------------------------------------------
46 #include "OSGConfig.h"
48 #include "OSGTimeSensor.h"
52 // Documentation for this class is emitted in the
53 // OSGTimeSensorBase.cpp file.
54 // To modify it, please change the .fcd file (OSGTimeSensor.fcd) and
55 // regenerate the base file.
57 /***************************************************************************\
59 \***************************************************************************/
61 /***************************************************************************\
63 \***************************************************************************/
65 void TimeSensor::initMethod(InitPhase ePhase
)
67 Inherited::initMethod(ePhase
);
69 if(ePhase
== TypeObject::SystemPost
)
75 /***************************************************************************\
77 \***************************************************************************/
79 /*-------------------------------------------------------------------------*\
81 \*-------------------------------------------------------------------------*/
83 /*----------------------- constructors & destructors ----------------------*/
85 TimeSensor::TimeSensor(void) :
90 TimeSensor::TimeSensor(const TimeSensor
&source
) :
95 TimeSensor::~TimeSensor(void)
99 /*----------------------------- class specific ----------------------------*/
101 void TimeSensor::changed(ConstFieldMaskArg whichField
,
105 if(0x0000 != (whichField
& ChangeFractionByFieldMask
))
107 if(_sfEnabled
.getValue() == false &&
108 _sfChangeFractionBy
.getValue() >= -1.0 &&
109 _sfChangeFractionBy
.getValue() <= 1.0 )
111 Time tVal
= _sfFraction
.getValue();
113 tVal
+= _sfChangeFractionBy
.getValue();
121 this->setFraction(tVal
);
126 Inherited::changed(whichField
, origin
, details
);
129 void TimeSensor::dump( UInt32 uiIndent
,
130 const BitVector bvFlags
) const
133 indentLog(uiIndent
, PLOG
);
134 PLOG
<< "TimeSensor (" << this->getId()
139 indentLog(uiIndent
+ 4, PLOG
);
140 PLOG
<< "enabled [" << _sfEnabled
.getValue()
141 << "] active [" << _sfIsActive
.getValue()
142 << "] loop [" << _sfLoop
.getValue()
146 indentLog(uiIndent
+ 4, PLOG
);
147 PLOG
<< "fraction [" << _sfFraction
.getValue()
148 << "] startTime [" << _sfStartTime
.getValue()
149 << "] stopTime [" << _sfStopTime
.getValue()
150 << "] cycleInterval [" << _sfCycleInterval
.getValue()
151 << "] cycleTime [" << _sfCycleTime
.getValue()
152 << "] time [" << _sfTime
.getValue()
156 void TimeSensor::frame(Time tTime
, UInt32 uiFrame
)
160 bool bDoTimeRange
= bool(_sfStartTime
.getValue() <
161 _sfStopTime
.getValue());
163 bool bDoCycle
= false;
168 Real64( tTime
- _sfStartTime
.getValue()) /
169 Real64(_sfStopTime
.getValue() - _sfStartTime
.getValue());
173 if(_sfCycleTime
.getValue() > 0.0)
176 Real64(tTime
- _sfCycleTime
.getValue()) /
177 Real64(_sfCycleInterval
.getValue());
184 Real64(tTime
- _sfStartTime
.getValue()) /
185 Real64(_sfCycleInterval
.getValue());
189 if(_sfEnabled
.getValue() == false)
191 if(_sfIsActive
.getValue() == true)
195 setFraction(Real32(dFraction
));
200 if(dFraction
< 0.0) // before start
204 if(_sfIsActive
.getValue() == true)
206 if(_sfLoop
.getValue() == false)
215 setCycleTime(_sfCycleTime
.getValue() -
216 _sfCycleInterval
.getValue());
219 setFraction (dFraction
+ 1.0);
227 else if(dFraction
> 1.0) // after end time
229 if(_sfIsActive
.getValue() == true)
231 if(_sfLoop
.getValue() == false)
241 setCycleTime(_sfCycleTime
.getValue() +
242 _sfCycleInterval
.getValue());
245 setFraction (dFraction
- 1.0);
250 if(bDoTimeRange
== false)
254 (_sfFraction
.getValue() *
255 _sfCycleInterval
.getValue() ));
264 if (_sfIsActive
.getValue() == false)
266 if(bDoTimeRange
== true)
268 setCycleTime(_sfStartTime
.getValue());
271 setFraction (dFraction
);
276 (_sfFraction
.getValue() *
277 _sfCycleInterval
.getValue() ));
279 if(_sfCycleTime
.getValue() >
280 TypeTraits
<Time
>::getDefaultEps())
290 if(tTime
>= _sfStopTime
.getValue() &&
291 bDoTimeRange
== true )
297 if(tTime
>= _sfStartTime
.getValue())
300 setFraction(dFraction
);