[Gcblue-commits] gcb_wx/src/graphics ObjectUpdater.cpp,1.4,1.5 tc3DModel.cpp,1.2,1.3
Status: Alpha
Brought to you by:
ddcforge
From: <ddc...@us...> - 2004-01-16 00:04:17
|
Update of /cvsroot/gcblue/gcb_wx/src/graphics In directory sc8-pr-cvs1:/tmp/cvs-serv26093/src/graphics Modified Files: ObjectUpdater.cpp tc3DModel.cpp Log Message: animation Index: ObjectUpdater.cpp =================================================================== RCS file: /cvsroot/gcblue/gcb_wx/src/graphics/ObjectUpdater.cpp,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** ObjectUpdater.cpp 14 Jan 2004 01:13:22 -0000 1.4 --- ObjectUpdater.cpp 16 Jan 2004 00:04:14 -0000 1.5 *************** *** 38,44 **** for(size_t n=0;n<nAnimations;n++) { ! osg::MatrixTransform *xform = model->animationInfo[n].transform; ! osg::Matrix matrix = xform->getMatrix(); ! xform->setMatrix(matrix * matrix.rotate(0.5f, model->animationInfo[n].axis)); } } --- 38,50 ---- for(size_t n=0;n<nAnimations;n++) { ! tcAnimationInfo& info = model->animationInfo[n]; ! int isActive = (info.switchVariable) ? *info.switchVariable : true; ! if (isActive) ! { ! osg::MatrixTransform *xform = info.transform; ! osg::Matrix matrix = xform->getMatrix(); ! double angle = info.omega * viewer->GetGameTime(); ! xform->setMatrix(matrix.rotate(angle , info.axis)); ! } } } Index: tc3DModel.cpp =================================================================== RCS file: /cvsroot/gcblue/gcb_wx/src/graphics/tc3DModel.cpp,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** tc3DModel.cpp 14 Jan 2004 01:13:22 -0000 1.2 --- tc3DModel.cpp 16 Jan 2004 00:04:14 -0000 1.3 *************** *** 30,33 **** --- 30,34 ---- #include "tc3DModel.h" #include "tcGameObject.h" + #include "tcPlatformObject.h" #include "ObjectUpdater.h" #include "tcGenericDBObject.h" *************** *** 41,45 **** #endif ! // started with CSP AnimationProcessor class /** * A visitor for model prototypes to attach animation --- 42,46 ---- #endif ! // started with CSP ModelProcessor class /** * A visitor for model prototypes to attach animation *************** *** 55,73 **** std::vector<tcAnimationInfo>& animationInfo; // vector of animation state info to update std::vector<animationDBInfo>& databaseInfo; ///< database info to find and configure animations - //simdata::Link<Animation>::vector const *m_Animations; public: - //AnimationProcessor(): NodeVisitor(TRAVERSE_ALL_CHILDREN), m_Animations(0) { } AnimationProcessor(std::vector<tcAnimationInfo>& ai, std::vector<animationDBInfo>& adb) : NodeVisitor(TRAVERSE_ALL_CHILDREN) , animationInfo(ai), databaseInfo(adb) { } ! /* ! virtual void apply(osg::Transform &node) ! { ! std::string name = node.getName(); ! std::cout << "MODEL TRANSFORM: " << name << "\n"; ! traverse(node); ! } ! */ virtual void apply(osg::Node &node) { --- 56,65 ---- std::vector<tcAnimationInfo>& animationInfo; // vector of animation state info to update std::vector<animationDBInfo>& databaseInfo; ///< database info to find and configure animations public: AnimationProcessor(std::vector<tcAnimationInfo>& ai, std::vector<animationDBInfo>& adb) : NodeVisitor(TRAVERSE_ALL_CHILDREN) , animationInfo(ai), databaseInfo(adb) { } ! virtual void apply(osg::Node &node) { *************** *** 118,126 **** tcAnimationInfo ai; ! ai.axis = (info.animationType == "propeller") ? ! osg::Vec3(0,1.0f,0) : osg::Vec3(0,0,1.0f); ! ai.omega = 1; ai.switchVariable = NULL; ai.transform = rotateTransform; animationInfo.push_back(ai); std::cout << "added animation info for: " << name <<"\n"; --- 110,129 ---- tcAnimationInfo ai; ! if (info.animationType == "propeller") ! { ! ai.axis = osg::Vec3(0,1.0f,0); ! ai.animationType = 0; ! ai.omega = 10.0f; ! } ! else ! { ! ai.axis = osg::Vec3(0,0,1.0f); ! ai.animationType = 1; ! ai.omega = 0.2f; ! ai.param = info.param; ! } ai.switchVariable = NULL; ai.transform = rotateTransform; + animationInfo.push_back(ai); std::cout << "added animation info for: " << name <<"\n"; *************** *** 137,142 **** }; /** ! * Custom copy op for cloning models with animation */ class ModelCopyOp : public osg::CopyOp --- 140,146 ---- }; + // TODO Move this to its own file /** ! * Custom copy op for cloning models with animation. */ class ModelCopyOp : public osg::CopyOp *************** *** 271,275 **** --- 275,318 ---- /** + * Called once per instance with animations to bind + * animation variables. + * SetupUpdate must be called first to attach game object + */ + void tc3DModel::SetupAnimation(tcGameObject *obj) + { + wxASSERT(obj); + size_t nAnimations = animationInfo.size(); + for(size_t n=0;n<nAnimations;n++) + { + tcAnimationInfo& info = animationInfo[n]; + info.switchVariable = NULL; + if (info.animationType == 0) // propeller + { + } + else if (info.animationType == 1) // sensor + { + if (tcPlatformObject *plat = dynamic_cast<tcPlatformObject*>(obj)) + { + if (info.param >= (int)plat->mapSensorState.size()) + { + std::cerr << "sensor animation param out of range\n"; + wxASSERT(0); + return; + } + info.switchVariable = &plat->mapSensorState[info.param]->mbActive; + float tscan = plat->mapSensorState[info.param]->mfCurrentScanPeriod_s; + info.omega = (tscan) ? C_TWOPI/tscan : 0; + } + } + else + { + wxASSERT(0); + } + } + } + + /** * Called once per instance to set and configure update callback. + * Bind switchVariable for animations */ void tc3DModel::SetupUpdate(tcGameObject *obj) |