Game Development Community

How do i make GUIs rotatable ?

by Cai Yundong · in Torque 3D Professional · 06/06/2010 (11:28 pm) · 1 replies

Hi, I'm wondering if there is a way to make gui objects rotatable ? For example, similar to the old PlasticBitmap. The reason i'm asking is that i need to attach a slider to 2 gui objects which requires a rotated slider.

For my particular slider case, the drawing portion seems to be below, any way to set a rotation ? Also, what doe mHasTexture do ? as i don't see anyway to set it and its false by default. Sorry if these are very stupid questions =X

// horz rule
         PrimBuild::vertex2i( pos.x + mid.x, pos.y );
         PrimBuild::vertex2i( pos.x + mid.x, pos.y + mid.y );

         // tick marks
         for( U32 t = 0; t <= ( mTicks + 1 ); t++ )
         {
            S32 y = (S32)( F32( mid.y - 1 ) / F32( mTicks + 1 ) * F32( t ) );
            PrimBuild::vertex2i( pos.x + mid.x - mShiftPoint, pos.y + y );
            PrimBuild::vertex2i( pos.x + mid.x + mShiftPoint, pos.y + y );
         }

#1
08/10/2010 (4:20 am)
Ok, kind of a late response but I'd still like to give it a shot.

Quote:any way to set a rotation ?

Not per se. One problem with rotation is that it also affects the hit detection and does so in a way that is very alien to the GUI system which exclusively deals with rectangular, axis-aligned areas.

One thing that can be quite easily build into the GUI rendering code is to alter the rendering matrix. This allows to easily apply custom rotations (save matrices, rotate, render, restore matrices) though you have to make sure to use the correct rotation centers. This could even be used in a hierarchical fashion.

However, for the hit detection, you would have to take rotation into account which is much more tricky. Rotations affect both bounding box hit detection as well as individual element hit detection. For bounding boxes, you could probably simply alter GuiControl to adapt to take rotation into account. For the individual element hit detection, your best bet is to pre-transform coordinates into place. Otherwise you'd have to go in and alter a lot of code.

Transforming coordinates before the queries would mean that, for example, you would pass rotated mouse coordinates into the control's event handlers.

With a little bit of smart, it might be possible to implement the entire thing inside GuiControl and GuiCanvas without affecting the implementation of any of the other GuiControl classes.

Quote:Also, what doe mHasTexture do ?

It's a check to make sure the bitmap that is assigned to the profile used by the slider is a bitmap array with at least as many entries as required to render all the tiles that a slider uses.