Game Development Community

Horizontal Compass not working?

by Richard Preziosi · in Torque Game Engine · 03/04/2009 (8:53 am) · 2 replies

I've been away for a year, and come back to 1.5 and nothing is working like it used to. I've fixed most, but cannot seem to get my compass to work.

Here's the link to the c files tork.beffy.de/index.php?option=com_remository&Itemid=28&func=select&...

I've added the .cc and .h files to the appropriate folders and rebuilt. and here is my script to bring up the compass.

here is my script for the compass in game
new guiHorizCompassCtrl() {
      canSaveDynamicFields = "0";
      Profile = "GuiDefaultProfile";
      HorizSizing = "right";
      VertSizing = "bottom";
      position = "242 86";
      Extent = "200 21";
      MinExtent = "8 8";
      canSave = "1";
      Visible = "1";
      hovertime = "1000";
      bitmap = "./compasscardinals.png";
      OuterRingBitmap = "./compassborder.png";
      FontWidth = "16";
   };

if i delete the bitmap =, it will show the outer ring just fine, but if i leave the bitmap in nothing shows up at all.

my picture sizes are 89x21 for the outer ring and 630x21 for the bitmap. So the sizing is right, any ideas how to get this working in 1.5.2?

Thanks,
Tannayr

#1
03/07/2009 (2:18 pm)
Figured I'd post the .cc and .h files and someone might be able to spot the problem easier. I'm guessing it's something to do with the mbitmap handling. Since as soon as you set a bitmap for it to use it just turns transparent. I can move it around in the gui editor and get it to be visible in the dead center of the screen, but this only works and shows up inside the gui editor. I've searched for about 3 hours through the project in c++ but I can't find anything that looks like it would cause a problem.

guihorizcompassctrl.cc
//-----------------------------------------------------------------------------
// Torque Game Engine
// 
// Portions Copyright (c) 2001-2002 GarageGames.Com
// Portions Copyright (c) 2001-2002 by Sierra Online, Inc.
//
// Horizontal compass by Stefan "Beffy" Moises
// The basic code (well, almost everything... ;-) for this compass gui
// was written by Xavier "eXoDuS" Amado.
// (with special thanks go to Matt for his compass code)
//-----------------------------------------------------------------------------

#include "console/console.h"
#include "console/consoleTypes.h"
#include "dgl/dgl.h"
#include "game/game.h"
#include "game/gameConnection.h"

#include "game/fps/guiHorizCompassCtrl.h"

IMPLEMENT_CONOBJECT(GuiHorizCompassCtrl);

GuiHorizCompassCtrl::GuiHorizCompassCtrl(void)
{
   mOuterBitmapName = StringTable->insert("");
	mFontWidth = 16.0f;
}


void GuiHorizCompassCtrl::initPersistFields()
{
   Parent::initPersistFields();
   addField("OuterRingBitmap",	TypeFilename, Offset(mOuterBitmapName, GuiHorizCompassCtrl));
   addField("FontWidth",	TypeF32, Offset(mFontWidth, GuiHorizCompassCtrl));
   removeField("wrap");
   removeField("autosize");
   removeField("command");
   removeField("altcommand");
}
void GuiHorizCompassCtrl::setFontWidth(const F32 width){
	mFontWidth = width;
}

bool GuiHorizCompassCtrl::onWake()
{
   if (! Parent::onWake())
      return false;
   setActive(true);
   setBitmap(mBitmapName);
   setOuterBitmap(mOuterBitmapName);
   setFontWidth(mFontWidth);
   return true;
}

void GuiHorizCompassCtrl::onSleep()
{
   mTextureHandle = NULL;
   mOuterTextureHandle = NULL;
   Parent::onSleep();
}


void GuiHorizCompassCtrl::setOuterBitmap(const char *name)
{
   mOuterBitmapName = StringTable->insert(name);
   if (*mOuterBitmapName)
      mOuterTextureHandle = TextureHandle(mOuterBitmapName, BitmapTexture, true);
   else
      mOuterTextureHandle = NULL;
   setUpdate();
}   

