Game Development Community

dev|Pro Game Development Curriculum

GuiRadarCtrl and GuiRadarTSCtrl port for T3D

by Sean Rice · 03/24/2010 (7:16 am) · 36 comments

Some credit for the original work!

www.torquepowered.com/community/resources/view/16417 3d spherical radar
www.torquepowered.com/community/resources/view/10333 Radar/Map/Compass

Download the files!www.filefront.com/15918935/radar.rar/

First the 3d Radar
Note: the sphere doesn't seem to want to render correctly. Sometimes it renders when you pop in the first control; although, any adjustment causes the sphere to disappear. Look at the link above to see how it is supposed to look. If anyone can give assistance for this aspect it would be greatly appreciated. Link is above for what it should look like.


source/gui/control/GuiRadarCtrl.cpp
//-----------------------------------------------------------------------------
// Torque Game Engine Advanced v1.0
// Copyright (C) GarageGames.com, Inc.
// Convertion to TGEA 1.8.1 with karakurty
//-----------------------------------------------------------------------------
#include "platform/platform.h"

#include "gui/core/guiControl.h"
#include "gfx/gfxDrawUtil.h"
#include "T3D/player.h"

#include "console/console.h"
#include "console/consoleTypes.h"
#include "gfx/gfxDevice.h"
#include "app/game.h"
#include "T3D/gameConnection.h"
#include "T3D/ShapeBase.h"
#include "gfx/primBuilder.h"

#include "gui/controls/GuiRadarCtrl.h"

IMPLEMENT_CONOBJECT(GuiRadarCtrl);

GuiRadarCtrl::GuiRadarCtrl(void)
{
	// Radar Background default
	mRadarBitmapName = StringTable->insert("art/gui/compass_map_radar/radar_base.png");

	// Blip defaults
	mBlipUpName = StringTable->insert("art/gui/compass_map_radar/dot_teal.png");
	mBlipBelowName = StringTable->insert("art/gui/compass_map_radar/dot_black.png");
	mBlipLevelName = StringTable->insert("art/gui/compass_map_radar/dot_red.png");
	mShowRadar = true;
	//mRadarWrap = false;
	mRadarRadiusRange = 100.0f;

	mLevelRange = 20.0f;

	// As default show only players
	mShowShapeBase = false;
	mShowVehicles = false;
	mShowPlayers = true;
    mShowBots = true;

	// Compass defaults
	mCompassBitmapName = StringTable->insert("art/gui/compass_map_radar/compass.png");
	mShowCompass = true;

	mCompassRotation = 0.0f;

	// <MH>
	// Map defaults
	mMapBitmapName = StringTable->insert("art/gui/compass_map_radar/scorchedPlanet.png");
	mShowMap = true;
	// </MH>

	mHideAll = false;
}


void GuiRadarCtrl::initPersistFields()
{
   Parent::initPersistFields();

    addGroup("Radar");
    addField("RadarBitmap",		TypeFilename,	  Offset(mRadarBitmapName,    GuiRadarCtrl));
    //addField("RadarWrap",		TypeBool,		  Offset(mRadarWrap,          GuiRadarCtrl));
    addField("blip_above",		TypeFilename,     Offset(mBlipUpName,         GuiRadarCtrl));
	addField("blip_below",		TypeFilename,     Offset(mBlipBelowName,      GuiRadarCtrl));
	addField("blip_level",		TypeFilename,     Offset(mBlipLevelName,      GuiRadarCtrl));
	addField("RadarRange",		TypeF32,		  Offset(mRadarRadiusRange,   GuiRadarCtrl));
	addField("ShowRadar",		TypeBool,		  Offset(mShowRadar,          GuiRadarCtrl));
	endGroup("Radar");
   
	addGroup("Compass");
	addField("CompassBitmap",	TypeFilename,	Offset(mCompassBitmapName, GuiRadarCtrl));
	addField("ShowCompass",		TypeBool,		Offset(mShowCompass,       GuiRadarCtrl),"Show Compass)");
    endGroup("Compass");		

	// <MH>
	addGroup("Map");
	addField("MapBitmap",		TypeFilename,	Offset(mMapBitmapName,    GuiRadarCtrl));
	addField("ShowMap",			TypeBool,		Offset(mShowMap,		  GuiRadarCtrl), "Show Map");
    endGroup("Map");	
	// </MH>
	
	addGroup("Misc");
	addField("RadarShowPlayers",	TypeBool,     Offset(mShowPlayers,     GuiRadarCtrl),"Show Players on Radar");
	addField("RadarShowVehicles",	TypeBool,     Offset(mShowVehicles,    GuiRadarCtrl),"Show Vehicles on Radar");
    addField("RadarShowBots",		TypeBool,     Offset(mShowBots,        GuiRadarCtrl),"Show Bots on Radar");
	addField("RadarShowShapeBase",	TypeBool,     Offset(mShowShapeBase,   GuiRadarCtrl),"Show All ShapeBase derived objects on Radar");
	addField("LevelRange",			TypeS32,      Offset(mLevelRange,      GuiRadarCtrl),"The height difference at which the Level blip is displayed");
	addField("HideAll",				TypeBool,     Offset(mHideAll,         GuiRadarCtrl));
	addField("ShowFrame",			TypeBool,     Offset(mShowFrame,       GuiRadarCtrl));
	endGroup("Misc");
}

ConsoleMethod( GuiRadarCtrl, setValue, void, 4, 4, "(int xAxis, int yAxis)"
              "Set the offset of the bitmap.")
{
	object->setValue(dAtoi(argv[2]), dAtoi(argv[3]));
}

ConsoleMethod( GuiRadarCtrl, setRadarBitmap, void, 3, 4, "(string filename, bool resize=false)"
               "Set the bitmap displayed in the control. Note that it is limited in size, to 256x256.")
{
   char fileName[1024];
   Con::expandScriptFilename(fileName, sizeof(fileName), argv[2]);
   object->setRadarBitmap(fileName, argc > 3 ? dAtob( argv[3] ) : false );
}

ConsoleMethod( GuiRadarCtrl, setRadarRange, void, 3, 3, "")
{
	Con::printf("Object->SetRadius = %f", dAtof(argv[2]));
	object->setRadius(dAtof(argv[2]));
}

bool GuiRadarCtrl::onWake()
{
   if (! Parent::onWake())
      return false;
   
	setActive(true);
    setRadarBitmap(mRadarBitmapName);
	setRadarUpBlipBitmap(mBlipUpName);
	setRadarBelowBlipBitmap(mBlipBelowName);
	setRadarLevelBlipBitmap(mBlipLevelName);
	setRadius(mRadarRadiusRange);
	setLevelRange(mLevelRange);
	setCompassBitmap(mCompassBitmapName);
	setMapBitmap(mMapBitmapName);

   return true;
}

void GuiRadarCtrl::onSleep()
{
    //Parent::onSleep();

    mRadarTextureObject = NULL;
	mRadarDot = NULL;
	mRadarUp = NULL;
	mRadarDown = NULL;

	mCompassTextureObject = NULL;
	mMapTextureObject = NULL;

    Parent::onSleep();
}

//-------------------------------------
void GuiRadarCtrl::inspectPostApply()
{
   // if the extent is set to (0,0) in the gui editor and appy hit, this control will
   // set it's extent to be exactly the size of the bitmap (if present)
   Parent::inspectPostApply();

   if ((getExtent().y == 0) && (getExtent().x == 0) && mRadarTextureObject)
   {
	   setExtent(mRadarTextureObject->getWidth(), mRadarTextureObject->getHeight());
   }

   if ((getExtent().y == 0) && (getExtent().x == 0) && mCompassTextureObject)
   {
	   //setExtent(mCompassTextureObject->getWidth(), mCompassTextureObject->getHeight());
   	   setExtent(mRadarTextureObject->getWidth(), mRadarTextureObject->getHeight());
   }

}

