MOC - Minimal Ogre Collision 1.0 - [Update 03.May.2009]

A place to show off your latest screenshots and for people to comment on them. Only start a new thread here if you have some nice images to show off!
User avatar
nikki
Old One
Posts: 2730
Joined: Sat Sep 17, 2005 10:08 am
Location: San Francisco
x 13

Post by nikki »

I have an Entity as a 'ground' mesh, and a little player object in my demo. I'm trying to make the player stick to the ground using calculateY, by doing this every frame (I don't use TSM or ETM):-

Code: Select all

collisionMgr->calculateY(mNode, false, true, 2);
But, it always gives me a vector with y=0. Did I miss something?
User avatar
Nauk
Gnoll
Posts: 653
Joined: Thu May 11, 2006 9:12 pm
Location: Bavaria
x 36

Post by Nauk »

If you just want to check against another ground-mesh without TSM or ETM, you would have to set a querymask for that mesh and then pass the querymask as last parameter. The groundmesh you check against, shouldn't be static-geometry because that is not supported (yet).

Code: Select all

collisionMgr->calculateY(mNode, false, true, 2, WHATEVER_GROUND_MASK);
Hope that helped :)

/Nauk
User avatar
nikki
Old One
Posts: 2730
Joined: Sat Sep 17, 2005 10:08 am
Location: San Francisco
x 13

Post by nikki »

Hmm... I tried that just now, it still gives me an (x,0,z) vector.
User avatar
Nauk
Gnoll
Posts: 653
Joined: Thu May 11, 2006 9:12 pm
Location: Bavaria
x 36

Post by Nauk »

I just checked it again, using the MOC Demo:
http://downloads.sourceforge.net/moc-co ... g_mirror=0

I commented out the terrain loading in the ArtifexLoader.cpp line 57 to 63:

Code: Select all

	/*
	initETM();		
	
	createColourLayer();	
	setupTextures();
	loadTerrain(mZoneName);
	*/
Then in the SampleApp.cpp I placed the mCamNode manually to be certainly above the waterplane for testing now, SampleApp.cpp line 79:

Code: Select all

	mCamNode->setPosition(mCamNode->getPosition().x,10000,mCamNode->getPosition().z);
	// place the camera node on the ground
	//mCollisionTools->calculateY(mCamNode);
And then I changed the calculateY in line 114 to ...

Code: Select all

			mCollisionTools->calculateY(mCamNode,false,true,2.0f,WATER_MASK | ENTITY_MASK);
...so it does check against whatever objects and the waterplane as collision object and it works just fine as intended.

Maybe you can try that too and see if you can get it to work with the demo just like I did it now. That could shed some light why your code is not working. Otherwise I can't say much more without seeing your code.

Edit: Oh and have you tried debugging into the calculateY? Should be easiest to find out why you dont get a response to the check.
User avatar
nikki
Old One
Posts: 2730
Joined: Sat Sep 17, 2005 10:08 am
Location: San Francisco
x 13

Post by nikki »

Its ok now, I got it to work somehow. :roll:
User avatar
Beauty
OGRE Community Helper
OGRE Community Helper
Posts: 767
Joined: Wed Oct 10, 2007 2:36 pm
Location: Germany
x 39

Post by Beauty »

This looks interesting :)

Now there even is a port for Mogre: www.ogre3d.org/phpBB2addons/viewtopic.php?t=8615

Also I created a stub in the wiki.
Now I have less time. Later I can fill it with information.
Or somebody else does it ...

www.ogre3d.org/wiki/index.php/Minimal_Ogre_Collision
Help to add information to the wiki. Also tiny edits will let it grow ... :idea:
Add your country to your profile ... it's interesting to know from where of the world you are.
User avatar
Nauk
Gnoll
Posts: 653
Joined: Thu May 11, 2006 9:12 pm
Location: Bavaria
x 36

Post by Nauk »

Now that is nice to hear :) muchas gracias for the info and the wiki entry. I'll try to fill it when I find the time, hopefully soon.
User avatar
xabila
Goblin
Posts: 225
Joined: Mon Jun 05, 2006 9:40 am
Location: rennes [FR]

Re: MOC - Minimal Ogre Collision - Demo1.0 Beta [Demo+Src+Video]

Post by xabila »

It's also working fine in linux.
But i have some problem, when i'm using the TSM.
Maybe it's because of the DotScene wich is loading my terrain, but it seems that the terrain mesh, is not at the right place.

The dotscene is moving the TerrainNode at a position indicated by the xml file.
Do you think it can be a problem?

And after currently to get the right elavation according the terrain, i have to compute it like that

Code: Select all


