Game Development Community

Porting Laser to TGEA - Done

by James Laker (BurNinG) · in Torque Game Engine Advanced · 01/24/2007 (3:57 am) · 28 replies

Hey there.

Me again. I'm trying to port the Continious Laser resource over to TGEA. Now I know I should debug it... but thats a looong story (Only have Visual Studio 2005 at work atm).

I've managed to get it to compile without errors, and it does fire the laser. I can even see the laser for like a fraction of a second, and then it crashes. I

Im thinking its in the rendering code, and would like you to just glance through this and tell me if you see any errors ive made in the porting process:

void Laser::renderObject(SceneState* state, RenderInst *ri)
{
   
	//AssertFatal(dglIsInCanonicalState(), "Error, GL not in canonical state on entry");

   //RectI viewport;
   //glMatrixMode(GL_PROJECTION);
   //glPushMatrix();
   //dglGetViewport(&viewport);

	RectI viewport = GFX->getViewport();
	MatrixF projection = GFX->getProjectionMatrix();
	MatrixF world = GFX->getWorldMatrix();
	MatrixF view = GFX->getViewMatrix();

	//GFX->disableShaders();
	state->setupBaseProjection();

   // Uncomment this if this is a "simple" (non-zone managing) object
   state->setupObjectProjection(this);
	GFX->setProjectionMatrix(projection);

   //prepModelView( state );
   //glScalef( mDataBlock->scale.x, mDataBlock->scale.y, mDataBlock->scale.z );

   if(mProjectileShape)
   {
      AssertFatal(mProjectileShape != NULL,
                  "Laser::renderObject: Error, projectile shape should always be present in renderObject");
      mProjectileShape->selectCurrentDetail();
      mProjectileShape->animate();

      Point3F cameraOffset;
      mObjToWorld.getColumn(3,&cameraOffset);
      cameraOffset -= state->getCameraPosition();
      F32 fogAmount = state->getHazeAndFog(cameraOffset.len(),cameraOffset.z);

      if (mFadeValue == 1.0) {
         mProjectileShape->setupFog(fogAmount, state->getFogColor());
      } else {
         mProjectileShape->setupFog(0.0, state->getFogColor());
         mProjectileShape->setAlphaAlways(mFadeValue * (1.0 - fogAmount));
      }
      mProjectileShape->render();
   }
<---------------- GLUE --------------- >
Page «Previous 1 2
#1
01/24/2007 (3:57 am)
<----------- GLUE -------------------->

//glDisable(GL_BLEND);					---> Check fxLight.cpp for reference
	GFX->setAlphaBlendEnable(false);

	//glDisable(GL_TEXTURE_2D);			---> Check fxLight.cpp for reference
	GFX->setLightingEnable(false);

   //glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);   ---> Check fxLight.cpp for reference
	//GFX->setTextureStageColorOp(0, GFXTOPDisable);
	//OR
	GFX->setTextureStageColorOp(0, GFXTOPSelectARG1);
	GFX->setTextureStageColorArg1(0, GFXTATexture);
	GFX->setTextureStageColorOp(1, GFXTOPDisable);

   //glMatrixMode(GL_PROJECTION); ---> Check fxLight.cpp for reference
	//glPopMatrix();
	GFX->setProjectionMatrix(projection);
	GFX->popWorldMatrix();	
   
   //glMatrixMode(GL_MODELVIEW);
	GFX->setViewMatrix(view);

   //dglSetViewport(viewport);
	GFX->setViewMatrix(view);

   // Debugging Bounding Box

   if (!mProjectileShape || gShowBoundingBox) {

      //glDisable(GL_DEPTH_TEST);
		GFX->setZEnable(true);
		GFX->setZWriteEnable(true);

      Point3F box;
      //glPushMatrix();
		GFX->pushWorldMatrix();

      //dglMultMatrix(&getRenderTransform());
		//GFX->multWorld(&getRenderTransform());

      //box = (mObjBox.min + mObjBox.max) * 0.5;
      //glTranslatef(box.x,box.y,box.z);

      //box = (mObjBox.max - mObjBox.min) * 0.5;
      //glScalef(box.x,box.y,box.z);
      //glColor3f(1, 0, 1);
      //wireCube(Point3F(1,1,1),Point3F(0,0,0));
      //glPopMatrix();

      //glPushMatrix();
      //box = (mWorldBox.min + mWorldBox.max) * 0.5;
      //glTranslatef(box.x,box.y,box.z);
      //box = (mWorldBox.max - mWorldBox.min) * 0.5;                               
      //glScalef(box.x,box.y,box.z);
      //glColor3f(0, 1, 1);
      //wireCube(Point3F(1,1,1),Point3F(0,0,0));
      //glPopMatrix();
      //glEnable(GL_DEPTH_TEST);
   }

   if(true) 
   {
      S32 thisTime = Sim::getCurrentTime();
	  S32 timeDelta = thisTime - mLastTime;
	  if (timeDelta > mDataBlock->interval)
	  {
 	     mIndex ++;
		 if (mIndex >= mNumTextures)
		    mIndex = 0;
	  }

      Point3F mMuzzlePosition;
      Point3F mMuzzleVector;

      if (bool(mSourceObject))
      {
         MatrixF muzzleTrans;
	     mSourceObject->getMuzzleTransform(mSourceObjectSlot, &muzzleTrans);
	     muzzleTrans.getColumn(3, &mMuzzlePosition);
	     mSourceObject->getMuzzleVector(mSourceObjectSlot, &mMuzzleVector);
	  }
	  
      // Sang -> 'billboarding' calculations
	  Point3F clientView = state->getCameraPosition();
	  Point3F clientVec = clientView - mMuzzlePosition;
	  clientVec.normalize();
	  
	  Point3F crossA, crossB;

	  mCross(clientVec, mMuzzleVector, crossA);
	  mCross(mMuzzleVector, clientVec, crossB);
     crossA.normalize();
	  crossB.normalize();

	  Point3F sPt1, sPt2, ePt1, ePt2;
	  

      switch(1)
	  {
	     case 0:
			 break;
		 
		 case 1:
				sPt1 = (crossA * mDataBlock->beamStartRadius) + mMuzzlePosition;
	         sPt2 = (crossB * mDataBlock->beamStartRadius) + mMuzzlePosition;
	         ePt1 = (crossA * mDataBlock->beamEndRadius) + mCurrPosition;
	         ePt2 = (crossB * mDataBlock->beamEndRadius) + mCurrPosition;

 			 // Setup our rendering state (alpha blending).
	         //glEnable(GL_BLEND);
				GFX->setAlphaBlendEnable(true);

	         //glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
				GFX->setSrcBlend(GFXBlendSrcAlpha);
				GFX->setDestBlend(GFXBlendInvSrcAlpha);

	         // Enable Texturing.
	         //glEnable(GL_TEXTURE_2D);  ---> Check tsLastDetail.cpp for reference
				GFX->setTextureStageColorOp(0, GFXTOPModulate);
				GFX->setTextureStageColorOp(1, GFXTOPDisable);

	         // Select the objects' texture.
			 //glBindTexture(GL_TEXTURE_2D, mTextureHandles[mIndex].getGLName());  ---> Check fxFoilageReplicator.cpp for reference
				GFX->setTexture(0, mTextureHandles[mIndex]);

			 // Set Colour/Alpha.
	         //glColor4f(1,1,1,1); ---> Check tsLastDetail.cpp for reference
				PrimBuild::color4f(1,1,1,1);
				
				//glBegin(GL_QUADS);  ---> Check fxlight.cpp for reference
				PrimBuild::begin(GFXTriangleFan, 4);
				//glTexCoord2f(0,0);
				PrimBuild::texCoord2f(0, 0);
				//glVertex3f(sPt1.x, sPt1.y, sPt1.z);   
				PrimBuild::vertex3f(sPt1.z, sPt1.y, sPt1.z);
				//glTexCoord2f(1,0);
				PrimBuild::texCoord2f(1, 0);
				//glVertex3f(sPt2.x, sPt2.y, sPt2.z);
				PrimBuild::vertex3f(sPt2.z, sPt2.y, sPt2.z);
				//glTexCoord2f(1,1);
				PrimBuild::texCoord2f(1, 1);
				//glVertex3f(ePt2.x, ePt2.y, ePt2.z);
				PrimBuild::vertex3f(ePt2.x, ePt2.y, ePt2.z);
				//glTexCoord2f(0,1);
				PrimBuild::texCoord2f(0, 1);
				//glVertex3f(ePt1.x, ePt1.y, ePt1.z);
				PrimBuild::vertex3f(ePt1.x, ePt1.y, ePt1.z);
				//glEnd();
				PrimBuild::end();                                   
                

			 // Restore our canonical rendering state.
	         //glDisable(GL_BLEND);
				GFX->setAlphaBlendEnable(false);
	         //glDisable(GL_TEXTURE_2D);
				GFX->setLightingEnable(false);
			 break;
		 
		 default:
			 break;
	  }
   }

   //dglSetCanonicalState();
   //AssertFatal(dglIsInCanonicalState(), "Error, GL not in canonical state on exit");
}
#2
01/24/2007 (7:06 am)
Okay... I've changed some of the values.

