Game Development Community

3rd/1st Person Super Crosshair

by Max Robinson · 11/29/2002 (12:27 pm) · 44 comments

Download Code File

A working crosshair for 1st and 3rd person views. Even if you rotate the 3rd person camera, it'll still be accurate. It doesn't predict the arcs for projectiles being dragged down, but that's a small gripe. The biggest problem it has is shaking, but it is still cool. Very good for anyone doing a 3rd person shooter (like Max Payne).

Read.txt has a lot more information
Page «Previous 1 2 3 Last »
#1
12/02/2002 (2:03 am)
Hm, I've tried it ... but besides the shaking and coloring I couldn't see any difference to changing the following if clause in game/fps/guiCrossHairHud.cc:
//if (!control || !(control->getType() & ObjectMask) || !conn->isFirstPerson())
   if (!control || !(control->getType() & ObjectMask))
which simply renders the crossHair in 3rd person, too...
Is there anything I'm missing?
Thx!
#2
12/02/2002 (1:01 pm)
yeah but that isn't an accurate crosshair. when you do that, you are simply rendering a circle in the middle of the screen. it doesn't mean anything at that point.
#4
01/07/2003 (7:19 pm)
Hmm... Since it does raycasts per frame, it would seem that higher frame rate = more raycasts. Which means more processor usage. I could see how this could lead to problems. I know of a way to get around this, but it would ruin the modularity of the whole thing. What happened to your framerate (specifics)?
#5
01/28/2003 (7:15 pm)
This would be cool, but I cant seem to get the recticle to appear at all in 3rd person and in first it takes up the entire screen. Am I missing something in the .gui file or in a script?

-s
#6
01/29/2003 (12:10 pm)
Probably. There is a size property for the bitmap, since the reticle iteself should be made to take up the whole screen.
#7
04/03/2003 (1:33 am)
One of our programmers has managed to stop the crosshair from shaking. He claims this was just a quick test and that's his excuse if the implementation seems a bit clunky. Here you go:

Basically you calculate the position as an average of the last X number of positions.
In guiCrossHairHud.cc make the following changes/additions:

Add
#define SMOOTH_FACTOR 10
under the #includes. This is the number of points over which to work out the average. I find 10 works well.

Add
Point2I mSmooth[SMOOTH_FACTOR];
to the list of variables just above the protected methods.

Add
void shuntSmoothArray();
Point2I avgSmoothArray();
to the list of protected methods.

