Sign in to follow this  
badderjet

HSI Rotating Numbers in GDI+

Recommended Posts

Hi all,working on my HSI i have a Problem with the Numbers for that. I spent many hours to solve this but it seems i can't see what's wrong. The Numbers are Drawn and rotatet, but both in the wrong Direction. "0" Degrees is drawn at 180 degrees and then all others are Anti-Clockwise.Will Post here the Code i'm using for that and also a Picture of the Result in FSX:

// Full Arc Numbers			float cx = 194; // center point xfloat cy = 194; // center point yfloat radius = 130; // Inner Radiusdouble rotation = (AdiruND.MagHeading() * -1); // Mag Headingfloat dx,dy, nx, ny, angle;int pointx, pointy;int numbers[12] = {0, 3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33};int i = 0;for (angle = 0.0 - rotation; angle < 358.0 - rotation; angle += 30.0){				nx = sin(angle * 3.1415926535 / 180.0);	ny = cos(angle * 3.1415926535 / 180.0);	dx = nx * radius;	dy = ny * radius;	pointx = cx + dx;	pointy = cy + dy;	Matrix matrix;  matrix.RotateAt(angle,PointF(pointx+11,pointy+11),MatrixOrderAppend);graphics.SetTransform(&matrix);RectF strRect(pointx, pointy, 22, 22);WCHAR nbr_wch[24] = L"";swprintf (nbr_wch, L"%d", numbers[i]);graphics.DrawString(nbr_wch, -1, &largeNumbers, strRect,&stringCenter,&whiteBrush);graphics.DrawRectangle(&whitePen, strRect); // As visual referencei++;}

RegardsSven

Share this post


Link to post
Share on other sites
Help AVSIM continue to serve you!
Please donate today!

Ok, now i have it working :-) . Here is the revised Code:float radius = 130; // Number Radiusint pointx, pointy;int numbers[12] = {18, 21, 24, 27, 30, 33, 0, 3, 6, 9, 12, 15};int i = 0;for (angle = 360.0 - rotation ; angle > 2.0 - rotation; angle -= 30.0){ nx = sin(angle * 3.1415926535 / 180.0); ny = cos(angle * 3.1415926535 / 180.0); dx = nx * radius; dy = ny * radius; pointx = (cx + dx) - 11; pointy = (cy + dy) - 11; Matrix matrix; matrix.RotateAt(((angle *-1) +180), PointF(pointx+11, pointy+11), MatrixOrderAppend); graphics.SetTransform(&matrix); RectF strRect(pointx, pointy, 22, 22); WCHAR nbr_wch[24] = L""; swprintf (nbr_wch, L"%d", numbers); graphics.DrawString(nbr_wch, -1, &largeNumbers, strRect, &stringCenter, &whiteBrush); i++;}Have anyone a better (or faster) Solution?RegardsSven

Share this post


Link to post
Share on other sites

>Have anyone a better (or faster) Solution?Graphics->RotateTransform (degs) etcCheers, :-beerchugEtienne :-waveEDITAh btw, for the loop you eventually *could* use something likegraphics->TranslateTransform (cx, cy);for (i = 0; i < 36; i++){ graphics->DrawThatTickMark (...) if (i % 3 == 0) DrawThatNumberString (...) graphics.RotateTransform (10);}Have not tested but something like this might work.

Share this post


Link to post
Share on other sites

Ok. I've tried the following:// Full Arc{ graphics.TranslateTransform(194,194); graphics.RotateTransform(AdiruND.MagHeading() *-1); { float cx = 0; // center point x float cy = 0; // center point y float radius1 = 158; // Outer Radius float radius2 = 146; // Inner Radius float dx,dy, dx2, dy2, nx, ny, angle; int v1x, v1y, v2x, v2y; int numbers[12] = {18, 21, 24, 27, 30, 33, 0, 3, 6, 9, 12, 15}; int i = 0; for (angle = 360.0; angle > 2.0; angle -= 10.0) { nx = sin(angle * 3.1415926535 / 180.0); ny = cos(angle * 3.1415926535 / 180.0); dx = nx * radius1; dy = ny * radius1; v1x = cx + dx; v1y = cy + dy; dx2 = nx * radius2; dy2 = ny * radius2; v2x = cx + dx2; v2y = cy + dy2; graphics.DrawLine(&largeWhitePen, v1x, v1y, v2x, v2y); if(MODULO(angle,3) == 0) { RectF strRect(v1x, v1y, 24, 22); WCHAR nbr_wch[24] = L""; swprintf (nbr_wch, L"%d", numbers); graphics.DrawString(nbr_wch, -1, &largeNumbers, strRect, &stringCenter, &whiteBrush); //graphics.RotateTransform (10); i++; } } }Works, but i can't rotate the Numbers using graphics.RotateTransform(10) in the if(MODULO...) Statement. If i uncomment them a few Tickmarks and most of the Numbers disappear from the HSI. Again, could you give me some Hint how to fix this?RegardsSven

Share this post


Link to post
Share on other sites

As for the mod, the number should usually be of int type, if that helps.Also, you should not need to use that number array (you can simply take your for-loop variable to draw the appropriate number).>nx = sin(angle * 3.1415926535 / 180.0);>ny = cos(angle * 3.1415926535 / 180.0);You actually should not need to do any of that trig calc at all. That's what the xform already does for you.In pseudo code, the only thing you should need to do to e. g. draw the ticks:...TranslateTransform (cx, cy);...RotateTransform (-heading);for (...){graphics.DrawLine (&largeWhitePen, 0, radius1, 0, radius2);......RotateTransform (10);}You could also upload a picture of your current results to make it easier to understand what is going wrong.If you need more help, don't hesitate to post here or just write me a PM.Regards,Etienne

Share this post


Link to post
Share on other sites

Hi Etienne,with some Help from you and others now i heave it working like it should.// Full Arc { graphics.TranslateTransform(194,194); graphics.RotateTransform(AdiruND.MagHeading() *-1); for(int i = 0; i < 358; i+= 5) { if (i % 30 == 0) { WCHAR nbr_wch[24] = L""; swprintf (nbr_wch, L"%d", (i/10)); graphics.DrawString(nbr_wch, -1, &largeNumbers, PointF(-5, -105), &whiteBrush); } if (i % 10 == 0) { graphics.DrawLine(&largeWhitePen, 0, -110, 0, -120); } graphics.RotateTransform(5.0); } }I think this is what you mean (or similar). So, thanks again.RegardsSven

Share this post


Link to post
Share on other sites

Ok yes, two things though. ;)First of all I am sure a 2-character buffer would also do instead of a 24 one, just to save some bits.And since you are not drawing anything in 5

Share this post


Link to post
Share on other sites

In practice, I've found that buffer should be n+1 at a minimum... ;)

Share this post


Link to post
Share on other sites

>In practice, I've found that buffer should be n+1 at a>minimum... ;)Ahm, in practice I think you are very right... LOL :-lol There you go, obvious I have not touched any code for months now. *:-*Thanks for the heads up. :-eekCheers, :-beerchugEtienne :-wave

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this