Skip to main content
gamedev.net
🔒 Locked 🎮 Unity

Collision Test.

Started by X5-Programmer 2 replies 700+ views
Original Post
X5-Programmer
X5-Programmer
Hello there. I have trying to make some sort of collision test agains some world objects, in this case the objects are 3ds models. This is what I have done so far. 1. Get my position. 2. Loop through all the models. 3. Loop through all the objects in the model. 4. Loop through all the Faces in the current object. 5. Made a Vector that holds the current vertex from current object. 6. Then try make some collision here.

//Model Collision
	Vector3 vPoly[3], pPos;

	pPos = m_game.GetMyPosition();
	
	vector<PhysicObjects>::iterator itr;
	for( itr = pPhysicObjList.begin(); itr != pPhysicObjList.end(); itr++ )
	{
		for(int index = 0; index < itr->pModel->m3DModel.numOfObjects; index++)
		{
			t3DObject *pObject = &(itr->pModel->m3DModel.pObject[index]);
			
			for(int i=0; i < pObject->numOfFaces; i++)
			{												
				vPoly[0] = pObject->pVerts[pObject->pFaces.vertIndex[0]];
				vPoly[1] = pObject->pVerts[pObject->pFaces.vertIndex[1]];
				vPoly[2] = pObject->pVerts[pObject->pFaces.vertIndex[2]];

				//How do I make the test agains the polys and my current position?
			}
		}
	}



Well like I said how can I make the collision test agains my position and the vPoly ? if anyone know and can help me I will be realy glad. Thanks alot!
-[ thx ]-
X5-Programmer
X5-Programmer
no one know how to make a collision test against the vPoly position and my position?

... help plz

thanks.!
-[ thx ]-
Zakwayda
Zakwayda
From what you posted at least, I think you're going about it the wrong way. A discrete test between a point and a triangle isn't particularly useful, and in any case will almost always return false when using floating-point math.

Perhaps you could describe what you're really trying to do. What is GetMyPosition()? The player? A camera? What kind of shape does this object have? What are these physics objects? Are they arbitrary meshes? Do they move? What's supposed to happen when you run into one? And so on.

The answers to all these questions will have some bearing on what collision detection and response scheme might be appropriate for the context. I'm willing to bet however that the 'discrete point vs. every triangle in every model' approach you appear to be taking currently won't be particularly useful or effective.
ViperG
ViperG
id recommend making a AABB (axis aligned bounding box)

and check against that before you check against the poly's/faces. 1 check vs 500 checks every update. etc.

you can also use big bounding boxes (sectors) in your world/map, and only those objects that are both in the same sector check one another for a collision. only problem with sectors is you can have 1 object occupy 4 sectors so you have to check for that :(

brute force for collision is usually frowned upon, unless you only have say 50 objects and 20 bullets, then its not so bad. but when you get over 100 objects and they can all collide, it starts to affect your game performance.

the idea is to not do checks that you shouldn't be doing, aka if an object is really far away, you shouldnt check it for a collision check, because its far away. the trick is figuring out how to tell if something is "far away".

there are a few solutions to this problem. easiest is probably dividing your world into sectors/areas and define collisions from those.

also if you have teams, you can exlude same team checks for weapons fire which would reduces your checks by 50% assuming a balanced friend and foe count.
Black Sky A Star Control 2/Elite like game

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.