drawing a hud radar

Archive of the old editing forum
Forum rules
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. This forum is archived - please use this set of forums to ask new questions.
blender81
Posts: 49
Joined: Fri Feb 20, 2004 6:13 pm
Contact:

drawing a hud radar

Post by blender81 »

I'm trying to implement a compass that points the player to the next objective (http://forum.zdoom.org/viewtopic.php?t= ... ur&start=0) and I'm having a bit of trouble getting it to work. I'm porting it over from a project on another game engine, so perhaps I am taking the wrong approach on it. Also, I am a bit unclear as to how to handle floats, since ACS doesn't seem to accomodate them.

The angle_hud variable currently displays the angle to the objective, relative to the player's current view angle. The only thing I am missing now is how to correctly translate that angle integer into a compass.

Code: Select all

        angle_to_monster = FindTIDAngle(0, 999) / 182; //finds angle to objective
        angle_player = GetActorAngle(0) / 182; //finds player angle
        
        angle_hud = (angle_player - angle_to_monster); //final result, angle to obj relative to player viewangle
        
        if (angle_hud < 0)
        {
        	angle_hud += 360;
        }

        SetHudSize(640,480,1);

       //for test purposes. up to here, everything works fine
        hudmessage (s: "ANGLE: ", d: angle_hud;
        HUDMSG_PLAIN,
        998,
        CR_WHITE,
        160.0,
        120.1,
        0.0);
       
		
			//======================= BEGIN DRAW RADAR ==========================================
			int drawdist = 88; //how large to draw the compass
			int radians = angle_hud * (3.1415926 / 180);
	
			drawx = sin(radians) * drawdist;
			drawy = cos(radians * drawdist;
			
			drawx = (drawx + 320); //compass is in center of screen (640 / 2)
			drawy = (drawy + 240); //compass is in center of screen (480 / 2)
	
			SetFont("h_pack"); //the objective icon
	        
			hudmessage (s:"a";
	        HUDMSG_PLAIN,
	        910,
	        CR_UNTRANSLATED,
	        drawx,
	        drawy,
	        0.0);
	        //========================== END DRAW RADAR ==========================================
anyone have any ideas on this?
User avatar
MasterOFDeath
... in rememberance ...
Posts: 2024
Joined: Sat Apr 03, 2004 10:58 am

Post by MasterOFDeath »

I think its 1337. Someone help him. :P
Linguica
Posts: 50
Joined: Thu Nov 13, 2003 6:00 pm

Post by Linguica »

The code looks like it oughta work, could you be a little more specific on what you're having problems with?

edit: sin() and cos() are all [censored word]. I had to write my own for my grav gun wad. If everything else is working right that is probably it.
blender81
Posts: 49
Joined: Fri Feb 20, 2004 6:13 pm
Contact:

Post by blender81 »

Linguica:

I am having trouble getting floats and decimals to work, which don't seem to play too well with ACS. This makes cosine and sine functions fairly difficult to use. The angle-to-radians conversion is also wonking out.

Is there some sort of trick to tricking ACS into recognizing decimal places? I've used (number << 16) + 0.1 to add decimals for hudmessage use, but I can't get the sin/cos stuff going. Linguica, care to perhaps share your homebrew sin/cos functions?

For the time being, I wrote a messy series of IF statements with my hardcoded sin/cos values plugged in. It does work, though I would MUCH prefer to implement it the "correct" way.

http://www.planethalflife.com/blended/zfiles/rad01.jpg
http://www.planethalflife.com/blended/zfiles/rad02.jpg
User avatar
Nmn
Posts: 4631
Joined: Fri Apr 16, 2004 1:41 pm
Preferred Pronouns: He/Him
Contact:

Post by Nmn »

wow :shock: I can't wait to see this thing in the game.
Ninja_of_DooM
Posts: 667
Joined: Tue Aug 05, 2003 2:42 am
Location: Lossiemouth, Scotland
Contact:

Post by Ninja_of_DooM »

And i can't wait to steal it. :twisted:
User avatar
Cutmanmike
Posts: 11351
Joined: Mon Oct 06, 2003 3:41 pm
Operating System Version (Optional): Windows 10
Location: United Kingdom
Contact:

Post by Cutmanmike »

Not if he deletes the SCRIPTS lump
User avatar
wildweasel
Posts: 21706
Joined: Tue Jul 15, 2003 7:33 pm
Preferred Pronouns: He/Him
Operating System Version (Optional): A lot of them
Graphics Processor: Not Listed
Contact:

Post by wildweasel »

cutmanmike wrote:Not if he deletes the SCRIPTS lump
Blender is usually pretty good about releasing his script source to the public. Just look at all his Half-Life and Doom 3 mods (Pathways Redux in particular, which makes me just wanna go out and buy Doom 3 just to play).
blender81
Posts: 49
Joined: Fri Feb 20, 2004 6:13 pm
Contact:

Post by blender81 »

yes, the script file will be released. the logic behind drawing blips on a compass is fairly simple. With some minor edits, I'm pretty sure someone can make a cool Aliens motion tracker feature.

I'm trying out the fixed-point math functions, but I still can't get the correct number from sin or cos. anyway, here's how the blip compass works right now:

1. find the angle between blip & player, relative to player's viewangle
angle = player_viewangle - angle_between_player_and_blip
(refer to this post by Destroyer for necessary functions)

2. convert the angle to radians
radians = angle * (pi / 180)

3. determine blip x-coordinate
x = sin(radians) * radius_of_hud_compass

4. determine blip y-coordinate
y = cos(radians) * radius_of_hud_compass

5. draw the blip on the hud compass

6. profit
User avatar
DoomRater
Posts: 8270
Joined: Wed Jul 28, 2004 8:21 am
Preferred Pronouns: He/Him
Location: WATR HQ
Contact:

Post by DoomRater »

I'd love to just mod this into a arrow radar that points to a particular direction of a thing... like how the South Park compass worked.
User avatar
jallamann
Posts: 2271
Joined: Mon May 24, 2004 8:25 am
Location: Ålesund, Norway
Contact:

Post by jallamann »

Like the compass in many FPS games
User avatar
DoomRater
Posts: 8270
Joined: Wed Jul 28, 2004 8:21 am
Preferred Pronouns: He/Him
Location: WATR HQ
Contact:

Post by DoomRater »

I first saw it in South Park. So sue me for being an N64 shipper.
User avatar
jallamann
Posts: 2271
Joined: Mon May 24, 2004 8:25 am
Location: Ålesund, Norway
Contact:

Post by jallamann »

Nah, that game was fun :P
User avatar
Your Name Is
Posts: 802
Joined: Sun Oct 31, 2004 5:06 pm
Location: Raleigh, NC
Contact:

Post by Your Name Is »

If you get it working, can you PM me the code, please? I just got an idea that requires me to modify your code, but should it work, I'll show you, blender
User avatar
jallamann
Posts: 2271
Joined: Mon May 24, 2004 8:25 am
Location: Ålesund, Norway
Contact:

Post by jallamann »

Maybe he'll be a nice chap and release it publically... Everyone should...
Locked

Return to “Editing (Archive)”