⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 scenecomponents.cpp

📁 3D仿真组实物机器人环境下的机器人模型的设计工具。可以查看和修改现有模型的详细参数
💻 CPP
📖 第 1 页 / 共 5 页
字号:
/***********************************************************************************                            In the name of Almighty                            **                                                                               **   SceneComponents.cpp : Robocup Soccer Simulator Developement Team: Zigorat   **                                                                               **  Date: 07/08/2007                                                             **  Author: Mahdi Hamdarsi                                                       **  Research Coordinator: Amin Mohammadi                                         **  Comments: Representors of scene nodes & joints                               **                                                                               ***********************************************************************************//*! \file SceneComponents.cpp<pre><b>File:</b>          SceneComponents.cpp<b>Project:</b>       Robocup Soccer Simulator Developement Team: Zigorat<b>Authors:</b>       Mahdi Hamdarsi, Amin Mohammadi<b>Created:</b>       12/02/2001<b>Last Revision:</b> $ID$<b>Contents:</b>      Representors of scene nodes & joints<hr size=2><h2><b>Changes</b></h2><b>Date</b>             <b>Author</b>          <b>Comment</b>07/08/2007       Mahdi Hamdarsi       Initial version created</pre>*/#include "SceneComponents.h"#include <cstdlib>#include "Parse.h"#include "GraphicEngine.h"extern TOpenGLEngine * OpenGLEngine;unsigned TSceneNode::m_GlobalReference; /*!< Declare the static m_GlobalReference of TSceneNode */const bool bStrict = true;// #define VERBOSE /*!< To print some logs on screen*/TRGBA getColorFromMaterial( TMaterial mat ){  switch( mat )  {    case MAT_BLUE:      return COLOR_BLUE;    case MAT_DARKGREY:      return COLOR_DARK_GREY;    case MAT_GREEN:      return COLOR_GREEN;    case MAT_GREY:      return COLOR_LIGHT_GREY;    case MAT_RED:      return COLOR_RED;    case MAT_WHITE:      return COLOR_WHITE;    case MAT_YELLOW:      return COLOR_YELLOW;    default:      break;  }    return COLOR_BLACK;}/*******************************************************************************//*******************************  TGenericData  ********************************//*******************************************************************************//** * This is the constructor of TGenericData, initializes the internals */TGenericData::TGenericData(){  m_DataType = DT_ILLEGAL;}/** * This is the constructor of TGenericData, initializes the internals * @param value value to initialize tha data with */TGenericData::TGenericData( const double & value ){  setValue( value );}/** * This is the constructor of TGenericData, initializes the internals * @param value value to initialize tha data with */TGenericData::TGenericData( const string & value ){  setValue( value );}/** * This is the constructor of TGenericData, initializes the internals * @param value value to initialize tha data with */TGenericData::TGenericData( const char * value ){  setValue( string(value) );}/** * This is the destructor of TGenericData, deinitializes the storage */TGenericData::~TGenericData(){}/** * This method returns the type of data currently residing in storage * @return type of the current data */int TGenericData::getDataType() const{  return m_DataType;}/** * This method returns the name of the data stored * @return The name of the data stored */string TGenericData::getName() const{  return m_DataName;}/** * This method sets the name of the data stored in storage * @param name The name of the data stored in storage */void TGenericData::setName( const string & name ){  m_DataName = name;}/** * This method returns the value of the data stored as a string * @return Value of the data */string TGenericData::getAsString() const{  return m_DataValue;}/** * This method sets the value of data as a double * @return Value of the data */double TGenericData::getAsDouble() const{  return getNumberFromString( m_DataValue );}/** * This method returns the value of data, this is renamed copy of getAsString() function * @return Value of the data */string TGenericData::getValue() const{  return m_DataValue;}/** * This method sets the value of data stored to the given one * @param value New value for the data */void TGenericData::setValue( const string & value ){                          m_DataValue = value;  m_DataType = DT_STRING;}/** * This method sets the value of data to the given one * @param value New value for data */void TGenericData::setValue( const double & value ){  char s[128];  sprintf( s, "%f", value );  m_DataValue = s;  m_DataType = DT_NUMBER;}/** * This operator copies the information on paramter instance given to this instance * @param data Data to be copied on self * @return TGenericData instance to allow furthor copies */TGenericData & TGenericData::operator = ( const TGenericData & data ){  setName( data.getName() );  setValue( data.getValue() );  return (*this);}/** * This method calculates the sum of the value of another storage to this storage and returns self * @param data Data for the sum to be calculated to current storage * @return current stoage to enable other uses */TGenericData TGenericData::operator + ( const TGenericData & data ){  TGenericData result = *this;  if( data.getDataType() == DT_STRING )    result.setValue( m_DataValue + data.getValue() );  else if( data.getDataType() == DT_NUMBER )    result.setValue( getAsDouble() + data.getAsDouble() );  return result;}/** * This method adds the value of another storage to this storage and returns self * @param data Data to be added to current storage * @return current stoage to enable other uses */TGenericData & TGenericData::operator += ( const TGenericData & data ){  (*this) = (*this) + data;  return (*this);}/** * This method calculates the subtract of the value of another storage to this storage and returns self * @param data Data for the sum to be calculated to current storage * @return current stoage to enable other uses */TGenericData TGenericData::operator - ( const TGenericData & data ){  TGenericData result = (*this);  if( data.getDataType() != DT_NUMBER )    result.setValue( 0 );  else    result.setValue( getAsDouble() - data.getAsDouble() );  return result;}/** * This method subtracts the value of another storage to this storage and returns self * @param data Data to be added to current storage * @return current stoage to enable other uses */TGenericData & TGenericData::operator -= ( const TGenericData & data ){  (*this) = (*this) - data;  return (*this);}/** * This method calculates the multiply of the value of another storage to this storage and returns self * @param data Data for the sum to be calculated to current storage * @return current stoage to enable other uses */TGenericData TGenericData::operator * ( const TGenericData & data ){  TGenericData result = (*this);  if( data.getDataType() != DT_NUMBER )    result.setValue( 0 );  else    result.setValue( getAsDouble() * data.getAsDouble() );  return result;}/** * This method multiplies the value of another storage to this storage and returns self * @param data Data to be added to current storage * @return current stoage to enable other uses */TGenericData & TGenericData::operator *= ( const TGenericData & data ){  (*this) = (*this) * data;  return (*this);}/** * This method calculates the division of the value of another storage to this storage and returns self * @param data Data for the sum to be calculated to current storage * @return current stoage to enable other uses */TGenericData TGenericData::operator / ( const TGenericData & data ){  TGenericData result = (*this);  if( data.getDataType() != DT_NUMBER )    result.setValue( 0 );  else    result.setValue( getAsDouble() / data.getAsDouble() );  return result;}/** * This method divides the value of another storage to this storage and returns self * @param data Data to be added to current storage * @return current stoage to enable other uses */TGenericData & TGenericData::operator /= ( const TGenericData & data ){  (*this) = (*this) / data;  return (*this);}/** * Overloaded version of the C++ output operator for TGenericDatas. * This operator makes it possible to use TGenericDatas in output * statements (e.g.  cout << data). The data name and values are * printed in the format '(name,value)'. * @param os Output stream which data is being printed * @param data Data which is being printed * @return Output stream instance to allow furthor prints */ostream& operator <<( ostream &os, const TGenericData & data ){  return ( os << "( '" << data.getName() << "', " << data.getValue() << " )" );}/** * Overloaded version of the C++ output operator for TGenericDatas. * This operator makes it possible to use TGenericDatas in output * statements (e.g.  cout << data). The data name and values are * printed in the format '(name,value)'. * @param os Output stream which data is being printed * @param data Pointer to data which is being printed * @return Output stream instance to allow furthor prints */ostream& operator <<( ostream &os, const TGenericData * data ){  return ( os << (*data) );}/** * This method returns number which resides in the string given * @param str string that contains the number * @return The number within the string */double TGenericData::getNumberFromString( const string & str ){  char s[128], *p;  strcpy( s, str.c_str() );  p = s;  return Parse::parseFirstDouble( &p );}/*********************************************************************************************//*************************************  Class TSceneNode  **************************************//*********************************************************************************************//** * This is the constructor of the TSceneNode wich initializes the internals with * default parameters * @return  */TSceneNode::TSceneNode(){  m_Shape     = SHAPE_ILLEGAL;  m_Material  = MAT_GREY;  m_Name      = "";  m_Mass      = 1;  m_Radius    = 1;  m_Length    = 1;  m_Width     = 1;  m_Height    = 1;  m_Parrent   = NULL;  m_Saved     = false;    m_GlobalReference++;  m_ID = m_GlobalReference;}/** * This is the destructor of TSceneJoint */TSceneNode::~TSceneNode(){  m_Children.clear();}/** * This method parses a name from the supplied string * @param str String to get out the name * @return  */string TSceneNode::parseName( string & str ){  if( str.compare( 0, CMD_NAME.length(), CMD_NAME ) != 0 )  {    cerr << "TSceneNode::parseName: This is not a setName command" << endl;    return "";  }  unsigned index = CMD_NAME.length();  string token;  if( !Parse::getToken( str, index, token ) )    return "";  else    return token;}/** * This method parses local rotation of the node * @param str String containing the local rotation information * @return Vetor containing local rotation */VecPosition TSceneNode::parseLocalRotation( string & str ){  unsigned index = 0;  if( str.compare( 0, CMD_ROTATATION.length(), CMD_ROTATATION ) != 0 )  {    cerr << "TSceneNode::parseLocalRotation: This is not a setLocalRotation command" << endl;    return UnknownPosition;  }  index = 18;  return parsePositions( str, index );}/** * This method parses position of node * @param str String containing position of node * @return Position of the node */VecPosition TSceneNode::parseNodePosition( string & str ){  unsigned index = 0;  if( str.compare( 0, CMD_POSITION.length(), CMD_POSITION ) != 0 )  {    cerr << "TSceneNode::parseNodePosition: This is not a setLocalPos command" << endl;    return UnknownPosition;  }  index = 13;  return parsePositions( str, index );}/** * This method returns material type parsed from the given string * @param str String that contains material information * @param index current position of string * @return Material residing in the string */TMaterial TSceneNode::parseMaterial( string & str, unsigned & index ){  string token;  if( !Parse::getToken( str, index, token ) )    return MAT_ILLEGAL;  if( token.compare( 0, 6, "matRed" ) == 0 )    return MAT_RED;  else if( token.compare( 0, 7, "matBlue" ) == 0 )    return MAT_BLUE;  else if( token.compare( 0, 7, "matWhite" ) == 0 )    return MAT_WHITE;  else if( token.compare( 0, 8, "matGreen" ) == 0 )    return MAT_GREEN;  else if( token.compare( 0, 7, "matGrey" ) == 0 )    return MAT_GREY;  else if( token.compare( 0, 11, "matDarkGrey" ) == 0 )    return MAT_DARKGREY;  else if( token.compare( 0, 8, "matWhite" ) == 0 )    return MAT_WHITE;  else if( token.compare( 0, 9, "matYellow" ) == 0 )    return MAT_YELLOW;  else  {    cerr << "TSceneNode::parseMaterial: parsed unknown material: '" << token << "'" << endl;    return MAT_ILLEGAL;  }}/** * This method parses the string given and takes out the material of node,

⌨️ 快捷键说明

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