void pawsTreeStruct::MoveChild(const csString &name, const csString &nextSibling) { pawsTreeNode* node, * parentNode, * nextSiblingNode; node = FindNodeByName(name); if(node == NULL) return; nextSiblingNode = FindNodeByName(nextSibling); if(nextSiblingNode == NULL) return; parentNode = node->GetParent(); if(parentNode != NULL) parentNode->MoveChild(node, nextSiblingNode); }
Attribute *GetAttribute(Element *element, char *attName) { Attribute *ret = NULL; if (element != NULL && attName != NULL) { ret = FindNodeByName(element->children, NODE_TYPE_ATTRIBUTE, attName); } return ret; }
void pawsTreeStruct::InsertChild(const csString &parent, pawsTreeNode* node) { pawsTreeNode* parentNode; parentNode = FindNodeByName(parent); if(parentNode == NULL) return; parentNode->InsertChild(node, NULL); }
void pawsTreeStruct::DeleteChild(const csString &name) { pawsTreeNode* node, * parentNode; node = FindNodeByName(name); if(node == NULL) return; parentNode = node->GetParent(); if(parentNode != NULL) parentNode->DeleteChild(node); else Clear(); }
void pawsTreeStruct::InsertChild(const csString &parent, pawsTreeNode* node, const csString &nextSibling) { pawsTreeNode* parentNode, * nextSiblingNode; parentNode = FindNodeByName(parent); // Allows a root to be added automatically. if(!parentNode) { if(!root) { SetRoot(node); node->SetTree(this); return; } else { parentNode = root; } } nextSiblingNode = FindNodeByName(nextSibling); parentNode->InsertChild(node, nextSiblingNode); }
int _tmain(int argc, _TCHAR* argv[]) { // construct the viewer osg::ref_ptr<osgViewer::Viewer> rViewer = new osgViewer::Viewer; // make the viewer create a 512x512 window and position it at 32, 32 rViewer->setUpViewInWindow( 32, 32, 512, 512 ); // create scene osg::Node* pScene = CreateScene(); osg::MatrixTransform* p = dynamic_cast<osg::MatrixTransform*>(FindNodeByName( pScene, "box1" )); p->setUpdateCallback( new osg::AnimationPathCallback(osg::Vec3(0, 0, 0), osg::Z_AXIS, osg::inDegrees(45.0f)) ); // set the scene-graph data the viewer will render rViewer->setSceneData( pScene ); // execute main loop return rViewer->run(); }
void SetAttribute(Element *element, Attribute *attr) { if (element != NULL && attr != NULL) { // Check attribute is exists? Attribute *tmp = FindNodeByName(element->children, NODE_TYPE_ATTRIBUTE, attr->nodeName); if (tmp != NULL) { // Set exists attribute by attribute's name tmp->nodeValue = attr->nodeValue; }else{ // set new attribute Node *last = FindLastChild(element); if (last == NULL) { element->children = attr; } else { last->nextSub = attr; attr->prevSub = last; } } } }
osg::Node* FindNodeByName( osg::Node* pNode, const std::string& sName ) { if ( pNode->getName()==sName ) { return pNode; } osg::Group* pGroup = pNode->asGroup(); if ( pGroup ) { for ( unsigned int i=0; i<pGroup->getNumChildren(); i++ ) { osg::Node* pFound = FindNodeByName( pGroup->getChild(i), sName ); if ( pFound ) { return pFound; } } } return 0; }
yyparse() { short yys[YYMAXDEPTH]; short yyj, yym; register YYSTYPE *yypvt; register short yystate, *yyps, yyn; register YYSTYPE *yypv; register short *yyxi; yystate = 0; yychar = -1; yynerrs = 0; yyerrflag = 0; yyps= &yys[-1]; yypv= &yyv[-1]; yystack: /* put a state and value onto the stack */ #ifdef YYDEBUG if( yydebug ) printf( "state %d, char 0%o\n", yystate, yychar ); #endif if( ++yyps>= &yys[YYMAXDEPTH] ) { yyerror( "yacc stack overflow" ); YYABORT; } *yyps = yystate; ++yypv; #ifdef UNION yyunion(yypv, &yyval); #else *yypv = yyval; #endif yynewstate: yyn = yypact[yystate]; if( yyn<= YYFLAG ) goto yydefault; /* simple state */ if( yychar<0 ) if( (yychar=yylex())<0 ) yychar=0; if( (yyn += yychar)<0 || yyn >= YYLAST ) goto yydefault; if( yychk[ yyn=yyact[ yyn ] ] == yychar ){ /* valid shift */ yychar = -1; #ifdef UNION yyunion(&yyval, &yylval); #else yyval = yylval; #endif yystate = yyn; if( yyerrflag > 0 ) --yyerrflag; goto yystack; } yydefault: /* default state action */ if( (yyn=yydef[yystate]) == -2 ) { if( yychar<0 ) if( (yychar=yylex())<0 ) yychar = 0; /* look through exception table */ for( yyxi=yyexca; (*yyxi!= (-1)) || (yyxi[1]!=yystate) ; yyxi += 2 ) ; /* VOID */ for(yyxi+=2; *yyxi >= 0; yyxi+=2) { if( *yyxi == yychar ) break; } if( (yyn = yyxi[1]) < 0 ) return(0); /* accept */ } if( yyn == 0 ){ /* error */ /* error ... attempt to resume parsing */ switch( yyerrflag ){ case 0: /* brand new error */ yyerror( "syntax error" ); // yyerrlab: //Comented out to shut up compiler since this is never referred to ++yynerrs; case 1: case 2: /* incompletely recovered error ... try again */ yyerrflag = 3; /* find a state where "error" is a legal shift action */ while ( yyps >= yys ) { yyn = yypact[*yyps] + YYERRCODE; if( yyn>= 0 && yyn < YYLAST && yychk[yyact[yyn]] == YYERRCODE ){ yystate = yyact[yyn]; /* simulate a shift of "error" */ goto yystack; } yyn = yypact[*yyps]; /* the current yyps has no shift onn "error", pop stack */ #ifdef YYDEBUG if( yydebug ) printf( "error recovery pops state %d, uncovers %d\n", *yyps, yyps[-1] ); #endif --yyps; --yypv; } /* there is no state on the stack with an error shift ... abort */ yyabort: YYABORT; case 3: /* no shift yet; clobber input char */ #ifdef YYDEBUG if( yydebug ) printf( "error recovery discards char %d\n", yychar ); #endif if( yychar == 0 ) goto yyabort; /* don't discard EOF, quit */ yychar = -1; goto yynewstate; /* try again in the same state */ } } /* reduction by production yyn */ #ifdef YYDEBUG if( yydebug ) printf("reduce %d\n",yyn); #endif yyps -= yyr2[yyn]; yypvt = yypv; yypv -= yyr2[yyn]; #ifdef UNION yyunion(&yyval, &yypv[1]); #else yyval = yypv[1]; #endif yym=yyn; /* consult goto table to find next state */ yyn = yyr1[yyn]; yyj = yypgo[yyn] + *yyps + 1; if( yyj>=YYLAST || yychk[ yystate = yyact[yyj] ] != -yyn ) yystate = yyact[yypgo[yyn]]; switch(yym){ case 1: //! # line 136 "mibyacc.Y" { if (0 != nNumberOfErrors) return 1; } break; case 7: //! # line 153 "mibyacc.Y" { if (warning_level(2)) fprintf (error_out, "(i%) : warning : optional module object identifier is ignored.", lineno); } break; case 43: //! # line 218 "mibyacc.Y" { lpCurrentNode = lpMIBRoot; } break; case 44: //! # line 220 "mibyacc.Y" { InsertChildNode (lpCurrentNode, NewChildNode (yypvt[-8].strval, (UINT) yypvt[-1].numval)); fYYErrorStopReturn(1); } break; case 45: //! # line 234 "mibyacc.Y" { lpCurrentNode = lpMIBRoot; } break; case 46: //! # line 236 "mibyacc.Y" { InsertChildNode (lpCurrentNode, NewChildNode (yypvt[-17].strval, (UINT) yypvt[-1].numval)); fYYErrorStopReturn(1); } break; case 146: //! # line 442 "mibyacc.Y" { lpCurrentNode = FindNodeByName (lpCurrentNode, yypvt[-0].strval); if (NULL == lpCurrentNode) { fprintf (error_out, "error: sub-identifier '%s' not found in tree. ", yypvt[-0].strval); yyerror ("Unknown sub-identifier"); fYYErrorStopReturn(1); } } break; case 147: //! # line 451 "mibyacc.Y" { lpCurrentNode = FindNodeAddToTree (lpCurrentNode, yypvt[-3].strval, (UINT) yypvt[-1].numval); if (NULL == lpCurrentNode) { fprintf (error_out, "error: sub-identifier '%s(%i)' not found in tree. ", yypvt[-3].strval, yypvt[-1].numval); yyerror ("Unknown sub-identifier"); fYYErrorStopReturn(1); } } break; case 148: //! # line 460 "mibyacc.Y" { lpCurrentNode = FindNodeByNumber (lpCurrentNode, (UINT) yypvt[-0].numval); if (NULL == lpCurrentNode) { fprintf (error_out, "error: sub-identifier '%s' not found in tree. ", yypvt[-0].numval); yyerror ("Unknown sub-identifier"); fYYErrorStopReturn(1); } } break; case 149: //! # line 469 "mibyacc.Y" { lpCurrentNode = FindNodeByName (lpCurrentNode, yypvt[-0].strval); if (NULL == lpCurrentNode) { fprintf (error_out, "error: sub-identifier '%s' not found in tree. ", yypvt[-0].strval); yyerror ("Unknown sub-identifier"); fYYErrorStopReturn(1); } } break; case 150: //! # line 478 "mibyacc.Y" { lpCurrentNode = FindNodeAddToTree (lpCurrentNode, yypvt[-3].strval, (UINT) yypvt[-1].numval); if (NULL == lpCurrentNode) { fprintf (error_out, "error: sub-identifier '%s(%i)' not found in tree. ", yypvt[-3].strval, yypvt[-1].numval); yyerror ("Unknown sub-identifier"); fYYErrorStopReturn(1); } } break; case 151: //! # line 487 "mibyacc.Y" { lpCurrentNode = FindNodeByNumber (lpCurrentNode, (UINT) yypvt[-0].numval); if (NULL == lpCurrentNode) { fprintf (error_out, "error: sub-identifier '%s' not found in tree. ", yypvt[-0].numval); yyerror ("Unknown sub-identifier"); fYYErrorStopReturn(1); } } break;/* End of actions */ } goto yystack; /* stack new state and value */ }
void Model::LoadNodeKeyframes(const aiScene* assimpScene) { // Get the number of animations. const unsigned int numAnimations = assimpScene->mNumAnimations; // Only proceed if there is an animation to load. if (numAnimations > 0) { // Check whether we will be ignoring any animations. // Only the first animation will be loaded. All other animations // will be ignored. // // TODO: Support multiple animations. if (numAnimations > 1) { std::cout << "WARNING: The model \"" << m_name << "\" contains multiple animations. " << "Only the first animation will be loaded." << std::endl; } // Get the first animation. const aiAnimation* assimpAnimation = assimpScene->mAnimations[0]; assert(assimpAnimation); // Get the animation speed. const double speedInTicksPerSecond = assimpAnimation->mTicksPerSecond; // Record the animation duration. m_animationDuration = assimpAnimation->mDuration; // Get the number of ASSIMP animation channels. // Each animation channel describes the movement of a single node // over time. const unsigned int numAnimationChannels = assimpAnimation->mNumChannels; // For each ASSIMP animation channel... for (unsigned int c = 0; c < numAnimationChannels; ++c) { // Get the ASSIMP channel. const aiNodeAnim* channel = assimpAnimation->mChannels[c]; // Get the ASSIMP node that the channel affects. const aiNode* targetNode = assimpScene->mRootNode->FindNode(channel->mNodeName); // Get the name for the node. const std::string targetNodeName(targetNode->mName.data); // Get the number of individual keyframes for the node. const unsigned int numPositionKeys = channel->mNumPositionKeys; // Determine the keyframe times in "ticks" for the node. // We will need to convert these times to seconds later by using // the animation speed provided by ASSIMP. std::set<double> keyframeTimes; for (unsigned int k = 0; k < numPositionKeys; ++k) { keyframeTimes.insert(channel->mPositionKeys[k].mTime); // TODO: Check whether it is necessary to insert the // keyframe times for other keys (rotation and scale). } // For each keyframe time... for (auto iter = keyframeTimes.begin(); iter != keyframeTimes.end(); ++iter) { // Get the keyframe time (in ticks). const double keyframeTimeInTicks = *iter; // Find our corresponding node. std::shared_ptr<Node> node = FindNodeByName(targetNodeName); // Get the local position for the node at the keyframe time. const glm::vec3 keyframePosition = DetermineNodeLocalPositionAtTime(channel, keyframeTimeInTicks); // Get the local rotation for the node at the keyframe time. const glm::quat keyframeRotation = DetermineNodeLocalRotationAtTime(channel, keyframeTimeInTicks); // Get the local scale for the node at the keyframe time. const glm::vec3 keyframeScale = DetermineNodeLocalScaleAtTime(channel, keyframeTimeInTicks); // Build the local transformation matrix for the node. const glm::mat4 localTransformationMatrix = glm::translate(keyframePosition) * glm::toMat4(keyframeRotation) * glm::scale(keyframeScale); // Create our new keyframe. std::shared_ptr<Node::Keyframe> keyframe = std::make_shared<Node::Keyframe>( keyframeTimeInTicks / speedInTicksPerSecond, // Convert ticks to seconds here! localTransformationMatrix ); // Add the keyframe to the node. node->AddKeyframe(keyframe); } } } }