|
#include <QStringList>
#include <QMap>
#include "matrixtransform.h"
#include "attribute_parser.h"
#include "trigger.h"
MatrixTransform::MatrixTransform(QObject *parent, QString Dir, QDomElement node) :
OSGControlLayout(parent, Dir, node)
{
Type = "MatrixTransform";
TypeDescendants = "Group";
if(!Copy)
{
_group = new osg::MatrixTransform;
for(unsigned int i=0; i < node.childNodes().count(); i++)
{
QDomElement tempElement = node.childNodes().item(i).toElement();
QString type = tempElement.nodeName();
QStringList list = type.split(".");
if(list.length() == 2)
{
if(list[0] == Type)
if(list[1] == "SetMatrix")
SetMatrix(tempElement);
}
}
}
else
copyElement();
setTriggers();
}
osg::Node *MatrixTransform::getNode()
{
osg::Node * out = static_cast<osg::Node *>(_group.get());
return out;
}
MatrixTransform::~MatrixTransform()
{
_group->setEventCallback(NULL);
}
void MatrixTransform::copyElement()
{
}
void MatrixTransform::SetMatrix(QDomElement node)
{
osg::Matrix Result;
Result = osg::Matrix::identity();
for(unsigned int i=0; i < node.childNodes().count(); i++)
{
QDomElement tempElement = node.childNodes().item(i).toElement();
QString type = tempElement.nodeName();
QStringList list = type.split(".");
if(list.length() == 1)
{
if(list[0] == "Translate")
{
QMap<QString, QString> map = Attribute_Parser::readAttributes(tempElement.attributes());
if(map.contains("X") || map.contains("Y") || map.contains("Z"))
{
float X, Y, Z;
bool ok = false;
QString temp = map["X"];
X = temp.toFloat(&ok);
if(!ok) X = 0.0f;
temp = map["Y"];
Y = temp.toFloat(&ok);
if(!ok) Y = 0.0f;
temp = map["Z"];
Z = temp.toFloat(&ok);
if(!ok) Z = 0.0f;
Result *= osg::Matrix::translate(X, Y, Z);
}
}
if(list[0] == "Rotate")
{
QMap<QString, QString> map = Attribute_Parser::splitAttribute(tempElement.attribute("Parametr"));
if(map.contains("Angle") && map.contains("Axis") && !map.contains("Option"))
{
float Angle;
bool ok = false;
QString temp = map["Angle"];
Angle = temp.toFloat(&ok);
if(!ok) Angle = 0.0f;
osg::Vec3f Axis = osg::X_AXIS;
if(map["Axis"] == "Y") Axis = osg::Y_AXIS;
if(map["Axis"] == "Z") Axis = osg::Z_AXIS;
Result *= osg::Matrix::rotate(osg::inDegrees(Angle), Axis);
}
if(map.contains("Angle") && map.contains("Axis") && map.contains("Option"))
{
if(map["Option"] == "Quat")
{
float Angle;
bool ok = false;
QString temp = map["Angle"];
Angle = temp.toFloat(&ok);
if(!ok) Angle = 0.0f;
osg::Vec3f Axis = osg::X_AXIS;
if(map["Axis"] == "Y") Axis = osg::Y_AXIS;
if(map["Axis"] == "Z") Axis = osg::Z_AXIS;
osg::Quat Quater(osg::inDegrees(Angle), Axis);
Result *= osg::Matrix::rotate(Quater);
}
}
}
if(list[0] == "Scale")
{
QMap<QString, QString> map = Attribute_Parser::readAttributes(tempElement.attributes());
if(map.contains("X") || map.contains("Y") || map.contains("Z"))
{
float X, Y, Z;
bool ok = false;
QString temp = map["X"];
X = temp.toFloat(&ok);
if(!ok) X = 1.0f;
temp = map["Y"];
Y = temp.toFloat(&ok);
if(!ok) Y = 1.0f;
temp = map["Z"];
Z = temp.toFloat(&ok);
if(!ok) Z = 1.0f;
Result *= osg::Matrix::scale(X, Y, Z);
}
}
}
}
_group->setMatrix(Result);
}
//void MatrixTransform::setTriggers()
//{
// for(int i = 0; i < _triggers.count(); i++)
// _group->addEventCallback(_triggers.at(i));
//}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.