float HeightComputation::getHeight ( float x, float z)
{
  if (_isTerrain && !_init)
  {
    _terrainNode = _sceneMgr->getSceneNode("Terrain");
    _centerPosition = getWorldCenterPosition();
    _relativePosition = getRelativeCenterPosition();
    _init = true;
  }

  float resultat;
  if ( !_isTerrain)
    resultat = _defaultHeight;
  else
  {
    Ogre::Vector3 shiftPosition (_relativePosition - _centerPosition);
    Ogre::TerrainRenderable * pTerrainPage = ((Ogre::TerrainSceneManager *)_sceneMgr)->getTerrainTile(Ogre::Vector3(x +shiftPosition[0], shiftPosition[1], z +shiftPosition[2]));
    if (pTerrainPage != 0)
    {
      resultat = pTerrainPage->getHeightAt( x +shiftPosition[0], z +shiftPosition[2]) + _defaultHeight - shiftPosition[1];
    }
    // Si on est en dehors de la map
    else
    {
      OMERROR ( "Can't find terrainTile");
      resultat = _defaultHeight;
    }
  }
    return resultat;
}
Ogre::Vector3 HeightComputation::getRelativeCenterPosition() const
{
  assert ( _isTerrain);
  Ogre::Vector3 mapSize (((Ogre::TerrainSceneManager *)_sceneMgr)->getScale() * (((Ogre::TerrainSceneManager *)_sceneMgr)->getPageSize()-1) / 2);

  return Ogre::Vector3(mapSize.x, (((Ogre::TerrainSceneManager *)_sceneMgr)->getHeightAt(mapSize.x, mapSize.z)), mapSize.z);
}

//------------------------------------------------------------
Ogre::Vector3 HeightComputation::getWorldCenterPosition() const
{
  assert ( _isTerrain);
  Ogre::Vector3 nodePosition = _terrainNode->getPosition();
  Ogre::Vector3 mapSize (((Ogre::TerrainSceneManager *)_sceneMgr)->getScale() * (((Ogre::TerrainSceneManager *)_sceneMgr)->getPageSize()-1) / 2);

  return Ogre::Vector3(nodePosition.x + mapSize.x, nodePosition.y + (((Ogre::TerrainSceneManager *)_sceneMgr)->getHeightAt(mapSize.x, mapSize.z)), nodePosition.z + mapSize.z);
}
I guess what you have done should be the same, but maybe i'm wrong.
User avatar
Nauk
Gnoll
Posts: 653
Joined: Thu May 11, 2006 9:12 pm
Location: Bavaria
x 36

Re: MOC - Minimal Ogre Collision - Demo1.0 Beta [Demo+Src+Video]

Post by Nauk »

Thanks Xabila, I am happy you like it :) About your problem, the Terrain Position shouldn't be a problem because the Height function is a simple Rayquery for a worldfragment intersection against it, but maybe I don't understand your question properly.
User avatar
xabila
Goblin
Posts: 225
Joined: Mon Jun 05, 2006 9:40 am
Location: rennes [FR]

Re: MOC - Minimal Ogre Collision - Demo1.0 Beta [Demo+Src+Video]

Post by xabila »

Well, I need first to make some debug stuff, to see if the elevation match my scene.
But actually what is make me crasy is that i've got some infinite loop on the intersectSegment or on TerrainRenderable::getHeightAt
So something seems wrong on the MOC::CollisionTools:raycast but i don't know why...
User avatar
Nauk
Gnoll
Posts: 653
Joined: Thu May 11, 2006 9:12 pm
Location: Bavaria
x 36

Re: MOC - Minimal Ogre Collision - Demo1.0 Beta [Demo+Src+Video]

Post by Nauk »

Weird, we basically used nothing else there than in the Ogre TSM demo.

Oh while I am at it, MOC moved from sourceforge to google-code:
http://code.google.com/p/minimal-ogre-c ... n-toolkit/
User avatar
xadhoom
Minaton
Posts: 973
Joined: Fri Dec 28, 2007 4:35 pm
Location: Germany
x 1

Re: MOC - Minimal Ogre Collision - Demo1.0 Beta [Demo+Src+Video]

Post by xadhoom »

Do you plan a non-Beta release soon?

Thanks, xad
User avatar
xabila
Goblin
Posts: 225
Joined: Mon Jun 05, 2006 9:40 am
Location: rennes [FR]

Re: MOC - Minimal Ogre Collision - Demo1.0 Beta [Demo+Src+Video]

Post by xabila »

