Re: [Plib-users] How to determine surface material by ssgState texture filena me ?
Brought to you by:
sjbaker
From: Steve B. <sjb...@ai...> - 2002-12-05 12:58:21
|
McEvoy, Nick wrote: > What is the best way to determine what type of 'surface' is under my players feet ? > > My setup is follows: > - I load a terrain (an AC3D model) with different textures, eg. grass, rock, ice. > - I get the hits: iNumHits = ssgIsect(reGetWorld(), &Sphere, InvMat, pHits) > - I get the SimpleState of the hit leaf, eg. > > ssgHit* h = &pHits[i]; > ssgState* pState = h->leaf->getState(); > if (pState->isA(ssgTypeSimpleState())) > { > char* sTexture = ((ssgSimpleState*)pState)->getTextureFilename(); > > // then depending on texture filename set different surface properties > // - this would be a bunch of strcmp() ... too slow !!! > } > > But doing a bunch of string compares on the texture filename is going to be slow ... is it not !? > > Is there a better way to do this ? There is a user-settable integer field in the ssgState: void ssgState::setExternalPropertyIndex(int i) int ssgState::getExternalPropertyIndex() ...you can use that to index into an array of external properties that you maintain. In my games, I store properties like friction, bounciness, etc in a structure and make a ulList of those. > Note: I had a quick look at the way TuxKart does it ... with a Material structure (ie. ssgState) ... but I don't quite follow how to apply these states when reading the AC3D model. > > I have the vague idea that I should load the AC3D model using ssgLoaderOptions ... to handle ssgState ... and as each texture is read create my own ssgState (which I can then get in the hit leaf) ... but I'm still trying to work out how the loader options are supposed to work ... or am I barking up the wrong tree here. The loader options allow you to have the file loader call your code whenever it wants to create a new ssgState - to give you the possibility to create your own ssgState instead of the loader doing it for you. That's one way to set the External Property Index - I also use it to add features to the ssgState that the loader can't. For example, AC3D doesn't support non-repeating textures - so I look up the texture filename in my master materials table and set the 'wrap' flags myself. This entire process is poorly documented right now - I kinda had the idea that one day I'd wrap up a material file parser along with all of this mechanism into an ssgAux thingy - but I havn't gotten around to doing that yet. ---------------------------- Steve Baker ------------------------- HomeEmail: <sjb...@ai...> WorkEmail: <sj...@li...> HomePage : http://web2.airmail.net/sjbaker1 Projects : http://plib.sf.net http://tuxaqfh.sf.net http://tuxkart.sf.net http://prettypoly.sf.net |