Game Development Community

RC1: (fixed) level builder creates concave collision poly

by Alex Rice · in Torque Game Builder · 06/01/2006 (6:52 am) · 2 replies

This seems to be basically fixed in RC1. However I still was able to create a concave collision poly with RC1, but i tried to replicate it several times but could not. So I guess it's fixed enough :-)

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

#1
06/03/2006 (10:04 am)
Alex, I have upped the console precision of Floating point values to 3 decimal places. This should be adequate for creating collision polygons. If you'd like to test it you can do the following below and let me know.

open up t2dUtility.cc and replace from line 160 or so down to look like this

//////////////////////////////////////////////////////////////////////////
// TypePoint2FVector
//////////////////////////////////////////////////////////////////////////
ConsoleType( point2FList, TypePoint2FVector, sizeof(Vector<Point2F>) )

ConsoleGetType( TypePoint2FVector )
{
   Vector<Point2F> *vec = (Vector<Point2F> *)dptr;
   char* returnBuffer = Con::getReturnBuffer( vec->size() * 64 );
   S32 maxReturn = 1024;
   returnBuffer[0] = '[[60c1ed2bc5510]]';
   S32 returnLeng = 0;
   for (Vector<Point2F>::iterator itr = vec->begin(); itr != vec->end(); itr++)
   {
      // concatenate the next value onto the return string
      dSprintf(returnBuffer + returnLeng, maxReturn - returnLeng, "%[b]4.3g %4.3[/b]g ", (*itr).x, (*itr).y);
      // update the length of the return string (so far)
      returnLeng = dStrlen(returnBuffer);
   }
   // trim off that last extra space
   if (returnLeng > 0 && returnBuffer[returnLeng - 1] == ' ')
      returnBuffer[returnLeng - 1] = '[[60c1ed2bc5510]]';
   return returnBuffer;
}

ConsoleSetType( TypePoint2FVector )
{
   Vector<Point2F> *vec = (Vector<Point2F> *)dptr;
   // we assume the vector should be cleared first (not just appending)
   vec->clear();
   if(argc == 1)
   {
      const char *values = argv[0];
      const char *endValues = values + dStrlen(values);
      Point2F value;
      // advance through the string, pulling off S32's and advancing the pointer
      while (values < endValues && dSscanf(values, "%[b]4.3g %4.3[/b]g", &value.x, &value.y) != 0)
      {
         vec->push_back(value);
         const char *nextSeperator = dStrchr(values, ' ');
         if( !nextSeperator )
            break;
         const char *nextValues = dStrchr(nextSeperator + 1, ' ');
         if (nextValues != 0 && nextValues < endValues)
            values = nextValues + 1;
         else
            break;
      }
   }
   else if (argc > 1)
   {
      for (S32 i = 0; i < (argc - 1); i += 2)
         vec->push_back(Point2F(dAtof(argv[i]), dAtof(argv[i + 1])));
   }
   else
      Con::printf("Vector<Point2F> must be set as { a, b, c, ... } or \"a b c ...\"");
}


then open up mathTypes.cc and around line 38 change the TypePoint2F definition to look like follows.

//////////////////////////////////////////////////////////////////////////
// TypePoint2F
//////////////////////////////////////////////////////////////////////////
ConsoleType( Point2F, TypePoint2F, sizeof(Point2F) )

ConsoleGetType( TypePoint2F )
{
   Point2F *pt = (Point2F *) dptr;
   char* returnBuffer = Con::getReturnBuffer(256);
   dSprintf(returnBuffer, 256, "%[b]4.3g %4.3[/b]g", pt->x, pt->y);
   return returnBuffer;
}

ConsoleSetType( TypePoint2F )
{
   if(argc == 1)
      dSscanf(argv[0], "%[b]4.3g %4.3[/b]g", &((Point2F *) dptr)->x, &((Point2F *) dptr)->y);
   else if(argc == 2)
      *((Point2F *) dptr) = Point2F(dAtof(argv[0]), dAtof(argv[1]));
   else
      Con::printf("Point2F must be set as { x, y } or \"x y\"");
}

Cheers,
-Justin
#2
06/03/2006 (11:08 pm)
Thanks Justin, I had a hard time replicating the bug in RC1, so I thought it had been fixed already. I'll try recompiling with this change later this week.