Game Development Community

How to get fxShapeReplicator work

by Vincent BILLET · in Torque Game Engine Advanced · 10/19/2005 (11:20 pm) · 16 replies

I post this message here, because I think many peaople want to have tests with fxShapeReplicator. Unfortunately it don't work with current HEAD version.

So, firstly add fxShapeReplicator.cpp and .h to your project.

open fxShapeReplicator.cpp and comment the first include :
#include "dgl/dgl.h"
to
//#include "dgl/dgl.h"

finally, comment the whole function "void fxShapeReplicator::renderObject(SceneState* state, SceneRenderImage*)". Leave no lines of code in this function.

Build your TSE, and play with fxShapeReplicator. It works !

I know, it's not an optimized version for TSE, but it allow you to make tests ;).

#1
10/20/2005 (3:41 am)
Stupid question: What is fxShapeReplicator? I'm guessing its to place grass and such, but I haven't had a chance to use it yet so thats just a guess :-P
#2
10/21/2005 (5:04 am)
FxShapeReplicator is, like, a VITAL component for outdoor level building. Place one of those in the level, and it'll replicate a given DTS shape randomly inside a given radius, with lots of parameters. It makes your .MIS file a lot smaller, since you can easily fill up a large area with hundreds of TSStatics by using a single object. Not to mention you get a more organically-looking distribution for things like rocks and trees, since you can set it up to randomly scale and rotate them within given ranges (something you'd need to do manually for each shape).

It's so usefull we modified it in our games to replicate things along lines, rectangular areas and circles. With some extra coding it's possible to get things replicating along a path, but I haven't done that yet.
#3
10/21/2005 (5:46 am)
Manoel is completely correct, but he missed the most important savings (and challenge as well to work within)--only the ShapeReplicator object itself is networked, not each shape. In that way, you cut down on your bandwidth considerably and still get the ability to have dozens/hundreds of objects managed.
#4
10/21/2005 (7:18 am)
www.solu-si.com/dragonhead/gg/_sr02.jpgThis scene contains 2 fxReplicator objects (1 for grass, one for trees)
#5
10/21/2005 (10:05 am)
When I try to delete a replicator in the World Editor Inspector (by selecting it and pressing the delete key) the program dies or freezes. Is there a fix or workaround for this? Thanks.
#6
10/21/2005 (10:25 am)
I believe the editor troubles are related to the 'new' tree control, and not the replicator. Ever since the TGE 1.4 editor was partially merged into TSE, we've had occasional crashes when deleting. It doesn't seem to matter what type of object it is, nor is it a guaranteed, reproducable crash.
#7
10/22/2005 (8:24 am)
Ok, thanks Erik.
#8
10/23/2005 (12:21 pm)
I tried putting on this fix, but I got the following link error, any idea how to fix this?

