mixedNumber::mixedNumber(long long int w, long long int n, long long int d) { setFraction(d*w+n,d); }
void mixedNumber::setValue(long long int w, long long int n, long long int d) { setFraction(d*w+n, d); }
void mixedNumber::copy(const fraction &other) { setFraction(other.getNum(), other.getDenom()); }
void TimeSensor::frame(Time tTime, UInt32 uiFrame) { Real64 dFraction; bool bDoTimeRange = bool(_sfStartTime.getValue() < _sfStopTime .getValue()); bool bDoCycle = false; if(bDoTimeRange) { dFraction = Real64( tTime - _sfStartTime.getValue()) / Real64(_sfStopTime.getValue() - _sfStartTime.getValue()); } else { if(_sfCycleTime.getValue() > 0.0) { dFraction = Real64(tTime - _sfCycleTime.getValue()) / Real64(_sfCycleInterval.getValue()); bDoCycle = true; } else { dFraction = Real64(tTime - _sfStartTime.getValue()) / Real64(_sfCycleInterval.getValue()); } } if(_sfEnabled.getValue() == false) { if(_sfIsActive.getValue() == true) { setTime (tTime); setIsActive(false); setFraction(Real32(dFraction)); } } else { if(dFraction < 0.0) // before start { if(bDoCycle == true) { if(_sfIsActive.getValue() == true) { if(_sfLoop.getValue() == false) { setIsActive (false); setTime (tTime); setFraction (1.0 ); setCycleTime(tTime); } else { setCycleTime(_sfCycleTime .getValue() - _sfCycleInterval.getValue()); setTime (tTime); setFraction (dFraction + 1.0); } } else { } } } else if(dFraction > 1.0) // after end time { if(_sfIsActive.getValue() == true) { if(_sfLoop.getValue() == false) { setIsActive (false); setTime (0.f ); setFraction (1.0 ); setCycleTime(0.f ); setEnabled (false); } else { setCycleTime(_sfCycleTime .getValue() + _sfCycleInterval.getValue()); setTime (tTime); setFraction (dFraction - 1.0); } } else { if(bDoTimeRange == false) { setFraction (0.f); setCycleTime(tTime - (_sfFraction .getValue() * _sfCycleInterval.getValue() )); setIsActive (true); setTime (tTime); } } } else // within cycle { if (_sfIsActive.getValue() == false) { if(bDoTimeRange == true) { setCycleTime(_sfStartTime.getValue()); setIsActive (true); setTime (tTime); setFraction (dFraction); } else { setCycleTime(tTime - (_sfFraction .getValue() * _sfCycleInterval.getValue() )); if(_sfCycleTime.getValue() > TypeTraits<Time>::getDefaultEps()) { setIsActive(true); } setTime(tTime); } } else { if(tTime >= _sfStopTime.getValue() && bDoTimeRange == true ) { setIsActive(false); } else { if(tTime >= _sfStartTime.getValue()) { setTime (tTime ); setFraction(dFraction); } } } } } }
void GUIProgressBar::setValue(float value) { setFraction((value - rangeMinValue_) / (rangeMaxValue_ - rangeMinValue_)); }
void AnimTimeSensor::frame(Time oTime, UInt32 uiFrame) { Time startT = _sfStartTime .getValue(); Time stopT = _sfStopTime .getValue(); Time currT = _sfTime .getValue(); Time length = _sfCycleLength.getValue(); Time deltaT = 0.0; setTime(oTime); if(getEnabled() == false) { if(getIsActive() == true) { setIsActive(false); } return; } if(startT < stopT) { if(oTime < startT) { if(getIsActive() == true) { SLOG << "ATS: start < stop, BEFORE startT, deactivating" << std::endl; setFraction(0.f ); setAnimTime(0.f ); setIsActive(false); } return; } else if(oTime > stopT) { if(getIsActive() == true) { SLOG << "ATS: start < stop, AFTER stopT"; setFraction(1.f ); setAnimTime(length); // only deactivate the second time oTime > stopT // to propagate the final state if(currT > stopT) { PLOG << ", deactivating"; setIsActive(false); } PLOG << std::endl; } return; } else { if(currT <= 0.0) { deltaT = oTime - startT; } else { deltaT = oTime - currT; } } } else { if(oTime < startT) { if(getIsActive() == true) { SLOG << "ATS: start >= stop, BEFORE startT, deactivating" << std::endl; setFraction(0.f ); setAnimTime(0.f ); setIsActive(false); } return; } else { if(currT <= 0.0) { deltaT = oTime - startT; } else { deltaT = oTime - currT; } } } // use deltaT to update Real32 oldAnimT = getAnimTime(); Real32 newAnimT = getAnimTime(); if(getForward() == true) { newAnimT += getTimeScale() * deltaT; } else { newAnimT -= getTimeScale() * deltaT; } if(getLoop() == true) { newAnimT = osgMod<Real64>(newAnimT, length); while(newAnimT < 0.f) newAnimT += length; setAnimTime(newAnimT ); setFraction(newAnimT / length); if(getIsActive() == false) setIsActive(true); } else { if(newAnimT < 0.f) { if(getIsActive() == true) { SLOG << "ATS: start >= stop, newAnimT < 0"; setAnimTime(0.f); setFraction(0.f); // only deactivate the second time newAnimT < 0.f // to propagate the final state if(oldAnimT <= 0.f) { PLOG << ", deactivating"; setIsActive(false); } PLOG << std::endl; } } else if(newAnimT > length) { if(getIsActive() == true) { SLOG << "ATS: start >= stop, newAnimT > length"; setAnimTime(length); setFraction(1.f ); // only deactivate the second time newAnimT > length // to propagate the final state if(oldAnimT >= length) { PLOG << ", deactivating"; setIsActive(false); } PLOG << std::endl; } } else { setAnimTime(newAnimT ); setFraction(newAnimT / length); if(getIsActive() == false) setIsActive(true); } } }