From: Mathias Froehlich Date: Sun, 2 Dec 2012 14:37:02 +0000 (+0100) Subject: hla: Add SGQuat data elements. X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=1e6ba0cdc495431761f416d0e7af8e1b0de5445d;p=simgear.git hla: Add SGQuat data elements. --- diff --git a/simgear/hla/HLAArrayDataElement.hxx b/simgear/hla/HLAArrayDataElement.hxx index 77b5032e..c6a83aea 100644 --- a/simgear/hla/HLAArrayDataElement.hxx +++ b/simgear/hla/HLAArrayDataElement.hxx @@ -492,12 +492,13 @@ class HLAQuatDataElement : public HLAAbstractArrayDataElement { public: HLAQuatDataElement(const HLAArrayDataType* dataType = 0) : HLAAbstractArrayDataElement(dataType), - _value(SGQuat::zeros()) + _value(SGQuat::unit()) {} HLAQuatDataElement(const HLAArrayDataType* dataType, const SGQuat& value) : HLAAbstractArrayDataElement(dataType), _value(value) {} + const SGQuat& getValue() const { return _value; } void setValue(const SGQuat& value) @@ -542,6 +543,151 @@ private: SGQuat _value; }; +template +class HLAQuatData { +public: + HLAQuatData() : + _value(new HLAQuatDataElement(0)) + { } + HLAQuatData(const SGQuat& value) : + _value(new HLAQuatDataElement(0, value)) + { } + + operator const SGQuat&() const + { return _value->getValue(); } + HLAQuatData& operator=(const SGQuat& value) + { _value->setValue(value); return *this; } + + const SGQuat& getValue() const + { return _value->getValue(); } + void setValue(const SGQuat& value) + { _value->setValue(value); } + + const HLAQuatDataElement* getDataElement() const + { return _value.get(); } + HLAQuatDataElement* getDataElement() + { return _value.get(); } + + const HLAArrayDataType* getDataType() const + { return _value->getDataType(); } + void setDataType(const HLAArrayDataType* dataType) + { _value->setDataType(dataType); } + +private: + SGSharedPtr > _value; +}; + +typedef HLAQuatData HLAQuatfData; +typedef HLAQuatData HLAQuatdData; + +template +class HLAQuat3DataElement : public HLAAbstractArrayDataElement { +public: + HLAQuat3DataElement(const HLAArrayDataType* dataType = 0) : + HLAAbstractArrayDataElement(dataType), + _value(SGQuat::unit()), + _imag(SGQuat::unit().getPositiveRealImag()) + {} + HLAQuat3DataElement(const HLAArrayDataType* dataType, const SGQuat& value) : + HLAAbstractArrayDataElement(dataType), + _value(value), + _imag(value.getPositiveRealImag()) + {} + + const SGQuat& getValue() const + { return _value; } + void setValue(const SGQuat& value) + { _value = value; _imag = _value.getPositiveRealImag(); setDirty(true); } + + virtual bool encode(HLAEncodeStream& stream) const + { + return HLAAbstractArrayDataElement::encode(stream); + } + virtual bool decode(HLADecodeStream& stream) + { + if (!HLAAbstractArrayDataElement::decode(stream)) + return false; + _value = SGQuat::fromPositiveRealImag(_imag); + return true; + } + + virtual bool setNumElements(unsigned count) + { + for (unsigned i = count; i < 3; ++i) + _imag[i] = 0; + return true; + } + virtual bool decodeElement(HLADecodeStream& stream, unsigned i) + { + if (i < 3) { + HLATemplateDecodeVisitor::value_type> visitor(stream); + getElementDataType()->accept(visitor); + _imag[i] = visitor.getValue(); + } else { + HLADataTypeDecodeVisitor visitor(stream); + getElementDataType()->accept(visitor); + } + return true; + } + + virtual unsigned getNumElements() const + { + return 3; + } + virtual bool encodeElement(HLAEncodeStream& stream, unsigned i) const + { + if (i < 3) { + HLATemplateEncodeVisitor::value_type> visitor(stream, _imag[i]); + getElementDataType()->accept(visitor); + } else { + HLADataTypeEncodeVisitor visitor(stream); + getElementDataType()->accept(visitor); + } + return true; + } + +private: + SGQuat _value; + SGVec3 _imag; +}; + +template +class HLAQuat3Data { +public: + HLAQuat3Data() : + _value(new HLAQuat3DataElement(0)) + { } + HLAQuat3Data(const SGQuat& value) : + _value(new HLAQuat3DataElement(0, value)) + { } + + operator const SGQuat&() const + { return _value->getValue(); } + HLAQuat3Data& operator=(const SGQuat& value) + { _value->setValue(value); return *this; } + + const SGQuat& getValue() const + { return _value->getValue(); } + void setValue(const SGQuat& value) + { _value->setValue(value); } + + const HLAQuat3DataElement* getDataElement() const + { return _value.get(); } + HLAQuat3DataElement* getDataElement() + { return _value.get(); } + + const HLAArrayDataType* getDataType() const + { return _value->getDataType(); } + void setDataType(const HLAArrayDataType* dataType) + { _value->setDataType(dataType); } + +private: + SGSharedPtr > _value; +}; + +typedef HLAQuat3Data HLAQuat3fData; +typedef HLAQuat3Data HLAQuat3dData; + } #endif