Difference between revisions of "Channel Mod Simple Kinematics"
(Created page with "Channel_Mod_Simple_Kinematics is a basic example plugin. This wiki page is intended as a walkthrough of the code in order to help you better understand the SDK. ==Functionali...") |
|||
Line 45: | Line 45: | ||
}; | }; | ||
− | To create an instance of the SimpleKinematics object we need to implement the | + | To create an instance of the SimpleKinematics object we need to implement the Simple Kinematics Package object so we inherit from [[Package_(lx-package.hpp)#Instance_Interface|CLxPackageInstance]]. We also need to modify channels as part of our instance, so we inherit from [[Chanmod_(lx-chanmod.hpp)#ILxChannelModItem_Interface|CLxImpl_ChannelModItem]]. |
class CSimpleKinematicsPackage : public CLxImpl_Package | class CSimpleKinematicsPackage : public CLxImpl_Package |
Revision as of 21:21, 9 September 2013
Channel_Mod_Simple_Kinematics is a basic example plugin. This wiki page is intended as a walkthrough of the code in order to help you better understand the SDK.
Contents
Functionality
This plugin adds the Simple Kinematics channel modifier
Code Walkthrough
Class Declarations
class CSimpleKinematicsLog : public CLxLuxologyLogMessage { public: CSimpleKinematicsLog () : CLxLuxologyLogMessage ("cmSimpleKinematics") { } const char * GetFormat () { return "Linear Blend Object"; } };
We want to have this class write out to the log, so we inherit from CLxLuxologyLogMessage.
class CSimpleKinematicsInstance : public CLxImpl_PackageInstance, public CLxImpl_ChannelModItem { CSimpleKinematicsLog log; public: CSimpleKinematicsPackage *src_pkg; CLxUser_Item m_item; ILxUnknownID inst_ifc; LxResult pins_Initialize (ILxUnknownID item, ILxUnknownID super); void pins_Cleanup (void); LxResult pins_SynthName (char *buf, unsigned len); unsigned int cmod_Flags (ILxUnknownID item, unsigned int index); LxResult cmod_Allocate ( ILxUnknownID cmod, ILxUnknownID eval, ILxUnknownID item, void **ppvData); void cmod_Cleanup (void *data); LxResult cmod_Evaluate (ILxUnknownID cmod, ILxUnknownID attr, void *data); };
To create an instance of the SimpleKinematics object we need to implement the Simple Kinematics Package object so we inherit from CLxPackageInstance. We also need to modify channels as part of our instance, so we inherit from CLxImpl_ChannelModItem.
class CSimpleKinematicsPackage : public CLxImpl_Package { public: static LXtTagInfoDesc descInfo[]; CLxPolymorph<CSimpleKinematicsInstance> chanmod_factory; CSimpleKinematicsPackage (); LxResult pkg_SetupChannels (ILxUnknownID addChan); LxResult pkg_TestInterface (const LXtGUID *guid); LxResult pkg_Attach (void **ppvObj); };
To set up our object we need a package, so we have this class inherit from CLxImpl_Package.
Server Tags
LXtTagInfoDesc CSimpleKinematicsPackage::descInfo[] = { { LXsPKG_SUPERTYPE, "chanModify" }, { LXsSRV_LOGSUBSYSTEM, "cmSimpleKinematics" }, { 0 } };
The tags here indicate that the CSimpleKinematicsPackage class is dependent on the chanmodify SuperType with the internal name of cmSimpleKinematics.
Initialize
initialize () { CLxGenericPolymorph *srv; srv = new CLxPolymorph<CSimpleKinematicsPackage>; srv->AddInterface (new CLxIfc_Package <CSimpleKinematicsPackage>); srv->AddInterface (new CLxIfc_StaticDesc <CSimpleKinematicsPackage>); thisModule.AddServer ("cmSimpleKinematics", srv); }
Our initialize function indicates that we will be exporting one server dependent on the CSimpleKinematicsPackage class that uses the Package and StaticDesc interfaces as well as being names cmSimpleKinematics.
Implementations
LxResult CSimpleKinematicsInstance::cmod_Evaluate ( ILxUnknownID cmod, // ILxChannelModifierID ILxUnknownID attr, // ILxAttributesID void *data) { CLxLoc_ChannelModifier chanMod (cmod); double t0, v0, x0, a, t=1; // log.Info ("cmod_Evaluate Method"); chanMod.ReadInputFloat (attr, 0, &x0); chanMod.ReadInputFloat (attr, 1, &t0); chanMod.ReadInputFloat (attr, 2, &v0); chanMod.ReadInputFloat (attr, 3, &a); chanMod.ReadInputFloat (attr, 4, &t); if(t>=t0) { t -= t0; x0 += v0*t + 0.5*a*t*t; } chanMod.WriteOutputFloat (attr, 0, x0); return LXe_OK; }
This function evaluates the modifiers we have used on the given channels.
CSimpleKinematicsPackage::CSimpleKinematicsPackage () { chanmod_factory.AddInterface (new CLxIfc_PackageInstance<CSimpleKinematicsInstance>); chanmod_factory.AddInterface (new CLxIfc_ChannelModItem<CSimpleKinematicsInstance>); }
We create factories here to export CMathMultiInstance.