radar var shows up as 0.000

Started by
1 comment, last by Chaotic_Attractor 15 years, 9 months ago
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;



DECLARE_HUDELEMENT( CRadarHud );

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
	SetHiddenBits( HIDEHUD_PLAYERDEAD);

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


void CRadarHud::Paint()
{
	// draws the radar	
	SetPaintBorderEnabled(false);
	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)
			continue;
		if(!pOtherPlayer->IsAlive( ))
			continue;
		if(!pOtherPlayer->IsClient( ))
			continue;
		// 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()) this->SetVisible(false); else this->SetVisible(true); } void CRadarHud::OnThink() { togglePrint(); BaseClass::OnThink(); } Thanks for your help
Advertisement
Are the values of scale, panelWidth and panelHeight valid?
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.
Strength without justice is no vice; justice without strength is no virtue.

This topic is closed to new replies.

Advertisement