Linking...
fxShapeReplicator.obj : error LNK2001: unresolved external symbol "public: virtual void __thiscall fxShapeReplicator::renderObject(class SceneState *,class SceneRenderImage *)" (?renderObject@fxShapeReplicator@@UAEXPAVSceneState@@PAVSceneRenderImage
@@@Z)
../example/TSE.exe : fatal error LNK1120: 1 unresolved externals
#9
10/23/2005 (12:25 pm)
Replace your void fxShapeReplicator::renderObject(SceneState* state, SceneRenderImage*) function with this ;)
void fxShapeReplicator::renderObject(SceneState* state, SceneRenderImage*)
{
	// Return if placement area not needed.
	if (!mFieldData.mShowPlacementArea) return;

	// Check we are in Canonical State.
/*AssertFatal(dglIsInCanonicalState(), "Error, GL not in canonical state on entry");

	// Setup out the Projection Matrix/Viewport.
	RectI viewport;
	glMatrixMode(GL_PROJECTION);
	glPushMatrix();
	dglGetViewport(&viewport);
	state->setupBaseProjection();

	// Setup our rendering state.
	glPushMatrix();
	dglMultMatrix(&getTransform());
	glEnable(GL_BLEND);
	glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);

	// Do we need to draw the Inner Radius?
	if (mFieldData.mInnerRadiusX || mFieldData.mInnerRadiusY)
	{
		// Yes, so draw Inner Radius.
		glBegin(GL_TRIANGLE_STRIP);
		for (U32 Angle = mCreationAreaAngle; Angle < (mCreationAreaAngle+360); Angle++)
		{
			F32		XPos, YPos;

			// Calculate Position.
			XPos = mFieldData.mInnerRadiusX * mCos(mDegToRad(-(F32)Angle));
			YPos = mFieldData.mInnerRadiusY * mSin(mDegToRad(-(F32)Angle));

			// Set Colour.
			glColor4f(	mFieldData.mPlaceAreaColour.red,
						mFieldData.mPlaceAreaColour.green,
						mFieldData.mPlaceAreaColour.blue,
						AREA_ANIMATION_ARC * (Angle-mCreationAreaAngle));

			// Draw Arc Line.
			glVertex3f(	XPos, YPos, -(F32)mFieldData.mPlacementBandHeight/2.0f);
			glVertex3f(	XPos, YPos, +(F32)mFieldData.mPlacementBandHeight/2.0f);

		}
		glEnd();
	}

	// Do we need to draw the Outer Radius?
	if (mFieldData.mOuterRadiusX || mFieldData.mOuterRadiusY)
	{
		// Yes, so draw Outer Radius.
		glBegin(GL_TRIANGLE_STRIP);
		for (U32 Angle = mCreationAreaAngle; Angle < (mCreationAreaAngle+360); Angle++)
		{
			F32		XPos, YPos;

			// Calculate Position.
			XPos = mFieldData.mOuterRadiusX * mCos(mDegToRad(-(F32)Angle));
			YPos = mFieldData.mOuterRadiusY * mSin(mDegToRad(-(F32)Angle));

			// Set Colour.
			glColor4f(	mFieldData.mPlaceAreaColour.red,
						mFieldData.mPlaceAreaColour.green,
						mFieldData.mPlaceAreaColour.blue,
						AREA_ANIMATION_ARC * (Angle-mCreationAreaAngle));

			// Draw Arc Line.
			glVertex3f(	XPos, YPos, -(F32)mFieldData.mPlacementBandHeight/2.0f);
			glVertex3f(	XPos, YPos, +(F32)mFieldData.mPlacementBandHeight/2.0f);

		}
		glEnd();
	}

	// Restore rendering state.
	glDisable(GL_BLEND);
	glPopMatrix();

	// Animate Area Selection.
	mCreationAreaAngle += 20;
	mCreationAreaAngle = mCreationAreaAngle % 360;

	// Restore out nice and friendly canonical state.
	glMatrixMode(GL_PROJECTION);
	glPopMatrix();
	glMatrixMode(GL_MODELVIEW);
	dglSetViewport(viewport);

	// Check we have restored Canonical State.
	AssertFatal(dglIsInCanonicalState(), "Error, GL not in canonical state on exit");*/
}
#10
10/23/2005 (12:58 pm)
Thanks man, it works
#11
03/12/2007 (4:53 am)
Has anyone ported this to TGEA (v1.0)?
#12
03/12/2007 (5:14 am)
There is a resource in the code section of the site. Be sure to use the fix in the comments to get it workign with 1.0.
#13
03/12/2007 (3:27 pm)
Aaah... Shows up with advanced search :-/ Thanx
#14
03/27/2007 (8:46 am)
Hi guys... can i have the link? I tried to find it with no success :/

Tnx ^_^
JoZ
#15
03/28/2007 (1:27 am)
Still some rendering issues with Placement Arc, but otherwise it works great and is based off my updated resource for TGEA:
fxShapeReplicator.h
fxShapeReplicator.cc

If you experience any problems, pls let me know.

BTW! This is for TGEA v1.0
#16
03/28/2007 (1:56 am)
Tnx James i'll try it immediately :)
JoZ