void GuiRadarCtrl::setRadarBitmap(const char *name, bool resize)
{
   mRadarBitmapName = StringTable->insert(name);
   if (*mRadarBitmapName)
	{
		mRadarTextureObject.set( mRadarBitmapName, &GFXDefaultGUIProfile, avar("%s() - mRadarTextureObject (line %d)", __FUNCTION__, __LINE__) );

      // Resize the control to fit the bitmap
      if( mRadarTextureObject && resize )
      {
	     setExtent(mRadarTextureObject->getWidth(), mRadarTextureObject->getHeight());
         updateSizing();

      }
   }
   else
      mRadarTextureObject = NULL;

   setUpdate();
}

void GuiRadarCtrl::setRadarLevelBlipBitmap(const char *name)
{
   mBlipLevelName = StringTable->insert(name);
   if (*mBlipLevelName)
		mRadarDot.set( mBlipLevelName, &GFXDefaultGUIProfile, avar("%s() - mRadarDot (line %d)", __FUNCTION__, __LINE__) );
   else
      mRadarDot = NULL;

   setUpdate();
}

void GuiRadarCtrl::setRadarUpBlipBitmap(const char *name)
{

   mBlipUpName = StringTable->insert(name);
   if (*mBlipUpName)
		mRadarUp.set( mBlipUpName, &GFXDefaultGUIProfile, avar("%s() - mRadarUp (line %d)", __FUNCTION__, __LINE__) );
   else
      mRadarUp = NULL;

   setUpdate();

}

void GuiRadarCtrl::setRadarBelowBlipBitmap(const char *name)
{

   mBlipBelowName = StringTable->insert(name);
   if (*mBlipBelowName)
		mRadarDown.set( mBlipBelowName, &GFXDefaultGUIProfile, avar("%s() - mRadarDown (line %d)", __FUNCTION__, __LINE__) );
   else
      mRadarDown = NULL;

   setUpdate();
}

void GuiRadarCtrl::setCompassBitmap(const char *name, bool resize)
{
   mCompassBitmapName = StringTable->insert(name);
   if (*mCompassBitmapName)
	{
		mCompassTextureObject.set( mCompassBitmapName, &GFXDefaultGUIProfile, avar("%s() - mCompassTextureObject (line %d)", __FUNCTION__, __LINE__) );

      // Resize the control to fit the bitmap
      if( mCompassTextureObject && resize )
      {
		 setExtent(mCompassTextureObject->getWidth(), mCompassTextureObject->getHeight());
         updateSizing();
      }
   }
   else
      mCompassTextureObject = NULL;

   setUpdate();
}

// <MH>
void GuiRadarCtrl::setMapBitmap(const char *name)
{
   mMapBitmapName = StringTable->insert(name);

   if (*mMapBitmapName)
		mMapTextureObject.set( mMapBitmapName, &GFXDefaultGUIProfile, avar("%s() - mMapTextureObject (line %d)", __FUNCTION__, __LINE__) );
   else
      mMapTextureObject = NULL;

   setUpdate();
}
// </MH>

void GuiRadarCtrl::setRadius(const F32 newRange)
{
	mRadarRadiusRange = newRange;
}

void GuiRadarCtrl::setLevelRange(const F32 newLevelRange)
{
	mLevelRange = newLevelRange;
}

void GuiRadarCtrl::setCompassRotation(const F32 rotation)
{
	mCompassRotation = rotation;
}

ConsoleMethod( GuiRadarCtrl, setCompassRotation, void, 3, 3, "")
{
	Con::printf("Object->SetRadius = %f", dAtof(argv[2]));
	object->setCompassRotation(dAtof(argv[2]));
}

float Vector3dToDegree(Point3F vector)
{
    float angle;
	if (vector.x == 0.0F)
    {
        if (vector.y > 0.0F)
            return 0.0F;
        else if (vector.y == 0.0F)
            return -1.0F;
        else
            return 180.0F;
    }
    if (vector.y == 0.0F)
    {
        if (vector.x < 0.0F)
            return 270.0F;
        else
            return 90.0F;
    }
    angle = atanf((vector.x) / (-vector.y)) * (180.0F / M_PI);
    if ((-vector.y) < 0.0F)
        return angle + 180.0F;
    else
    {
        if (vector.x > 0.0F)
            return angle;
        else
            return angle + 360.0F;
    }
}

// Conversion function, Degrees to vector (used after manipulating camera angle to represent angle of object on radar)
void DegreeToVector2d(float angle, float length, Point3F &vector)
{
	angle = (angle / 180.0F) * M_PI;
    vector.x = length * (sin(angle) );
	vector.y = length * (-cos(angle) );
}

