Artificial Horizon GUI Control
by Brett Fattori · 03/01/2003 (5:05 pm) · 19 comments
Updated 03/04/2003
You'll prolly find out that roll is backwards. I fixed my in game models and the change isn't to Yaw, it's to Roll. Change the line that reads:
Updated 03/02/2003
I've fixed the files, you can get the fixed ones at this site now, the limit appears to be 100Kb and the file is at 106Kb...
As for the required dglDrawBitmapRotated function, if you don't use the supplied dlg.h and dgl.cc files, you can just follow the instructions in the ReadMe, or here ya go:
In dgl.h, right after the declaration for dglDrawBitmap, add the following:
Then in dlg.cc, following the definition of dglDrawBitmap, add the following function:
I've removed the bad include file, sorry for the mixup!!
I have included a ReadMe file that spells it all out. It's (hopefully now) just another one of those controls that you can drop in and run with! It'll be especially useful for those of you making flying simulators (Frank and team making DoP!!)
Anyhoo.. if ya have comments/concerns/bugs/donations (kidding!!) send them along to my email.
Again, the updated files are at this site now.
You'll prolly find out that roll is backwards. I fixed my in game models and the change isn't to Yaw, it's to Roll. Change the line that reads:
roll = mRadToDeg(rot.y);to read:
roll = -mRadToDeg(rot.y);
Updated 03/02/2003
I've fixed the files, you can get the fixed ones at this site now, the limit appears to be 100Kb and the file is at 106Kb...
As for the required dglDrawBitmapRotated function, if you don't use the supplied dlg.h and dgl.cc files, you can just follow the instructions in the ReadMe, or here ya go:
In dgl.h, right after the declaration for dglDrawBitmap, add the following:
void dglDrawBitmapRotated(TextureObject *texObject,
const RectI& in_rStretch,
const RectI& in_rSubRegion,
const U32 in_flip = GFlip_None,
const F32 spinAngle = 0.0f,
const Point2F spinOffset = Point2F(0,0) );Then in dlg.cc, following the definition of dglDrawBitmap, add the following function:
void dglDrawBitmapRotated(TextureObject *texture,const RectI& dstRect,const RectI& srcRect,const U32 in_flip,F32 spinAngle, const Point2F spinOffset)
{
AssertFatal(texture != NULL, "GSurface::drawBitmapStretchSR: NULL Handle");
if(!dstRect.isValidRect())
return;
AssertFatal(srcRect.isValidRect() == true,
"GSurface::drawBitmapRotated: routines assume normal rects");
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, texture->texGLName);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glDisable(GL_LIGHTING);
F32 texLeft = F32(srcRect.point.x) / F32(texture->texWidth);
F32 texRight = F32(srcRect.point.x + srcRect.extent.x) / F32(texture->texWidth);
F32 texTop = F32(srcRect.point.y) / F32(texture->texHeight);
F32 texBottom = F32(srcRect.point.y + srcRect.extent.y) / F32(texture->texHeight);
F32 screenLeft = dstRect.point.x;
F32 screenRight = dstRect.point.x + dstRect.extent.x;
F32 screenTop = dstRect.point.y;
F32 screenBottom = dstRect.point.y + dstRect.extent.y;
if(in_flip & GFlip_X)
{
F32 temp = texLeft;
texLeft = texRight;
texRight = temp;
}
if(in_flip & GFlip_Y)
{
F32 temp = texTop;
texTop = texBottom;
texBottom = temp;
}
glColor4ub(sg_bitmapModulation.red,
sg_bitmapModulation.green,
sg_bitmapModulation.blue,
sg_bitmapModulation.alpha);
F32 X = 0;
// calculate the centroid of the rectangle (to use as rotation pivot)
if (screenLeft < screenRight)
{
X = screenLeft + ((screenRight - screenLeft)*0.5f);
}
else
{
X = screenRight + ((screenLeft - screenRight)*0.5f);
};
F32 Y = 0;
if (screenTop < screenBottom)
{
Y = screenTop + ((screenBottom - screenTop)*0.5f);
}
else
{
Y = screenBottom + ((screenTop - screenBottom)*0.5f);
};
// spin angle is in degree's so convert to radians..radians = degrees * pi /180
spinAngle = spinAngle * 3.14 / 180.0f;
Point2F screenPoint(X,Y);
F32 width = dstRect.extent.x;
width *= 0.5;
MatrixF rotMatrix( EulerF( 0.0, 0.0, spinAngle ) );
Point3F offset( screenPoint.x, screenPoint.y, 0.0 );
Point3F points[4];
points[0] = Point3F(-width+spinOffset.x, -width+spinOffset.y, 0.0);
points[1] = Point3F(-width+spinOffset.x, width+spinOffset.y, 0.0);
points[2] = Point3F( width+spinOffset.x, width+spinOffset.y, 0.0);
points[3] = Point3F( width+spinOffset.x, -width+spinOffset.y, 0.0);
for( int i=0; i<4; i++ )
{
rotMatrix.mulP( points[i] );
points[i] += offset;
}
glBegin(GL_TRIANGLE_FAN);
glTexCoord2f(texLeft,texTop);
glVertex2fv(points[0]);
glTexCoord2f(texLeft, texBottom);
glVertex2fv(points[1]);
glTexCoord2f(texRight, texBottom);
glVertex2fv(points[2]);
glTexCoord2f(texRight, texTop);
glVertex2fv(points[3]);
glEnd();
glDisable(GL_BLEND);
glDisable(GL_TEXTURE_2D);
}I've removed the bad include file, sorry for the mixup!!
I have included a ReadMe file that spells it all out. It's (hopefully now) just another one of those controls that you can drop in and run with! It'll be especially useful for those of you making flying simulators (Frank and team making DoP!!)
Anyhoo.. if ya have comments/concerns/bugs/donations (kidding!!) send them along to my email.
Again, the updated files are at this site now.
About the author
Recent Blogs
• A small hello• Recent Stuph
• So long and so out of touch...
• Plan for Brett Fattori
• Plan for Brett Fattori
#2
Again, sorry for the mixup. The new file (as stated above) can be found here.
- Brett
03/02/2003 (8:05 am)
Sorry about the problems, Badguy, I missed the include for my heliVehicle class (which isn't even used in it!!). I've fixed up the files and included the necessary dglDrawBitmapRotated function above and in the ReadMe file.Again, sorry for the mixup. The new file (as stated above) can be found here.
- Brett
#3
03/02/2003 (1:15 pm)
gw Brett thanks for the fix's ill try this out now :)
#4
Does anyone else see this or is it just me?
03/08/2003 (5:52 pm)
This is a cool control. It works nicely with one exception, at least for me... and that is that when I run from the visual C++ debugger, I get a stack error. I'm pretty sure it has to do with passing in a default Point2F in the draw rotated function, but I'm not sure exactly what the problem is. The stack somehow gets corrupted.Does anyone else see this or is it just me?
#5
- Brett
03/11/2003 (8:38 am)
I haven't had that particular problem with it... If it pops up, you'll be the first one to know.- Brett
#6
I fixed it by replacing the block:
03/15/2003 (7:42 pm)
Yeah. I can't use a Point2F constructor inside dgl.h, since it isn't using the full class, just a little "class Point2F;" at the top.I fixed it by replacing the block:
class Point2I; class Point2F; class Point3F;with
#ifndef _MPOINT_H_ #include "math/mPoint.h" #endif //class Point2I; //class Point2F; //class Point3F;
#7
- Brett
03/16/2003 (6:54 pm)
Thanks for finding this, Max. Hope that this control is finding uses amongst y'all.- Brett
#8
Also, is there a way to keep the attitude_spin.png from being so squished vertically that when you pitch heavily, you see passed the end of the image?
Thanks a lot =) Robert
03/16/2003 (9:00 pm)
Hrm... it doesn't seem to fix the problem I get "Run-Time Check Failure #2 - stack around the variable 'dstRect' was corrupted." Again, this only happens when I set a break point in say onRender() and then run the program.Also, is there a way to keep the attitude_spin.png from being so squished vertically that when you pitch heavily, you see passed the end of the image?
Thanks a lot =) Robert
#9
However, the answer to your other questions is the option spinKeepAspect Setting this to 1 makes the spin bitmap keep the aspect of the control. This causes the squishing you're seeing. Set it to 0 and make it larger than the image of the frame.
- Brett
03/17/2003 (6:41 am)
Hrm... I need to try this again from the debugger cause I just didn't get these problems!However, the answer to your other questions is the option spinKeepAspect Setting this to 1 makes the spin bitmap keep the aspect of the control. This causes the squishing you're seeing. Set it to 0 and make it larger than the image of the frame.
- Brett
#10
03/24/2003 (1:16 am)
Yeah, might not be a bad idea. I have confirmed what I found by removing your control and retesting in debug. I don't know what if any problems will occur on all machine types and memory configs in the release version.
#11
09/07/2003 (7:59 am)
Does this play well with the other compass controls?
#12
- Brett
09/10/2003 (2:04 pm)
It should.. The only issue might be the dglDrawBitmapRotated function. It might conflict with them.- Brett
#13
05/04/2004 (6:29 pm)
attitude indicator :p
#14
mSpinOffset.y = pitch; to mSpinOffset.y = -pitch.
But everything else worked fine. Great resource.
06/06/2004 (4:12 pm)
I corrected a strange behaviour where the pitch was backward, the more you climbed, the more yellow ( ground ) you got. just set line 225 :mSpinOffset.y = pitch; to mSpinOffset.y = -pitch.
But everything else worked fine. Great resource.
#15
e:\torque\sdk\engine\dgl\dgl.cc(17) : fatal error C1083: Cannot open include file: 'sim/frameAllocator.h': No such file or directory
is it ok to just comment it out?
01/18/2006 (11:26 pm)
I cant seem to get this working with 1.4 i dont have sim/frameallocator.h it requires? am i missing something?e:\torque\sdk\engine\dgl\dgl.cc(17) : fatal error C1083: Cannot open include file: 'sim/frameAllocator.h': No such file or directory
is it ok to just comment it out?
#16
In dgl.cc, change #include "sim/frameAllocator.h" to #include "core/frameAllocator.h", that should work.
04/07/2006 (9:02 pm)
@Greg, In dgl.cc, change #include "sim/frameAllocator.h" to #include "core/frameAllocator.h", that should work.
#17
10/12/2009 (8:25 pm)
Does anyone have the files for this resource?
#18
03/30/2010 (11:28 am)
BUMP ... can someone re-host / re-post the files required for this resource ? 
Torque Owner Badguy
Not Quit drop in
1.) including : #include "game/vehicles/heliVehicle.h"
not available in head.
2.) function required : dglDrawBitmapRotated(.. 6 param ..)
I did dig out a 5 param found in PC's Old Tut, but what did you use the bool for?
where did this function come from?
(neither are mentioned in the ReadMe.txt)