Archived

This topic is now archived and is closed to further replies.

Guest VAPilot

A couple of questions

Recommended Posts

I am getting on quite well learning C++, but I have a couple of problems, which I can not seem to get my head around, so am hoping one of the experts can point me in the right direction.1/. I have made a pitch inclinmeter using MAKE_MOVING, which works ok untill the engine is stopped then instead of the pitch indicator falling to display down 20 degrees, is shows climb 20 degrees. I have tried reversing the range values, but that reverses the way the indcator works when the engine is running. Is it possible to reverse a token variable in a MAKE_MOVING so it work the same way as it does in a MAKE_SPRITE ?2/. I am using MAKE_NEEDLE to rotate my fuel control switch. My code works but it rotates to quickly. How do you slow a needle down ? The switch has two positions.Thanks in advanced for any help

Share this post


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

>I am getting on quite well learning C++, but I have a couple>of problems, which I can not seem to get my head around, so am>hoping one of the experts can point me in the right>direction.>>1/. I have made a pitch inclinmeter using MAKE_MOVING, which>works ok untill the engine is stopped then instead of the>pitch indicator falling to display down 20 degrees, is shows>climb 20 degrees. I have tried reversing the range values, but>that reverses the way the indcator works when the engine is>running. Is it possible to reverse a token variable in a>MAKE_MOVING so it work the same way as it does in a>MAKE_SPRITE ?>I have no idea what variable you're using... a bit more information would be helpful.>2/. I am using MAKE_NEEDLE to rotate my fuel control switch.>My code works but it rotates to quickly. How do you slow a>needle down ? The switch has two positions.>>Thanks in advanced for any help>>Is there a reason you are using MAKE_NEEDLE? Most switches and knobs are created with MAKE_ICON.

Share this post


Link to post
Share on other sites

Hi Ed1/.The Token variable is ATTITUDE_INDICATOR_PITCH_DEGREES, when used in a MAKE_SPRITE macro, you can scale it -1.0 for example, so when the aircraft is nose up the card comes down, and the card comes up when in a nose down position, turn the engines off and the attitude card will come down, in my MAKE_MOVING code this work differently. I am using an indicator instead of a card, the range is set to -20 20, it displays correctly while the engine is running, but turn it off and the indicator moves up rather than down. So I surpose what I need to do is make the variable display the other way around, then alter the range and it should work how I want it to. I think it might be a case of change to a MAKE_SPRITE macro. 2/.In xml I used rotate for gauges like fuel cutoff switches, it means I only have to draw one bitmap and then FS rotates it for me :-) as I said the gauge works, but would like it to turn slower. For a working example of what I am trying to do, look at the Curtis Jenny in FS9 fuel_shutoff.

Share this post


Link to post
Share on other sites

It's rather basic math to invert the sign of a value... it's value*-1. That should allow you to change the behavior as you see fit.As for your knob... if a knob has 2 positions... it's going to move instantly between those two positions. So... what are you trying to "slow down"?

Share this post


Link to post
Share on other sites

I guess because it looks pretty... I used to use that method but I abandoned it because you can't (easily) create shadows for a needle.You need to slow the needle rotation in the callback routine. For example, let's assume you have a two-position switch and that you are moving from 0 degrees to 90 degrees on the first click and 90 degrees to 180 degrees on the second click:int switch_pos=0;//switch position on the backgroundint click1=0;//Mouse callback selection 0,1,2//----------Needle callback routine//Rotate clockwise one positionif (click1==1 && switch_pos<90){ switch_pos+=0.25;}//Turn the switch to fully onif (click1==2 && switch_pos<180){ switch_pos+=0.25;}//Rotate anticlockwise one positionif (click1==1 && switch_pos>90){ switch_pos-=0.25;}//Return the switch to offif (click1==0 && switch_pos>0){ switch_pos-=0.25;}return switch_pos;Adjust the switch_pos calculations to suit your required speed.-Dai

Share this post


Link to post
Share on other sites

