Game Development Community

Horizontal Compass

by Chris Byars · in Torque Game Engine · 05/04/2005 (3:35 am) · 23 replies

Thread continued from: www.garagegames.com/mg/forums/result.thread.php?qt=5578

Using the Horizontal Compass code bit: tork.beffy.de/modules.php?op=modload&name=Downloads&file=index&req=getit&lid=11.

The Horizontal Compass, as seen in other Torque based games, was designed so that a smaller bitmap (border) could be placed around a 630px length North East South West image, and the image scrolls according to the direction your character is facing. The code was designed so that the 630px bitmap appeared to repeat when the bar scrolled and such. It does, however the only way to get this to function for some reason is if the border bitmap is the same size as the N E S W bitmap. But the entire bar shows up, and it will move erratically if you look at the edges as compared to the smooth flowing as it shows in the center, because the bar was coded to be able to give the illusion that it repeats, because normally the "border" bitmap would prevent the user from viewing the rest of the bar not within however many pixels wide the border was. If you take a look at this resource's example game, coded in Torque 1.2, if functions correctly:

www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=6165

Here's how it should work. Here is a 100px border bitmap.
_______________
[______________] 

Here is the 630px x 32px N E S W bar.
___________________________________________________
[___N___E____S_____W_____N______E______S_______W__]

So, it should only show in the border bitmap 100px of that at a time.But, since with the 1.3 code, it seems that the border bitmap must be the 630x32 as the bar is. You see that entire NESWNESW bar, and it "jumps" at the edges after a certain amount of scrolling so that the center part of it stays smooth to give the illusion of a perfectly scrolling compass.

So there must be something wrong with the .cc or .h files for them to not function as they did in Torque 1.2, in 1.3. Or maybe it's my fault. I don't know, that's why I'm posting for help here.

Thanks.
Page «Previous 1 2
#1
05/06/2005 (5:08 pm)
*raises eyebrow*
#2
05/06/2005 (10:57 pm)
*winks and drinks his root beer*
#3
05/07/2005 (8:06 am)
*wonders if there is a kind soul out there with knowledge on this issue, as I do not contain it* hehe
#4
05/07/2005 (8:29 am)
*Wonders why this is in discussions now and what happened to the other thread on the exact same subject*
#5
05/07/2005 (8:41 am)
*took the thread and reposted it in the private forums, because it originally was in the Public*
#6
05/07/2005 (4:43 pm)
The source code as is doesn't seem to do any smooth wrapping. Just moves the one strip around in a way that looks good if you don't see the edges.
#7
05/07/2005 (6:20 pm)
Exactly.

But, the way it's supposed to be is so that the only part viewable is however large the border bitmap is. :/ Some reason it's not doing that.
#8
05/07/2005 (10:31 pm)
Post a screenshot of the problem?
#9
05/08/2005 (6:02 am)
How it should work:
ion-productions.com/screenCompass1.jpg

To see that example, download this resource:
torque.intelligentdevelopment.sk/beginners/AndyGFX_UNI_TGE_1.2.2.c.zip

How it appears in my game, using the same HorizCompass.cc/h files:
ion-productions.com/screenCompass.jpg

For some reason it works with Torque 1.2.2 and not Torque 1.3.
#10
05/08/2005 (3:09 pm)
Looks like the clip rect isn't getting set properly. (dglSetClipRect, I believe, is the appropriate call).
#11
05/08/2005 (3:20 pm)
I'm not much of a C++ person, so bear with me. I assume I would put a dglSetClipRect in this part of the horizCompass.cc code?

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);
}

Not sure how to word that in the code. :P
#12
05/08/2005 (6:18 pm)
You'd set it right before you drew the inner rectangle... The rectangle you pass is in screen co-ordinates the area you want to limit drawing to.
#13
05/08/2005 (6:33 pm)
*doesn't know how to do that* :(
#14
05/09/2005 (3:04 am)
Have you tried looking for other places dglSetClipRect is used, to see how it solves similar problems? (For instance, the GuiArrayCtrl, which implements basic rendering functionality for grid controls, might use it.)

I'd love to help you out and just give you a working implementation, but I'm too busy to do more than give general guidance. :-/
#15
05/11/2005 (9:20 pm)
Try changing the first if block in onRender to this:

if (mTextureHandle) 
{ 
  dglClearBitmapModulation();  
  TextureObject* texture = (TextureObject*) mTextureHandle;  

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

  struct CameraQuery query;   
  GameProcessCameraQuery(&query);   
  MatrixF cameraMatrix = query.cameraMatrix;   
  Point3F cameraRot;   
  cameraMatrix.getColumn(1, &cameraRot);   
  cameraRot.neg();   
  cameraRot.z = 0;   

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

This worked for me to get the compass to scroll correctly.
#16
05/12/2005 (3:37 am)
Thanks, I'll try that. :)
#17
05/12/2005 (3:16 pm)
Works like a dream. :)
#18
01/14/2006 (11:08 pm)
I got really strange behaviour here... (tge1.4, apprx "New Year HEAD")
In debug it's working fine! Very nice looking, etc..
But when I run "release" build, it does not want to render... If I remove "bitmap" picture - it renders the border nice. When I set the picture back - it doesn't show up...
meh... I did made a "clean" build, did delete *.dso files... and feel myself like an idiot now..
I can't debug it, as debug build works fine... grrrh
#19
01/16/2006 (1:09 pm)
I'm currently working on porting our game from 1.3 to 1.4 which uses the compass too. I havent gotten to the point of porting the compass yet, but when I do I'll let you know if I find anything out. So far it worked great for us in 1.3
#20
03/28/2006 (4:49 pm)
Okay... it's long time past since I tried to make it working...
I've just found some time to play with it...
After checking the code, playing with GUI, etc... I found really strange .... bug(?)
As I said before, this works fine in debug build, but don't want in release.. In January I used HEAD.. Now - i have heavily modified 1.4+TLK but still the same...
www.afterworld.ru/gg/horizCompass.jpg
this picture shows what I'm talking about... If I move this GUI object up - it disapears complitely when the extend V is less 194. If I move it down (see horizCompass at left) - the object is moved, but picture stays at the same place.. If I move more down - nothing rendered on screen. Moving left-right does not make any difference.
And, additionaly, if I remove "bitmap" from this component it renders border at any place of screen.. until I set texture back.. ;-/
I've looked at GuiBitmapCtrl where it gets "setBitmap" attribute from .. and it's written there:
"Set the bitmap displayed in the control. Note that it is limited in size, to 256x256."
Does it somehow related?
and WHY ITS WORKING IN DEBUG and not in RELEASE build? ;) I'm getting crazy now.. hehe..
hope someone will find out where is a problem...
Page «Previous 1 2