Game Development Community

Gui rotation

by UZON · in Torque Game Engine · 10/25/2007 (11:07 am) · 5 replies

I need to have the ability to rotate my guis, or at least rotate a guiBitmapCtrl, can some one give me a hand on this ? i think it is a preaty basic feature, I think it should be easy to implement for someone that know better about render stuff.

#1
10/25/2007 (11:16 am)
Rotating general GUIs is a fairly daunting task,
especially inheriting the rotation from parent to children.

however, i have frequently wanted a rotating guiBitmapCtrl,
and i think that one control would be relatively straight-forward.

i think you'd want to pass an angle in to dglDrawBitmapStretchSR() and rotate the polygon.

another option would be to integrate TGB with TGE,
which i hear is not difficult,
and then take advantage of all the cool 2D gui stuff which TGB provides.
#2
10/25/2007 (12:41 pm)
Dont i have to own a TGB licence to do it ? I dont know the TGB 2D gui abilitys, but what i already have with torque (excluding the editor :D ) i think is very good, not a adobe flash, but good enough to make a gui for my game, maybe some add-ons would be good for the mini-games that i have on it, but i think the only thing that it really lack is the rotation function, that like i said, in my vision, is a simple thing to implement.

But i will follow your hint and try to understand the dglDrawBitmapStretchSR. :)
#3
10/25/2007 (12:51 pm)
Take a look at the code in the guiRadar resources, Google Results.
From that code you can likely figure out how they rotate the compass and the radar bitmap
and use that same method to alter the rotation of your gui control.
#4
10/25/2007 (1:23 pm)
@kevin, can you point the exact resource? i took a look on some of them but didnt find anything.

Ok, now i have something to work with, my Bitmaps are already rotating, but i think i need to recalculate its area somehow because it is cutting some parts of image, or it will only work with square images (wich luckly is my case). Here is what i done:

if(mWrap)
		{
 			TextureObject* texture = (TextureObject *) mTextureHandle;
			RectI srcRegion;
			RectI dstRegion;
			float xdone = ((float)mBounds.extent.x/(float)texture->bitmapWidth)+1;
			float ydone = ((float)mBounds.extent.y/(float)texture->bitmapHeight)+1;

			int xshift = startPoint.x%texture->bitmapWidth;
			int yshift = startPoint.y%texture->bitmapHeight;
			for(int y = 0; y < ydone; ++y)
				for(int x = 0; x < xdone; ++x)
				{
		 			srcRegion.set(0,0,texture->bitmapWidth,texture->bitmapHeight);
  					dstRegion.set( ((texture->bitmapWidth*x)+offset.x)-xshift,
								      ((texture->bitmapHeight*y)+offset.y)-yshift,
								      texture->bitmapWidth,	
								      texture->bitmapHeight);
   				[b]dglDrawBitmapStretchSR(texture,dstRegion, srcRegion, false, mRotation);[/b]
				}
		}
		else
      {
         RectI rect(offset, mBounds.extent);
	      [b]dglDrawBitmapStretch(mTextureHandle, rect, false, mRotation);[/b]
      }
   }

void GuiBitmapCtrl::setRotation(F32 rotation)
{
    mRotation = rotation;
}

ConsoleMethod(GuiBitmapCtrl, setRotation, void, 3, 3, "(F32 Rotation)")
{
	object->setRotation(dAtof(argv[2]));
}

Hope for some help to finish it.
#5
10/25/2007 (2:00 pm)
The first one that comes up is for the original guiRadar resource.

You also might look at the Artificial Horizon resource. I'm basically working
with this one myself to come up with a combination radar and heading indicator for space flight.

Take a look at the messages posted in the artifical horizon link. There's more information in there
that might help. In any rotation of an image you're likely to want the image to be square, or it will
look funny when it gets rotated.