boxes/boxquaternion/orboxquaternion_box.cxx

boxes/boxquaternion/orboxquaternion_box.cxx
/***************************************************************************************
Autodesk(R) Open Reality(R) Samples
(C) 2009 Autodesk, Inc. and/or its licensors
All rights reserved.
AUTODESK SOFTWARE LICENSE AGREEMENT
Autodesk, Inc. licenses this Software to you only upon the condition that
you accept all of the terms contained in the Software License Agreement ("Agreement")
that is embedded in or that is delivered with this Software. By selecting
the "I ACCEPT" button at the end of the Agreement or by copying, installing,
uploading, accessing or using all or any portion of the Software you agree
to enter into the Agreement. A contract is then formed between Autodesk and
either you personally, if you acquire the Software for yourself, or the company
or other legal entity for which you are acquiring the software.
AUTODESK, INC., MAKES NO WARRANTY, EITHER EXPRESS OR IMPLIED, INCLUDING BUT
NOT LIMITED TO ANY IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR
PURPOSE REGARDING THESE MATERIALS, AND MAKES SUCH MATERIALS AVAILABLE SOLELY ON AN
"AS-IS" BASIS.
IN NO EVENT SHALL AUTODESK, INC., BE LIABLE TO ANYONE FOR SPECIAL, COLLATERAL,
INCIDENTAL, OR CONSEQUENTIAL DAMAGES IN CONNECTION WITH OR ARISING OUT OF PURCHASE
OR USE OF THESE MATERIALS. THE SOLE AND EXCLUSIVE LIABILITY TO AUTODESK, INC.,
REGARDLESS OF THE FORM OF ACTION, SHALL NOT EXCEED THE PURCHASE PRICE OF THE
MATERIALS DESCRIBED HEREIN.
Autodesk, Inc., reserves the right to revise and improve its products as it sees fit.
Autodesk and Open Reality are registered trademarks or trademarks of Autodesk, Inc.,
in the U.S.A. and/or other countries. All other brand names, product names, or
trademarks belong to their respective holders.
GOVERNMENT USE
Use, duplication, or disclosure by the U.S. Government is subject to restrictions as
set forth in FAR 12.212 (Commercial Computer Software-Restricted Rights) and
DFAR 227.7202 (Rights in Technical Data and Computer Software), as applicable.
Manufacturer is Autodesk, Inc., 10 Duke Street, Montreal, Quebec, Canada, H3C 2L7.
***************************************************************************************/
//--- Class declaration
#include "orboxquaternion_box.h"
//--- Registration defines
#define ORBOXROTQUAT__CLASS ORBOXROTQUAT__CLASSNAME
#define ORBOXROTQUAT__NAME ORBOXROTQUAT__CLASSSTR
#define ORBOXROTQUAT__LOCATION "Plugins"
#define ORBOXROTQUAT__LABEL "OR - Rotation to Quaternion"
#define ORBOXROTQUAT__DESC "OR - Rotation to Quaternion Description"
#define ORBOXQUATROT__CLASS ORBOXQUATROT__CLASSNAME
#define ORBOXQUATROT__NAME ORBOXQUATROT__CLASSSTR
#define ORBOXQUATROT__LOCATION "Plugins"
#define ORBOXQUATROT__LABEL "OR - Quaternion to Rotation"
#define ORBOXQUATROT__DESC "OR - Quaternion to Rotation Description"
//--- implementation and registration
FBBoxImplementation ( ORBOXROTQUAT__CLASS ); // Box class name
FBRegisterBox ( ORBOXROTQUAT__NAME, // Unique name to register box.
ORBOXROTQUAT__CLASS, // Box class name
ORBOXROTQUAT__LOCATION, // Box location ('plugins')
ORBOXROTQUAT__LABEL, // Box label (name of box to display)
ORBOXROTQUAT__DESC, // Box long description.
FB_DEFAULT_SDK_ICON ); // Icon filename (default=Open Reality icon)
FBBoxImplementation ( ORBOXQUATROT__CLASS ); // Box class name
FBRegisterBox ( ORBOXQUATROT__NAME, // Unique name to register box.
ORBOXQUATROT__CLASS, // Box class name
ORBOXQUATROT__LOCATION, // Box location ('plugins')
ORBOXQUATROT__LABEL, // Box label (name of box to display)
ORBOXQUATROT__DESC, // Box long description.
FB_DEFAULT_SDK_ICON ); // Icon filename (default=Open Reality icon)
/************************************************
* Creation
************************************************/
bool ORBoxRotationQuaternion::FBCreate()
{
if( FBBox::FBCreate() )
{
// Create the input node.
mR = AnimationNodeInCreate ( 0, "Rotation", ANIMATIONNODE_TYPE_VECTOR );
// Create the output nodes
mQ[0] = AnimationNodeOutCreate( 1, "Q0", ANIMATIONNODE_TYPE_NUMBER );
mQ[1] = AnimationNodeOutCreate( 2, "Q1", ANIMATIONNODE_TYPE_NUMBER );
mQ[2] = AnimationNodeOutCreate( 3, "Q2", ANIMATIONNODE_TYPE_NUMBER );
mQ[3] = AnimationNodeOutCreate( 4, "Q3", ANIMATIONNODE_TYPE_NUMBER );
return true;
}
return false;
}
/************************************************
* Destruction.
************************************************/
void ORBoxRotationQuaternion::FBDestroy()
{
FBBox::FBDestroy();
}
/************************************************
* Real-time engine evaluation
************************************************/
bool ORBoxRotationQuaternion::AnimationNodeNotify( FBAnimationNode* pAnimationNode, FBEvaluateInfo* pEvaluateInfo )
{
double lRot[3];
FBRVector lRotation;
FBQuaternion lQuaternion;
int lStatus; // Status of input node
// Read the data from the input node
lStatus = mR->ReadData( lRot, pEvaluateInfo );
// If the read was not from a dead node.
if( lStatus )
{
// Assign the roation vector
lRotation.Set( lRot );
// Convert to quaternion
FBRotationToQuaternion( lQuaternion, lRotation );
// Write the quaternion values to the output nodes.
mQ[0]->WriteData( &lQuaternion[0], pEvaluateInfo );
mQ[1]->WriteData( &lQuaternion[1], pEvaluateInfo );
mQ[2]->WriteData( &lQuaternion[2], pEvaluateInfo );
mQ[3]->WriteData( &lQuaternion[3], pEvaluateInfo );
return true;
}
return false;
}
/************************************************
* Creation
************************************************/
bool ORBoxQuaternionRotation::FBCreate()
{
if( FBBox::FBCreate() )
{
// Create the input nodes.
mQ[0] = AnimationNodeInCreate( 1, "Q0", ANIMATIONNODE_TYPE_NUMBER );
mQ[1] = AnimationNodeInCreate( 1, "Q1", ANIMATIONNODE_TYPE_NUMBER );
mQ[2] = AnimationNodeInCreate( 1, "Q2", ANIMATIONNODE_TYPE_NUMBER );
mQ[3] = AnimationNodeInCreate( 1, "Q3", ANIMATIONNODE_TYPE_NUMBER );
// Create the ouput node.
mR = AnimationNodeOutCreate ( 0, "Rotation", ANIMATIONNODE_TYPE_VECTOR );
return true;
}
return false;
}
/************************************************
* Destruction.
************************************************/
void ORBoxQuaternionRotation::FBDestroy()
{
FBBox::FBDestroy();
}
/************************************************
* Real-time engine evaluation
************************************************/
bool ORBoxQuaternionRotation::AnimationNodeNotify( FBAnimationNode* pAnimationNode, FBEvaluateInfo* pEvaluateInfo )
{
double lRot[3];
FBRVector lRotation;
FBQuaternion lQuaternion;
bool lStatus[5]; // Status of input node
// Read the input nodes.
lStatus[0] = mQ[0]->ReadData( &lQuaternion[0], pEvaluateInfo );
lStatus[1] = mQ[1]->ReadData( &lQuaternion[1], pEvaluateInfo );
lStatus[2] = mQ[2]->ReadData( &lQuaternion[2], pEvaluateInfo );
lStatus[3] = mQ[3]->ReadData( &lQuaternion[3], pEvaluateInfo );
lStatus[4] = lStatus[0] && lStatus[1] && lStatus[2] && lStatus[3] ;
// If the read was not from a dead node.
if( lStatus[4] )
{
// Convert to rotation.
FBQuaternionToRotation( lRotation, lQuaternion );
lRot[0] = lRotation[0];
lRot[1] = lRotation[1];
lRot[2] = lRotation[2];
// Write the rotation out.
mR->WriteData( lRot, pEvaluateInfo );
return true;
}
return false;
}