Gui Reticle HUD for TGE(A) With Target Cycling
by Martin Schultz · 12/17/2007 (7:59 am) · 67 comments
Download Code File
This resource contains a gui control element which displays a rectangle around every shape in the view frustrum and displays the currently selected shape in a different color (target selection). The display style of the rectangles can be chosen between full rectangles and rendering only the corners around the shape. Furthermore the normal / selected colors can be freely chosen as well as the minimum size of the rectangle once the shape is very far away (minimum rectangle size).
Cycling through the targets is done by using the mouse wheel. The client transmits then the selected ghost id to the server and the server then does a lookup to find out the server player id. The id is then stored in the %client variable for the corresponding client. This player id can then be used in an weapon onFire function to actually track the target for example when using a homing missile.
The attached zip cointains a readme file and the source file for TGE and TGEA.
Please note that the target cycling code is somewhat buggy and not battle-proven, so excuse that the cycling code is not perfect yet. Will improve this soon. :-)
This resource contains a gui control element which displays a rectangle around every shape in the view frustrum and displays the currently selected shape in a different color (target selection). The display style of the rectangles can be chosen between full rectangles and rendering only the corners around the shape. Furthermore the normal / selected colors can be freely chosen as well as the minimum size of the rectangle once the shape is very far away (minimum rectangle size).
Cycling through the targets is done by using the mouse wheel. The client transmits then the selected ghost id to the server and the server then does a lookup to find out the server player id. The id is then stored in the %client variable for the corresponding client. This player id can then be used in an weapon onFire function to actually track the target for example when using a homing missile.
The attached zip cointains a readme file and the source file for TGE and TGEA.
Please note that the target cycling code is somewhat buggy and not battle-proven, so excuse that the cycling code is not perfect yet. Will improve this soon. :-)
#42
...and then when I press F10 it gets a Bad Ptr. Admittedly I don't understand how to fully override the GuiControl class but I copied the what GuiRadar did it, and that seems to work okay.
Any ideas what special consideration I have to make when including bitmaps and being able to edit via F10 without losing the pointer to the bitmap?
04/21/2008 (6:16 am)
Arghhh!! For some reason when I load the game this is set...bool GuiReticleHud::onWake()
{
if (! Parent::onWake())
return false;
setActive(true);
setRecticleBitmap(mRecticleBitmapName); // <-- valid
return true;
}...and then when I press F10 it gets a Bad Ptr. Admittedly I don't understand how to fully override the GuiControl class but I copied the what GuiRadar did it, and that seems to work okay.
Any ideas what special consideration I have to make when including bitmaps and being able to edit via F10 without losing the pointer to the bitmap?
#43
www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=14628
04/21/2008 (8:45 am)
I'm still trying to fix the crash but in the meantime here's some screenies of the action so far...www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=14628
#44
EDIT: Well, now the targeting boxes render around vehicles and players, and not static shapes. But my turrets still don't get them. Any ideas?
04/24/2008 (4:36 pm)
Gah. Any chance you could point me to the part of the code where the objects the control picks up are defined, Andy? Static shapes get targeting rectangles around them, while my turrets don't, and I'd like to change that.EDIT: Well, now the targeting boxes render around vehicles and players, and not static shapes. But my turrets still don't get them. Any ideas?
#45
Here's the file updates...
GuiRecticleHud With Bitmaps
To change what is a candidate for a target go to this line...334 in my code
Here's a list of object types...
There's a new type of Recticle using the "b" definition...
rectangleStyle = "b";
used in code here in client/ui/playerGui.gui
Also note the inclusion of the two recticles. The first one is the lock, the second is the selected only.
04/24/2008 (7:02 pm)
@Maddermadcat - here's an early version that deletes the links to the recticles if you enter F10 - so you have to enter these values manually - BE WARNED this is not complete code yet and needs more testing so there are some bugs. I have asked for some help fixing that as it seems when the textures are added, the links are killed. Anyway - so use at your own risk - email me for help.Here's the file updates...
GuiRecticleHud With Bitmaps
To change what is a candidate for a target go to this line...334 in my code
if ((*itr)->getType() & VehicleObjectType)to what ever else or not that you want to check for like PlayerObjectType, StaticObjectType etc. NOTE!! Make sure you change it at ~ lines 178, 231 and 460 (you'll notice mine is buggy)
Here's a list of object types...
GameBaseObjectType = BIT(10), ShapeBaseObjectType = BIT(11), CameraObjectType = BIT(12), StaticShapeObjectType = BIT(13), PlayerObjectType = BIT(14), ItemObjectType = BIT(15), VehicleObjectType = BIT(16), VehicleBlockerObjectType = BIT(17), ProjectileObjectType = BIT(18), ExplosionObjectType = BIT(19), CorpseObjectType = BIT(20), DebrisObjectType = BIT(22), PhysicalZoneObjectType = BIT(23), StaticTSObjectType = BIT(24), AIObjectType = BIT(25), StaticRenderedObjectType = BIT(26),
There's a new type of Recticle using the "b" definition...
rectangleStyle = "b";
used in code here in client/ui/playerGui.gui
Also note the inclusion of the two recticles. The first one is the lock, the second is the selected only.
new GuiReticleHud(ReticleHUD) {
canSaveDynamicFields = "0";
Profile = "GuiDefaultProfile";
HorizSizing = "width";
VertSizing = "height";
position = "0 0";
Extent = "1024 768";
MinExtent = "0 0";
canSave = "1";
Visible = "1";
hovertime = "1000";
fillColorDefault = "0 1 0 1";
fillColorSelected = "1 0 0 1";
rectangleMinSize = "30";
cornerLength = "8";
rectangleStyle = "b";
distanceFade = "0.1";
RecticleBitmap = "./recticle1_smooth.png";
RecticleBitmap2 = "./recticle2_smooth.png";
};
#46
Here's what I changed (changes indicated by +):
Then at around line 204:
Around 307:
At around line 432:
And that's it. Pretty much I just replaced the object type with a mask. Now why don't my turrets get targeting boxes? Everything else works as I want it to.
04/25/2008 (9:04 am)
Well, as I said, I got it to show targets around only vehicles and players, but turrets still don't work.Here's what I changed (changes indicated by +):
static void initPersistFields(); DECLARE_CONOBJECT(GuiReticleHud); }; + //Objects we want to be picked up for targeting + static const U32 RetObjMask = PlayerObjectType | VehicleObjectType | TurretObjectType; //----------------------------------------------------------------------------- IMPLEMENT_CONOBJECT(GuiReticleHud);
Then at around line 204:
for (SimSetIterator itr(conn); *itr; ++itr)
{
//if ((*itr)->getType() & ShapeBaseObjectType)
+ if ((*itr)->getType() & RetObjMask)
{
ShapeBase* shape = static_cast<ShapeBase*>(*itr);Around 307:
for (SimSetIterator itr(conn); *itr; ++itr)
{
//if ((*itr)->getType() & ShapeBaseObjectType)
+ if ((*itr)->getType() & RetObjMask)
{
ShapeBase* shape = static_cast<ShapeBase*>(*itr);At around line 432:
for (SimSetIterator itr(conn); *itr; ++itr)
{
+ if ((*itr)->getType() & RetObjMask)
{
ShapeBase* shape = static_cast<ShapeBase*>(*itr);
if (shape != control && shape->getShapeName())
{And that's it. Pretty much I just replaced the object type with a mask. Now why don't my turrets get targeting boxes? Everything else works as I want it to.
#47
04/25/2008 (4:38 pm)
@Maddermadcat - apologies for not reading properly - I do this all the time :) So what type of object is your turret? Is it a StaticShapeObjectType, StaticTSObjectType or StaticRenderedObjectType because TurretObjectType seems a little strange? Which resource did you use to add the turret?
#48
04/25/2008 (4:39 pm)
By the way are you able to hit f10 with this resource and see the bitmap? (if you're using my implementation that is)
#49
04/25/2008 (4:46 pm)
Also you line at 204 wont compile - it's not the right name, should be RetObjMask
#50
Just wanted to say that turrets do get targeting boxes, the reason they didn't show was because the turrets were partially below the terrain. Unfortunately it's a bit difficult to position the turrets nicely without them being slightly below ground. Maybe there's something wrong with the way the model is set up. I'll check.
I haven't gotten a chance to implement your resource yet Andy, I'll do that tonight and get back to you.
EDIT: Yep, turrets are targeting just fine. Had to change some stuff with my bounding box, that's all. Now for your resource. :]
EDIT 2: ..\engine\gui\game\guiReticleHud.cc(20) : fatal error C1083: Cannot open include file: 'gfx/gfxDevice.h': No such file or directory
Yeah, not compiling for me, unfortunately. :[
04/25/2008 (6:56 pm)
Agh, sorry, I guess I threw that change in there somewhat absent-mindedly. Fixed the naming problem in my post.Just wanted to say that turrets do get targeting boxes, the reason they didn't show was because the turrets were partially below the terrain. Unfortunately it's a bit difficult to position the turrets nicely without them being slightly below ground. Maybe there's something wrong with the way the model is set up. I'll check.
I haven't gotten a chance to implement your resource yet Andy, I'll do that tonight and get back to you.
EDIT: Yep, turrets are targeting just fine. Had to change some stuff with my bounding box, that's all. Now for your resource. :]
EDIT 2: ..\engine\gui\game\guiReticleHud.cc(20) : fatal error C1083: Cannot open include file: 'gfx/gfxDevice.h': No such file or directory
Yeah, not compiling for me, unfortunately. :[
#51
Regarding the gfx/gfxdevice.h file - you don't need it - delete it.
04/26/2008 (3:53 am)
If you get the bitmaps working in the F10 gui editor let me know. Mine get erased if I try to edit them.Regarding the gfx/gfxdevice.h file - you don't need it - delete it.
#52
04/26/2008 (8:30 am)
Commented out that include, now I get this mess of errors:../engine\gui/game/GuiReticleHud.h(42) : error C2146: syntax error : missing ';' before identifier 'mRecticleTextureObject'
../engine\gui/game/GuiReticleHud.h(42) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
../engine\gui/game/GuiReticleHud.h(42) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
../engine\gui/game/GuiReticleHud.h(45) : error C2146: syntax error : missing ';' before identifier 'mRecticleTextureObject2'
../engine\gui/game/GuiReticleHud.h(45) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
../engine\gui/game/GuiReticleHud.h(45) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
..\engine\gui\game\guiReticleHud.cc(44) : error C2065: 'mRecticleTextureObject' : undeclared identifier
..\engine\gui\game\guiReticleHud.cc(45) : error C2065: 'mRecticleTextureObject2' : undeclared identifier
..\engine\gui\game\guiReticleHud.cc(628) : error C2065: 'GFX' : undeclared identifier
..\engine\gui\game\guiReticleHud.cc(628) : error C2227: left of '->drawRect' must point to class/struct/union/generic type
type is ''unknown-type''
..\engine\gui\game\guiReticleHud.cc(633) : error C2227: left of '->drawLine' must point to class/struct/union/generic type
type is ''unknown-type''
..\engine\gui\game\guiReticleHud.cc(634) : error C2227: left of '->drawLine' must point to class/struct/union/generic type
type is ''unknown-type''
..\engine\gui\game\guiReticleHud.cc(635) : error C2227: left of '->drawLine' must point to class/struct/union/generic type
type is ''unknown-type''
..\engine\gui\game\guiReticleHud.cc(636) : error C2227: left of '->drawLine' must point to class/struct/union/generic type
type is ''unknown-type''
..\engine\gui\game\guiReticleHud.cc(637) : error C2227: left of '->drawLine' must point to class/struct/union/generic type
type is ''unknown-type''
..\engine\gui\game\guiReticleHud.cc(638) : error C2227: left of '->drawLine' must point to class/struct/union/generic type
type is ''unknown-type''
..\engine\gui\game\guiReticleHud.cc(639) : error C2227: left of '->drawLine' must point to class/struct/union/generic type
type is ''unknown-type''
..\engine\gui\game\guiReticleHud.cc(640) : error C2227: left of '->drawLine' must point to class/struct/union/generic type
type is ''unknown-type''
..\engine\gui\game\guiReticleHud.cc(649) : error C2227: left of '->drawBitmap' must point to class/struct/union/generic type
type is ''unknown-type''
..\engine\gui\game\guiReticleHud.cc(651) : error C2227: left of '->drawBitmap' must point to class/struct/union/generic type
type is ''unknown-type''
..\engine\gui\game\guiReticleHud.cc(689) : error C2227: left of '->setBitmapModulation' must point to class/struct/union/generic type
type is ''unknown-type''
..\engine\gui\game\guiReticleHud.cc(690) : error C2227: left of '->drawText' must point to class/struct/union/generic type
type is ''unknown-type''
..\engine\gui\game\guiReticleHud.cc(691) : error C2227: left of '->clearBitmapModulation' must point to class/struct/union/generic type
type is ''unknown-type''
..\engine\gui\game\guiReticleHud.cc(700) : error C2228: left of '.set' must have class/struct/union
type is ''unknown-type''
..\engine\gui\game\guiReticleHud.cc(700) : error C2065: 'GFXDefaultGUIProfile' : undeclared identifier
..\engine\gui\game\guiReticleHud.cc(705) : error C2227: left of '->getWidth' must point to class/struct/union/generic type
type is ''unknown-type''
..\engine\gui\game\guiReticleHud.cc(706) : error C2227: left of '->getHeight' must point to class/struct/union/generic type
type is ''unknown-type''
..\engine\gui\game\guiReticleHud.cc(736) : error C2228: left of '.set' must have class/struct/union
type is ''unknown-type''
..\engine\gui\game\guiReticleHud.cc(741) : error C2227: left of '->getWidth' must point to class/struct/union/generic type
type is ''unknown-type''
..\engine\gui\game\guiReticleHud.cc(742) : error C2227: left of '->getHeight' must point to class/struct/union/generic type
type is ''unknown-type''
#53
10/04/2008 (10:06 am)
How hard would be be to make this have another mode to select 4 targets at once? I want to make a special weapon that targets 4 airplanes, and shoots 4 missiles at the planes.
#54
I am putting this resource into my project now and after adding the resource I fly over bots, and vehicles and I get nothing. In the code I have vehicleObjectType and it does not pick them up. Do you have to have a player in a vehicle before it picks them up or is there something wrong with my implementation of the resource?
Thanks
10/06/2008 (5:34 am)
HelloI am putting this resource into my project now and after adding the resource I fly over bots, and vehicles and I get nothing. In the code I have vehicleObjectType and it does not pick them up. Do you have to have a player in a vehicle before it picks them up or is there something wrong with my implementation of the resource?
Thanks
#55
sg490.digitalkingdomgames.com/files/video/Player/Targeting.html
This is a college project that is being done by myself and 4 others, in fact, this is our FINAL project that will graduate us. We are in week 5 of a 9 week course, and because of resources like this, we are able to smash our way through this project. So thanks again man! You saved us!
11/11/2008 (8:57 pm)
Hey! Thanks for the resource man! Here it is in action:sg490.digitalkingdomgames.com/files/video/Player/Targeting.html
This is a college project that is being done by myself and 4 others, in fact, this is our FINAL project that will graduate us. We are in week 5 of a 9 week course, and because of resources like this, we are able to smash our way through this project. So thanks again man! You saved us!
#56
11/12/2008 (1:47 am)
Looks great! I like the cockpit ;-)
#57
11/14/2008 (2:07 pm)
I think I am going to modify this tonight so that I can pass in the color I want the reticle to be. I would like to be able to color code the shapes. For example, if it is a jumpgate (in our Space Duel game), I could put a variable (reticleColor) in my datablock to tell the engine to render yellow. Looking at the render logic, it shouldn't be difficult at all.
#58
Thanks!
03/25/2009 (6:33 am)
Can anyone confirm this still works with 1.8.1? I'd love to have this in my project but I get tons of errors while re-compiling the project. Thanks!
#59
03/25/2009 (6:44 am)
Cool to see people are still using my resource. Nice! :-) Good luck on the 1.8.1 thing.
#60
04/05/2009 (7:44 pm)
By the looks of it, the reticle hud doesnt do any checks to see if objects are in the way of targets you want to select, so you can select targets behind terrain and other objects. Any idea on what would have to be added to the code to do checking for obstructions? 
Associate Andy Hawkins
DrewFX
I think I will also do the "Top Gun"-like lock up sequence in that you have to keep the enemy's plane within the HUD while the "lock" recticle chases the reticle over the plane.
All exciting stuff I want for BRAVE but if I get it working everyone else can have it too. Of course as I'm trying to put this in BRAVE before the end of this month it will be very simple and I'll embellish it after the release.
The way I'm going to allow you to classify targets is via an internal Torque-Script string for each entity called "targetType". This will feed through to the engine to find the right targets. So you can do things like "find next enemy", "find next ally", "find ground target" etc. It will also warn you if you are targeting an ally or civilian target using this system.
More soon.