void GuiRadarCtrl::onRender(Point2I offset, const RectI &updateRect)
{
	// Must have a connection
	GameConnection* conn = GameConnection::getConnectionToServer();
	if (!conn) return;
	// Must have controlled object
	GameBase* control = conn->getControlObject();
	if (!control) return;

	//Find distance from top-left corner to center of radar image 
	Point2F center(getExtent().x / 2, getExtent().y / 2); 

	F32 HW = getExtent().y / 2.0;

	//Make center the UI object's coordinate center 
	center.x += getBounds().point.x; 
	center.y += getBounds().point.y; 


    MatrixF cam;
	VectorF camDir;
	Point3F cameraRot;

    conn->getControlCameraTransform(0,&cam);	// store camera information
    cam.getColumn(3, &mMyCoords);				// get camera position
    cam.getColumn(1, &camDir);					// get camera vector
	cam.getRow(1,&cameraRot);					// get camera rotation

	// Remove Rotation around the X/Y axis
	//cameraRot.x = 0;
	//cameraRot.y = 0;
	
	cameraRot.neg();							// bug forces us to need to invert camera rotation angle

	// get angle that camera is facing
	float cameraAngle = Vector3dToDegree(cameraRot);

	if (mMapTextureObject && mShowMap)
    {
		GFX->getDrawUtil()->clearBitmapModulation();

        GFXTextureObject* texture = mMapTextureObject;

        setupStateBlocks();
        GFX->setStateBlock(mBeforeStateBlock);

		GFX->setTexture( 0, texture );
        GFX->disableShaders();
		
    	F32 width = getBounds().extent.x * 0.5;

		MatrixF rotMatrix(EulerF(0.0, 0.0, mDegToRad(cameraAngle)));

//		Point3F offset(offset.x + mBounds.extent.x / 2, offset.y + mBounds.extent.y / 2, 0.0);
		Point3F offset( offset.x + getBounds().extent.x / 2, offset.y + getBounds().extent.y / 2, 0.0);

		// The 8 will help model the scale of which the player moves across the map
		Point2F offsetTexture(mMyCoords.x / ((float)mMapTextureObject->getBitmapWidth() * 8), 
							 -mMyCoords.y / ((float)mMapTextureObject->getBitmapHeight() * 8));

//		F32 uvOffset = (float)mBounds.extent.x / (float)mMapTextureObject->getBitmapWidth() / 2;
		F32 uvOffset = (float)getBounds().extent.x / (float)mMapTextureObject->getBitmapWidth() / 2;

		// Octagons Vertices
		Point3F points[10];
		points[0] = Point3F(0.0f, 0.0f, 0.0f);
		points[1] = Point3F(0.0f, width, 0.0f);
		points[2] = Point3F(width * 0.7f, width * 0.7f, 0.0f);
		points[3] = Point3F(width, 0.0f, 0.0f);
		points[4] = Point3F(width * 0.7f, -width * 0.7f, 0.0f);
		points[5] = Point3F(0.0f, -width, 0.0f);
		points[6] = Point3F(-width * 0.7f, -width * 0.7f, 0.0f);
		points[7] = Point3F(-width, 0.0f, 0.0f);
		points[8] = Point3F(-width * 0.7f, width * 0.7f, 0.0f);
		points[9] = Point3F(0.0f, width, 0.0f);

		for (int i = 0; i < 10; i++)
		{
			rotMatrix.mulP(points[i]);
			points[i] += offset;
		}

		PrimBuild::color3f(1.0f, 1.0f, 1.0f);

		PrimBuild::begin(GFXTriangleFan, 10);
		PrimBuild::texCoord2f(offsetTexture.x + 0.0f, offsetTexture.y + 0.0f);
		PrimBuild::vertex3fv(points[0]);
		PrimBuild::texCoord2f(offsetTexture.x + 0.0f, offsetTexture.y + uvOffset);
		PrimBuild::vertex3fv(points[1]);
		PrimBuild::texCoord2f(offsetTexture.x + uvOffset * 0.7f, offsetTexture.y + uvOffset * 0.7f);
		PrimBuild::vertex3fv(points[2]);
		PrimBuild::texCoord2f(offsetTexture.x + uvOffset, offsetTexture.y + 0.0f);
		PrimBuild::vertex3fv(points[3]);
		PrimBuild::texCoord2f(offsetTexture.x + uvOffset * 0.7f, offsetTexture.y + -uvOffset * 0.7f);
		PrimBuild::vertex3fv(points[4]);
		PrimBuild::texCoord2f(offsetTexture.x + 0.0f, offsetTexture.y + -uvOffset);
		PrimBuild::vertex3fv(points[5]);
		PrimBuild::texCoord2f(offsetTexture.x + -uvOffset * 0.7f, offsetTexture.y + -uvOffset * 0.7f);
		PrimBuild::vertex3fv(points[6]);
		PrimBuild::texCoord2f(offsetTexture.x + -uvOffset, offsetTexture.y + 0.0f);
		PrimBuild::vertex3fv(points[7]);
		PrimBuild::texCoord2f(offsetTexture.x + -uvOffset * 0.7f, offsetTexture.y + uvOffset * 0.7f);
		PrimBuild::vertex3fv(points[8]);
		PrimBuild::texCoord2f(offsetTexture.x + 0.0f, offsetTexture.y + uvOffset);
		PrimBuild::vertex3fv(points[9]);
		PrimBuild::end();


		GFX->setStateBlock(mBlendDisabledStateBlock);
	}

	if (mRadarTextureObject && mShowRadar)
    {
        GFX->getDrawUtil()->clearBitmapModulation();

        RectI rect(offset, getExtent());
        GFX->getDrawUtil()->drawBitmapStretch(mRadarTextureObject, rect);
    }

	GFX->getDrawUtil()->clearBitmapModulation();

	GFXTextureObject* LevelBlip = (GFXTextureObject*) mRadarDot;
	GFXTextureObject* HighBlip = (GFXTextureObject*) mRadarUp;
	GFXTextureObject* LowBlip = (GFXTextureObject*) mRadarDown;	

	// Go through all ghosted objects on connection (client-side)
	for (SimSetIterator itr(conn); *itr; ++itr) {
      // Make sure that the object is a ShapeBase object
      if ((*itr)->getType() & ShapeBaseObjectType) {
         ShapeBase* shape = static_cast<ShapeBase*>(*itr);
		 // Make sure that the object isn't the client
		 if (shape != control  && shape->getShapeName()) { 
			// Make sure the ShapeBase object is a player

			 if (shape->getType()) {
					
				   //ONly check when ShapeBase is not selecting, we are after all iterating through ShapeBaseObjects
					if (!mShowShapeBase)
					{
						if (!mShowPlayers && shape->getType() == PlayerObjectType)
							continue;

						if (!mShowVehicles && shape->getType() == VehicleObjectType) 
							continue;

                        if (!mShowBots && shape->getType() == AIObjectType)
                            continue;
					}

					Point3F newCoord;
   					// Get coords of player object
					newCoord = shape->getPosition();

					// Find distance from point A (player object) to point B (client's player)
					VectorF shapeDir = newCoord - mMyCoords;

					// Test to see if player object in range (deal with squared objects in cheap way to use non-negative value)
					F32 shapeDist = shapeDir.lenSquared();
					if (shapeDist == 0 || shapeDist > (mRadarRadiusRange * mRadarRadiusRange))
						continue;

					// Convert map coordinates to screen coordinates
					newCoord.x -= mMyCoords.x;
					newCoord.y -= mMyCoords.y;
					newCoord.y = -newCoord.y;
					
					float coord_z = newCoord.z - mMyCoords.z; 

					newCoord.z = 0;

					// Adjust object's vector to represent rotation of camera
					float objectAngle = Vector3dToDegree(newCoord);
					float length = newCoord.len()*HW/mRadarRadiusRange;
					DegreeToVector2d(((360-objectAngle)+(cameraAngle) ), length, newCoord);
					
					newCoord.x = -newCoord.x;

					// Add tour calculation to the centre of the GuiControl
					newCoord.x += (center.x);
					newCoord.y += (center.y);
						
					// Draw radar blips based on height
					if(coord_z < F32(0 - mLevelRange)){
						if (LowBlip) 
						{
							GFX->getDrawUtil()->drawBitmap(LowBlip, Point2I(newCoord.x,newCoord.y));
						}
					}
					else if(coord_z > mLevelRange){
						if (HighBlip) 
						{
							GFX->getDrawUtil()->drawBitmap(HighBlip, Point2I(newCoord.x,newCoord.y));
						}
					}
					else{
						if (LevelBlip) 
						{
							GFX->getDrawUtil()->drawBitmap(LevelBlip, Point2I(newCoord.x,newCoord.y));
						}
					}
					}
				}
			}
		}

   if (mProfile->mBorder || !mRadarTextureObject)
   {
		if (mShowFrame)
		{
			RectI rect(offset.x, offset.y, getExtent().y, getExtent().x);
			GFX->getDrawUtil()->drawRect(rect, mProfile->mBorderColor);
		}
   }
	
   if (mCompassTextureObject && mShowCompass)
   {

		GFX->getDrawUtil()->clearBitmapModulation();

		GFXTextureObject* texture = mCompassTextureObject;

        setupStateBlocks();
        GFX->setStateBlock(mBeforeStateBlock);

		GFX->setTexture( 0, texture );
		GFX->disableShaders();

		F32 width = getExtent().y * 0.5;

		MatrixF rotMatrix( EulerF( 0.0, 0.0, mDegToRad(cameraAngle)));

		Point3F offset( offset.x + getExtent().y / 2,
			offset.y + getExtent().x / 2, 0.0);

		Point3F points[4];
		points[0] = Point3F(-width, -width, 0.0f);
		points[1] = Point3F(-width, width, 0.0f);
		points[2] = Point3F( width, width, 0.0f);
		points[3] = Point3F( width, -width, 0.0f);

		for(int i = 0; i < 4; i++)
		{
			rotMatrix.mulP( points[i] );
			points[i] += offset;
		}

		PrimBuild::color3f(1.0f,1.0f,1.0f);

		PrimBuild::begin(GFXTriangleFan, 4);
		PrimBuild::texCoord2f(0, 0);
		PrimBuild::vertex3fv(points[0]);
		PrimBuild::texCoord2f(0, 1);
		PrimBuild::vertex3fv(points[1]);
		PrimBuild::texCoord2f(1, 1);
		PrimBuild::vertex3fv(points[2]);
		PrimBuild::texCoord2f(1, 0);
		PrimBuild::vertex3fv(points[3]);
		PrimBuild::end();

		GFX->setStateBlock(mBlendDisabledStateBlock);

	}

   renderChildControls(offset, updateRect);
}