1/. Inclinmeter>It's rather basic math to invert the sign of a value... >it's value*-1. That should allow you to change the >behavior as you see fit.Thats what I thought, but after testing again tonight I have come to the conclusion that what ever I do, it will not work the way I want it to without adding a bit of custom code. Tonight I changed it to a MAKE_SPRITE and get the same results, if the pitch is displayed how I want it to be displayed, then when the engine is turned off the indicator is going to move upwards, to get it to move downwards when the engine is turn off, it then does not show the pitch correctly in flight. I came up with this code so when the engine are running it displays the correct pitch, but if the engine are not running it then displays 20 degrees pitch down,but keep getting illegal else without matching if :-hang I think it is a case of tired eyes, so will call it a night the code:FLOAT64 FSAPI pitch_cb( PELEMENT_MOVING_IMAGE pelement ){ lookup_var(current_pitch); pitch = (current_pitch.var_value.n); lookup_var(&engine_running); engine_started = (engine_running.var_value.n); if( engine_started = 1 && pitch > 20 ) pitch = 20; else if( engine_started = 1 && pitch < -20 ) pitch = -20; return pitch; else return 20;}2/. Fuel Cutoff switch>I guess because it looks pretty...excatly the reason Dai. I thought it might be quite complex, but will give it a go. So much easier in XML :-)

Share this post


Link to post
Share on other sites

