boxes/boxsineramp/orboxsineramp_box.cxx

boxes/boxsineramp/orboxsineramp_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.
***************************************************************************************/
#define _USE_MATH_DEFINES // To get M_PI defined
//--- Class declarations
#include "orboxsineramp_box.h"
#include <math.h>
//--- Registration defines
#define ORBOXSINERAMP__CLASS ORBOXSINERAMP__CLASSNAME
#define ORBOXSINERAMP__NAME ORBOXSINERAMP__CLASSSTR
#define ORBOXSINERAMP__LOCATION "Plugins"
#define ORBOXSINERAMP__LABEL "OR - Sine Ramp"
#define ORBOXSINERAMP__DESC "OR - Sine Ramp Description"
//--- implementation and registration
FBBoxImplementation ( ORBOXSINERAMP__CLASS ); // Box class name
FBRegisterBox ( ORBOXSINERAMP__NAME, // Unique name to register box.
ORBOXSINERAMP__CLASS, // Box class name
ORBOXSINERAMP__LOCATION, // Box location ('plugins')
ORBOXSINERAMP__LABEL, // Box label (name of box to display)
ORBOXSINERAMP__DESC, // Box long description.
FB_DEFAULT_SDK_ICON ); // Icon filename (default=Open Reality icon)
/************************************************
* Creation
************************************************/
bool ORBoxSineRamp::FBCreate()
{
if( FBBox::FBCreate() )
{
// Input Nodes
mAmplitude = AnimationNodeInCreate ( 0, "Amplitude", ANIMATIONNODE_TYPE_NUMBER );
mFrequency = AnimationNodeInCreate ( 1, "Frequency", ANIMATIONNODE_TYPE_NUMBER );
mPhase = AnimationNodeInCreate ( 2, "Phase % ", ANIMATIONNODE_TYPE_NUMBER );
// Output Node
mResult = AnimationNodeOutCreate( 3, "Result", ANIMATIONNODE_TYPE_NUMBER );
return true;
}
return false;
}
/************************************************
* Destruction.
************************************************/
void ORBoxSineRamp::FBDestroy()
{
FBBox::FBDestroy();
}
/************************************************
* Real-time engine evaluation
************************************************/
bool ORBoxSineRamp::AnimationNodeNotify( FBAnimationNode* pAnimationNode, FBEvaluateInfo* pEvaluateInfo )
{
double lA, lF, lP, lR;
double lTime, lPhase;
bool lStatus[4];
FBTime lEvaluationTime;
// Read connector in values
lStatus[0] = mAmplitude ->ReadData( &lA, pEvaluateInfo );
lStatus[1] = mFrequency ->ReadData( &lF, pEvaluateInfo );
lStatus[2] = mPhase ->ReadData( &lP, pEvaluateInfo );
// Set default values if no input connection.
if( lStatus[0] == false )
{
lA = 10.0;
}
if( lStatus[1] == false )
{
lF = 10.0;
}
if( lStatus[2] == false )
{
lP = 0.0;
}
// Get the current evaluation time, indicating if recording.
if( pEvaluateInfo->IsStop() )
{
lEvaluationTime = pEvaluateInfo->GetSystemTime();
}
else
{
lEvaluationTime = pEvaluateInfo->GetLocalTime();
}
// Calculate result.
lPhase = lP * 2 * M_PI;
lTime = lEvaluationTime.GetSecondDouble();
lR = lA*sin( lF*lTime + lPhase );
// Write result out to connector.
mResult->WriteData( &lR, pEvaluateInfo );
return true;
}
/************************************************
* FBX Storage.
************************************************/
bool ORBoxSineRamp::FbxStore( FBFbxObject* pFbxObject, kFbxObjectStore pStoreWhat )
{
return true;
}
/************************************************
* FBX Retrieval.
************************************************/
bool ORBoxSineRamp::FbxRetrieve( FBFbxObject* pFbxObject, kFbxObjectStore pStoreWhat )
{
return true;
}