SO actually, the getTSMHeight always retun 0 on my scene :(

Do we need to set a QueryFlag on the terrain?
Thanks
User avatar
Nauk
Gnoll
Posts: 653
Joined: Thu May 11, 2006 9:12 pm
Location: Bavaria
x 36

Re: MOC - Minimal Ogre Collision - Demo1.0 Beta [Demo+Src+Video]

Post by Nauk »

@Xadhoom: Once the next Artifex is out the door MOC will get more attention again.

@Xabila: I just looked at my TSM test-app again just to be sure, it is supposed to work out of the box. But you have to comment out the

Code: Select all

#define ETM_TERRAIN
in the header if you work with standard TSM, and use the constructor without terrainInfo. If that doesn't work I can send you my TSM test-app code.
User avatar
xabila
Goblin
Posts: 225
Joined: Mon Jun 05, 2006 9:40 am
Location: rennes [FR]

Re: MOC - Minimal Ogre Collision - Demo1.0 Beta [Demo+Src+Video]

Post by xabila »

Yes i allready did that, so why not try whith your test app...
Thanks.
mickeyren
Greenskin
Posts: 142
Joined: Thu Dec 18, 2008 11:32 am

Re: MOC - Minimal Ogre Collision - Demo1.0 Beta [Demo+Src+Video]

Post by mickeyren »

Hi

Does this work on manual objects or just entity?

Since its based from the wiki entry - the wiki entry needs the mesh information from the entity - i don't think manual objects returns these information?
User avatar
Beauty
OGRE Community Helper
OGRE Community Helper
Posts: 767
Joined: Wed Oct 10, 2007 2:36 pm
Location: Germany
x 39

Re: MOC - Minimal Ogre Collision - Demo1.0 Beta [Demo+Src+Video]

Post by Beauty »

mickeyren wrote:i don't think manual objects returns these information?
You can create a mesh instance by ManualObject::convertToMesh().
The API description is here: http://www.ogre3d.org/docs/api/html/cla ... 7f02b07efe
Maybe this helps (as alternatively way).
Help to add information to the wiki. Also tiny edits will let it grow ... :idea:
Add your country to your profile ... it's interesting to know from where of the world you are.
User avatar
VileMK3
Halfling
Posts: 70
Joined: Fri Nov 28, 2008 8:49 pm
Location: Flanders, Belgium

Re: MOC - Minimal Ogre Collision - Demo1.0 Beta [Demo+Src+Video]

Post by VileMK3 »

I've taken a look at MOC and decided to use it for my small presentation but I'm having difficulties getting it implemented. Is there a small tutorial or other file with information on how to properly use the MOC?
User avatar
Nauk
Gnoll
Posts: 653
Joined: Thu May 11, 2006 9:12 pm
Location: Bavaria
x 36

Re: MOC - Minimal Ogre Collision - Demo1.0 Beta [Demo+Src+Video]

Post by Nauk »

There is a demo application, you can find the link just at the beginning of the post here, that should make it clear. :)
User avatar
VileMK3
Halfling
Posts: 70
Joined: Fri Nov 28, 2008 8:49 pm
Location: Flanders, Belgium

Re: MOC - Minimal Ogre Collision - Demo1.0 Beta [Demo+Src+Video]

Post by VileMK3 »

I4ve looked at it and certain parts still remained unclear but I managed to figure it out myself. One last question though, whenever I let it check if there's collision with other entities I keep ending up in an infinite loop, I believe I've seen that questrion before, any idea why this occurs?
User avatar
Nauk
Gnoll
Posts: 653
Joined: Thu May 11, 2006 9:12 pm
Location: Bavaria
x 36

Re: MOC - Minimal Ogre Collision - Demo1.0 Beta [Demo+Src+Video]

Post by Nauk »

I can't see an inifinite loop where you could possibly end up, which one is it? (maybe I am just sitting on my cable :) )
User avatar
VileMK3
Halfling
Posts: 70
Joined: Fri Nov 28, 2008 8:49 pm
Location: Flanders, Belgium

Re: MOC - Minimal Ogre Collision - Demo1.0 Beta [Demo+Src+Video]

Post by VileMK3 »

lol, this is the code I use:

Code: Select all

	Vector3 oldpos = m_CameraNode->getPosition();

	// Translates the camera according to the translate vector
	m_CameraNode->translate(m_CameraYawNode->getOrientation() * m_CameraPitchNode->getOrientation() * m_Direction, Ogre::SceneNode::TS_LOCAL);

	m_pCollisionTool->calculateY(m_CameraNode,true,true,2.0f);//,ENTITY_MASK);
		
	// When I leave this part uncommented my program simply freezes, can't use Escape to exit either so that's why I think it's an infinite loop or something but I have no idea what's causing it. I also
                // commented the ENTITY_MASK because I don't have any masks right now, could that be it?
	if (m_pCollisionTool->collidesWithEntity(oldpos, m_CameraNode->getPosition(), 2.5f, -1.0f))//, ENTITY_MASK))
	{
		// undo move
		m_CameraNode->setPosition(oldpos);
	}
User avatar
Nauk
Gnoll
Posts: 653
Joined: Thu May 11, 2006 9:12 pm
Location: Bavaria
x 36

Re: MOC - Minimal Ogre Collision - Demo1.0 Beta [Demo+Src+Video]

Post by Nauk »

Ok, it should work out of the box like this - going to have a look, anyway.