void GuiRadarCtrl::setupStateBlocks()
{
   if (mBeforeStateBlock.isNull())
   {
       GFXStateBlockDesc desc;
       
       desc.setCullMode(GFXCullNone);
       //desc.setZEnable(false);

       desc.setBlend(true, GFXBlendSrcAlpha, GFXBlendInvSrcAlpha);

       desc.samplersDefined = true;
       desc.samplers[0].textureColorOp = GFXTOPModulate;
       desc.samplers[1].textureColorOp = GFXTOPDisable;
	   desc.samplers[0].addressModeU = GFXAddressWrap;
       desc.samplers[0].addressModeV = GFXAddressWrap;

       mBeforeStateBlock = GFX->createStateBlock( desc );
   }

   if (mBlendDisabledStateBlock.isNull())
   {
      GFXStateBlockDesc desc;
      desc.setBlend(false, GFXBlendOne, GFXBlendZero);
      mBlendDisabledStateBlock = GFX->createStateBlock( desc );
   }

}

now source/gui/control/GuiRadarCtrl.h
//-----------------------------------------------------------------------------
// Torque Game Engine Advanced
// Copyright (C) GarageGames.com, Inc.
// Convertion to TGEA 1.8.1 with karakurty
//-----------------------------------------------------------------------------

#ifndef _GUIRADARCTRL_H_
#define _GUIRADARCTRL_H_

#ifndef _GUIBITMAPCTRL_H_
#include "gui/controls/guiBitmapCtrl.h"
#endif

/// Renders a bitmap.
class GuiRadarCtrl : public GuiBitmapCtrl //GuiControl
{
private:
	typedef /*GuiControl*/ GuiBitmapCtrl Parent;
	Point3F mMyCoords;

protected:
	// Radar
    StringTableEntry mRadarBitmapName;
	StringTableEntry mBlipUpName;
	StringTableEntry mBlipLevelName;
	StringTableEntry mBlipBelowName;

    GFXTexHandle mRadarTextureObject;
    GFXTexHandle mRadarDot;
    GFXTexHandle mRadarUp;
    GFXTexHandle mRadarDown;

	bool mShowRadar;

	bool mShowVehicles;
	bool mShowPlayers;
	bool mShowShapeBase;
    bool mShowBots;
	bool mShowFrame;

	F32 mLevelRange;
	F32 mRadarRadiusRange;

	bool mHideAll;

	//Compass
	StringTableEntry mCompassBitmapName;
	GFXTexHandle mCompassTextureObject;

	bool mShowCompass;

	// <MH>
	// Map
	StringTableEntry mMapBitmapName;
	GFXTexHandle mMapTextureObject;

	bool mShowMap;

	F32 mCompassRotation;
	// </MH>

    Point2I startPoint;
    //bool mRadarWrap;

	GFXStateBlockRef mBlendDisabledStateBlock;
	GFXStateBlockRef mBeforeStateBlock;

public:
    //creation methods
    DECLARE_CONOBJECT(GuiRadarCtrl);
    GuiRadarCtrl();
    static void initPersistFields();

    //Parental methods
    bool onWake();
    void onSleep();
    void inspectPostApply();

    void setRadarBitmap(const char *name, bool resize = false);
    void setRadarBitmap(GFXTexHandle handle, bool resize = false);

	void setRadarLevelBlipBitmap(const char *name);
	void setRadarUpBlipBitmap(const char *name);
	void setRadarBelowBlipBitmap(const char *name);

	void setCompassBitmap(const char *name, bool resize = false);
	void setCompassBitmap(GFXTexHandle handle, bool resize = false);

	void setMapBitmap(const char *name);

	void setRadius(const F32 newRange);
	void setLevelRange(const F32 newLevelRange);

    S32 getWidth() const       { return ( (mRadarTextureObject == NULL) ? 0 : mRadarTextureObject->getWidth() ) ; }
    S32 getHeight() const      { return( (mRadarTextureObject == NULL) ? 0 : mRadarTextureObject->getHeight() ); }

	void setCompassRotation(const F32 rotation);

    void onRender(Point2I offset, const RectI &updateRect);

	void setupStateBlocks();
};

#endif


Now the Radar/Map/Compass
now source/gui/control/GuiRadarTSCtrl.cpp
//-----------------------------------------------------------------------------
// Torque Game Engine
// Copyright (C) GarageGames.com, Inc.
//-----------------------------------------------------------------------------
// Class: GuiRadarTSCtrl for TGEA
// Tested with TGEA 1.0.3
// A 3d Spherical Radar system, ideal for space and flight games
// If you've played Elite, you know the score :)
// Uses some ideas from the GuiRadarCtrl by Matt "CaptFallout" Webster
// Guy Allard 2008
//-----------------------------------------------------------------------------
// Upgraded and cleaned by James Laker
//-----------------------------------------------------------------------------
#include "platform/platform.h"

#include "gui/core/guiControl.h"
#include "gfx/gfxDrawUtil.h"
#include "T3D/player.h"

#include "console/console.h"

#include "gfx/gfxDevice.h"
#include "app/game.h"

#include "T3D/ShapeBase.h"
#include "gui/controls/guiRadarTSCtrl.h"
#include "console/consoleTypes.h"
#include "t3d/gameConnection.h"
#include "t3d/shapeBase.h"
#include "t3d/sphere.h"
#include "gfx/primBuilder.h"

IMPLEMENT_CONOBJECT(GuiRadarTSCtrl);

// vertices for the quad used for rendering the elliptic plane
static const Point3F planeVerts[4]=
{
   Point3F(-1, 1, 0),
   Point3F(1, 1, 0),
   Point3F(-1, -1, 0),
   Point3F(1, -1, 0)
};

// and these are for the blip billboards
static const Point3F quadVerts[4]=
{
   Point3F(-1, 0, 1),
   Point3F(1, 0, 1),
   Point3F(-1, 0, -1),
   Point3F(1, 0, -1)
};

// texture coords for the quads (when drawn as a trianglestrip)
static const Point2F quadTexCoords[4] =
{
   Point2F(0,0),
   Point2F(1,0),
   Point2F(0,1),
   Point2F(1,1)
};

// sphere
static Sphere sphere(Sphere::Icosahedron);

//--------------------------------------------------------------------------
GuiRadarTSCtrl::GuiRadarTSCtrl()
{

	 mSphereDetail = 2;

   // textures
   mEllipticBitmap = StringTable->insert("");
   mEllipticTextureHandle = NULL;
   mBlipBitmap = StringTable->insert("");
   mBlipTextureHandle = NULL;
	mTargetBlipBitmap = StringTable->insert("");
	mTargetBlipTextureHandle = NULL;

	strcpy(mTargetShapeName,"");

   // colors
   mEllipticColor.set(0.0, 0.75, 0.0, 0.75);
   mSphereColor.set(0.0f, 0.5f, 0.0f, 0.25f);
   mBlipColor.set(1.0f, 1.0f, 1.0f, 1.0f);
   mStemColor.set(1.0f, 1.0f, 1.0f, 1.0f);

   // range
   mRange = 250.0f;

   // blip size
   mBlipSize = 1.0f;
}

