MOC and GetMeshInformation

Problems building or running the engine, queries about how to use features etc.
Sharsnik
Halfling
Posts: 44
Joined: Wed Feb 11, 2009 5:41 pm

MOC and GetMeshInformation

Post by Sharsnik »

I'm trying to implement mesh intersection tests. I was told to use MOC and/or the GetMeshInformation function found here: http://www.ogre3d.org/wiki/index.php/Ra ... ygon_level

However, this function seems to cause a crash in the system (nothing in the log file) when it exits. Also, there's two lines of code that seem to be outdated in the MOC code...

Code: Select all

pentity->getParentNode()->getWorldPosition(),
pentity->getParentNode()->getWorldOrientation(),
Can anyone help me either get MOC running, or show me another way to pull the intersection triangle from an entity?

Edit:
Here's the full code of the getHeight function... mebbe I'm missing something stupid

Code: Select all

float ogreEngine::getHeight(Vector3 start)
{
	float closeHit = -1;

	start.y += PATHING_CUTOFF;

	rayTest = Ray(start, Vector3::NEGATIVE_UNIT_Y);
	raySceneQuery->setRay(rayTest);

	RaySceneQueryResult &result = raySceneQuery->execute();
	
	for (u_int i = 0; i < result.size(); i++)
    {
		if (result[i].worldFragment)
			return result[i].worldFragment->singleIntersection.y;
		else if (result[i].movable )
		{
			Ogre::Entity* entity = static_cast<Ogre::Entity*>(result[i].movable);

			if (entity->getParentNode())
			{
				size_t vertex_count = 0;
				size_t index_count = 0;
				Ogre::Vector3 *vertices = NULL;
				unsigned long *indices = NULL;

				collision->GetMeshInformation(entity->getMesh(), vertex_count, vertices, index_count, indices,             
								  entity->getParentNode()->_getDerivedPosition(),
								  entity->getParentNode()->_getDerivedOrientation(),
								  entity->getParentNode()->_getDerivedScale());

				if (vertices)
				{
					for (int i = 0; i < static_cast<int>(index_count); i += 3)
					{
						std::pair<bool, Ogre::Real> hit = Ogre::Math::intersects(rayTest, vertices[indices[i]], vertices[indices[i+1]], vertices[indices[i+2]], true, false);

						if (hit.first)
						{
							if ((closeHit < 0.0f) || (hit.second < closeHit))
							{
								closeHit = hit.second;
							}
						}
					}

					delete[] vertices;
					delete[] indices;

					return rayTest.getPoint(closeHit).y;
				}
			}
		}
	}

	return -1000;
}
Seems to crash on the _getDerivedScale() line...
User avatar
ajs15822
OGRE Expert User
OGRE Expert User
Posts: 570
Joined: Mon Jan 02, 2006 2:05 am
Location: Texas
x 2

Re: MOC and GetMeshInformation

Post by ajs15822 »

Try replacing "_getDerivedScale()" with "getScale()".
Sharsnik
Halfling
Posts: 44
Joined: Wed Feb 11, 2009 5:41 pm

Re: MOC and GetMeshInformation

Post by Sharsnik »

Nah, doesn't work :/