Game Development Community

Porting Assitance

by Taylor Petrick · in Torque Game Engine Advanced · 04/10/2009 (3:04 am) · 4 replies

I've nearly finished porting some code from TGE to TGEA 1.8.1, and need a little help with the RenderObject function. I've got it ported and running, but any time the object is in view the terrain will flicker and change shape slightly.

Original RenderObject function:
void ClothItem::renderObject(SceneState* state, SceneRenderImage* image)
{
 
  Parent::renderImage(state, image);
       int i, j;
       if (!mTextureHandle) return;
       RectI viewport;
       glMatrixMode(GL_PROJECTION);
       glPushMatrix();
       dglGetViewport(&viewport);

       state->setupBaseProjection();
       glPushMatrix();
       dglMultMatrix(&getTransform());
       glEnable(GL_TEXTURE_2D);
       glBindTexture(GL_TEXTURE_2D, mTextureHandle.getGLName());
       glColor4f(1,1,1,1);
       for(i = 0; i < CLOTH_RESOLUTION - 1; i++)
       {
               glBegin(GL_TRIANGLE_STRIP);
               for(j = 0; j < CLOTH_RESOLUTION; j++)
               {
                       glNormal3fv(&(mNormals[3 * ((i + 1) * CLOTH_RESOLUTION + j)]));
                       glTexCoord2f(((float)j) / (CLOTH_RESOLUTION - 1), ((float)(i + 1)) / (CLOTH_RESOLUTION - 1));
                       glVertex3fv(&(mCurrentcloth[4 * ((i + 1) * CLOTH_RESOLUTION + j)]));
                       glNormal3fv(&(mNormals[3 * (i * CLOTH_RESOLUTION + j)]));
                       glTexCoord2f(((float)j) / (CLOTH_RESOLUTION - 1), ((float)i) / (CLOTH_RESOLUTION - 1));
                       glVertex3fv(&(mCurrentcloth[4 * (i * CLOTH_RESOLUTION + j)]));
               }
               glEnd();
       }
       glDisable(GL_TEXTURE_2D);
       glPopMatrix();
       glMatrixMode(GL_PROJECTION);
       glPopMatrix();
       glMatrixMode(GL_MODELVIEW);
       dglSetViewport(viewport);
}

My ported version:

void ClothItem::renderObject(ObjectRenderInst *ri, BaseMatInstance* overrideMat)
{  
       int i, j;

       if (!mTextureHandle) return;

       RectI viewport;

       MatrixF projection = GFX->getProjectionMatrix();
       GFX->setProjectionMatrix(projection);
       GFX->pushWorldMatrix();

       MatrixF view = GFX->getViewMatrix();

       //state->setupBaseProjection();
       MatrixF world = GFX->getWorldMatrix();
	   GFX->pushWorldMatrix();
       GFX->multWorld(getTransform());

       //GFX->setTextureStageColorOp(0, GFXTOPModulate);

       GFX->setTexture(0, mTextureHandle);

       PrimBuild::color4f(1,1,1,1);

       for(i = 0; i < CLOTH_RESOLUTION - 1; i++)
       {
               PrimBuild::begin(GFXTriangleStrip, 100);
               for(j = 0; j < CLOTH_RESOLUTION; j++)
               {
                       PrimBuild::texCoord2f(((float)j) / (CLOTH_RESOLUTION - 1), ((float)(i + 1)) / (CLOTH_RESOLUTION - 1));
                       PrimBuild::vertex3fv(&(mCurrentcloth[4 * ((i + 1) * CLOTH_RESOLUTION + j)]));
                       PrimBuild::texCoord2f(((float)j) / (CLOTH_RESOLUTION - 1), ((float)i) / (CLOTH_RESOLUTION - 1));
                       PrimBuild::vertex3fv(&(mCurrentcloth[4 * (i * CLOTH_RESOLUTION + j)]));
               }
               PrimBuild::end();
       }
       GFX->popWorldMatrix();
       GFX->setProjectionMatrix(projection);
       GFX->popWorldMatrix();
       GFX->setViewMatrix(view);
       GFX->setViewport(viewport);

	Parent::renderObject(ri,overrideMat);
}

I'm probably just missing something silly.



#1
04/10/2009 (6:39 am)
Scratch that, I got it working. ;)
#2
04/10/2009 (8:15 am)
Glad we could help :)
#3
04/10/2009 (9:45 am)
Resource?
#4
04/10/2009 (10:12 am)
I'm working on a port of the fxClothItem to TGEA 1.8.1, as well as adding in some additional stuff.

The cloth object is just a set of verts that are rendered by PrimBuild, and physics calculations are done with Verlet Integration. What would be the best way to add collision? OPCode?

Here's the link to the original resource:
www.garagegames.com/community/resource/view/8942