Product not found

Game Development Community

Runtime Terrain Deformation problem

by Ronald J Nelson · in Torque Game Engine · 08/11/2006 (12:31 pm) · 14 replies

First let me start by saying that I installed the Basic TerrainDeformer Object for Torque resource found here:

www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=7343

Everything works wonderfully except the fact that objects in the radius of the deformation don't seem to mind that there is no longer any ground beneath them!

Then I found Gary Preston's code here:

www.garagegames.com/mg/forums/result.thread.php?qt=32978

He was also kind enough to share the following code with me in the GG IRC chat room:

void TankBase::terrainDeformed()
{
   // Remove terrain from working list
   for (CollisionWorkingList* itr = mConvex.getWorkingList().wLink.mNext; 
                              itr != &mConvex.getWorkingList(); itr = itr->wLink.mNext) 
   {
      if (itr->mConvex->getType() == TerrainConvexType)
      {
         CollisionWorkingList* cl = itr;
         itr = itr->wLink.mPrev;
         cl->free();
      }
   }
   // and force an update of working set
   mWorkingQueryBox.min.x = -1e9;
   // don't update collision set immediatly, leave it for next processTick overwise
   // we end up with a jittering tank in certain terrain deformation positions
   updateWorkingCollisionSet();
 
}

I got everthing working(mostly) and tested the functionality with console logs. Except the part where it is supposed to free all of the terrain from the objects working list. I have confirmed that everything is happening to the if statement, but for some reason waht is supposed to be happening within the if statement is not.

What I would like help with is why it is not working, I have tried the code with wheeled vehicles, rigid shapes and static shapes. Additionally I noticed that footprint decals remain floating too if your drop the bomb and back away. Could someone please tell me why it isn't working and even better, how to make it work?

Here is a screenshot:
i72.photobucket.com/albums/i192/DTDA/terraindeformproblem.jpg

#1
08/11/2006 (11:33 pm)
I did notice from the post up there that there was considerably different code in the version I downloaded from the site. If someone still has an older version, or better yet, has made a successfully working version of this they could send me, I would really appreciate it.

RJNelson68@cox.net
#2
08/12/2006 (12:39 pm)
OK further testing shows that the the objects are infact dropping a bit but then stopping. I have been trying different types of shapes too to see if it was just a contact collision point issue, but nope a square object which should have cleared it's entire contact point area still does the same thing.

If I do this to the car I spawn in it does the same thing. However if I spawn in my car in the same exact place, I fall into the crater.

I have been going through all of the convex functions and trying to get some sort of reaction but nothing works.

HELP!!!
#3
08/12/2006 (1:32 pm)
OK well this is disappointing. Apparently the function Gary gave me makes no difference at all. I tested this by commenting it out. Everything he helped me with up to that function will work, but unfortunately it does nothing to solve my problem.
#4
08/12/2006 (4:31 pm)
OK I have been trying and will continue to do so. It would really help if someone could tell me where to find in an object's creation the part where the terrain beneath it is cached.
#5
08/12/2006 (11:14 pm)
Well I had been searching around on the forums and it was suggested to me in IRC as well that it could be a client server communication issue. I tested that on my LAN and found that the server and client have great communications from the terrain deformer resource. I also tested other things like throwing a weapon and trying to see if it would fall if I deformed the ground below it, it did not. It is obvious that Gary was totally right in his information he gave me on why the problem exists. Unfortunately his method does not fix it for me.
#6
08/13/2006 (6:48 pm)
Tried one more thing that has me confused again. I managed to throw the dynamite I am using to do this dformation, under a vehicle and then mounted it before it exploded.

When I dismounted the vehicle, my player was walking in the air. I got back in the vehicle and couldn't drive it because even though it was floating apparently the wheels weren't and just spun freely.

I have tried using the worl editor drop fucntions by making them work in the shapebase system, it makes for a dramatic game crash. I have no idea where to move next to update the cached terrain for each object.
#7
08/14/2006 (7:43 am)
Here is what I added to shapeBase.cc and this time it doesn't crash, but it doesn't fix my problem either.

//For use of updating shapebase objects that are affected by a runtime terrain deformation
void ShapeBase::terrainDeformed()
{
	Con::errorf(ConsoleLogEntry::General, "Terrain Deformer ShapeBase Test");

    Point3F start;
    MatrixF mat = getTransform();
    mat.getColumn(3, &start);
    Point3F end = start;
    start.z = -2000.f;
    end.z = 2000.f;

    RayInfo ri;
    bool hit;

    hit = gServerContainer.castRay(start, end, TerrainObjectType, &ri);

    if(hit)
    {
        mat.setColumn(3, ri.point);
        setTransform(mat);
    }
}

Any suggestions would be very helpful.
#8
08/14/2006 (8:07 am)
OK I added a console log entry to the if statement and it is definitely finding the terrain, just not moving it.

Although, this also brings up the fact that if it still thinks there is a terrain cache beneath the car, it could be reading that instead of my newly deformed terrain.
#9
08/15/2006 (8:42 pm)
Looks like this guy had the right idea just like Gary.

www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=6021

Gary also explained to me that in his code he primarily just used it for player objects which according to what I read in this resource looks like it would have worked.
#10
08/16/2006 (1:29 pm)
Ok I have managed to force the updateWorkingCollisionSet function for each item and confirmed it through console log but it didn't make any difference. This tells me there must be something else. I also tried a test where I made the deformation directly under the player, he had to walk for what seemed to be 1 terrain block and then fell into the crater. I have no idea what it is I am missing. Suggestions on where ever else this sucker might be would be really appreciated.
#11
08/16/2006 (1:33 pm)
This is what I did to force the updateWorkingCollisionSet to update

void Vehicle::terrainDeformed()
{
    Con::errorf(ConsoleLogEntry::General, "Terrain Deformer Vehicle First Test");
	resetRenderWorldBox();
	resetWorldBox();
	ShapeBase::mTerrDeformedServer = true;

	updateWorkingCollisionSet(getCollisionMask());
}
#12
08/16/2006 (1:35 pm)
That code is almost identical in each item such as Item::terrainDeformed()

in the Item::updateWorkingCollisionSet I used this:

// force an update of the cached collision data if 
   // a collision mesh state has changed.   
   if(isServerObject())   
   {
	   if(ShapeBase::mTerrDeformedServer == true)
	   {
		   updateSet = true;
		   ShapeBase::mTerrDeformedServer = false;
		   Con::errorf(ConsoleLogEntry::General, "Terrain Deformer Item Second Test");
	   }
   }

   // Actually perform the query, if necessary
   if (updateSet == true)
#13
08/16/2006 (8:24 pm)
Thought I would add I even tried this in the shapeBase

mConvexList->nukeList();

No help.
#14
08/31/2006 (5:41 pm)
I moved my discussion of this a few days ago to here since it is more applicable.

www.garagegames.com/mg/forums/result.thread.php?qt=49391