TGEA 1.7 problem in convertion of Horizontal Compass Ctrl TSE
by Andrea Fraboni · in Torque Game Engine Advanced · 06/03/2008 (10:40 am) · 20 replies
Hi to all ... in these days I study a method to convert this resource to TGEA 1.7 :
http://www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=11425
Following the indications readed in community posts I rewrite some rows but the horizontal compass didn't show in the game !!!
Can anyone help me ??
this the link to my code :
xoomer.alice.it/afraboni/teamitalia/horizontal.htm
Thanks
Bye
Andrea
http://www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=11425
Following the indications readed in community posts I rewrite some rows but the horizontal compass didn't show in the game !!!
Can anyone help me ??
this the link to my code :
xoomer.alice.it/afraboni/teamitalia/horizontal.htm
Thanks
Bye
Andrea
About the author
ASTRO SLAYERS my first game is on iTunes : https://itunes.apple.com/it/app/astro-slayers/id458581104?mt=8
#2
thanks Eric
P.S.
Is there a same convertion on GuiRadarCtrl ??? ;-)
06/03/2008 (11:26 am)
Wao good notice !! I wait you ;-)thanks Eric
P.S.
Is there a same convertion on GuiRadarCtrl ??? ;-)
#3
06/03/2008 (12:13 pm)
I have the Radar control pretty much up and working, I think there might be one graphic issue, but that might just be project related. I'll put that code up here too...
#5
horizCompassCtrl.h
06/03/2008 (5:52 pm)
Ok first the horizontal compass control:horizCompassCtrl.h
//-----------------------------------------------------------------------------
// Torque Game Engine
//
// Portions Copyright (c) 2001-2002 GarageGames.Com
// Portions Copyright (c) 2001-2002 by Sierra Online, Inc.
//
// Horizontal compass by Stefan "Beffy" Moises
// The basic code (well, almost everything... ;-) for this compass gui
// was written by Xavier "eXoDuS" Amado.
// (with special thanks go to Matt for his compass code)
//
// Converted in TSE code by Andrea Fraboni Knight72
//
//-----------------------------------------------------------------------------
#ifndef _HORIZCOMPASSCTRL_H_
#define _HORIZCOMPASSCTRL_H_
#ifndef _GUIBITMAPCTRL_H_
#include "gui/controls/guiBitmapCtrl.h"
#endif
struct CameraQuery
{
SimObject* object;
F32 nearPlane;
F32 farPlane;
F32 fov;
MatrixF cameraMatrix;
};
class HorizCompassCtrl : public GuiBitmapCtrl
{
private:
typedef GuiBitmapCtrl Parent;
F32 mOffset;
protected:
StringTableEntry mOuterBitmapName;
GFXTexHandle mTextureHandle;
GFXTexHandle mOuterTextureHandle;
F32 mFontWidth;
public:
//creation methods
DECLARE_CONOBJECT(HorizCompassCtrl);
HorizCompassCtrl();
static void initPersistFields();
//Parental methods
bool onWake();
void onSleep();
void setOuterBitmap(const char *name);
// adjust graphic position in regard to the font/letter size of the compass
void setFontWidth(const F32 width);
void setOuterBitmap(const GFXTexHandle &handle);
void setBitmap(const char *name, bool resize = false);
void setBitmap(GFXTexHandle handle, bool resize = false);
S32 getWidth() const { return(mTextureObject->getWidth()); }
S32 getHeight() const { return(mTextureObject->getHeight()); }
void onRender(Point2I offset, const RectI &updateRect);
};
#endif
#6
06/03/2008 (5:54 pm)
And now the .cpp file part 1://-----------------------------------------------------------------------------
// Torque Game Engine
//
// Portions Copyright (c) 2001-2002 GarageGames.Com
// Portions Copyright (c) 2001-2002 by Sierra Online, Inc.
//
// Horizontal compass by Stefan "Beffy" Moises
// The basic code (well, almost everything... ;-) for this compass gui
// was written by Xavier "eXoDuS" Amado.
// (with special thanks go to Matt for his compass code)
//
// Converted in TSE code by Andrea Fraboni Knight72
//
//-----------------------------------------------------------------------------
#include "console/console.h"
#include "console/consoleTypes.h"
#include "gfx/gfxDevice.h"
#include "T3D/gameFunctions.h"
#include "T3D/gameconnection.h"
#include "horizCompassCtrl.h"
IMPLEMENT_CONOBJECT(HorizCompassCtrl);
HorizCompassCtrl::HorizCompassCtrl(void)
{
mOuterBitmapName = StringTable->insert("");
mTextureHandle = NULL;
mOuterTextureHandle = NULL;
mFontWidth = 16.0f;
}
void HorizCompassCtrl::initPersistFields()
{
Parent::initPersistFields();
addField("OuterRingBitmap", TypeFilename, Offset(mOuterBitmapName, HorizCompassCtrl));
addField("FontWidth", TypeF32, Offset(mFontWidth, HorizCompassCtrl));
removeField("wrap");
removeField("autosize");
removeField("command");
removeField("altcommand");
}
void HorizCompassCtrl::setFontWidth(const F32 width)
{
mFontWidth = width;
}
bool HorizCompassCtrl::onWake()
{
if (! Parent::onWake()) return false;
setActive(true);
setBitmap(mBitmapName);
setOuterBitmap(mOuterBitmapName);
setFontWidth(mFontWidth);
return true;
}
void HorizCompassCtrl::onSleep()
{
mTextureHandle = NULL;
mOuterTextureHandle = NULL;
Parent::onSleep();
}
void HorizCompassCtrl::setBitmap(const char *name, bool resize)
{
mBitmapName = StringTable->insert(name);
if (*mBitmapName)
{
mTextureHandle.set( mBitmapName, &GFXDefaultGUIProfile );
// Resize the control to fit the bitmap
if( mTextureObject && resize )
{
setExtent(mTextureObject->getWidth(), mTextureObject->getHeight());
updateSizing();
}
}
else
mTextureHandle = NULL;
setUpdate();
}
void HorizCompassCtrl::setBitmap(GFXTexHandle handle, bool resize)
{
mTextureHandle = handle;
// Resize the control to fit the bitmap
if (resize)
{
setExtent(mTextureObject->getWidth(), mTextureObject->getHeight());
updateSizing();
}
}
void HorizCompassCtrl::setOuterBitmap(const char *name)
{
mOuterBitmapName = StringTable->insert(name);
if (*mOuterBitmapName)
mOuterTextureHandle.set( mOuterBitmapName, &GFXDefaultGUIProfile );
else
mOuterTextureHandle = NULL;
setUpdate();
}
void HorizCompassCtrl::setOuterBitmap(const GFXTexHandle &handle)
{
mOuterTextureHandle = handle;
}
float Vector2dToOffset(Point3F vector)
{
float offset;
offset = atanf((1.0F * vector.x) / (-1.0F * vector.y)) * (180.0F / M_PI);
if ((-1.0F * vector.y) < 0.0F){
return offset + 180.0f;
}
else{
return offset;
}
}
#7
06/03/2008 (5:55 pm)
And .cpp part 2:void HorizCompassCtrl::onRender(Point2I offset, const RectI &updateRect)
{
if (mTextureHandle)
{
GFX->getDrawUtil()->clearBitmapModulation();
GFXTextureObject* texture = mTextureHandle;
// okay, so the "letters" graphic is placed 90px (=90 degrees) to the left initially
// also, the size of the letters (mFontWidth) is taken into account so that
// the letters and the graphic are exactly centered and in the correct position
Point2I BorderOffset(getBounds().extent.x - texture->mBitmapSize.x - (mFontWidth/2) - 90, getBounds().extent.y - texture->mBitmapSize.y);
//struct CameraQuery query;
//GameProcessCameraQuery(&query);
GameConnection* connection = GameConnection::getConnectionToServer();
MatrixF cameraMatrix;
if(!connection)
return;
connection->getControlCameraTransform(0.032f, &cameraMatrix);
Point3F cameraRot;
cameraMatrix.getColumn(1, &cameraRot);
cameraRot.neg();
cameraRot.z = 0;
mOffset = Vector2dToOffset(cameraRot);
RectI dstRect(getBounds().point.x + BorderOffset.x/2 + mOffset, getBounds().point.y + BorderOffset.y/2,
texture->mBitmapSize.x, texture->mBitmapSize.y);
GFX->getDrawUtil()->drawBitmapStretch(mTextureHandle, dstRect);
}
renderChildControls(offset, updateRect);
}
#8
06/03/2008 (5:57 pm)
Finally, what I have in the .gui file:new HorizCompassCtrl(navHUD_macroCompass) {
profile = "GuiDefaultProfile";
horizSizing = "center";
vertSizing = "bottom";
position = "220 100";
extent = "200 30";
minExtent = "8 8";
visible = "1";
helpTag = "0";
bitmap = "~/data/gui/hud/1024/compass/compass_bar_normal.png";
FontWidth = "16";
};
#9
06/03/2008 (5:59 pm)
Ok, guiRadarCtrl.h ://-----------------------------------------------------------------------------
// Torque Game Engine Advanced
// Copyright (C) GarageGames.com, Inc.
//-----------------------------------------------------------------------------
#ifndef _GUIBITMAPCTRL_H_
#define _GUIBITMAPCTRL_H_
#ifndef _GUICONTROL_H_
#include "gui/core/guiControl.h"
#endif
/// Renders a bitmap.
class GuiRadarCtrl : public GuiControl
{
private:
typedef GuiControl 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 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 mWrap;
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->getWidth()); }
S32 getHeight() const { return(mRadarTextureObject->getHeight()); }
void setCompassRotation(const F32 rotation);
void updateSizing();
void onRender(Point2I offset, const RectI &updateRect);
void setValue(S32 x, S32 y);
};
#endif
#10
06/03/2008 (6:01 pm)
And now the .cpp file part 1://-----------------------------------------------------------------------------
// Torque Game Engine Advanced v1.0
// Copyright (C) GarageGames.com, Inc.
//-----------------------------------------------------------------------------
#include "console/console.h"
#include "console/consoleTypes.h"
#include "gfx/gfxDevice.h"
#include "T3D/shapeBase.h"
#include "T3D/gameConnection.h"
#include "gfx/primBuilder.h"
#include "GuiRadarCtrl.h"
IMPLEMENT_CONOBJECT(GuiRadarCtrl);
GuiRadarCtrl::GuiRadarCtrl(void)
{
// Radar Background default
mRadarBitmapName = StringTable->insert("");
// Blip defaults
mBlipUpName = StringTable->insert("");
mBlipBelowName = StringTable->insert("");
mBlipLevelName = StringTable->insert("");
mShowRadar = true;
mWrap = true;
mRadarRadiusRange = 2500.0f;
mLevelRange = 20.0f;
// As default show only players
mShowShapeBase = false;
mShowVehicles = false;
mShowPlayers = true;
// Compass defaults
mCompassBitmapName = StringTable->insert("");
mShowCompass = true;
mCompassRotation = 0.0f;
// <MH>
// Map defaults
mMapBitmapName = StringTable->insert("");
mShowMap = true;
// </MH>
mHideAll = false;
}
void GuiRadarCtrl::initPersistFields()
{
Parent::initPersistFields();
addGroup("Radar");
addField("RadarBitmap", TypeFilename, Offset(mRadarBitmapName, GuiRadarCtrl));
addField("wrap", TypeBool, Offset(mWrap, 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("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()
{
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();
RectI newBounds;
if (!mWrap && (getBounds().extent.x == 0) && (getBounds().extent.y == 0) && mRadarTextureObject)
{
newBounds.extent.x = mRadarTextureObject->getWidth();
//getBounds().extent.x = mRadarTextureObject->getWidth();
newBounds.extent.y = mRadarTextureObject->getWidth();
//getBounds().extent.y = mRadarTextureObject->getHeight();
}
if (!mWrap && (getBounds().extent.x == 0) && (getBounds().extent.y == 0) && mCompassTextureObject)
{
newBounds.extent.x = mRadarTextureObject->getWidth();
newBounds.extent.y = mRadarTextureObject->getHeight();
}
resize(getBounds().point, newBounds.extent);
}
void GuiRadarCtrl::setRadarBitmap(const char *name, bool resize)
{
mRadarBitmapName = StringTable->insert(name);
if (*mRadarBitmapName)
{
mRadarTextureObject.set( mRadarBitmapName, &GFXDefaultGUIProfile ); // mBitmapName = directory + filename
// Resize the control to fit the bitmap
if( mRadarTextureObject && resize )
{
setExtent(mRadarTextureObject->getWidth(), mRadarTextureObject->getHeight());
updateSizing();
}
}
else
mRadarTextureObject = NULL;
setUpdate();
}
void GuiRadarCtrl::updateSizing()
{
if(!getParent())
return;
// updates our bounds according to our horizSizing and verSizing rules
RectI fakeBounds( getPosition(), getParent()->getExtent());
parentResized( fakeBounds, fakeBounds);
}
void GuiRadarCtrl::setRadarLevelBlipBitmap(const char *name)
{
mBlipLevelName = StringTable->insert(name);
if (*mBlipLevelName)
mRadarDot.set( mBlipLevelName, &GFXDefaultGUIProfile );
else
mRadarDot = NULL;
setUpdate();
}
void GuiRadarCtrl::setRadarUpBlipBitmap(const char *name)
{
mBlipUpName = StringTable->insert(name);
if (*mBlipUpName)
mRadarUp.set( mBlipUpName, &GFXDefaultGUIProfile );
else
mRadarUp = NULL;
setUpdate();
}
void GuiRadarCtrl::setRadarBelowBlipBitmap(const char *name)
{
mBlipBelowName = StringTable->insert(name);
if (*mBlipBelowName)
mRadarDown.set( mBlipBelowName, &GFXDefaultGUIProfile );
else
mRadarDown = NULL;
setUpdate();
}
void GuiRadarCtrl::setCompassBitmap(const char *name, bool resize)
{
mCompassBitmapName = StringTable->insert(name);
if (*mCompassBitmapName)
{
mCompassTextureObject.set( mCompassBitmapName, &GFXDefaultGUIProfile );
// 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 );
else
mMapTextureObject = NULL;
setUpdate();
}
// </MH>
void GuiRadarCtrl::setRadius(const F32 newRange)
{
mRadarRadiusRange = newRange;
}
#11
06/03/2008 (6:05 pm)
.cpp part 2: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(getBounds().extent.x / 2,getBounds().extent.y / 2);
//F32 HWidth = mBounds.extent.x/2.0;
//F32 HHeight = mBounds.extent.y/2.0;
F32 HW = getBounds().extent.x/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);
// <MH>
if (mMapTextureObject && mShowMap)
{
GFX->getDrawUtil()->clearBitmapModulation();
GFXTextureObject* texture = mMapTextureObject;
GFX->setBaseRenderState();
F32 width = getBounds().extent.x * 0.5;
MatrixF rotMatrix( EulerF( 0.0, 0.0, mDegToRad(cameraAngle)) );
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)getBounds().extent.x / (float)mMapTextureObject->getBitmapWidth() / 2;
GFXVertexBufferHandle<GFXVertexPCT> verts( GFX, 10, GFXBufferTypeVolatile );
verts.lock();
// Octagons Vertices
verts[0].point.set( 0.0f, 0.0f, 0.0f);
verts[1].point.set( 0.0f, width, 0.0f);
verts[2].point.set( width * 0.7f, width * 0.7f, 0.0f);
verts[3].point.set( width, 0.0f, 0.0f);
verts[4].point.set( width * 0.7f, -width * 0.7f, 0.0f);
verts[5].point.set( 0.0f, -width, 0.0f);
verts[6].point.set( -width * 0.7f, -width * 0.7f, 0.0f);
verts[7].point.set( -width, 0.0f, 0.0f);
verts[8].point.set( -width * 0.7f, width * 0.7f, 0.0f);
verts[9].point.set( 0.0f, width, 0.0f);
//verts[0].color = verts[1].color = verts[2].color = verts[3].color = verts[4].color = verts[5].color = verts[6].color = verts[7].color = verts[8].color = verts[9].color = GFX->mBitmapModulation;
// Octagons UV coordinates
verts[0].texCoord.set( 0.0f, 0.0f);
verts[1].texCoord.set( 0.0f, uvOffset);
verts[2].texCoord.set( uvOffset * 0.7f, uvOffset * 0.7f);
verts[3].texCoord.set( uvOffset, 0.0f);
verts[4].texCoord.set( uvOffset * 0.7f, -uvOffset * 0.7f);
verts[5].texCoord.set( 0.0f, -uvOffset);
verts[6].texCoord.set( -uvOffset * 0.7f, -uvOffset * 0.7f);
verts[7].texCoord.set( -uvOffset, 0.0f);
verts[8].texCoord.set( -uvOffset * 0.7f, uvOffset * 0.7f);
verts[9].texCoord.set( 0.0f, uvOffset);
for( int i = 0; i < 10; i++ )
{
rotMatrix.mulP( verts[i].point );
verts[i].point += offset;
verts[i].texCoord += offsetTexture;
}
verts.unlock();
GFX->setVertexBuffer( verts );
GFX->setCullMode( GFXCullNone );
GFX->setLightingEnable( false );
GFX->setAlphaBlendEnable( true );
GFX->setSrcBlend( GFXBlendSrcAlpha );
GFX->setDestBlend( GFXBlendInvSrcAlpha );
GFX->setTextureStageAddressModeU(0, GFXAddressWrap);
GFX->setTextureStageAddressModeV(0, GFXAddressWrap);
GFX->setTextureStageColorOp( 0, GFXTOPModulate );
GFX->setTextureStageColorOp( 1, GFXTOPDisable );
GFX->setTexture( 0, texture );
GFX->drawPrimitive( GFXTriangleFan, 0, 8);
GFX->setAlphaBlendEnable( false );
}
// </MH>
#12
06/03/2008 (6:05 pm)
if (mRadarTextureObject && mShowRadar)
{
GFX->getDrawUtil()->clearBitmapModulation();
if(mWrap)
{
GFXTextureObject* texture = mRadarTextureObject;
RectI srcRegion;
RectI dstRegion;
float xdone = ((float)getBounds().extent.x/(float)texture->mBitmapSize.x)+1;
float ydone = ((float)getBounds().extent.y/(float)texture->mBitmapSize.y)+1;
int xshift = startPoint.x%texture->mBitmapSize.x;
int yshift = startPoint.y%texture->mBitmapSize.y;
for(int y = 0; y < ydone; ++y)
for(int x = 0; x < xdone; ++x)
{
srcRegion.set(0,0,texture->mBitmapSize.x,texture->mBitmapSize.y);
dstRegion.set( ((texture->mBitmapSize.x*x)+offset.x)-xshift,
((texture->mBitmapSize.y*y)+offset.y)-yshift,
texture->mBitmapSize.x,
texture->mBitmapSize.y);
GFX->getDrawUtil()->drawBitmapStretchSR(texture,dstRegion, srcRegion);
}
}
else
{
RectI rect(offset, getBounds().extent);
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;
}*/
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, getBounds().extent.x, getBounds().extent.y);
GFX->getDrawUtil()->drawRect(rect, mProfile->mBorderColor);
}
}
if (mCompassTextureObject && mShowCompass)
{
GFX->getDrawUtil()->clearBitmapModulation();
GFXTextureObject* texture = mCompassTextureObject;
GFX->setCullMode( GFXCullNone );
GFX->setLightingEnable( false );
GFX->setAlphaBlendEnable( true );
GFX->setSrcBlend( GFXBlendSrcAlpha );
GFX->setDestBlend( GFXBlendInvSrcAlpha );
GFX->setTextureStageColorOp( 0, GFXTOPModulate );
GFX->setTextureStageColorOp( 1, GFXTOPDisable );
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 + getBounds().extent.x / 2,
offset.y + getBounds().extent.y / 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->setAlphaBlendEnable( false );
}
renderChildControls(offset, updateRect);
}
void GuiRadarCtrl::setValue(S32 x, S32 y)
{
if (mRadarTextureObject)
{
x += mRadarTextureObject->getWidth() / 2;
y += mRadarTextureObject->getHeight() / 2;
}
while (x < 0)
x += 256;
startPoint.x = x % 256;
while (y < 0)
y += 256;
startPoint.y = y % 256;
}
#13
06/03/2008 (6:06 pm)
Let me know if you have any trouble with any of the above... I have this all working, so it should fall in...
#15
But now with other these rows we can complete horizontalcompass :
indeed the radar not showed ... but I must study what is the problem for it .....:-S
06/04/2008 (12:10 pm)
OK ! I test your code with success !!! Good !!But now with other these rows we can complete horizontalcompass :
mOffset = Vector2dToOffset(cameraRot);
RectI dstRect(getBounds().point.x + BorderOffset.x/2 + mOffset, getBounds().point.y + BorderOffset.y/2,
texture->mBitmapSize.x, texture->mBitmapSize.y);
GFX->getDrawUtil()->drawBitmapStretch(mTextureHandle, dstRect);
}
[b]
if(mOuterTextureHandle)
{
GFXTextureObject* texture = mOuterTextureHandle;
//mBounds.extent.set(texture->mBitmapSize.x, texture->mBitmapSize.y);
setExtent(texture->mBitmapSize.x, texture->mBitmapSize.y);
//RectI outerRect(offset, mBounds.extent);
RectI outerRect(offset, getBounds().extent);
GFX->getDrawUtil()->drawBitmapStretch(mOuterTextureHandle, outerRect);
}
if (mProfile->mBorder || !mTextureHandle && !mOuterTextureHandle)
{
// RectI rect(offset.x, offset.y, mBounds.extent.x, mBounds.extent.y);
RectI rect(offset.x, offset.y, getBounds().extent.x, getBounds().extent.y);
GFX->getDrawUtil()->drawRect(rect, mProfile->mBorderColor);
}
[/b]
renderChildControls(offset, updateRect);
}indeed the radar not showed ... but I must study what is the problem for it .....:-S
#16
xoomer.alice.it/afraboni/teamitalia/resources.htm
Good coding to all
Bye
^_^
06/05/2008 (2:09 pm)
I resolve the problem about RadarGui with your code too and here the final release of codes thanks Eric :xoomer.alice.it/afraboni/teamitalia/resources.htm
Good coding to all
Bye
^_^
#17
06/11/2008 (9:32 pm)
OK, this all works correctly now except my maps is all skewed. When I turn on the screen the map rotates likes it should but it Stretches out the land mass Across the radar map.
#18
07/21/2008 (11:13 pm)
Awesome! Thanks... I'm not getting quite so lost on my maps!
#19
12/28/2008 (8:45 pm)
Anyone looked into getting this working with TGEA 1.8?
#20
and hopefully they include a migration/porting section
12/30/2008 (1:59 am)
Still too new at the moment, might have to wait for the TGEA 1.8 documents to come outand hopefully they include a migration/porting section
Torque 3D Owner Eric Armstrong
Bloody Tongue Games