00001 #include "Transform.h" 00002 00003 using namespace X3DTK; 00004 00005 Transform::Transform() 00006 : X3DGroupingNode(), X3DBoundedObject(), center_(SFVec3f(0.0f, 0.0f, 0.0f)), rotation_(SFRotation(0.0f, 0.0f, 1.0f, 0.0f)), scale_(SFVec3f(1.0f, 1.0f, 1.0f)), scaleOrientation_(SFRotation(0.0f, 0.0f, 1.0f, 0.0f)), translation_(SFVec3f(0.0f, 0.0f, 0.0f)) 00007 { 00008 defineTagName("Transform", "Grouping"); 00009 } 00010 00011 Transform::Transform(const SFVec3f ¢er, const SFRotation &rotation, const SFVec3f &scale, const SFRotation &scaleOrientation, const SFVec3f &translation, const SFVec3f &bboxCenter, const SFVec3f &bboxSize) 00012 : X3DGroupingNode(), X3DBoundedObject(bboxCenter, bboxSize), center_(center), rotation_(rotation), scale_(scale), scaleOrientation_(scaleOrientation), translation_(translation) 00013 { 00014 defineTagName("Transform", "Grouping"); 00015 } 00016 00017 Transform::Transform(const Transform &T) 00018 : X3DGroupingNode(T), X3DBoundedObject(T), center_(T.center_), rotation_(T.rotation_), scale_(T.scale_), scaleOrientation_(T.scaleOrientation_), translation_(T.translation_) 00019 { 00020 defineTagName("Transform", "Grouping"); 00021 } 00022 00023 SFNode Transform::clone() const 00024 { 00025 return new Transform(*this); 00026 } 00027 00028 Transform::~Transform() 00029 { 00030 } 00031 00032 void Transform::setCenter(const SFVec3f ¢er) 00033 { 00034 center_ = center; 00035 } 00036 00037 void Transform::setRotation(const SFRotation &rotation) 00038 { 00039 rotation_ = rotation; 00040 } 00041 00042 void Transform::setScale(const SFVec3f &scale) 00043 { 00044 scale_ = scale; 00045 } 00046 00047 void Transform::setScaleOrientation(const SFRotation &scaleOrientation) 00048 { 00049 scaleOrientation_ = scaleOrientation; 00050 } 00051 00052 void Transform::setTranslation(const SFVec3f &translation) 00053 { 00054 translation_ = translation; 00055 } 00056 00057 void Transform::loadAttributes(const X3DFileElement *element) 00058 { 00059 X3DBoundedObject::loadAttributes(element); 00060 00061 int index; 00062 index = element->getIndexAttribute("center"); 00063 if (index != -1) 00064 center_ = SFVec3f(element->getAttribute(index)); 00065 00066 index = element->getIndexAttribute("rotation"); 00067 if (index != -1) 00068 rotation_ = SFRotation(element->getAttribute(index)); 00069 00070 index = element->getIndexAttribute("scale"); 00071 if (index != -1) 00072 scale_ = SFVec3f(element->getAttribute(index)); 00073 00074 index = element->getIndexAttribute("scaleOrientation"); 00075 if (index != -1) 00076 scaleOrientation_ = SFRotation(element->getAttribute(index)); 00077 00078 index = element->getIndexAttribute("translation"); 00079 if (index != -1) 00080 translation_ = SFVec3f(element->getAttribute(index)); 00081 } 00082 00083 SFString Transform::writeAttributes() const 00084 { 00085 SFString attr; 00086 if (center_ != SFVec3f(0.0f, 0.0f, 0.0f)) 00087 attr += " center=\"" + toSFString(center_) + "\""; 00088 if (rotation_ != SFRotation(0.0f, 0.0f, 1.0f, 0.0f)) 00089 attr += " rotation=\"" + toSFString(rotation_) + "\""; 00090 if (scale_ != SFVec3f(1.0f, 1.0f, 1.0f)) 00091 attr += " scale=\"" + toSFString(scale_) + "\""; 00092 if (scaleOrientation_ != SFRotation(0.0f, 0.0f, 1.0f, 0.0f)) 00093 attr += " scaleOrientation=\"" + toSFString(scaleOrientation_) + "\""; 00094 if (translation_ != SFVec3f(0.0f, 0.0f, 0.0f)) 00095 attr += " translation=\"" + toSFString(translation_) + "\""; 00096 00097 return attr; 00098 }