Still have this problem:
burningza.googlepages.com/Screenshot_LaserProb.jpg
Will post new file when I get back to work again, so you (anyone???) can look at it for me, please!
#3
01/24/2007 (8:10 am)
I'll bet my left foot (ouch) that it has to do with the primBuilder or how you begin/end states.

Can't help much, good luck.
#4
01/24/2007 (9:00 am)
If it crashes after a while it might be a matrix stack overflow issue. Check your for incomplete matrix push/pop blocks.
#5
01/24/2007 (9:57 pm)
Thanx for the replies... I fixed the crashing. So It doesn't crash anymore.

The problem is with the offset off the lasers. There should be 2 lasers like in the picture, so that's right. And it shoots to the correct place... I can kill my target.

I'll try to play around with some other values, today.
#6
02/17/2007 (3:35 pm)
Dunno if you fixed this... but you have 2 typos that are causing your offset issue.

//glVertex3f(sPt1.x, sPt1.y, sPt1.z);   
				PrimBuild::vertex3f(sPt1.z, sPt1.y, sPt1.z);
				//glTexCoord2f(1,0);
				PrimBuild::texCoord2f(1, 0);
				//glVertex3f(sPt2.x, sPt2.y, sPt2.z);
				PrimBuild::vertex3f(sPt2.z, sPt2.y, sPt2.z);

