📄 scenecomponents.cpp
字号:
index1 = child.rfind( "/" ); if( index1 == child.npos || index1 == 0 ) { cerr << "TSceneJoint::parseAttach: Could not get child name (1): index1 = " << index1 << endl; return false; } index2 = child.rfind( "/", index1 - 1 ); if( index2 == child.npos ) index2 = 0; child = child.substr( index2 + 1, index1 - index2 - 1 ); /// Get into action if( self == ".." && child == ".." ) { cerr << "TSceneJoint::parseAttach: Child is the node itslef; could not continue" << endl; return false; } if( self == ".." ) setParrent( parrent ); else for( index = 0; index < list.size(); index++ ) if( list[index]->getName() == self ) { setParrent( list[index] ); break; } if( getParrent() == NULL ) { cerr << "TSceneJoint::parseAttach: Could not get any parrent with name: '" << self << "'" << endl; return false; } if( child == ".." ) setChild( parrent ); else for( index = 0; index < list.size(); index++ ) if( list[index]->getName() == child ) { setChild( list[index] ); break; } if( getChild() == NULL ) { cerr << "TSceneJoint::parseAttach: Could not get any child with name: '" << child << "'" << endl; return false; } return true;}/** * This method parses an anchor for joints. An anchor is the point that actually two * objects stick together in and move around that area * @param str String that contains the anchor value * @return Indicates that the anchor was parsed successfully */bool TSceneJoint::parseAnchor( string & str ){ unsigned index = 0; if( str.compare( 0, CMD_ANCHOR.length(), CMD_ANCHOR ) != 0 ) { cerr << "TSceneJoint::parseAnchor: This is not a setAnchor command" << endl; return false; } index = CMD_ANCHOR.length(); VecPosition pos; if( (pos = TSceneNode::parsePositions( str, index ) ) == UnknownPosition ) return false; setAnchor( pos ); return true;}/** * This method parses axis information for joints, axis is the line that joint makes * the nodes rotate along * @param str String that contains axis information * @param joint joint instance to copy data to * @return Indicates that parse was successfull */bool TSceneJoint::parseAxis( string & str ){ if( str.compare( 0, 8, "(setAxis" ) != 0 ) { cerr << "TSceneJoint::parseAxis: This is not a setAxis command" << endl; return false; } unsigned index_start = 9; int motor = 1; if( str.compare( 0, 9, "(setAxis2" ) == 0 ) motor = 2; else if( str.compare( 0, 9, "(setAxis " ) == 0 ) index_start = 8; if( motor == 2 && getType() != JOINT_UNIVERSAL ) { cerr << "TSceneJoint::parseAxis: Attempted to set second axis for non universal joint" << endl; return false; } if( getType() == JOINT_FIXED ) { cerr << "TSceneJoint::parseAxis: Attempted to set axis for a fixed joint" << endl; return false; } string token; unsigned index = index_start; VecPosition axis; if( !Parse::getToken( str, index, token ) ) return false; if( !Parse::gotoFirstParsableModule( str, index ) ) { index = index_start; Parse::getToken( str, index, token ); if( token == "0" ) axis = VecPosition( 1, 0, 0 ); else if( token == "1" ) axis = VecPosition( 0, 1, 0 ); else if( token == "2" ) axis = VecPosition( 0, 0, 1 ); else { cerr << "TSceneJoint::parseAxis: Attempted to set axis value more than 2" << endl; return false; } } else { index = index_start; axis = TSceneNode::parsePositions( str, index ); if( axis == UnknownPosition ) return false; } setAxis( axis, motor ); return true;}/** * This method parses maximum motor force afrom the string given and copies it to the joint specified * @param str String that contains the motor force information * @param joint Joint to copy the information to * @return Indicates that the parse process was successfull */bool TSceneJoint::parseMotorForce( string & str ){ unsigned index = 0; if( str.compare( 0, CMD_MOTOR.length(), CMD_MOTOR ) != 0 ) { cerr << "TSceneJoint::parseMotorForce: This is not a setMaxMotorForce command" << endl; return false; } index = 17; string motor, force; if( !Parse::getToken( str, index, motor ) ) return false; if( !Parse::getToken( str, index, force ) ) return false; double m = TGenericData::getNumberFromString( motor ); double f = TGenericData::getNumberFromString( force ); if( f < 0 ) { cerr << "TSceneJoint::parseMotorForce: Force is less than zero" << endl; return false; } if( m != 0 && getType() == JOINT_HINGE ) { cerr << "TSceneJoint::parseMotorForce: Joint is hinge but motor # is not 0" << endl; return false; } if( m != 0 && m != 1 && getType() == JOINT_UNIVERSAL ) { cerr << "TSceneJoint::parseMotorForce: Joint is universal but motor # is not 0 or 1" << endl; return false; } if( getType() == JOINT_FIXED ) { cerr << "TSceneJoint::parseMotorForce: Joint is fixed and want to put a motor for it" << endl; return false; } if( getType() == JOINT_HINGE2 ) setMaxMotorForce( f, 0 ); else setMaxMotorForce( f, (int)m + 1 ); return true;}/** * This method asssign a unique number to joints so that they can be accessed via it */void TSceneJoint::assignNumber( TJointList & joints ){ if( joints.size() == 0 ) { setNumber( 1 ); return; } bool done = false; int number = 0; while( !done ) { number++; done = true; for( unsigned i = 0; i < joints.size(); i++ ) if( number == joints[i]->getNumber() ) { done = false; break; } if( done ) setNumber( number ); }}void TSceneJoint::saveInformation( ostream & os, string strGap, TSceneNode* thisNode ){ //""}/** * This method updates joint for a render * @return Indicates that joint is updated successfully */bool TSceneJoint::update(){ return true;}/** * This method renders the joint on screen * @return Indicates that joint has rendered itself successfully */bool TSceneJoint::render(){ if( m_Renderable ) TOpenGLSphere::render(); return true;}/** * This method returns the type of joint * @return type of the joint */TJoint TSceneJoint::getType() const{ return m_Joint;}/** * This method sets the type of the joint * @param joint type of the joint */void TSceneJoint::setType( TJoint joint ){ m_Joint = joint;}/** * This method returns the axis of joint * @param number information of the joint * @return Vectors of the joint axises */VecPosition TSceneJoint::getAxis( int number ) const{ return m_Axis[ number - 1 ];}/** * This method sets the axis of the joint * @param axis New value of the axis of joint * @param number motor number of the joint */void TSceneJoint::setAxis( VecPosition axis, int number ){ m_Axis[number - 1] = axis;}/** * This method returns the anchor of joint * @return anchor value of the joint */VecPosition TSceneJoint::getAnchor() const{ return m_Anchor;}/** * This method sets the of the joint * @param anchor New anchor value of the joint */void TSceneJoint::setAnchor( VecPosition anchor ){ m_Anchor = anchor;}/** * This method returns the maximum motor of joint * @param number The motor number of the joint * @return Maximum motor force joint */double TSceneJoint::getMaxMotorForce( int number ) const{ return m_MaxMotorForce[ number - 1 ];}/** * This method sets the maximum motor force of the joint * @param max_force Maximum motor force of the joint * @param number Motor number to change the value */void TSceneJoint::setMaxMotorForce( double max_force, int number ){ m_MaxMotorForce[number - 1] = max_force;}/** * This method returns the effector of joint * @return Effector name of the joint */string TSceneJoint::getEffectorName() const{ return m_EffectorName;}/** * This method sets the effector name of the joint * @param name effector name of the joint */void TSceneJoint::setEffectorName( string name ){ m_EffectorName = name;}/** * This method returns the perceptor name of joint * @return Perceptor name of the joint */string TSceneJoint::getPerceptorName() const{ return m_PercetorName;}/** * This method sets the of the joint * @param name perceptor name of the joint */void TSceneJoint::setPerceptorName( string name ){ m_PercetorName = name;}/** * This method returns the relative position of the joint to * the parrent of the joint * @return VecPosition Relative psoition of the parrent to the joint */VecPosition TSceneJoint::getPosRelParrent() const{ return m_PosRelParrent;}/** * This method sets the position of the joint relative to its parrent * @param pos Position of the joint relative to its parrent */void TSceneJoint::setPosRelParrent( VecPosition pos ){ m_PosRelParrent = pos;}/** * This method returns the relative position of the joint to the child of the joint * @return Relative psoition of the child to the joint */VecPosition TSceneJoint::getPosRelChild() const{ return m_PosRelChild;}/** * This method sets the position of the joint relative to its child * @param pos Position of the joint relative to its child */void TSceneJoint::setPosRelChild( VecPosition pos ){ m_PosRelChild = pos;}/** * This method returns the parrent of the joint * @return Parrent of the joint */TSceneNode * TSceneJoint::getParrent() const{ return m_Parrent;}/** * This method sets the parrent of the joint * @param parrent Parrent of the joint */void TSceneJoint::setParrent( TSceneNode * parrent ){ if( m_Parrent != NULL ) m_Parrent->removeJoint( this ); m_Parrent = parrent; if( m_Parrent ) parrent->addJoint( this );}/** * This method returns the child of the joint * @return Child of the joint */TSceneNode * TSceneJoint::getChild() const{ return m_Child;}/** * This method sets the child of the joint * @param child Child of the joint */void TSceneJoint::setChild( TSceneNode * child ){ if( m_Child != NULL ) m_Child->removeJoint( this ); m_Child = child; if( m_Child ) m_Child->addJoint( this ); calculateRelativePositions();}/** * This method returns wether the joint can * be rendered at this time or not * @return Render status of joint */bool TSceneJoint::isRenderable() const{ return m_Renderable;}/** * This methos sets a joint to be able to render itself or not * @param renderable Sets wether joint can render itself or not */void TSceneJoint::setRenderable( bool renderable ){ m_Renderable = renderable;}/** * This method returns the number of joint, the identifier * @return int Number of the joint */int TSceneJoint::getNumber() const{ return m_Number;}/** * This method sets the number of the joint (The identifier) * @param num Number of the joint */void TSceneJoint::setNumber(int num){ m_Number = num;}bool TSceneJoint::isSaved() const{ return m_Saved;}void TSceneJoint::setNotSaved(){ m_Saved = false;}/** * This method determines where is the actual joint positio
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -