Example #1
0
string
MMOMath::getExp ()
{
  ASTNode *e;
  if (_type == MATH_EQUATION)
    {
      e = _equation->getEquation ();
      _processNode (e);
      return (MMOUtils::getInstance ()->getExp (e));
    }
  if (_type == MATH_ASSIGNMENT)
    {
      e = _assignment->getAssignment ();
      _processNode (e);
      return (MMOUtils::getInstance ()->getExp (e));
    }
  return ("");
}
Example #2
0
void
MMOMath::parseZeroCrossing (ASTNode *node)
{
  _type = MATH_ZERO_CROSSING;
  _exp = new ASTNode (*node);
  _processNode (_exp);
  _replaceFunctions (_exp);
  _equation = new MMOEquation (_exp);
  _zerocrossing = new MMOZeroCrossing (_equation->ASTExpression ());
}
Example #3
0
void
MMOMath::parseAssignment (ASTNode *node)
{
  _type = MATH_ASSIGNMENT;
  _exp = new ASTNode (*node);
  _processNode (_exp);
  if (_replace)
    {
      _replaceFunctions (_exp);
    }
  _assignment = new MMOAssignment (_exp);
}
Example #4
0
void
MMOMath::parseEquation (const ASTNode *node)
{
  _type = MATH_EQUATION;
  _exp = new ASTNode (*node);
  _processNode (_exp);
  if (_replace)
    {
      _replaceFunctions (_exp);
    }
  _equation = new MMOEquation (_exp);
}
Example #5
0
	void _loadModel( const char * xPath )
	{
		std::string path( xPath );

		Assimp::Importer importer;

#if 0
        	const aiScene* scene = importer.ReadFile(path
							, aiProcess_Triangulate      |
							  aiProcess_FlipUVs          |
							  aiProcess_CalcTangentSpace |
							  aiProcess_GenNormals       |
                                                          aiProcess_SplitLargeMeshes |
							  aiProcess_OptimizeMeshes );


#else
		size_t out;

		char * buffer = fileToBuffer( xPath, &out );

        	const aiScene* scene = importer.ReadFileFromMemory( buffer
								  , out
								  , aiProcess_Triangulate      |
	 							    aiProcess_FlipUVs          |
	 							    aiProcess_CalcTangentSpace |
								    aiProcess_GenNormals       |
	                                                            aiProcess_SplitLargeMeshes |
		  						    aiProcess_OptimizeMeshes
								  , "" );

		free ( buffer );
#endif


 	       // Check for errors
	        if(!scene || scene->mFlags == AI_SCENE_FLAGS_INCOMPLETE || !scene->mRootNode) // if is Not Zero
	        {
        	    std::cerr << "ERROR::ASSIMP:: " << importer.GetErrorString() << std::endl;
	            return;
	        }
	        // Retrieve the directory path of the filepath
        	mDirectory = path.substr(0, path.find_last_of('/'));

	        // Process ASSIMP's root node recursively
       		_processNode(scene->mRootNode, scene);
	}
Example #6
0
	void _processNode( aiNode* xNode, const aiScene* xScene )
	{
	        // Process each mesh located at the current node
	        for(GLuint i = 0; i < xNode->mNumMeshes; i++)
	        {
	            // The node object only contains indices to index the actual objects in the scene.
	            // The scene contains all the data, node is just to keep stuff organized (like relations between nodes).
	            aiMesh* mesh = xScene->mMeshes[ xNode->mMeshes[ i ] ];

	            mMeshes.push_back( _processMesh( mesh, xScene ) );
        	}

	        // After we've processed all of the meshes (if any) we then recursively process each of the children nodes
	        for(GLuint i = 0; i < xNode->mNumChildren; i++)
	        {
	            _processNode( xNode->mChildren[ i ], xScene );
	        }
	}
Example #7
0
void
MMOMath::_processNode (ASTNode* node)
{
  ASTNodeType_t t = node->getType ();
  if (t == AST_FUNCTION_ROOT)
    {
      ASTNode *first = new ASTNode (*node->getChild (0));
      ASTNode *exp = new ASTNode (AST_DIVIDE);
      ASTNode *constant = new ASTNode (AST_REAL);
      constant->setValue (1);
      exp->addChild (constant);
      exp->addChild (first);
      node->setType (AST_POWER);
      node->removeChild (0);
      node->addChild (exp);
    }
  else if (t == AST_NAME && !_prefix.empty ()
      && node->getId ().compare ("REPLACED_FUNCTION"))
    {
      string controlName = node->getName ();
      string flatName = _prefix + "_";
      if (controlName.compare (0, flatName.size (), flatName))
	{
	  flatName.append (node->getName ());
	  node->setName (flatName.c_str ());
	}
    }
  string package = MMOUtils::getInstance ()->checkPredefinedFunctions (node);
  if (!package.empty ())
    {
      _imports[package] = package;
    }
  int childs = node->getNumChildren ();
  int i;
  for (i = 0; i < childs; i++)
    {
      _processNode (node->getChild (i));
    }
}
Example #8
0
pair<string, list<string> >
MMOMath::_generateAlgebraic (pair<list<string>, ASTNode*> function,
			     list<string> args, ASTNode *node)
{
  ASTNode *repNode = new ASTNode (*function.second);
  _processNode (repNode);
  list<string>::iterator defArgs = function.first.begin ();
  list<string> variables;
  for (list<string>::iterator it = args.begin (); it != args.end (); it++)
    {
      repNode->renameSIdRefs (*defArgs, *it);
      defArgs++;
    }
  string ret = MMOUtils::getInstance ()->getExp (repNode);
  _getVariables (repNode, &variables);
  int childs = node->getNumChildren (), i;
  for (i = 0; i < childs; i++)
    {
      node->removeChild (0);
    }
  if (_type == MATH_ZERO_CROSSING)
    {
      node->setType (repNode->getType ());
      childs = repNode->getNumChildren ();
      for (i = 0; i < childs; i++)
	{
	  node->addChild (new ASTNode (*repNode->getChild (i)));
	}
    }
  else
    {
      node->setType (AST_NAME);
      node->setName (ret.c_str ());
      node->setId ("REPLACED_FUNCTION");
    }
  delete repNode;
  return (pair<string, list<string> > (ret, variables));
}