//---------------------------------------------------------------------------
void GuiRadarTSCtrl::initPersistFields()
{
	Parent::initPersistFields();

	addGroup("Radar");
	addField("PlaneBitmap",		TypeFilename,	   Offset(mEllipticBitmap,    GuiRadarTSCtrl));
   addField("PlaneColor",     TypeColorF,       Offset(mEllipticColor,     GuiRadarTSCtrl));
   addField("BlipBitmap",     TypeFilename,     Offset(mBlipBitmap,        GuiRadarTSCtrl));
   addField("BlipColor",	   TypeColorF,       Offset(mBlipColor,         GuiRadarTSCtrl));
   addField("BlipSize",       TypeF32,          Offset(mBlipSize,          GuiRadarTSCtrl));
   addField("StemColor",      TypeColorF,       Offset(mStemColor,         GuiRadarTSCtrl));
   addField("SphereColor",    TypeColorF,       Offset(mSphereColor,       GuiRadarTSCtrl));
	 addField("SphereDetail",    TypeS32,       Offset(mSphereDetail,       GuiRadarTSCtrl));
   addField("Range",          TypeF32,          Offset(mRange,             GuiRadarTSCtrl));
	endGroup("Radar");
}

void GuiRadarTSCtrl::setTarget(const char *TargetShapeBaseName)
{
	if (*TargetShapeBaseName)
		strcpy(mTargetShapeName,TargetShapeBaseName);	
}

//---------------------------------------------------------------------------
void GuiRadarTSCtrl::setEllipticBitmap(const char *name)
{
   mEllipticBitmap = StringTable->insert(name);

   if (*mEllipticBitmap) 
	  mEllipticTextureHandle = GFXTexHandle(mEllipticBitmap, &GFXDefaultStaticDiffuseProfile, "Adescription");
      //mEllipticTextureHandle = GFXTexHandle(mEllipticBitmap, &GFXDefaultStaticDiffuseProfile);
   else 
      // Reset handles if UI object is hidden
	   mEllipticTextureHandle = NULL;
   
   setUpdate();
}

//---------------------------------------------------------------------------
void GuiRadarTSCtrl::setBlipBitmap(const char *name)
{
   mBlipBitmap = StringTable->insert(name);

   if (*mBlipBitmap) 
	  mBlipTextureHandle = GFXTexHandle(mBlipBitmap, &GFXDefaultStaticDiffuseProfile, "Adescription");
      //mBlipTextureHandle = GFXTexHandle(mBlipBitmap, &GFXDefaultStaticDiffuseProfile);
   else 
      // Reset handles if UI object is hidden
	   mBlipTextureHandle = NULL;
   
   setUpdate();
}

//---------------------------------------------------------------------------
bool GuiRadarTSCtrl::onWake()
{
	if (! Parent::onWake())
		return false;
	setActive(true);

	setEllipticBitmap(mEllipticBitmap);
   setBlipBitmap(mBlipBitmap);

   return true;
}

//--------------------------------------------------------------------------
void GuiRadarTSCtrl::onSleep()
{
	mEllipticTextureHandle = NULL;
   mBlipTextureHandle = NULL;
	Parent::onSleep();
}

//---------------------------------------------------------------------------
// set up the camera position for rendering the 3D scene within this control
bool GuiRadarTSCtrl::processCameraQuery(CameraQuery *camq)
{
   // pretty hacky hardcoded values
   // gives a reasonable viewing angle
   camq->nearPlane = 0.1f; // near clip plane
   camq->farPlane = 20.0f; // far clip plane
   camq->fov = (F32)M_PI/6;     // field of view
   MatrixF cam;
   cam.set(EulerF((F32)M_PI/8, 0, 0)); // rotation
   cam.setColumn(3, Point3F(0, -4, 1.65f)); // position
   camq->cameraMatrix = cam;
   return (true);
}

//---------------------------------------------------------------------------
// render the world that this control sees
void GuiRadarTSCtrl::renderWorld(const RectI &updateRect)
{
   // Must have a connection
   GameConnection* conn = GameConnection::getConnectionToServer();
   if (!conn) return;
   
   // Must have controlled object
   GameBase * control = dynamic_cast<GameBase*>(conn->getControlObject());
   if (!control) return;

   // get the camera transform for the connection
   MatrixF camMat;
   conn->getControlCameraTransform(0,&camMat);
   // get the position for use later
   Point3F camPos = camMat.getPosition();

   // invert the camera transform - 
   // this will then allow us to transform other objects into our own object space
   camMat.inverse();

   // set up the graphics

   // HNG
   /*
   GFX->setAlphaBlendEnable(true);
   GFX->setSrcBlend(GFXBlendSrcAlpha);
   GFX->setDestBlend(GFXBlendInvSrcAlpha);
   GFX->setZEnable( false );
   GFX->setCullMode( GFXCullNone );
   GFX->setTextureStageColorOp(0, GFXTOPModulate);
	GFX->setTextureStageColorOp(1, GFXTOPDisable);
   GFX->disableShaders();*/



   GFXStateBlockDesc desc;
   desc.zEnable = false;
   desc.ffLighting = false;  
   desc.setCullMode( GFXCullNone );  
   desc.setBlend(true, GFXBlendSrcAlpha, GFXBlendInvSrcAlpha);  
   desc.samplers[0].textureColorOp = GFXTOPModulate;  
   desc.samplers[1].textureColorOp = GFXTOPDisable;
   GFXStateBlockRef myState = GFX->createStateBlock(desc);  
   GFX->setStateBlock(myState);
   // HNG

   // first draw the elliptic plane if we need to
   if(mEllipticTextureHandle)
   {
      GFXTextureObject *texture = mEllipticTextureHandle;
      GFX->setTexture(0, texture);

	   PrimBuild::color(mEllipticColor);
      PrimBuild::begin(GFXTriangleStrip, 4);
      for(int i=0; i<4; i++)
      {
         PrimBuild::texCoord2f(quadTexCoords[i].x, quadTexCoords[i].y);
		   PrimBuild::vertex3fv(planeVerts[i]);
      }
      PrimBuild::end();
   }
   
	 if (mSphereDetail > 4)
			mSphereDetail = 4;

const Sphere::TriangleMesh *sphereMesh = sphere.getMesh(mSphereDetail); // sphere.getMesh(2) gives a slighty 'chunky' sphere - go higher if you can handle the framerate hit  
    S32 numPoly = sphereMesh->numPoly;  
    S32 totalPoly = 0;  
  
    GFXVertexBufferHandle<GFXVertexPC> verts(GFX, numPoly*3, GFXBufferTypeVolatile);  
    verts.lock();  
    S32 vertexIndex = 0;  
    for (S32 i=0; i<numPoly; i++)  
    {  
        totalPoly++;  
  
        verts[vertexIndex].point = sphereMesh->poly[i].pnt[0];  
        verts[vertexIndex].color = mSphereColor;  
        vertexIndex++;  
  
        verts[vertexIndex].point = sphereMesh->poly[i].pnt[1];  
        verts[vertexIndex].color = mSphereColor;  
        vertexIndex++;  
  
        verts[vertexIndex].point = sphereMesh->poly[i].pnt[2];  
        verts[vertexIndex].color = mSphereColor;  
        vertexIndex++;  
    }  
    verts.unlock();  
  
    GFXStateBlockDesc desc2;  
    desc2.setCullMode(GFXCullNone);  
    desc2.zEnable = false;  
    desc2.setBlend(true, GFXBlendSrcAlpha, GFXBlendInvSrcAlpha);  
  
    GFX->setStateBlockByDesc( desc2 );  
    GFX->setupGenericShaders( GFXDevice::GSColor );  
  
    GFX->setVertexBuffer( verts );  
    GFX->drawPrimitive( GFXTriangleList, 0, totalPoly );  
  
    GFX->setStateBlockByDesc( desc );  
    GFX->setupGenericShaders(); 
   
   // Now do the radar signatures
   // firstly, we will be drawing billboards, so get the current world transform matrix
   MatrixF worldMat = GFX->getWorldMatrix();
   // extract the up and right vectors
   Point3F up;
   Point3F right;
   worldMat.getRow(0,&right);
   worldMat.getRow(2,&up);
   right.normalize();
   up.normalize();
   // then build the coordinates that we'll use for the billboards
   // oops, another hard coded value, ah well...
   right *= mBlipSize * 0.05f;
   up    *= mBlipSize * 0.05f; 

   // set up the texture that we'll use for the blips
   // is this the correct way to do it???
   GFXTextureObject *texture = mBlipTextureHandle;
	GFXTextureObject *targetTexture = mTargetBlipTextureHandle;

   // Go through all ghosted objects on connection (client-side)
   for (SimSetIterator itr(conn); *itr; ++itr) 
   {
	   // Make sure that the object is a shapebase object
	   if ((*itr)->getType() & ShapeBaseObjectType) 
      {
		   ShapeBase* shape = static_cast<ShapeBase*>(*itr);
		   // Make sure that the object isn't the client
		   if (shape != control) 
         {
			   // Make sure the shapebase object is a player (or Vehicle)
			   if (shape->getType() & ( PlayerObjectType | VehicleObjectType ) ) 
            {
               // get position of object
				   Point3F objPos = shape->getPosition();

               // get vector between object and observer
               Point3F objVec = objPos - camPos;

               // don't draw if outside of current radar range
               if(objVec.lenSquared() > (mRange * mRange))
                  continue;
               
               // transform it into the coordinate space of the viewer
               camMat.mulP(objPos);

               // scale it according to the current radar range
               objPos /= mRange;

               // compress the z transform a bit, just for looks
               //objPos.z *= 0.5f;

					if (!strcmp(mTargetShapeName,""))
						GFX->setTexture(0, targetTexture);
					else
						GFX->setTexture(0, texture);

               // draw the blip
               // unfortunately, DX doesn't appear to allow specification of point size or line width like opengl
               // SO, lets build a quad using the view aligned coordinates we generated earlier....
               desc.samplers[0].textureColorOp = GFXTOPModulate;
			//GFX->setTextureStageColorOp(0, GFXTOPModulate);
               PrimBuild::color(mBlipColor);
               PrimBuild::begin(GFXTriangleStrip, 4);
                  PrimBuild::texCoord2f(quadTexCoords[0].x, quadTexCoords[0].y);
                  PrimBuild::vertex3fv(objPos - right + up);
                  PrimBuild::texCoord2f(quadTexCoords[1].x, quadTexCoords[1].y);
                  PrimBuild::vertex3fv(objPos + right + up);
                  PrimBuild::texCoord2f(quadTexCoords[2].x, quadTexCoords[2].y);
                  PrimBuild::vertex3fv(objPos - right - up);
                  PrimBuild::texCoord2f(quadTexCoords[3].x, quadTexCoords[3].y);
                  PrimBuild::vertex3fv(objPos + right - up);
               PrimBuild::end();
               
               // draw a line from the blip to the elliptic - will have to use quads if you want a line thicker than 1px
               // end point of line
               Point3F endPos = objPos;
               endPos.z = 0;

               // draw the line
			   desc.samplers[1].textureColorOp = GFXTOPDisable;
               //GFX->setTextureStageColorOp(0, GFXTOPDisable);
               PrimBuild::color(mStemColor);
               PrimBuild::begin(GFXLineList, 2);
                  PrimBuild::vertex3fv(objPos);
                  PrimBuild::vertex3fv(endPos);
               PrimBuild::end();
			   }
		   }
	   }
   }
   
   // all done
   GFX->setClipRect(updateRect);
       
}

