scenecomponents.cpp

来自「3D仿真组实物机器人环境下的机器人模型的设计工具。可以查看和修改现有模型的详细参」· C++ 代码 · 共 2,568 行 · 第 1/5 页

CPP
2,568
字号
  {    cerr << "TSceneNode::parseCylinderNode: This is not a cylinder node information" << endl;    return false;  }  index = 14;  int pran = 1;  if( !parseInformation( str, index, pran, nodes, joints ) )  {    cerr << "TSceneNode::parseCylinderNode: In parsing a cylinder node" << endl << endl;    return false;  }  setShape( SHAPE_CAPSULE );  bool bReturn = false;  if( pran != 1 )  {}  else if( !initialized() )  {    for( unsigned k = 0; m_Children.size(); k++ )    {      for( unsigned j = 0; j < nodes.size(); j++ )        if( nodes[j] == m_Children[k] )          nodes.erase( nodes.begin() + j );      delete m_Children[k];    }    m_Children.clear();    unsigned jindex = index;    Parse::eatMessage( str, jindex, pran );    cerr << "TSceneNode::parseCylinderNode: Node is not inited: " << this << endl;    cerr << "TSceneNode::parseCylinderNode: '" << str.substr( index - 15, jindex - (index - 15) + 1 ) << "'" << endl;  }  else  {    setNodeName( NODE_CCYLINDER );    bReturn = true;  }  return bReturn;      if( pran != 1 )    return false;  if( !initialized() )  {    cerr << "TSceneNode::parseCylinderNode: No cylinder taken out: " << this << endl;    return false;  }  return true;}/** * This method parses a box node and adds it to the node list * @param str String that contains the box node * @param parrent Parrent of this node to use * @param nodes All the nodes that have been previously parsed * @param joints All the joints that havve been  * @return Indicates wheather any node was taken out or not */bool TSceneNode::parseBoxNode( string & str, TSceneNode * parrent, TNodeList & nodes, TJointList & joints ){  unsigned index = 0;  if( str.compare( index + 4, NODE_BOX.length(), NODE_BOX ) != 0 )  {    cerr << "TSceneNode::parseBoxNode: This is not a transform node" << endl;    return false;  }  index += 8;  int        pran = 1;  if( !parseInformation( str, index, pran, nodes, joints ) )  {    cerr << "TSceneNode::parseBoxNode: In parsing a box node" << endl << endl;    return false;  }  setShape( SHAPE_BOX );  bool bReturn = false;  if( pran != 1 )  {}  else if( !initialized() )  {    unsigned jindex = index;    Parse::eatMessage( str, jindex, pran );        clearChildren( nodes );    cerr << "TSceneNode::parseBoxNode: Node is not inited: " << this << endl;    cerr << "TSceneNode::parseBoxNode: '" << str.substr( index - 15, jindex - (index - 15) + 1 ) << "'" << endl;  }  else  {    setNodeName( NODE_BOX );    bReturn = true;  }  return bReturn;      if( pran != 1 )    return false;  if( !initialized() )  {    cerr << "TSceneNode::parseBoxNode: No box taken out: " << this << endl;    return false;  }  return true;}/** * This method parses a transform node and adds it to the node list * @param str String that contains the box node * @param parrent Parrent of this node to use * @param nodes All the nodes that have been previously parsed * @param joints All the joints that havve been  * @return Indicates wheather any node was taken out or not */bool TSceneNode::parseTransformNode( string str, TSceneNode * parrent, TNodeList & nodes, TJointList & joints ){  unsigned index = 0;  if( str.compare( index + 4, NODE_TRANSFORM.length(), NODE_TRANSFORM ) != 0 )  {    cerr << "TSceneNode::parseTransformNode: This is not a transform node" << endl;    return false;  }  index += 15;  int pran = 1;  if( !parseInformation( str, index, pran, nodes, joints ) )  {    cerr << "TSceneNode::parseTransformNode: In parsing a transform node" << endl << endl;    return false;  }  bool bReturn = false;  if( pran != 1 )  {}  else if( !initialized() )  {    unsigned jindex = index;    Parse::eatMessage( str, jindex, pran );        clearChildren( nodes );    cerr << "TSceneNode::parseTransformNode: Node is not inited: " << this << endl;    cerr << "TSceneNode::parseTransformNode: '" << str.substr( index - 15, jindex - (index - 15) + 1 ) << "'" << endl;  }  else  {    setNodeName( NODE_TRANSFORM );    bReturn = true;  }  return bReturn;}/** * This method is responsible for updating the node * @return Indicates updates was successfull */bool TSceneNode::update(){  return true;}/** * This method renders the node  * @return Indicates render was successfull */bool TSceneNode::render(){  TOpenGLDrawing::changeDiffuseColor( m_DiffuseColor );  if( m_Shape == SHAPE_CAPSULE )    glTranslatef( m_Position.getX(), m_Position.getY(), m_Position.getZ() - m_Length / 2.0 );  else    glTranslatef( m_Position.getX(), m_Position.getY(), m_Position.getZ() );  glRotatef( m_Direction.getZ(), 0, 0, 1 );  glRotatef( m_Direction.getY(), 0, 1, 0 );  glRotatef( m_Direction.getX(), 1, 0, 0 );  if( m_Shape == SHAPE_SPHERE )    TOpenGLDrawing::drawSphere( m_Radius );  else if( m_Shape == SHAPE_BOX )    TOpenGLDrawing::drawBox( m_Length, m_Width, m_Height );  else if( m_Shape == SHAPE_CAPSULE )  {    e_Capsule.setDiffuseColor(m_DiffuseColor);    e_Capsule.setTopRadius( m_Radius );    e_Capsule.setBottomRadius( m_Radius );    e_Capsule.setHeight( m_Length );    e_Capsule.update();    e_Capsule.render();  }  for( unsigned i = 0; i < m_Children.size(); i++ )  {    glPushMatrix();    m_Children[i]->update();    m_Children[i]->render();    glPopMatrix();  }  return true;}/** * This method overrides the default position setter for this object to enable other nodes re-positioning * @param pos New Position to set for the object * @return  */bool TSceneNode::setPosition( const VecPosition & pos ){  TOpenGLObject::setPosition( pos );  rePosition( NULL );  return true;}/** * This method returns ID of node to be used in calling nodes * Each node'd ID is unique so that nodes can be used individually * with it * @return Unique global id of node */unsigned TSceneNode::getID() const{  return m_ID;}/** * This method returns the name of node * @return name of the node */string TSceneNode::getName() const{  return m_Name;}/** * This method sets the name of node * @param name New name for the node */void TSceneNode::setName( string name ){  m_Name = name;}/** * This method returns the name of node itself * @return name of the node itself */string TSceneNode::getNodeName() const{  return m_NodeName;}/** * This method sets the name of node itself * @param name New name for the node itself */void TSceneNode::setNodeName( string name ){  m_NodeName = name;}/** * This method returns the shape of node * @return TShape shape of node */           TShape TSceneNode::getShape() const{  return m_Shape;}/** * This method sets the shape of node * @param shape Shape of the node */void TSceneNode::setShape( TShape shape ){  m_Shape = shape;}/** * This method returns the length of node * @return double Length of node */double TSceneNode::getLength() const{  return m_Length;}/** * This method sets the length of node * @param length Length of the node */void TSceneNode::setLength( double length ){  m_Length = length;}/** * This method returns the width of node * @return double Width of node */double TSceneNode::getWidth() const{  return m_Width;}/** * This method sets the width of node * @param width Width of the node */void TSceneNode::setWidth( double width ){  m_Width = width;}/** * This method returns the height of node * @return double height of node */double TSceneNode::getHeight() const{  return m_Height;}/** * This method sets the height of node * @param height Height of the node */void TSceneNode::setHeight( double height ){  m_Height = height;}/** * This method returns the radius of node * @return double radius of node */double TSceneNode::getRadius() const{  return m_Radius;}/** * This method sets the radius of node * @param radius Radius of the node */void TSceneNode::setRadius( double radius ){  m_Radius = radius;}/** * This method returns the mass of node * @return mass of node */double TSceneNode::getMass() const{  return m_Mass;}/** * This method sets the mass of node * @param mass mass of the node */void TSceneNode::setMass( double mass ){  m_Mass = mass;}/** *  This method returns the material of node * @return material of node */TMaterial TSceneNode::getMaterial() const{  return m_Material;}/** * This method sets material of node * @param material Material of the node */void TSceneNode::setMaterial( TMaterial material ){  m_Material = material;  m_DiffuseColor = getColorFromMaterial( m_Material );}/** * The method returns wheather node has been saved before or not, * this is used in joint that wants to attach the nodes in saving * the result to a scene file * @return Indicates that node has been saved before or not */bool TSceneNode::isSaved() const{  return m_Saved;}/** * This method sets the internal memory of node about being saved to be cleared, *  and thats because the node and its joint can be saved  */void TSceneNode::setNotSaved(){  m_Saved = false;}/** * This method resizes the node and moves the up and down other nodes */void TSceneNode::resize(){}/** * This method repositions the node and  moves the up and down nodes * @param caller Caller of the position */void TSceneNode::rePosition( TSceneNode * caller ){  if( caller != NULL )  {    for( unsigned i = 0; i < m_Joints.size(); i++ )      if( m_Joints[ i ]->getChild() == caller || m_Joints[ i ]->getParrent() == caller )      {        if( m_Joints[ i ]->getChild() == caller )          m_Position = m_Joints[ i ]->getPosRelParrent() + m_Joints[ i ]->getPosRelChild() + caller->getPosition();        else          m_Position = caller->getPosition() - m_Joints[ i ]->getPosRelParrent() - m_Joints[ i ]->getPosRelChild();                m_Joints[ i ]->setPosition( ( m_Joints[ i ]->getChild()->getPosition() + m_Joints[ i ]->getParrent()->getPosition() ) / 2.0 );      }  }  for( unsigned i = 0; i < m_Joints.size(); i++ )    if( m_Joints[ i ]->getChild() != caller && m_Joints[ i ]->getParrent() != caller )    {      if( m_Joints[ i ]->getChild() == this )        m_Joints[ i ]->getParrent()->rePosition( this );      else        m_Joints[ i ]->getChild()->rePosition( this );    }}/** * This method adds a joint to node * @param joint Joint to be added to node */void TSceneNode::addJoint( TSceneJoint * joint ){  if( joint == NULL )    return;  for( unsigned i = 0; i < m_Joints.size(); i++ )    if( m_Joints[ i ] == joint )      return;  m_Joints.push_back( joint );}/** * This method removes a joint from node * @param joint Joint reference to remove * @return Indicating joint was removed */bool TSceneNode::removeJoint( TSceneJoint * joint ){  bool bFound = false;  for( unsigned i = 0; i < m_Joints.size(); i++ )    if( m_Joints[i] == joint )    {      m_Joints.erase( m_Joints.begin() + i );      bFound = true;      i--;    }  return bFound;}/** * This checks wheather the node is intialized enough to be added to nodes or not * @return Initialization status of node */bool TSceneNode::initialized() const{  for( unsigned i = 0; i < m_Children.size(); i++ )    if( m_Children[i]->initialized() )      return true;  if( m_Shape == SHAPE_ILLEGAL || m_Position == UnknownPosition || m_Material == MAT_ILLEGAL )    return false;  else    return true;}/**

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?