Always use curly brackets on your if/else if/else clauses :->FLOAT64 FSAPI pitch_cb( PELEMENT_MOVING_IMAGE pelement ){ lookup_var(current_pitch); pitch = (current_pitch.var_value.n); lookup_var(&engine_running); engine_started = (engine_running.var_value.n); if( engine_started = 1 && pitch > 20 ) { // cap high end value pitch = 20; } else if( engine_started = 1 && pitch < -20 ) { // cap low end value pitch = -20; } else if (engine_started != 1) { // set specific value if engines aren't running pitch = -20; } return pitch;}

Share this post


Link to post
Share on other sites

Tim tried using {, but does not work. My compiler chucked out so many error messages, that my computer went in to melt down. A couple of days ago I got the code I posted to work. The first time I compiled it I got the same error, I then altered something and it worked ok, but can not remember what. Stupidly I altered it to see if I could get it to work without having to use a bit of custom code, and forgot to back it up.If I take out the else return 20; bit, it compiles and works ok, but if you look an the SDK Whiskey Compass it uses the same sort of code, and my whiskey compass code compiled perfectly. I am confused :-hmmm

Share this post


Link to post
Share on other sites

If you get it figured, I'd expand the end of Tim's if-then statement slightly so that the display doesn't suddenly go clunk! to -20. else if (engine_started != 1) { // set specific value if engines aren't running if(pitch!=-20)pitch-=0.5; }Good method for making gyros run down nicely too.-Dai

Share this post


Link to post
Share on other sites

Tims code should have worked, my typing I expect, I tried this and it worked:if(engine_started == 1 && pitch > 20 ) pitch = 20;else if( engine_started == 1 && pitch < -20 ) pitch = -20; else if( engine_started == 0 ) pitch = 20;Then I added the { and that worked :-rollif(engine_started == 1 && pitch > 20 ) { pitch = 20; }else if( engine_started == 1 && pitch < -20 ) { pitch = -20; } else if( engine_started == 0 ) { pitch = 20; }I have been trying to come up with a bit of code to stop the clunk to 20, will try you code tomorrow Dai. Stupid question: Does it have to be added in place of "else if( engine_started == 0 ) { pitch = 20; }" or as another line. I have been adding code to the last line to try and get it to slowly move to 20, but as you will guess from my C++ coding skills it does not work yet. The three books I ordered come in handy though, saves me wacking my head on the desk :-)

Share this post


Link to post
Share on other sites

Simply replace the last set of braces: { } with Dai's... ;)if(engine_started == 1 && pitch > 20 ) { pitch = 20; }else if( engine_started == 1 && pitch < -20 ) { pitch = -20; }else if( engine_started == 0 ) { // set specific value if engines aren't runningif(pitch!=-20)pitch-=0.5;}

Share this post


Link to post
Share on other sites

This is weird. Tried Dai code and no sucess. When the engine is stopped, the pitch indicator rises and contines rising untill it disapears out of the gauge, then after about a minute returns and stops at pitch up 20 degrees. I think I understand the code correctly, If pitch not equal to 20, then the variable value is modified by the compound assignment, 0.5 untill 20 is reached. I have a string on the variable so I can read the number the variable is displaying and it is using negative numbers for pitch up ie -20, and positive number for pitch down ie. 20 ( I want it to display 20 degrees pitch down when engine not running ). So altered Dai code to this else if( engine_started == 0 ) { if( pitch != 20 ) pitch += 0.5; } and get the same results. I have tried other alternatives but they either do nothing or give me the same results. I am now out of ideas.Thought I might as well post the whole code in case I have done something wrong which is causing the problems with the above bit of code.//Inclinometerchar inclinometer_gauge_name[] = GAUGE_NAME;extern PELEMENT_HEADER inclinometer_list;extern MOUSERECT inclinometer_mouse_rect[];GAUGE_CALLBACK inclinometer_callback;GAUGE_HEADER_FS700 ( GAUGE_W, inclinometer_gauge_name, &inclinometer_list, inclinometer_mouse_rect, inclinometer_callback, 0, 0, 0 );FAILURE_RECORD inclinometer_fail[] = { {FAIL_SYSTEM_ELECTRICAL_PANELS, FAIL_ACTION_ZERO}, {FAIL_GAUGE_ATTITUDE, FAIL_ACTION_ZERO}, {FAIL_NONE, FAIL_ACTION_NONE}};MODULE_VAR current_pitch = {ATTITUDE_INDICATOR_PITCH_DEGREES};double pitch = 0;FLOAT64 engine_started;FLOAT64 FSAPI pitch_cb( PELEMENT_MOVING_IMAGE pelement ){ lookup_var(current_pitch); pitch = (current_pitch.var_value.n); lookup_var(&engine_running); engine_started = (engine_running.var_value.n); if(engine_started == 1 && pitch > 20 ) { pitch = 20; } else if( engine_started == 1 && pitch < -20 ) { pitch = -20; } else if( engine_started == 0 ) { if( pitch != 20 ) pitch += 0.5; } return pitch;}FLOAT64 FSAPI bank_cb( PELEMENT_MOVING_IMAGE pelement ){ return 1.0; //Dummy Callback}//2MAKE_MOVING( inclinometer_indicator, INCLINOMETER_INDICATOR, NULL, NULL, IMAGE_USE_TRANSPARENCY | IMAGE_USE_ERASE | BIT7, 0, 40,8, MODULE_VAR_NONE, bank_cb, 0, 0, ATTITUDE_INDICATOR_PITCH_DEGREES, pitch_cb, -20, 20)PELEMENT_HEADER inclinometer_indicator_plist[] = { (PELEMENT_HEADER) &inclinometer_indicator.header, NULL };//1MAKE_STATIC( inclinometer_alpha, INCLINOMETER_ALPHA, inclinometer_indicator_plist, NULL, IMAGE_USE_TRANSPARENCY | IMAGE_USE_ALPHA, 0, 0,0 )PELEMENT_HEADER inclinometer_alpha_plist[] = {&inclinometer_alpha.header, NULL, };//0MAKE_STATIC( inclinometer_background, INCLINOMETER_BACKGROUND, inclinometer_alpha_plist, NULL, IMAGE_USE_TRANSPARENCY | IMAGE_USE_ERASE | BIT7, 0, 0,0 )PELEMENT_HEADER inclinometer_list = &inclinometer_background.header;MOUSE_BEGIN(inclinometer_mouse_rect,HELP_NONE,0,0)MOUSE_TOOLTIP_TEXT_ID(TOOLTIPTEXT_SPIRIT_PITCH_INDICATOR,NULL)MOUSE_END///////////////////////////////////////////////////////////////////void FSAPI inclinometer_callback (PGAUGEHDR pgauge, int service_id, UINT32 extra_data){ switch(service_id){/* "install_routine()" */ case PANEL_SERVICE_PRE_INSTALL: break;/* "initialize_routine()" */ case PANEL_SERVICE_PRE_INITIALIZE: break;/* "update_routine()" */ case PANEL_SERVICE_PRE_UPDATE: lookup_var(&lights_on); if (lights_on.var_value.n == 0) { DARKEN_LISTELEMENT(pgauge->elements_list[0],0); DARKEN_LISTELEMENT(pgauge->elements_list[0],2); } else { LIGHT_LISTELEMENT(pgauge->elements_list[0],0); LIGHT_LISTELEMENT(pgauge->elements_list[0],2); } break;/* "draw_routine()" */ case PANEL_SERVICE_PRE_DRAW: break;/* "kill_routine()" */ case PANEL_SERVICE_PRE_KILL: break;}} #undef GAUGE_NAME#undef GAUGEHDR_VAR_NAME#undef GAUGE_W

Share this post


Link to post
Share on other sites