//------------------------------------------------------------------------
// script interface
ConsoleMethod( GuiRadarTSCtrl, setEllipticBitmap, void, 3, 3, "(string filename)"
              "Set the bitmap for the horizontal plane of the control.")
{
   object->setEllipticBitmap(argv[2]);
}

ConsoleMethod( GuiRadarTSCtrl, SetRange, void, 3, 3, "(float)"
              "Sets the Range of the the control. Default is 250")
{
   object->setRange(dAtof(argv[2]));
}

ConsoleMethod( GuiRadarTSCtrl, getRange, F32, 2, 2, "()"
              "gets the current range of the control")
{
   return object->getRange();
}

ConsoleMethod( GuiRadarTSCtrl, setEllipticColor, void, 3, 3, "(Color)"
              "set the color of the horizontal plane")
{
   ColorF color;
   dSscanf(argv[2], "%g %g %g %g", &color.red, &color.green, &color.blue, &color.alpha);
   object->setEllipticColor(color);
}

ConsoleMethod( GuiRadarTSCtrl, setSphereColor, void, 3, 3, "(Color)"
              "set the color of the sphere")
{
   ColorF color;
   dSscanf(argv[2], "%g %g %g %g", &color.red, &color.green, &color.blue, &color.alpha);
   object->setSphereColor(color);
}

ConsoleMethod( GuiRadarTSCtrl, setBlipColor, void, 3, 3, "(Color)"
              "set the color of the radar blips")
{
   ColorF color;
   dSscanf(argv[2], "%g %g %g %g", &color.red, &color.green, &color.blue, &color.alpha);
   object->setBlipColor(color);
}

ConsoleMethod( GuiRadarTSCtrl, setStemColor, void, 3, 3, "(Color)"
              "set the color of the blip lines")
{
   ColorF color;
   dSscanf(argv[2], "%g %g %g %g", &color.red, &color.green, &color.blue, &color.alpha);
   object->setStemColor(color);
}

ConsoleMethod( GuiRadarTSCtrl, setTarget, void, 2, 3, "(str Target ShapebaseName)"
               "Set the target ShapeBaseName, if no Target is sent it is cleared.")
{
	if (argv[2])
		object->setTarget(argv[2]);
	else
		object->setTarget("");

}

now source/gui/control/GuiRadarTSCtrl.h
//-----------------------------------------------------------------------------
// Torque Game Engine
// Copyright (C) GarageGames.com, Inc.
//-----------------------------------------------------------------------------

#ifndef _GUIRADARTSCTRL_H_
#define _GUIRADARTSCTRL_H_

#ifndef _GUITSCONTROL_H_
#include "gui/3d/guiTSControl.h"
#endif
#ifndef _GFXTEXTUREHANDLE_H_
#include "gfx/gfxTextureHandle.h"
#endif

//----------------------------------------------------------------------------
class GuiRadarTSCtrl : public GuiTSCtrl
{
private:
   typedef GuiTSCtrl Parent;

   StringTableEntry  mEllipticBitmap;           // path to the bitmap for the horizontal plane
   GFXTexHandle      mEllipticTextureHandle;    // texture handle for the horizontal plane

   StringTableEntry  mBlipBitmap;               // path to the bitmap we'll use for the blips
   GFXTexHandle      mBlipTextureHandle;        // texture handle for the blip texture

   StringTableEntry  mTargetBlipBitmap;               // path to the bitmap we'll use for the blips
   GFXTexHandle      mTargetBlipTextureHandle;        // texture handle for the blip texture

	 S32			mSphereDetail;

   ColorF   mEllipticColor;   // color to use when drawing the elliptic plane
   ColorF   mSphereColor;     // color of the sphere
   ColorF   mBlipColor;       // color for the radar 'blips'
   ColorF   mStemColor;       // color for the stems of the blips
   F32      mRange;           // range of the radar
   F32      mBlipSize;        // base size for the blips

	char		mTargetShapeName[32]; //This keeps the name of the locked target
  
public:
   GuiRadarTSCtrl();

