Game Development Community

Custom water...

by kc_0045 · in Torque Game Engine · 04/15/2006 (1:14 pm) · 4 replies

Hello, Im trying to add custom water to my game using the fxRenderobject, but for some reason i cant seem to get the rendering part to work correctly. If all the values are 0 for each point it renders fine, But if even one is changed it goes all crazy and i cant figure out why. Heres some pictures.

1 Is changed...
[IMG]http://img98.imageshack.us/img98/592/screenshot002000016ll.th.png[/IMG]

All the same...
[IMG]http://img424.imageshack.us/img424/2631/screenshot003000013el.th.jpg[/IMG]

and my rendering code is...

void fxRenderObject::renderObject(SceneState* state, SceneRenderImage*)
{
	// Check we are in Canonical State.
	AssertFatal(dglIsInCanonicalState(), "Error, GL not in canonical state on entry");
	// Calculate Elapsed Time and take new Timestamp.
	S32 Time = Platform::getVirtualMilliseconds();
	F32 ElapsedTime = (Time - mLastRenderTime) * 0.001f;
	mLastRenderTime = Time;
	// Return if we don't have a texture.
	if (!mTextureHandle) return;
	// Save state.
	RectI viewport;
	// Save Projection Matrix so we can restore Canonical state at exit.
	glMatrixMode(GL_PROJECTION);
	glPushMatrix();
	// Save Viewport so we can restore Canonical state at exit.
	dglGetViewport(&viewport);
    state->setupBaseProjection();
	// Save ModelView Matrix so we can restore Canonical state at exit.
	glPushMatrix();
	// Transform by the objects' transform e.g move it.
	dglMultMatrix(&getTransform());
	glRotatef(180.0f, 1,0,0);
	// Setup our rendering state (alpha blending).
	glEnable(GL_BLEND);
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
	// Enable Texturing.
	glDisable(GL_TEXTURE_2D);
	// Select the objects' texture.
	//glBindTexture(GL_TEXTURE_2D, mTextureHandle.getGLName());
	glPolygonMode( GL_FRONT, GL_LINE );
	// Set Colour/Alpha.
	glColor4f(1,0,0,1);
	
    int x, y; 
    
    F32 n;
    for(x=1;x<99;x++)
    {
        for(y=1;y<99;y++)
        {
            n=((mVHeight[x-1][y] +
                    mVHeight[x+1][y] +
                    mVHeight[x][y-1] +
                    mVHeight[x][y+1] )/2) -
                    PreviousResultMap[x][y];
            n=n-(n/16.0f);
            PreviousResultMap[x][y]=mVHeight[x][y];
            mVHeight[x][y]=n;
                   
        }
    }  
    
    for(x = 0; x < 100; x++)
    {
       glBegin(GL_QUAD_STRIP);
       for(y = 0; y < 100; y++)
       {
          glVertex3f(x, y,5);//mVHeight[x][y]);
          glVertex3f(x + 1,y,5);// mVHeight[x+1][y]); 
       }
       glEnd();
    }
    
	// Restore our canonical rendering state.
	glDisable(GL_BLEND);
	glDisable(GL_TEXTURE_2D);
	glPolygonMode (GL_FRONT, GL_FILL);
	// Restore our canonical matrix state.
	glPopMatrix();
	glMatrixMode(GL_PROJECTION);
	glPopMatrix();
	glMatrixMode(GL_MODELVIEW);
	// Restore our canonical viewport state.
	dglSetViewport(viewport);

	// Check we have restored Canonical State.
	AssertFatal(dglIsInCanonicalState(), "Error, GL not in canonical state on exit");
}
Any ideas?

#1
04/15/2006 (1:30 pm)
Just based on the images and without looking too closely at the code, it looks like your variables aren't setup right and all the vertices are being modified as the same point, but I ain't too keen on lookin' real close at mathy stuff.
#2
04/15/2006 (3:38 pm)
Ok, i dont have accese to how i setup the varables Right now, but just to make this clear that all thoose lines that are collecting togethers are always over the cursor, im not just aimed at the spot they collect they follow it around :S
#3
04/15/2006 (3:56 pm)
Ok, in the fxRenderobject.h i have
F32                      	mVHeight[100][100];
F32                             PreviousResultMap[100][100];
In the Protected Area

In fxrendorobject.cc
fxRenderObject::onAdd()
int x,y;
for(x = 0; x < 100; x++)
for(y = 0; y < 100; y++) {
    mVHeight[x][y]=0.0f;
    PreviousResultMap[x][y]=0.0f;
}

Just to make sure they are 0 and dont cause problems.


And thats pretty much it, Any ideas?(And thanks)
#4
04/16/2006 (6:03 pm)
Ok, i got everything working that was going wrong before, But im still having one problem with ConsoleMethod's

ConsoleMethod( fxRenderObject, SetHeight, void, 5, 5, "(int x,int y, F32 amount)")
{
   object->SetHeightc(dAtoi(argv[2]),dAtoi(argv[3]),dAtof(argv[4]));
}
Is there anything wrong with that? the SetHeightc function works fine, but if i try it from the console it doesnt work :S

void fxRenderObject::SetHeightc(int x,int y,F32 am) 
{ 
     mVHeight[x][y]=am;  
}
and in the .h file void SetHeightc(int x,int y,F32 am); is under the public tab of class fxRenderObject : public SceneObject

Edit: sorry for the triple post :P