void GuiHorizCompassCtrl::setOuterBitmap(const TextureHandle &handle)
{
   mOuterTextureHandle = handle;   
}   


float Vector2dToOffset(Point3F vector)
{
    float offset;
    offset = atanf((1.0F * vector.x) / (-1.0F * vector.y)) * (180.0F / M_PI);
    if ((-1.0F * vector.y) < 0.0F){
		 return offset + 180.0f;
	 }
    else{
		 return offset;
    }
}

void GuiHorizCompassCtrl::onRender(Point2I offset, const RectI &updateRect)
{
   if (mTextureHandle) 
   { 
      dglClearBitmapModulation();  
      TextureObject* texture = (TextureObject*) mTextureHandle;  

      mBounds.extent.set(texture->bitmapWidth, texture->bitmapHeight + 2);   

      struct CameraQuery query;   
      GameProcessCameraQuery(&query);   
      MatrixF cameraMatrix = query.cameraMatrix;   
      Point3F cameraRot;   
      cameraMatrix.getColumn(1, &cameraRot);   
      // this rotates the compass by 180&deg;
      //cameraRot.neg();   
      cameraRot.z = 0;   

      mOffset = Vector2dToOffset(cameraRot);   
      //RectI dstRect(offset.x + mOffset-270, offset.y, mBounds.extent.x, mBounds.extent.y);   
      RectI dstRect(offset.x + mOffset-315, offset.y + 2 ,mBounds.extent.x, mBounds.extent.y);   
      dglDrawBitmapStretch(mTextureHandle, dstRect); 
   }

   if(mOuterTextureHandle)
   {
	   TextureObject* texture = (TextureObject*) mOuterTextureHandle;
	   mBounds.extent.set(texture->bitmapWidth, texture->bitmapHeight);

	   RectI outerRect(offset, mBounds.extent);
	   dglDrawBitmapStretch(mOuterTextureHandle, outerRect);
   }

   if (mProfile->mBorder || !mTextureHandle && !mOuterTextureHandle)   
   {
      RectI rect(offset.x, offset.y, mBounds.extent.x, mBounds.extent.y);
      dglDrawRect(rect, mProfile->mBorderColor);
   }

   renderChildControls(offset, updateRect);
}

#2
03/07/2009 (2:19 pm)
guihorizcompassctrl.h
//-----------------------------------------------------------------------------
// Torque Game Engine
// 
// Copyright (c) 2001 GarageGames.Com
// Portions Copyright (c) 2001 by Sierra Online, Inc.
//-----------------------------------------------------------------------------

#ifndef _GUIHORIZCOMPASSCTRL_H_
#define _GUIHORIZCOMPASSCTRL_H_

#ifndef _GUIBITMAPCTRL_H_
#include "gui/controls/guiBitmapCtrl.h"
#endif

struct CameraQuery
{
   SimObject*  object;
   F32         nearPlane;
   F32         farPlane;
   F32         fov;
   MatrixF     cameraMatrix;
};

class GuiHorizCompassCtrl : public GuiBitmapCtrl
{
private:
	typedef GuiBitmapCtrl Parent;
	F32 mOffset;

protected:
   StringTableEntry mOuterBitmapName;
   TextureHandle mOuterTextureHandle;
	F32 mFontWidth;

public:
	//creation methods
	DECLARE_CONOBJECT(GuiHorizCompassCtrl);
	GuiHorizCompassCtrl();
   static void initPersistFields();

   //Parental methods
   bool onWake();
   void onSleep();

   void setOuterBitmap(const char *name);
	// adjust graphic position in regard to the font/letter size of the compass
   void setFontWidth(const F32 width);
   void setOuterBitmap(const TextureHandle &handle);

   void onRender(Point2I offset, const RectI &updateRect);
};

#endif