Questions on Collisions and Culling
by Kevin Rogers · in Torque Game Engine · 06/18/2004 (3:20 pm) · 7 replies
Hey guys,
Two quick questions (both related to performance):
1) Does TGE always use the collision hulls that are created with the model or is there a way to use simple cubic/spheric collision?
(I don't need anything more complex than spherical collision in my game, so, for performance' sake, I'd like to use a simpler collision check.)
2) Do interior objects cull hidden objects, specifically other interior objects and terrain? Or maybe the question should be: How exactly are hidden objects culled?
(My game is primarily interior-based; terrain would only be visible through windows, etc., so I only want to use the terrain if it's fast. Also, I'm considering tiling smaller interior objects to create larger levels, but if it's going to take a large performance hit....)
I just want to make sure TGE can handle some of the things I'm planning on doing (before I waste time implementing them, of course). So, hopefully someone can share some info/experience on these or on performance issues in general....
Thanks in advance!
Kevin
Two quick questions (both related to performance):
1) Does TGE always use the collision hulls that are created with the model or is there a way to use simple cubic/spheric collision?
(I don't need anything more complex than spherical collision in my game, so, for performance' sake, I'd like to use a simpler collision check.)
2) Do interior objects cull hidden objects, specifically other interior objects and terrain? Or maybe the question should be: How exactly are hidden objects culled?
(My game is primarily interior-based; terrain would only be visible through windows, etc., so I only want to use the terrain if it's fast. Also, I'm considering tiling smaller interior objects to create larger levels, but if it's going to take a large performance hit....)
I just want to make sure TGE can handle some of the things I'm planning on doing (before I waste time implementing them, of course). So, hopefully someone can share some info/experience on these or on performance issues in general....
Thanks in advance!
Kevin
#2
The player uses a bounding box for collision against other things (which have to be represented as a hull). The vehicles use collision hulls. If you want spherical collision for the vehicles I can post some simple code (still a little rough) to get you started.
06/21/2004 (6:49 am)
Kevin,The player uses a bounding box for collision against other things (which have to be represented as a hull). The vehicles use collision hulls. If you want spherical collision for the vehicles I can post some simple code (still a little rough) to get you started.
#3
Love to see some code! Code is good! =)
So, yeah, anything you can give me would me much appreciated. I figure I know enough to write my own implementation if necessary, but a good shove in the right direction at least will save a bit on time and exasperation. =P
Thanks!
06/21/2004 (4:19 pm)
Matt,Love to see some code! Code is good! =)
So, yeah, anything you can give me would me much appreciated. I figure I know enough to write my own implementation if necessary, but a good shove in the right direction at least will save a bit on time and exasperation. =P
Thanks!
#4
Thanks for the quick reply... let me clarify a bit on question #2, however, and see what you think. Excuse the ASCII art; hopefully it will be clear. =)
To use the TGE fps example, where interiors are used for the towers...
Imagine an orc (the 'x') looking (this way '->') at a long row of towers (the 'O's).
x -> O O O O O O O O O O
........1 2 3 4 5 6 7 8 9 10
Towers 2 thru 10 are obscurred from view by Tower 1. Does TGE properly cull the hidden towers? Or will it render them all? Also, are terrain and and DTS models culled behind interior objects?
Thanks again for the help, guys!
Kevin
06/21/2004 (4:30 pm)
Ben,Thanks for the quick reply... let me clarify a bit on question #2, however, and see what you think. Excuse the ASCII art; hopefully it will be clear. =)
To use the TGE fps example, where interiors are used for the towers...
Imagine an orc (the 'x') looking (this way '->') at a long row of towers (the 'O's).
x -> O O O O O O O O O O
........1 2 3 4 5 6 7 8 9 10
Towers 2 thru 10 are obscurred from view by Tower 1. Does TGE properly cull the hidden towers? Or will it render them all? Also, are terrain and and DTS models culled behind interior objects?
Thanks again for the help, guys!
Kevin
#5
06/21/2004 (5:14 pm)
bool Vehicle::updateCollision(F32 dt)
{
// Update collision information
//MatrixF mat,cmat;
//mConvex.transform = &mat;
//mRigid.getTransform(&mat);
//cmat = mConvex.getTransform();
mCollisionList.count = 0;
//CollisionState *state = mConvex.findClosestState(cmat, getScale(), mDataBlock->collisionTol);
//if (state && state->dist <= mDataBlock->collisionTol) {
// //resolveDisplacement(ns,state,dt);
// mConvex.getCollisionInfo(cmat, getScale(), &mCollisionList, mDataBlock->collisionTol);
//}
Box3F box = mConvex.getBoundingBox(getTransform(), getScale());
F32 len = (mRigid.linVelocity.len() + 50) * dt;
F32 l = (len * 1.1) + 0.1; // fudge factor
box.min -= Point3F(l, l, l);
box.max += Point3F(l, l, l);
ConcretePolyList polyList;
CollisionWorkingList& rList = mConvex.getWorkingList();
CollisionWorkingList* pList = rList.wLink.mNext;
while (pList != &rList) {
Convex* pConvex = pList->mConvex;
if ((pConvex->getObject()->getType() & StaticObjectType) != 0)
{
Box3F convexBox = pConvex->getBoundingBox();
if (box.isOverlapped(convexBox))
pConvex->getPolyList(&polyList);
}
pList = pList->wLink.mNext;
}
ConcretePolyList::Poly* ps = polyList.mPolyList.begin();
ConcretePolyList::Poly* pe = polyList.mPolyList.end();
for (; ps != pe; ps++)
{
if (mCollisionList.count < CollisionList::MaxCollisions)
{
float dist = ps->plane.distToPlane(mRigid.linPosition);
if (dist < mDataBlock->radius && dist > -mDataBlock->radius)
{
if (ps->vertexCount > 2)
{
bool inside = true;
Point3F v = ps->plane.project(mRigid.linPosition);
for (U32 i = 0; i < ps->vertexCount - 1; i++)
{
U32 i0 = polyList.mIndexList[ps->vertexStart + i];
U32 i1 = polyList.mIndexList[ps->vertexStart + i + 1];
Point3F p0 = polyList.mVertexList[i0];
Point3F p1 = polyList.mVertexList[i1];
VectorF q;
mCross(ps->plane, p1 - p0, &q);
if (mDot(q, v - p0) >= 0.0f)
{
inside = false;
break;
}
}
if (inside)
{
Collision& info = mCollisionList.collision[mCollisionList.count++];
info.point = v;
info.normal = ps->plane;
info.material = ps->material;
info.object = ps->object;
info.distance = 0.0f;
}
}
}
}
}
// Resolve collisions
bool collided = resolveCollision(mRigid,mCollisionList);
resolveContacts(mRigid,mCollisionList,dt);
return collided;
}
#6
06/21/2004 (9:28 pm)
@Kevin: No, that sort of occlusion isn't in. A few people have worked on adding it... it seems like the wins are only big if you have very big, complex environments divvied up between relatively few actual objects.
#7
@Ben: Ah, I was afraid of that. Yeah, the big, complex environment thing is what I'm looking at... I want to be able to build level content stochastically from smaller interior pieces. (This has be done in a few games, namely Diablo, with it's random dungeons.) Maybe I need to scale my plans back a bit... =(
At any rate, I really appreciate all the info. Thanks!
Kevin
06/22/2004 (1:32 pm)
@Matt: Thanks man! Just a bit of code can sometimes go a long way toward clearing things up...@Ben: Ah, I was afraid of that. Yeah, the big, complex environment thing is what I'm looking at... I want to be able to build level content stochastically from smaller interior pieces. (This has be done in a few games, namely Diablo, with it's random dungeons.) Maybe I need to scale my plans back a bit... =(
At any rate, I really appreciate all the info. Thanks!
Kevin
Associate Kyle Carter
2) Yes, Torque uses a portalized system. So as long as your interiors are well-made you should see good performance.
Quick answers, but I'm just about to go to dinner... :)