void
ColladaNode::handleTranslate(domTranslate *translate)
{
    if(translate == NULL)
        return;

    domNodeRef        node   = getDOMElementAs<domNode>();

    TransformUnrecPtr xform  = Transform::create();
    NodeUnrecPtr      xformN = makeNodeFor(xform);

    xform->editMatrix().setTranslate(translate->getValue()[0],
                                     translate->getValue()[1],
                                     translate->getValue()[2] );

    if(getGlobal()->getOptions()->getCreateNameAttachments() == true && 
       node->getName()                                       != NULL   )
    {
        std::string nodeName = node->getName();

        if(translate->getSid() != NULL)
        {
            nodeName.append("."                );
            nodeName.append(translate->getSid());
        }

        setName(xformN, nodeName);
    }

    appendXForm(xformN);
}
void
ColladaNode::handleMatrix(domMatrix *matrix, InstData &instData)
{
    if(matrix == NULL)
        return;

    Matrix m(matrix->getValue()[0],      // rVal00
             matrix->getValue()[1],      // rVal10
             matrix->getValue()[2],      // rVal20
             matrix->getValue()[3],      // rVal30
             matrix->getValue()[4],      // rVal01
             matrix->getValue()[5],      // rVal11
             matrix->getValue()[6],      // rVal21
             matrix->getValue()[7],      // rVal31
             matrix->getValue()[8],      // rVal02
             matrix->getValue()[9],      // rVal12
             matrix->getValue()[10],     // rVal22
             matrix->getValue()[11],     // rVal32
             matrix->getValue()[12],     // rVal03
             matrix->getValue()[13],     // rVal13
             matrix->getValue()[14],     // rVal23
             matrix->getValue()[15] );   // rVal33

    std::string xformSID;

    if(matrix->getSid() != NULL)
        xformSID.assign(matrix->getSid());

    appendXForm(m, xformSID, instData);
}
void
ColladaNode::handleMatrix(domMatrix *matrix)
{
    if(matrix == NULL)
        return;

    domNodeRef        node   = getDOMElementAs<domNode>();

    Matrix m(matrix->getValue()[0],      // rVal00
             matrix->getValue()[1],      // rVal10
             matrix->getValue()[2],      // rVal20
             matrix->getValue()[3],      // rVal30
             matrix->getValue()[4],      // rVal01
             matrix->getValue()[5],      // rVal11
             matrix->getValue()[6],      // rVal21
             matrix->getValue()[7],      // rVal31
             matrix->getValue()[8],      // rVal02
             matrix->getValue()[9],      // rVal12
             matrix->getValue()[10],     // rVal22
             matrix->getValue()[11],     // rVal32
             matrix->getValue()[12],     // rVal03
             matrix->getValue()[13],     // rVal13
             matrix->getValue()[14],     // rVal23
             matrix->getValue()[15] );   // rVal33

    if(getGlobal()->getOptions()->getFlattenNodeXForms())
    {
        MatrixTransformationElementUnrecPtr MatrixElement = MatrixTransformationElement::create();
        MatrixElement->setMatrix(m);
        setName(MatrixElement, matrix->getSid());

        appendStackedXForm(MatrixElement, node);
    }
    else
    {
        TransformUnrecPtr xform = Transform::create();

        NodeUnrecPtr      xformN = makeNodeFor(xform);
        
        xform->setMatrix(m);

        if(getGlobal()->getOptions()->getCreateNameAttachments() == true && 
           node->getName()                                       != NULL   )
        {
            std::string nodeName = node->getName();

            if(matrix->getSid() != NULL&& 
			    getGlobal()->getOptions()->getFlattenNodeXForms() == false)
            {
                nodeName.append("."             );
                nodeName.append(matrix->getSid());
            }

            setName(xformN, nodeName);
        }

        appendXForm(xformN);
    }
}
void
ColladaNode::handleSkew(domSkew *skew)
{
    if(skew == NULL)
        return;
	
    domNodeRef        node   = getDOMElementAs<domNode>();
    Vec3f rotationAxis(skew->getValue()[1],skew->getValue()[2],skew->getValue()[3]), 
          translationAxis(skew->getValue()[4],skew->getValue()[5],skew->getValue()[6]);
    Real32 angle(skew->getValue()[0]);

    if(getGlobal()->getOptions()->getFlattenNodeXForms())
    {
        SkewTransformationElementUnrecPtr SkewElement = SkewTransformationElement::create();
        SkewElement->setRotationAxis(rotationAxis);
        SkewElement->setTranslationAxis(translationAxis);
        SkewElement->setAngle(angle);
        setName(SkewElement, skew->getSid());

        appendStackedXForm(SkewElement, node);
    }
    else
    {

        TransformUnrecPtr xform = Transform::create();
	    NodeUnrecPtr      xformN = makeNodeFor(xform);

        Matrix skewMatrix;
        MatrixSkew(skewMatrix,rotationAxis, translationAxis, angle);

	    xform->setMatrix(skewMatrix);

	     if(getGlobal()->getOptions()->getCreateNameAttachments() == true && 
           node->getName()                                       != NULL   )
        {
            std::string nodeName = node->getName();

            if(skew->getSid() != NULL && 
			    getGlobal()->getOptions()->getFlattenNodeXForms() == false)
            {
                nodeName.append("."                );
                nodeName.append(skew->getSid());
            }

            setName(xformN, nodeName);
        }

        appendXForm(xformN);
    }

}
void
ColladaNode::handleRotate(domRotate *rotate)
{
    if(rotate == NULL)
        return;

    domNodeRef        node   = getDOMElementAs<domNode>();

    Vec3f axis(rotate->getValue()[0], rotate->getValue()[1], rotate->getValue()[2]);
    Real32 angle(rotate->getValue()[3]);

    if(getGlobal()->getOptions()->getFlattenNodeXForms())
    {
        RotationTransformationElementUnrecPtr RotationElement = RotationTransformationElement::create();
        RotationElement->setAxis(axis);
        RotationElement->setAngle(angle);
        setName(RotationElement, rotate->getSid());

        appendStackedXForm(RotationElement, node);

	    if(getGlobal()->editAnimationMap()[rotate] != NULL) 
	    {
            SLOG << "Found Rotation Animation" << std::endl;
		    getGlobal()->editAnimationMap()[rotate]->getAnimation()->setAnimatedField(RotationElement,std::string("Angle"));
	    }
    }
    else
    {
        TransformUnrecPtr xform = Transform::create();
        NodeUnrecPtr      xformN = makeNodeFor(xform);
        
        xform->editMatrix().setRotate(Quaternion(axis, osgDegree2Rad(angle)));

        if(getGlobal()->getOptions()->getCreateNameAttachments() == true && 
           node->getName()                                       != NULL   )
        {
            std::string nodeName = node->getName();

            if(rotate->getSid() != NULL&& 
			    getGlobal()->getOptions()->getFlattenNodeXForms() == false)
            {
                nodeName.append("."             );
                nodeName.append(rotate->getSid());
            }

            setName(xformN, nodeName);
        }

        appendXForm(xformN);
    }
}
void
ColladaNode::handleLookAt(domLookat *lookat)
{
    if(lookat == NULL)
        return;
	
    domNodeRef        node   = getDOMElementAs<domNode>();
    Pnt3f eyePosition(lookat->getValue()[0],lookat->getValue()[1],lookat->getValue()[2]), 
          lookAtPoint(lookat->getValue()[3],lookat->getValue()[4],lookat->getValue()[5]);
    Vec3f upDirection(lookat->getValue()[7],lookat->getValue()[8],lookat->getValue()[9]);

    if(getGlobal()->getOptions()->getFlattenNodeXForms())
    {
        LookAtTransformationElementUnrecPtr LookAtElement = LookAtTransformationElement::create();
        LookAtElement->setEyePosition(eyePosition);
        LookAtElement->setLookAtPosition(lookAtPoint);
        LookAtElement->setUpDirection(upDirection);
        setName(LookAtElement, lookat->getSid());

        appendStackedXForm(LookAtElement, node);
    }
    else
    {

        TransformUnrecPtr xform = Transform::create();
	    NodeUnrecPtr      xformN = makeNodeFor(xform);

        Matrix lookAtMatrix;
        MatrixLookAt(lookAtMatrix,eyePosition, lookAtPoint, upDirection);

	    xform->setMatrix(lookAtMatrix);

	     if(getGlobal()->getOptions()->getCreateNameAttachments() == true && 
           node->getName()                                       != NULL   )
        {
            std::string nodeName = node->getName();

            if(lookat->getSid() != NULL && 
			    getGlobal()->getOptions()->getFlattenNodeXForms() == false)
            {
                nodeName.append("."                );
                nodeName.append(lookat->getSid());
            }

            setName(xformN, nodeName);
        }

        appendXForm(xformN);
    }
}
void
ColladaNode::handleTranslate(domTranslate *translate)
{
    if(translate == NULL)
        return;

    domNodeRef        node   = getDOMElementAs<domNode>();
    Vec3f translation(translate->getValue()[0], translate->getValue()[1], translate->getValue()[2]);

    if(getGlobal()->getOptions()->getFlattenNodeXForms())
    {
        TranslationTransformationElementUnrecPtr TranslateElement = TranslationTransformationElement::create();
        TranslateElement->setTranslation(translation);
        setName(TranslateElement, translate->getSid());

        appendStackedXForm(TranslateElement, node);

	    if(getGlobal()->editAnimationMap()[translate] != NULL) 
	    {
				SLOG << "Found Translation Animation" << std::endl;
				getGlobal()->editAnimationMap()[translate]->getAnimation()->setAnimatedField(TranslateElement,std::string("Translation")) ;
	    }
    }
    else
    {

        TransformUnrecPtr xform = Transform::create();
        NodeUnrecPtr      xformN = makeNodeFor(xform);

        xform->editMatrix().setTranslate(translation);

        if(getGlobal()->getOptions()->getCreateNameAttachments() == true && 
           node->getName()                                       != NULL   )
        {
            std::string nodeName = node->getName();

            if(translate->getSid() != NULL && 
			    getGlobal()->getOptions()->getFlattenNodeXForms() == false)
            {
                nodeName.append("."                );
                nodeName.append(translate->getSid());
            }

            setName(xformN, nodeName);
        }

        appendXForm(xformN);
    }
}
void
ColladaNode::handleScale(domScale *scale, InstData &instData)
{
    if(scale == NULL)
        return;

    Matrix m;
    m.setScale(scale->getValue()[0],
               scale->getValue()[1],
               scale->getValue()[2] );

    std::string xformSID;

    if(scale->getSid() != NULL)
        xformSID.assign(scale->getSid());

    appendXForm(m, xformSID, instData);
}
void
ColladaNode::handleTranslate(domTranslate *translate, InstData &instData)
{
    if(translate == NULL)
        return;

    Matrix m;
    m.setTranslate(translate->getValue()[0],
                   translate->getValue()[1],
                   translate->getValue()[2] );

    std::string nameSuffix;

    if(translate->getSid() != NULL)
    {
        nameSuffix.append("."                );
        nameSuffix.append(translate->getSid());
    }

    appendXForm(m, nameSuffix, instData);  
}
void
ColladaNode::handleRotate(domRotate *rotate, InstData &instData)
{
    if(rotate == NULL)
        return;

    Matrix     m;
    Quaternion q;
    q.setValueAsAxisDeg(rotate->getValue()[0],
                        rotate->getValue()[1],
                        rotate->getValue()[2],
                        rotate->getValue()[3] );

    m.setRotate(q);

    std::string xformSID;

    if(rotate->getSid() != NULL)
        xformSID.assign(rotate->getSid());

    appendXForm(m, xformSID, instData);
}