Should read:

//glVertex3f(sPt1.x, sPt1.y, sPt1.z);   
				PrimBuild::vertex3f(sPt1.x, sPt1.y, sPt1.z);
				//glTexCoord2f(1,0);
				PrimBuild::texCoord2f(1, 0);
				//glVertex3f(sPt2.x, sPt2.y, sPt2.z);
				PrimBuild::vertex3f(sPt2.x, sPt2.y, sPt2.z);
#7
02/18/2007 (10:45 pm)
Can you please post the updated files for this? thanks.
#8
02/19/2007 (12:23 am)
Yes Bryce I fixed that, thanx... ;)

This doesn't work in TGEA 1.0. It did however work in TGEA MS4. It fires, but crashes again right after.

laser.cc
#9
02/23/2007 (4:59 am)
Thanks!
#10
03/04/2007 (2:05 am)
You ever get this working in 1.0?
#11
03/07/2007 (3:19 am)
Nope. Couldn't find what was causing the crash, so I just moved past that for now.
#12
03/07/2007 (5:25 pm)
Email me.

cogburn AT versusthegame DOT com
#13
03/15/2007 (1:14 am)
Find it here: laser.cc

Fanx for all the help!
#14
03/15/2007 (9:58 am)
So this latest laser.cc is fully working on 1.0?

www.linkedin.com/img/webpromo/btn_viewmy_160x25.gif

www.mmogamedev.info/images/imgdc_ad1.gif
#15
03/15/2007 (10:29 am)
Yep... been working for quite some time... hehe... I forgot to make the Projectile.cpp changes when I moved over to TGEA v1.
#16
03/16/2007 (9:10 am)
I'm still looking to make this a little more TGEA. Shader effects on the lasers themselves would just look damn good.

I've got hooks for it in, but I'm not satisfied with the implementation. I think I might just release the changes as-is and move on to fxGrass.
#17
01/21/2008 (12:57 am)
@Bryce
It would be great, if we can see any glow effect attached laser on TGEA. :-)
#18
11/29/2008 (1:49 pm)
If you are using max you can export an actual shape object and set the skin to not use environment lighting. Basically a "full lit or bright" object.
#19
02/08/2009 (10:28 pm)
is the laser.cc resource still available?
I am porting over from TGE to TGEA 1.0.3 first, then 1.8.1

#20
02/08/2009 (10:32 pm)
I've managed to fix this laser ages ago... and got help to even add Interpolation. I haven't worked on TGEA for quite a while now however, so I'll have to dig it up.
Page «Previous 1 2