   bool processCameraQuery(CameraQuery *query);
   void renderWorld(const RectI &updateRect);
   
   static void initPersistFields();
   bool onWake();
	void onSleep();

   // gets and sets
   void setEllipticBitmap(const char *name);
   void setBlipBitmap(const char *name);
   void setRange(F32 range) { mRange = range; }
   F32 getRange() { return mRange; }
   void setEllipticColor(ColorF color) { mEllipticColor = color; }
   void setSphereColor(ColorF color) { mSphereColor = color; }
   void setBlipColor(ColorF color) { mBlipColor = color; }
   void setStemColor(ColorF color) { mStemColor = color; }

	void setTarget(const char *TargetShapeBaseName);

   DECLARE_CONOBJECT(GuiRadarTSCtrl);
};

#endif

The videos of the stuff in action.


Page«First 1 2 Next»
#21
08/25/2011 (7:03 am)
I have gotten this working properly within T3D 1.1 without issue.

guiradarctrl.cpp
Replace
#include "T3D/gameConnection.h"

With this
#include "T3D/gameBase/gameConnection.h"

Search for

// Go through all ghosted objects on connection (client-side)
	for (SimSetIterator itr(conn); *itr; ++itr) {
      // Make sure that the object is a ShapeBase object
      if ((*itr)->getType() & ShapeBaseObjectType) {
         ShapeBase* shape = static_cast<ShapeBase*>(*itr);
		 // Make sure that the object isn't the client
		 if (shape != control  && shape->getShapeName()) { 
			// Make sure the ShapeBase object is a player

			 if (shape->getType()) {
					
				   //ONly check when ShapeBase is not selecting, we are after all iterating through ShapeBaseObjects
					if (!mShowShapeBase)
					{
						if (!mShowPlayers && shape->getType() == PlayerObjectType)
							continue;

						if (!mShowVehicles && shape->getType() == VehicleObjectType) 
							continue;

                        if (!mShowBots && shape->getType() == AIObjectType)
                            continue;
					}


Replace it with
// Go through all ghosted objects on connection (client-side)

	for (SimSetIterator itr(conn); *itr; ++itr) {
      // Make sure that the object is a ShapeBase object
		ShapeBase* shape = static_cast<ShapeBase*>(*itr);
      if (shape->getTypeMask() & ShapeBaseObjectType) {
         
		 // Make sure that the object isn't the client
		 //if (shape != control  && shape->getShapeName()) { 
			if (shape != control) {
			// Make sure the ShapeBase object is a player

			 if (shape->getTypeMask()) {
					
				   //ONly check when ShapeBase is not selecting, we are after all iterating through ShapeBaseObjects
					if (!mShowShapeBase)
					{
						if (!mShowPlayers && shape->getTypeMask() == PlayerObjectType)
							continue;

						if (!mShowVehicles && shape->getTypeMask() == VehicleObjectType) 
							continue;

					}


#22
08/25/2011 (7:05 am)
guiradarctrl.h

search for
S32 getWidth() const       { return ( (mRadarTextureObject == NULL) ? 0 : mRadarTextureObject->getWidth() ) ; }
    S32 getHeight() const      { return( (mRadarTextureObject == NULL) ? 0 : mRadarTextureObject->getHeight() ); }

replace it with

S32 getWidth() const { return mRadarTextureObject ? mRadarTextureObject->getWidth() : 0; }
	S32 getHeight() const { return mRadarTextureObject ? mRadarTextureObject->getHeight() : 0; }


#23
08/25/2011 (7:06 am)
guiradartsctrl.cpp

search for
#include "t3d/gameConnection.h"

replace it with
#include "t3d/gameBase/gameConnection.h"

add
#include "scene/sceneManager.h"



Search for
// then the sphere
   // I was planning on texturing the sphere at some point....or maybe even a nice shader......
   PrimBuild::color(mSphereColor);
   desc.samplers[0].textureColorOp = GFXTOPDisable;
   //GFX->setTextureStageColorOp( 0, GFXTOPDisable ); // turn off texture
   const Sphere::TriangleMesh *sphereMesh = sphere.getMesh(mSphereDetail); // sphere.getMesh(2) gives a slighty 'chunky' sphere - go higher if you can handle the framerate hit
   PrimBuild::begin(GFXTriangleList, (sphereMesh->numPoly * 3));
   for(int i=0; i<sphereMesh->numPoly; i++)
   {
      Sphere::Triangle *tri = &sphereMesh->poly[i];
      
      for(int j=0; j<3; j++)
         PrimBuild::vertex3fv(tri->pnt[j]);
   }
   PrimBuild::end();
   
   // Now do the radar signatures
   // firstly, we will be drawing billboards, so get the current world transform matrix
   MatrixF worldMat = GFX->getWorldMatrix();
   // extract the up and right vectors
   Point3F up;
   Point3F right;
   worldMat.getRow(0,&right);
   worldMat.getRow(2,&up);
   right.normalize();
   up.normalize();
   // then build the coordinates that we'll use for the billboards
   // oops, another hard coded value, ah well...
   right *= mBlipSize * 0.05f;
   up    *= mBlipSize * 0.05f; 

   // set up the texture that we'll use for the blips
   // is this the correct way to do it???
   GFXTextureObject *texture = mBlipTextureHandle;
	GFXTextureObject *targetTexture = mTargetBlipTextureHandle;

   // Go through all ghosted objects on connection (client-side)
   for (SimSetIterator itr(conn); *itr; ++itr) 
   {
	   // Make sure that the object is a shapebase object
	   if ((*itr)->getType() & ShapeBaseObjectType) 
      {
		   ShapeBase* shape = static_cast<ShapeBase*>(*itr);
		   // Make sure that the object isn't the client
		   if (shape != control) 
         {
			   // Make sure the shapebase object is a player (or Vehicle)
			   if (shape->getType() & ( PlayerObjectType | VehicleObjectType ) )
#24
08/25/2011 (7:08 am)
Replace it with
// then the sphere
   // I was planning on texturing the sphere at some point....or maybe even a nice shader......
   PrimBuild::color(mSphereColor);
   desc.samplers[0].textureColorOp = GFXTOPDisable;
   //GFX->setTextureStageColorOp( 0, GFXTOPDisable ); // turn off texture
   const Sphere::TriangleMesh *sphereMesh = sphere.getMesh(mSphereDetail); // sphere.getMesh(2) gives a slighty 'chunky' sphere - go higher if you can handle the framerate hit
   PrimBuild::begin(GFXTriangleList, (sphereMesh->numPoly * 3));
   for(int i=0; i<sphereMesh->numPoly; i++)
   {
      Sphere::Triangle *tri = &sphereMesh->poly[i];
      
      for(int j=0; j<3; j++)
         PrimBuild::vertex3fv(tri->pnt[j]);
   }
   PrimBuild::end();
   */
	 const Sphere::TriangleMesh *sphereMesh = sphere.getMesh(mSphereDetail); // sphere.getMesh(2) gives a slighty 'chunky' sphere - go higher if you can handle the framerate hit
	S32 numPoly = sphereMesh->numPoly;
	S32 totalPoly = 0;

	GFXVertexBufferHandle<GFXVertexPC> verts(GFX, numPoly*3, GFXBufferTypeVolatile);
	verts.lock();
	S32 vertexIndex = 0;
	for (S32 i=0; i<numPoly; i++)
	{
		totalPoly++;

		verts[vertexIndex].point = sphereMesh->poly[i].pnt[0];
		verts[vertexIndex].color = mSphereColor;
		vertexIndex++;

		verts[vertexIndex].point = sphereMesh->poly[i].pnt[1];
		verts[vertexIndex].color = mSphereColor;
		vertexIndex++;

		verts[vertexIndex].point = sphereMesh->poly[i].pnt[2];
		verts[vertexIndex].color = mSphereColor;
		vertexIndex++;
	}
	verts.unlock();

	GFXStateBlockDesc desc2;
	desc2.setCullMode(GFXCullNone);
	desc2.zEnable = false;
	desc2.setBlend(true, GFXBlendSrcAlpha, GFXBlendInvSrcAlpha);

	GFX->setStateBlockByDesc( desc2 );
	GFX->setupGenericShaders( GFXDevice::GSColor );

	GFX->setVertexBuffer( verts );
	GFX->drawPrimitive( GFXTriangleList, 0, totalPoly );

	GFX->setStateBlockByDesc( desc );
	GFX->setupGenericShaders();
   
   // Now do the radar signatures
   // firstly, we will be drawing billboards, so get the current world transform matrix
   MatrixF worldMat = GFX->getWorldMatrix();
   // extract the up and right vectors
   Point3F up;
   Point3F right;
   worldMat.getRow(0,&right);
   worldMat.getRow(2,&up);
   right.normalize();
   up.normalize();
   // then build the coordinates that we'll use for the billboards
   // oops, another hard coded value, ah well...
   right *= mBlipSize * 0.05f;
   up    *= mBlipSize * 0.05f; 

   // set up the texture that we'll use for the blips
   // is this the correct way to do it???
   GFXTextureObject *texture = mBlipTextureHandle;
	GFXTextureObject *targetTexture = mTargetBlipTextureHandle;

   // Go through all ghosted objects on connection (client-side)
   for (SimSetIterator itr(conn); *itr; ++itr) 
   {
	   ShapeBase* shape = static_cast<ShapeBase*>(*itr);
	   // Make sure that the object is a shapebase object
	   if (shape->getTypeMask() & ShapeBaseObjectType) 
      {
		   
		   // Make sure that the object isn't the client
		   if (shape != control) 
         {
			   // Make sure the shapebase object is a player (or Vehicle)
			   if (shape->getTypeMask() & ( PlayerObjectType | VehicleObjectType ) )
#25
08/25/2011 (7:09 am)
Garagegames needs to address this post limit BS, once per minute and only 1000 words is WAY to short. I had to split the fix into multiple posts to simply get it in here and I almost stopped because it took 5 minutes to post it!
#26
08/25/2011 (7:58 pm)
I agree, it makes posting resources a pain, thanks for your help!
#27
08/26/2011 (3:29 pm)
I'm getting errors from sphere.h no longer being a part of it, like this:
Error	1	error C2146: syntax error : missing ';' before identifier 'sphere'	h:torqueafx2 for t3d pro 1.1 qrenginesourceguicontrolsguiradartsctrl.cpp	66
Error	2	error C4430: missing type specifier - int assumed. Note: C++ does not support default-int	h:torqueafx2 for t3d pro 1.1 qrenginesourceguicontrolsguiradartsctrl.cpp	66
Error	3	error C2825: 'Sphere': must be a class or namespace when followed by '::'	h:torqueafx2 for t3d pro 1.1 qrenginesourceguicontrolsguiradartsctrl.cpp	66
Error	4	error C2039: 'Icosahedron' : is not a member of '`global namespace''	h:torqueafx2 for t3d pro 1.1 qrenginesourceguicontrolsguiradartsctrl.cpp	66
Error	5	error C2146: syntax error : missing ')' before identifier 'Icosahedron'	h:torqueafx2 for t3d pro 1.1 qrenginesourceguicontrolsguiradartsctrl.cpp	66
Error	6	error C4430: missing type specifier - int assumed. Note: C++ does not support default-int	h:torqueafx2 for t3d pro 1.1 qrenginesourceguicontrolsguiradartsctrl.cpp	66
Error	7	error C2059: syntax error : ')'	h:torqueafx2 for t3d pro 1.1 qrenginesourceguicontrolsguiradartsctrl.cpp	66
Error	8	error C2825: 'Sphere': must be a class or namespace when followed by '::'	h:torqueafx2 for t3d pro 1.1 qrenginesourceguicontrolsguiradartsctrl.cpp	256
Error	9	error C4430: missing type specifier - int assumed. Note: C++ does not support default-int	h:torqueafx2 for t3d pro 1.1 qrenginesourceguicontrolsguiradartsctrl.cpp	256
Error	10	error C2825: 'Sphere': must be a class or namespace when followed by '::'	h:torqueafx2 for t3d pro 1.1 qrenginesourceguicontrolsguiradartsctrl.cpp	256
Error	11	error C2039: 'TriangleMesh' : is not a member of '`global namespace''	h:torqueafx2 for t3d pro 1.1 qrenginesourceguicontrolsguiradartsctrl.cpp	256
Error	12	error C2146: syntax error : missing ';' before identifier 'TriangleMesh'	h:torqueafx2 for t3d pro 1.1 qrenginesourceguicontrolsguiradartsctrl.cpp	256
Error	13	error C2065: 'TriangleMesh' : undeclared identifier	h:torqueafx2 for t3d pro 1.1 ...ect
Am I missing something obvious?
#28
08/30/2011 (6:36 am)
sorry man, been really busy! I will look at this today and verify that there were no additional changes needed.
#29
08/30/2011 (6:44 am)
Do you have sphere.h and .cpp in your build? If it is, try cleaning and rebuilding after adding in the GUI objects. There is nothing different that I can find between the P and F builds.
#30
08/30/2011 (9:30 pm)
I see one issue, after really breaking it down, theres a missing"/*" somewhere, to match the "*/" on line 16, of the guiRadarTSCtrl...
#31
08/30/2011 (9:44 pm)
I ended up throwing the "/*" right above "//then the sphere" and got a good build, also I had to copy sphere.h, and sphere.cpp from beta 3 into the 1.1 project.

Thanks alot for your help yet again! I'm going crazy between the alpha test, and trying to complete the project. Your a life saver!
#32
09/02/2011 (8:29 am)
Change that, I found the error and it was unrelated, I left the "/*" where I first got the good build and I'm good to go! Thank you very much for your help!
#33
09/08/2011 (12:25 pm)
I don't see sphere.h and sphere.cpp in the T3D source tree. Do those files need to be added and if so from where? I get a compile error because they are missing.
I also noticed a non matched */, where should the matching /* go?
thanks
#34
09/08/2011 (8:12 pm)
Yeah I had to copy them in from beta 3, however at its current state here, it only works in a single player setting, in multiplayer the client crashes on the radar being rendered. I moved the comment brackets all around, but couldn't fix it yet.

I placed the "/*" above "// then the sphere"
#35
11/07/2011 (4:18 am)
Did anyone get this rendering properly, and working in MP ?
#36
11/09/2011 (6:16 am)
No, I have not. We have so many issues with things we can easily fix that this has been thrown far on the back burner. It sucks too, because our GUI now has a big non-working control, but due to game design, it's a necessary evil.
I'm not sure what happened to Sean, he must either be really busy, or maybe he switched to unity?.. Just kidding! I haven't heard back from him though in quite some time. I can't really blame him, I think I once flaked out on him a years ago, involving fixing something else.
Eventually, I will have to return to this and fix it. I bet it's all in the placement of that damn "/*". Actually, I have placed it everywhere possible and tested it, so there is some code missing too. Unfortunately, I can't possibly say when. My best guess would be (include some shameless self-promotion here) before December 2012? Our plan with ATROX NOCTIS, our project, is to be ready to release by that ominous and foreboding date. So, we will have fixed it by then...
Page«First 1 2 Next»