An example of querying/modifying animations(osg::sequence) of an DtOsgArticulatedModel.
Each 'entity' is our numbered grid model (a row with 7 boxes): -The row has 7 boxes, each of which have a different type of animation. Starting animations in the model starting from Large box on the far left are as follows:
Each box's animation is basically a numbered sequence with the textures indicating the 'frame number'
Pressing key '1' tests DtOsgArticulatedModel::setAnimationFrame and DtOsgArticulatedModel::setAnimationSpeed methods using row 1 (the top row). The first time key '1' is pressed, all the boxes in the top row will be reset to frame 0 and the animation speed will be set to 0.5 fps (every 2 seconds). The second time it is pressed, the animations will be set to frame 5 and the animation speed set to 1.0 fps. All subsequent presses of the '1' key will set the animations to frame 10 and the animation speed to 5.0 fps.
Pressing key '2' tests DtOsgArticulatedModel::setAnimationRange() methods using row 2. The first time key '2' is pressed, the animation range is set to be from frame 0 to frame 9 (1-10). The second time it is pressed the range is set from frame 4 to frame 7 (5-8). The third time it is pressed the range is from from frame 1 to frame 3 (2-4). On the fourth key press the range is set from frame 4 to frame 4 (5 only). Subsequent presses have no effect.
Pressing key '3' tests DtOsgArticulatedModel::setAnimationState methods using row 3. The first, third, fifth, etc. presses of key '3' will pause the first four boxes and stop the last three. The second, fourth, sixth, etc. key press resumes the first four boxes and restarts the last three.
Pressing key '4' tests DtOsgArticulatedModel::animationCurrentFrame methods using row 4. This test reports the animation frame for each box in row 4 (to the console window).
Pressing key 5 will test any random code you wish to add for row 5. The example also outputs the animations it found in the articulated model with their initial values. Please see the comments in the code as well since it describes what is being queried/set, etc.
This example is an application. You can run it by running ./bin64/exampleSequenceControl.exe (on Windows) or ./bin64/exampleSequenceControl (on Linux). For more information about running examples, please see Running Applications and Examples.
#include <matrix/vlTaitBryan.h>
#include <matrix/vlVector.h>
#include <string>
#include <cmath>
#include <array>
class MyArticulationDriver :
public DtDriver
{
public:
MyArticulationDriver(
DtDe& de ) :
DtDriver( de.agentManager(),
"MyArticulationDriver" )
, myModelDefinition( "testModel" )
, mySceneObjectsAndModels()
{
const std::string modelFilePath( "../examples/exampleSequenceControl/media/FlipBookTest.flt" );
myModelDefinition.setParameter( "filename", modelFilePath );
resetCounts();
}
virtual void destroyObjects()
{
for( auto& val : mySceneObjectsAndModels )
{
if( sceneObject && model )
{
}
delete model;
model = 0;
delete sceneObject;
sceneObject = 0;
}
}
virtual ~MyArticulationDriver()
{
destroyObjects();
}
virtual bool onStart()
{
for( int i = 0; i < mySceneObjectsAndModels.size(); ++i )
{
DtArticulatedModelAgent* model = DtArticulatedModelAgent::create( myAgentManager );
DtSceneObjectAgent* sceneObject = DtSceneObjectAgent::create( myAgentManager );
mySceneObjectsAndModels[i] = std::make_pair( sceneObject, model );
}
const float xPos = 0.0f;
const float yPos = 25.0f;
const float zDecrement = 3;
float posZ = 5.4;
DtTaitBryan taitBryan;
taitBryan.setPsi( -10.554191782826420 );
static const int partId = 4096;
for( int i = 0; i < mySceneObjectsAndModels.size(); ++i )
{
mySceneObjectsAndModels[i].first->setPosition( 0, DtVector( xPos, yPos, posZ ) );
mySceneObjectsAndModels[i].second->setPartOrientation( partId, taitBryan, DtVector(), DtArticulatedModel::PartUpdateTypeManual );
posZ -= zDecrement;
}
return true;
}
virtual bool onStop()
{
destroyObjects();
return true;
}
static std::string toString( const DtArticulatedModel::AnimationState state )
{
if( state == DtArticulatedModel::START )
{
return "START";
}
if( state == DtArticulatedModel::STOP )
{
return "STOP";
}
if( state == DtArticulatedModel::PAUSE )
{
return "PAUSE";
}
if( state == DtArticulatedModel::RESUME )
{
return "RESUME";
}
return "UNKNOWN!!";
}
virtual bool onTick()
{
static bool once = false;
if( once )
{
return true;
}
DtArticulatedModelAgent* model = mySceneObjectsAndModels[0].second;
{
DtOsgArticulatedModel* articulatedModel =
dynamic_cast<DtOsgArticulatedModel*
>(model->
findObject());
const DtArticulatedModelParser::AnimationMap& animations = articulatedModel->
animations();
for( auto it = animations.begin(); it != animations.end(); ++it )
{
std::cout << "animation: " << it->first << ":" << std::endl;
const std::string& animationName = it->first;
std::cout <<
" animationFrameCount: " << articulatedModel->
animationFrameCount( animationName ) << std::endl;
std::cout <<
" animationFirstFrame: " << articulatedModel->
animationFirstFrame( animationName ) << std::endl;
std::cout <<
" animationLastFrame: " << articulatedModel->
animationLastFrame( animationName ) << std::endl;
std::cout <<
" animationSpeed: " << articulatedModel->
animationSpeed( animationName ) << std::endl;
std::cout <<
" animationState: " << toString( articulatedModel->
animationState( animationName ) ) << std::endl;
std::cout <<
" animationLastFrameTime: " << articulatedModel->
animationLastFrameTime( animationName ) << std::endl;
std::cout <<
" animationLoopCount: " << articulatedModel->
animationLoopCount( animationName ) << std::endl;
std::cout << " ------------------" << std::endl;
std::cout << std::endl;
myAnimationNames.insert( animationName );
once = true;
}
}
return true;
}
void setAnimationSpeedAndAnimationFrameTest( void )
{
if( myAnimationNames.empty() )
{
return;
}
DtOsgArticulatedModel* articulatedModel = findOsgArticulatedModel( 0 );
if( articulatedModel == nullptr )
{
return;
}
std::cout << "row 1: " << std::endl;
if( mySpeedAndAnimationFrameTestCount == 0 )
{
std::cout << "reset to 0th frame (entity 0)" << std::endl;
std::cout << "reset to 0.5 fps (entity 0)" << std::endl;
std::cout << std::endl;
for( auto it = myAnimationNames.begin(); it != myAnimationNames.end(); ++it )
{
}
}
else if( mySpeedAndAnimationFrameTestCount == 1 )
{
std::cout << "reset to 5th frame (entity 0)" << std::endl;
std::cout << "reset to 1 fps (entity 0)" << std::endl;
std::cout << std::endl;
for( auto it = myAnimationNames.begin(); it != myAnimationNames.end(); ++it )
{
}
}
else
{
std::cout << "reset to 10th frame (entity 0)" << std::endl;
std::cout << "reset to 5 fps (entity 0)" << std::endl;
std::cout << std::endl;
for( auto it = myAnimationNames.begin(); it != myAnimationNames.end(); ++it )
{
}
}
++mySpeedAndAnimationFrameTestCount;
}
void setAnimationRangeTest( void )
{
if( myAnimationNames.empty() )
{
return;
}
DtOsgArticulatedModel* articulatedModel = findOsgArticulatedModel( 1 );
if( articulatedModel == nullptr )
{
return;
}
std::cout << "row 2: " << std::endl;
if( myAnimationRangeTestCount == 0 )
{
std::cout << "reset animation range [1-10] (entity 1)" << std::endl;
std::cout << std::endl;
for( auto it = myAnimationNames.begin(); it != myAnimationNames.end(); ++it )
{
}
}
else if( myAnimationRangeTestCount == 1 )
{
std::cout << "reset animation range [5-8] (entity 1)" << std::endl;
std::cout << std::endl;
for( auto it = myAnimationNames.begin(); it != myAnimationNames.end(); ++it )
{
}
}
else if( myAnimationRangeTestCount == 2 )
{
std::cout << "reset animation range [2-4] (entity 1)" << std::endl;
std::cout << std::endl;
for( auto it = myAnimationNames.begin(); it != myAnimationNames.end(); ++it )
{
}
}
else if( myAnimationRangeTestCount == 3 )
{
std::cout << "reset animation range [5-5] (entity 1)" << std::endl;
std::cout << std::endl;
for( auto it = myAnimationNames.begin(); it != myAnimationNames.end(); ++it )
{
}
}
++myAnimationRangeTestCount;
}
void setAnimationStateTest( void )
{
if( myAnimationNames.empty() )
{
return;
}
DtOsgArticulatedModel* articulatedModel = findOsgArticulatedModel( 2 );
if( articulatedModel == nullptr )
{
return;
}
std::cout << "row 3: " << std::endl;
if( myAnimationStateTestCount % 2 == 0 )
{
std::cout << "Pause first 4" << std::endl;
std::cout << "Stop last 3" << std::endl;
std::cout << std::endl;
}
if( myAnimationStateTestCount % 2 == 1 )
{
std::cout << "Resume first 4" << std::endl;
std::cout << "Start last 3 again" << std::endl;
std::cout << std::endl;
}
++myAnimationStateTestCount;
}
void queryAnimationCurrentFrameTest( void )
{
if( myAnimationNames.empty() )
{
return;
}
DtOsgArticulatedModel* articulatedModel = findOsgArticulatedModel( 3 );
if( articulatedModel == nullptr )
{
return;
}
int i = 0;
std::cout << "row 4: " << std::endl;
std::cout << "current frame (left to right): " << std::endl;
std::cout <<
"\t box[" << i++ <<
"]: " << articulatedModel->
animationCurrentFrame(
"Slow" ) << std::endl;
std::cout <<
"\t box[" << i++ <<
"]: " << articulatedModel->
animationCurrentFrame(
"Fast" ) << std::endl;
std::cout <<
"\t box[" << i++ <<
"]: " << articulatedModel->
animationCurrentFrame(
"VeryFast" ) << std::endl;
std::cout <<
"\t box[" << i++ <<
"]: " << articulatedModel->
animationCurrentFrame(
"OneLoop" ) << std::endl;
std::cout <<
"\t box[" << i++ <<
"]: " << articulatedModel->
animationCurrentFrame(
"Swing" ) << std::endl;
std::cout <<
"\t box[" << i++ <<
"]: " << articulatedModel->
animationCurrentFrame(
"Backwards" ) << std::endl;
std::cout <<
"\t box[" << i++ <<
"]: " << articulatedModel->
animationCurrentFrame(
"LastFrame" ) << std::endl;
}
void testOtherThings( void )
{
if( myAnimationNames.empty() )
{
return;
}
std::cout << "row 5: " << std::endl;
DtOsgArticulatedModel* articulatedModel = findOsgArticulatedModel( 4 );
if( articulatedModel == nullptr )
{
return;
}
if( myTestOtherStuffCount == 0 )
{
std::cout << "setting animation loop count to 5" << std::endl;
for( auto it = myAnimationNames.begin(); it != myAnimationNames.end(); ++it )
{
}
}
else if( myTestOtherStuffCount == 1 )
{
}
++myTestOtherStuffCount;
}
void resetCounts()
{
mySpeedAndAnimationFrameTestCount = 0;
myAnimationRangeTestCount = 0;
myAnimationStateTestCount = 0;
myTestOtherStuffCount = 0;
}
virtual const std::string& className() const
{
static const std::string name( "MyArticulationDriver" );
return name;
}
DtOsgArticulatedModel* findOsgArticulatedModel( int index )
{
if( index >= mySceneObjectsAndModels.size() )
{
return nullptr;
}
DtArticulatedModelAgent* articulatedModelAgent = mySceneObjectsAndModels[index].second;
if( articulatedModelAgent == nullptr )
{
return nullptr;
}
DtOsgArticulatedModel* articulatedModel =
dynamic_cast<DtOsgArticulatedModel*
>(articulatedModelAgent->
findObject());
return articulatedModel;
}
protected:
std::set<std::string> myAnimationNames;
static const int numEntities = 5;
std::array< std::pair<DtSceneObjectAgent*, DtArticulatedModelAgent*>, numEntities> mySceneObjectsAndModels;
DtModelDefinition myModelDefinition;
int mySpeedAndAnimationFrameTestCount;
int myAnimationRangeTestCount;
int myAnimationStateTestCount;
int myTestOtherStuffCount;
};
int main( int argc, char** argv )
{
MyArticulationDriver* driver =
new MyArticulationDriver( igApp.
de() );
keyMapManager.
addKeyFunction(
"setAnimationSpeedAndAnimationFrameTest", boost::bind(
keyMapManager.
addKeyFunction(
"queryAnimationCurrentFrameTest", boost::bind(
if( obsFrame )
{
}
return 0;
}
Contains makVrv:DtAgentManager class.
Contains makVrv::DtArticulatedModelParser class.
Contains makVrv::DtDe class.
Contains makVrv::DtDeSharedState class.
Contains makVrv:DtDriver class.
Contains makVrv:DtMasterScene class.
Contains makVrv::DtKeyMapManager class.
Interaction makVrv::DtModelDefinition class.
Contains vrvCore::DtObserverMode class.
Contains the makVrv::DtOsgArticulatedModel class declaration.
Contains makVrv::DtOsgEmptySceneLogo class.
Contains DtVantageIgCommandLineProcessor class.
Contains makVrv::DtVrvApplication implementation.
Agent class for the scene object class: DtArticulatedModel.
Definition DtArticulatedModelAgent.hpp:30
DtArticulatedModel * findObject()
Attempt to find the actual object the agent is controlling. warning Any modifications to the actual o...
The DtDe is the core component of any VR-Vantage application. It owns a DtRenderer,...
Definition DtDe.h:77
virtual DtDriverManager & driverManager()
The DtMasterScene accessor. The function will throw before the initialize function is called.
virtual DtDeSharedState & sharedState()
Returns the DtDeSharedState object.
virtual void addModelDefinition(const DtModelDefinition &definition)
The DtDriver is an abstract class. Developers derive from this to create logic that "directs" things ...
Definition DtDriver.h:32
void addDriver(DtDriver *driver)
Add a host driver to the master scene. The host is now owned by the Master Scene.
DtInputDriver & inputDriver()
Return the DtInputDriver associated with the master scene.
void startDriver(DtDriver *driver)
Start a driver driver modifying the scene.
a Key Map contains a map of keys to FunctionMapEntrys, as well as a list of functions to execute when...
Definition DtKeyMap.h:313
The manager for owning key maps.
Definition DtKeyMapManager.h:32
@ Miscellaneous
Definition DtKeyMapManager.h:45
static DtKeyMapManager & instance(DtDe &de)
Get an instance of the key map.
virtual void addKeyFunction(const std::string &functionName, const KeyFunction &function, FunctionCategory functionCategory, bool categorize=true)
bind a function to string name that can be used in a key map (or binary function set)
virtual DtKeyMap * findKeyMap(const std::string &mapName)
look up a key map
@ KEY_3
Definition DtKeyState.h:49
@ KEY_4
Definition DtKeyState.h:50
@ KEY_2
Definition DtKeyState.h:48
@ KEY_5
Definition DtKeyState.h:51
@ KEY_1
Definition DtKeyState.h:47
virtual void setModelDefinition(const std::string &definitionName)=0
virtual void setAnimationState(const std::string &animationName, AnimationState mode) override
Set the animation mode.
virtual AnimationState animationState(const std::string &animationName) const
virtual void setAnimationSpeed(const std::string &animationName, double framesPerSecond) override
Set the animation speed.
virtual int animationLoopCount(const std::string &animationName) const
Get the animation loop count in an animation.
virtual void setAnimationFrame(const std::string &animationName, int frameIndex) override
Set the current frame of an animation.
virtual const DtArticulatedModelParser::AnimationMap & animations() const
Get a map of the current animations.
virtual int animationLastFrame(const std::string &animationName) const
virtual int animationFrameCount(const std::string &animationName) const
virtual double animationSpeed(const std::string &animationName) const
virtual double animationLastFrameTime(const std::string &animationName) const
virtual int animationCurrentFrame(const std::string &animationName) const
virtual int animationFirstFrame(const std::string &animationName) const
virtual void setAnimationRange(const std::string &animationName, int firstFrameIndex, int lastFrameIndex) override
Set the animation range.
virtual void setAnimationLoopCount(const std::string &animationName, int loopCount)
static void setEnabled(bool enabled)
This global method will enable or disable the use of an empty scene overlay for all uses of this clas...
Agent class for the scene object class: DtSceneObject.
Definition DtSceneObjectAgent.hpp:32
virtual void removeModel(makVrv::DtModelAgent *modelInstanceOwner)=0
virtual void setModelSet(makVrv::DtModelSetId modelSet)=0
Set the model set this object uses; ignored if isProp is true Make sure this is set BEFORE element ID...
virtual void addModel(makVrv::DtModelAgent *modelInstanceOwner, int visualizerType)=0
The MAK Vantage IG Application's command line processor.
Definition DtVantageIgCommandLineProcessor.h:22
The Root IG Application object. To run the IG simply create one, initialize it and call run.
Definition DtVrvApplication.h:58
DtDe & de()
DtDe accessor.
virtual void initialize()
Create the GUI, initialize the DtDe. Call before calling run(). Call preInitialize before this.
virtual void run()
Kick off the IG event loop. This function will block until the application is done running....
virtual void installCommandLineProcessor(DtVrvCommandLineProcessor *commandLineProcessor)
Add a configuration transformer that runs at command line processor level priority.
virtual void preInitialize(int argc, char **argv)
Pre-initialize Call before calling initialize().
Contains DtCreateSensorFieldOfViewCommand and DtCreateSensorFieldOfViewCommandCreator class declarati...
Definition DtGridLinesSettingsRecord.h:16