Game Development Community

Compass Control

by nohbdy · in Torque Game Engine · 08/27/2001 (4:29 pm) · 14 replies

I've more or less finished implementing a Compass control for use in game

Features:
2d and 3d modes (2d by default)
Needle Color controlled by FillColor in the control's GuiContentProfile
Field to make your own background image

Issues:
Odd behavior when facing more than about 45 degrees up or down
Possibly also a problem scaling to different compass sizes (haven't really checked) - as it is now if the needle didn't fit your compass you'd have to change a hardcoded number, should be moved to a variable

I went ahead and posted a link to download the code and a semi-decent compass PNG file to use

Example Screenshot
Download

To use it, either add it to your playgui through the GUI Editor or just add the following to client/ui/playgui.gui just before the last bracket-semicolon:
new GuiCompassCtrl(Compass) {
   profile = "GuiDefaultProfile";
   horizSizing = "right";
   vertSizing = "top";
   position = "3 377";
   extent = "100 100";
   minExtent = "8 8";
   visible = "1";
   helpTag = "0";
   bitmap = "client/ui/compass.png";
   wrap = "0";
   3d = "0";
};
The needle comes up grey unless you changed your default profile.. its not the prettiest color in the world but it's easy enough to change by changing profiles

Enjoy
-nohbdy

Edit: forgot to mention, if anyone figures out how to get rid of the compass acting weird when you face up or down please let me know so I can fix it, I played with it a bit and couldn't figure it out.. stupid vectors

#1
08/28/2001 (10:37 am)
Hehehe.. well, yet again, we have duplicated effort..

I hope the GG guys get together and decide on something for small "addition/modification" submissions soon. This is pretty loony :)0

If youve got some problems when you get over a certain angle, its quite possible that your having problems with sign values on dot product operations..

I'll post my compass control sometime soon and we can compare :))

I basically added a rotated bitmap on top of the standard bitmap control which rotates with the player orientation.

Thats going to extend into a waypoint control too..

Phil.
#2
09/04/2001 (5:01 pm)
Now, if everyone could flip the image n/s I would be happy :)

COmpass control doesn't read true, looks 180 degrees off (meaning, I know which way is north in real life, when I face that way, compass needle points south). Rather, if I import the png file the way I want it to render the features :)

See inverted terrain bug description in bug forum :)
#3
09/04/2001 (5:13 pm)
insert this change at line 155 or so of guiCompassCtrl.cc:

...
center.y += mBounds.point.y;
cameraRot.neg(); // <--- this flips the orientation, caused by the upside down terrains from bitmaps
Point2F pointA(cameraRot.x * 40, cameraRot.y * 40);
...

That fixes the inverted needle. Next, is to truncate the
needle to constant length as it spins - means changing
the way the needle is rendered. Oh well, that's for another day ...
#4
09/04/2001 (6:09 pm)
Duuuuuuuuuddde!

:)

Thanks :)
#5
09/04/2001 (7:13 pm)
north... south.. its all a matter of prospective :)
I guess I was just interpreting the terrain control backwards (as an arrow pointing where you're facing instead of it being your viewing area.. though it makes much more sense as a viewing area now that I think about it)

Been working on some other things recently but when I get those I'm going to revisit that stupid compass and hammer out some of the bugs with it

-nohbdy
#6
09/04/2001 (7:50 pm)
Well, it only matters if you are working with real terrain data, rather, you only notcie it :)

"Hey, I thought that mountain was to the SOUTH of here..."

That's the only reason I noticed it to begin with :)
#7
09/04/2001 (8:00 pm)
Some duplication isn't a bad thing... writing gui controls is certainly an easy way to started with the engine.

If you want to post small "mods" you can upload them as code snippets :) I've already set up some V12 resource categories for this purpose.
#8
09/30/2001 (12:51 pm)
Am I the only person who had a problem with the script code line,

3d = "0";

in this thread? On my system that seems to be a no-no. I am assuming the having a variable starting with a number is the problem, since when I commented it out the whole thing worked splendidly.
#9
10/01/2001 (6:47 pm)
yes I had the same problem. Once I got the compass in and working, I able to re-add the 3d="1" to fix the pointer length ...
#10
10/16/2001 (8:37 am)
I attempted to readd the compass control to the 1.1 version of the code and I got a link error claiming that the number of parameters to the function below is no longer 3. However, I can't find the function in the code anywhere. Tried "Find in Files" and a hand search of each of the header files being called to no avail.

Does anybody recognize this function and what parameters it now expects? Thanks.

ps. It's on the very last line of the guiCompassCtrl.cc code for those who are wondering where I pulled this line from.

renderChildControls(offset, updateRect, firstResponder);
#11
12/31/2007 (9:30 am)
I added this to TGE 1.5 and had the following issue when compiling:

'renderChildControls' : function does not take 3 parameters"



To repair this, find this code in guiCompassCtrl.cc:

void GuiCompassCtrl::onRender(Point2I offset, const RectI &updateRect, GuiControl *firstResponder)

And change it to:

void GuiCompassCtrl::onRender(Point2I offset, const RectI &updateRect)



Then find this line:

renderChildControls(offset, updateRect, firstResponder);

And change it to:

renderChildControls(offset, updateRect);



Also, in the guiCompassCtrl.h, find line:

void onRender(Point2I offset, const RectI &updateRect, GuiControl *firstResponder);

And change it to:

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



As it says above, in the playGUI.gui, find:

3d = "0";

And comment it out,

// 3d = "0";

After you sucessfully display the compass, you can restore this line, or change it to:

3d = "1";

To fix the pointer length issue.



Also, as it says above, to invert the pointer direction, find these lines in guiCompassCtrl.cc:

center.y += mBounds.point.y;
Point2F pointA(cameraRot.x * 40, cameraRot.y * 40);

And modify it to look like this:

center.y += mBounds.point.y;
cameraRot.neg(); // <--- this flips the orientation, caused by the upside down terrains from bitmaps
Point2F pointA(cameraRot.x * 40, cameraRot.y * 40);
#12
02/01/2008 (8:35 am)
Wow, really old thread. Have to try this anyway.
#13
02/06/2008 (6:27 pm)
Can u change the Compass pic to whatever u want or not?
#14
02/07/2008 (2:15 am)
I would suggest you looking at the newer resource