Add
U8 i;
for(i=0;i {
mSmooth[i] = Point2I(0,0);
}
to the end of the GuiCrossHairHud::GuiCrossHairHud() constructor

Add these 2 functions:
//------------------------------------------------------------------------------
void GuiCrossHairHud::shuntSmoothArray()
{
U8 i;

for (i=1;i {
mSmooth[i-1] = mSmooth[i];
}
}


//------------------------------------------------------------------------------
Point2I GuiCrossHairHud::avgSmoothArray()
{
U8 i;
Point2I average(0,0);

for (i=0;i {
average.x += mSmooth[i].x;
average.y += mSmooth[i].y;
}
average.x /= SMOOTH_FACTOR;
average.y /= SMOOTH_FACTOR;
return average;

}

In the void GuiCrossHairHud::onRender(Point2I offset, const RectI &updateRect) method, in the if(bool(mTextureHandle)) block, find the line
TextureObject* texture = (TextureObject *) mTextureHandle;
and add these 2 lines below it:
shuntSmoothArray();
mSmooth[SMOOTH_FACTOR-1] = Point2I( projPnt.x - (mBitmapSize.x / 2) , projPnt.y - (mBitmapSize.y / 2));

Finally, on the line below, change
Point2I aimOffset = Point2I( projPnt.x - (mBitmapSize.x / 2) , projPnt.y - (mBitmapSize.y / 2) );
to
Point2I aimOffset = avgSmoothArray();

That should be it. If I've left something out and it doesn't work just shout at me. Enjoy
#8
04/03/2003 (2:25 am)
I've just noticed a slight problem with the new update. When turning the side of the crosshair seems to be cut off by it's bounding box. I'll try and get this sorted. Aaargh, I was so close!!
#9
04/03/2003 (3:44 am)
Found the problem. Just needed to make my GuiCrossHairHud a bit bigger. I changed the extent from "32 32" to "64 64" and the problem went away.
#10
04/03/2003 (7:44 am)
OK, getting a bit picky now, but I spent ages chasing this problem and I just want to save people some aggro. You need the extent to be quite a lot bigger or you won't be able to see the health bar when it's shown.
Also, the last part of the update where you change/add the code in the if(bool(mTextureHandle)) block, you also need to do this in the else block below it.
#11
07/16/2003 (1:18 pm)
I've just implemented all the modfications, starting with Max's and then Alastair's. I love it but I have to agree with Sebasti
#12
12/23/2003 (10:48 pm)
I'm running a GeForce Ti 4200 and I just put it in, and I didn't notice any difference in performance... I didn't spend too much time in fiddling with it, but it's the same as it was before. However, I didn't add the updates from Alastair (yet), when I get around to that, I'll go ahead and let everyone know.

(By the way, yes, I'm well aware that nobody has posted in quite some time, but better late than never, right?...)
#13
04/13/2006 (12:58 am)
I have the code working but my crosshair is low and right cant figuer out why any tips?
#14
06/17/2006 (3:58 am)
This works pretty well in 1.4 (HEAD with TLK) however it lags terribly when you look at something far away, like the sky. Other then that its great, no jittering with Alastairs extra code.

I have been looking through the code I can't fathom why it lags when I look to the sky. Maybe it has somthing to do with the fluid camera resource I have. Can anyone else confirm lag?

I remove the camera code from the resource and it's fine now. Must of been somthing to do with the fluid camera resource. I get some clipping of the crosshair now but I'll look into that some other time!
#15
06/17/2006 (9:59 pm)
Just so people know

the fix for

GameConnection* conn = GameConnection::getServerConnection();

is

GameConnection *con = GameConnection::getConnectionToServer();


sorry for no explaination but i pasted this in while coding thought it might be useful
#16
07/29/2006 (2:42 pm)
Ello! I guess this was built with an older version of the engine, since I had to change some of the include paths to get it to work with the starter.fps structure:

#include "dgl/dgl.h"
#include "gui/core/guiControl.h"
#include "gui/controls/guiBitmapCtrl.h"
#include "console/consoleTypes.h"
#include "sceneGraph/sceneGraph.h"
#include "game/gameConnection.h"
#include "game/shapeBase.h"

#include "gui/core/guiTSControl.h"
#include "terrain/terrData.h"
#include "interior/interior.h"

As well as that getConnectionToServer change above.

It was easy to get working and looks great ... just one problem - in my build (adding it to the Lighting Pack) it breaks when you look at the sky or something very far away.

Thankfully I found a quick, dirty workaround .... If you're not fussy about having the damage bar display when you target another player, you can solve this easily by commenting out:

// if we have an object, render the hud part
if (hasObject)
{
drawDamage(Point2I(projPnt.x,projPnt.y + mBitmapSize.y) + mDamageOffset,dmgLevel , 1);
}

That will get it working although I found that it seemed to lag a lot more in debug mode... I don't know enough about C programming to figure out why this is ... if anyone has any ideas, please do fire away!!

Thanks for a great resource! :)
#17
08/29/2006 (10:05 am)
hi, i added al the updates, etc. and im getting these errors:

1>------ Build started: Project: Torque Demo, Configuration: Release Win32 ------
1>Compiling...
1>guiCrossHairHud.cc
1>..\engine\game\fps\guiCrossHairHud.cc(107) : error C2065: 'conn' : undeclared identifier
1>..\engine\game\fps\guiCrossHairHud.cc(109) : error C2227: left of '->getControlObject' must point to class/struct/union/generic type
1>        type is ''unknown-type''
1>..\engine\game\fps\guiCrossHairHud.cc(116) : error C2227: left of '->getControlObject' must point to class/struct/union/generic type
1>        type is ''unknown-type''
1>..\engine\game\fps\guiCrossHairHud.cc(116) : error C2227: left of '->getMuzzleTransform' must point to class/struct/union/generic type
1>..\engine\game\fps\guiCrossHairHud.cc(134) : error C2227: left of '->getControlCameraTransform' must point to class/struct/union/generic type
1>        type is ''unknown-type''
1>Build log was saved at "file://f:\docs\july 16\Torque\SDK\engine\out.VC8.RELEASE\BuildLog.htm"
1>Torque Demo - 5 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 6 up-to-date, 0 skipped ==========

anyone know how to fix this :S, please help me out

...i hope this thread isnt dead...
#18
09/20/2006 (6:58 pm)
The fix to this to run with 1.4.2 are as follows.

Quote:
Replace the includes in guiCrossHairHud.cc with these:

#include "dgl/dgl.h"
#include "gui/core/guiControl.h"
#include "gui/controls/guiBitmapCtrl.h"
#include "console/consoleTypes.h"
#include "sceneGraph/sceneGraph.h"
#include "game/gameConnection.h"
#include "game/shapeBase.h"

#include "gui/core/guiTSControl.h"
#include "terrain/terrData.h"
#include "interior/interior.h"


After that is done, scroll down to the method GuiCrossHairHud::onRender() and replace the creating of the con pointer to this.

GameConnection *con = GameConnection::getConnectionToServer();

Now that we have those two things done, we needs to go about and do a find and replace of conn with con. Now do a build and it will compile without flaw.

Hope this helps you out Tom, if you hadn't got it already.
#19
10/17/2006 (2:34 am)
The engine freeze when i aim at the sky any ideas ?
#20
10/30/2006 (7:25 am)
when making the changes Alastair Paterson mentioned to get rid of the bumpyness in thecrosshair I run into the following errors:

(267): error C2601: 'GuiCrossHairHud::avgSmoothArray' : local function definitions are illegal
(192): error C2601: 'GuiCrossHairHud::avgSmoothArray' : local function definitions are illegal
(267): error C2601: 'GuiCrossHairHud::avgSmoothArray' : local function definitions are illegal
(192): error C2601: 'GuiCrossHairHud::avgSmoothArray' : local function definitions are illegal

anybody know why this is. equally if someone who has implemented the changes Allister Patterson mentioned could post the entire .cc file onto here that would be super.
Page «Previous 1 2 3 Last »