Jump to content
  • Advertisement
Sign in to follow this  

radar var shows up as 0.000

This topic is 3624 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm trying to make a simple radar for a HL2MP mod. I'm trying to get an idea of what vars are being passed around by using the Msg() function. However, when I call it on int drawX & Y I get the value of 0.000. Is there something wrong with my code that could be doing this?
#include "hud.h"
#include "cbase.h"
#include "radar_hud.h"
#include "iclientmode.h"
#include "hud_macros.h"
#include "vgui_controls/controls.h"
#include "vgui/ISurface.h"

#include "tier0/memdbgon.h"

using namespace vgui;


static ConVar show_radar("show_radar", "1", 0, "toggles radar on and off");

CRadarHud::CRadarHud( const char *pElementName ) : CHudElement( pElementName ), BaseClass( NULL, "HudImport" )
	Panel *pParent = g_pClientMode->GetViewport();
	SetParent( pParent );   
	SetVisible( true );

	// create radar texture
	m_nImport = surface()->CreateNewTextureID();
	surface()->DrawSetTextureFile( m_nImport, "HUD/hud_radar" , true, true);
	// hides radar if player is dead

	// Draw the radar
	surface()->DrawSetTexture( m_nImport );
	surface()->DrawTexturedRect( 2, 2, 128, 128 );

void CRadarHud::Paint()
	// draws the radar	
	surface()->DrawSetTexture( m_nImport );
	surface()->DrawTexturedRect( 2, 2, 128, 128 );
	//	TODO:  We need to update the dots on the screen according to where the players are

	// create player pointer
	C_BasePlayer *pOtherPlayer = NULL;
	surface()->DrawSetColor( 250, 250, 250, 10 );
	surface()->DrawFilledRect(10, 60, 15, 65);
	C_BasePlayer *pLocalPlayer = C_BasePlayer::GetLocalPlayer();
	for(int i = 1; i <= gpGlobals->maxClients; i++ )
		pOtherPlayer = UTIL_PlayerByIndex( i );

		if(!pOtherPlayer->IsAlive( ))
		if(!pOtherPlayer->IsClient( ))
		// draw everyone
		/*if(pOtherPlayer->GetTeamNumber( ) != pPlayer->GetTeamNumber( ))
			continue; // Don't draw enemies TODO radar amplifier */
		if(pOtherPlayer == C_BasePlayer::GetLocalPlayer( ))
			continue; // Don't draw self

		Vector offset = pOtherPlayer->GetAbsOrigin() - pLocalPlayer->GetAbsOrigin();
		offset /= scale; 
		offset.x += panelWidth/2;
		offset.y += panelHeight/2;
		//int drawX = offset.x + panelWidth/2;
		//int drawY = offset.x + panelHeight/2;
		const Vector fixed = Vector(offset.x,offset.y,0);
		QAngle angles;
		VectorAngles(fixed, angles);
		angles.y += pLocalPlayer->EyeAngles().y; // not sure whether you want to add to x, y or z here
		const QAngle angleRef = angles;
		Vector rotated;
		AngleVectors(angleRef, &rotated);
		int drawX = rotated.x;
		int drawY = rotated.y;
		Msg("DrawX = %f \nDrawY = %f", drawX, drawY);
		if ( drawX > 0 && drawY > 0 
		   && drawX < panelWidth && drawY < panelHeight )
		{// this clips to a square, which is less pretty but easier
			surface()->DrawFilledRect( drawX-1, drawY-1, drawX+1, drawY+1 );
			Msg( "surface()->DrawFilledRect( drawX-1 %f, drawY-1 %f, drawX+1 %f, drawY+1 %f );",
				drawX-1, drawY-1, drawX+1, drawY+1 );
	} // end for loop

void CRadarHud::togglePrint()
	if (!show_radar.GetBool())

void CRadarHud::OnThink()

Thanks for your help

Share this post

Link to post
Share on other sites
This is the kind of situation where the debugger will be your best friend. You should start at the beginning of your paint method and follow the variables' values line-by-line. More than likely, you are either using an uninitialized variable or perhaps one of your functions is returning the wrong variable.

Also, since drawX and drawY are integers, your Msg call should use %i instead of %f:

Msg("DrawX = %i \nDrawY = %i", drawX, drawY);

I don't think this would give you the error you are getting, though.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!