C++ Question Incremented animation

JMW

Aspiring Addon Developer
Joined
Aug 5, 2008
Messages
670
Reaction score
89
Points
43
Location
Happy Wherever
Help (Again),
I'm trying to animate a nosecone (Concorde), but can't figure the code to do it in 5 degree increments. I would appreciate some help.
I need it to drop down 5 degrees on key press and then stop. Then the next 5 degrees and so on. up to 15 degrees, and then back up again incrementally.
For your amusement, I ended last night with this frustrated mess!:

This in
void ShuttlePB::clbkPostStep (double simt, double simdt, double mjd)
Code:
// Variable Geometry
 
if( animactive5 ) {PlayVesselWave3(MySoundID,BRAKE,NOLOOP,255);
 
if( animactive5 == 1 ) {
vario += 0.001;
if (variofirst > 0)
if( vario > 0.33 ){
vario = 0.33;
}
if (variofirst < 1) 
animactive5 = 0;
 
if (variofirst > 1)
animactive5 = 1;
vario += 0.001;
if( vario > 0.66 ){
vario = 0.66;
}
if (variofirst < 2)
animactive5 = 0;
 
}
else { 
vario -= 0.001;
if( vario < 0.0 ){
vario = 0.0;
animactive5 = 0;
}
 
}
 
SetAnimation( anim_vario, vario );
SetAnimation( anim_vario1, vario );
SetAnimation( anim_variolever, vario );
 
}

And this in
int ShuttlePB::clbkConsumeBufferedKey (DWORD key, bool down, char *kstate)
Code:
case OAPI_KEY_V: // Geom Fully Up or Down
 
if( vario > 0.5 )
animactive5 = 2;
else
if (GetAirspeed() <139)//safe speed 
animactive5 = 1;
 
variofirst = (variofirst + 1);
//{
//PlayVesselWave3(MySoundID,FLAPS,NOLOOP,255);
//}
 
return 1;
//////////////////////////////////////////////////////////////////
case OAPI_KEY_C: // Down 5 deg
if (variofirst > 3)
variofirst = 3;
if (variofirst < 0)
variofirst = 0;
 
if (variofirst = 3)
{if (vario > 1)
vario = 1;
animactive5 = 1;
variofirst = (variofirst +1);
}
else
if (variofirst = 3)
{if (vario < 1)
vario = 1;
animactive5 = 2;
variofirst = (variofirst -1);
}
 
if (variofirst = 2)
{if (vario > 0.66)
vario = 0.66;
animactive5 = 1;
variofirst = (variofirst +1);
}
else
if (variofirst = 2)
{if (vario < 0.66)
vario = 0.66;
animactive5 = 2;
variofirst = (variofirst -1);
}
 
if (variofirst = 1)
{if (vario > 0.33)
vario = 0.33;
animactive5 = 1;
variofirst = (variofirst +1);
}
else
if (variofirst = 1)
{if (vario < 0.33)
vario = 0.33;
animactive5 = 2;
variofirst = (variofirst -1);
}
if (variofirst = 0)
{if (vario > 0)
vario = 0;
animactive5 = 1;
variofirst = (variofirst +1);
}
else
if (variofirst = 0)
{if (vario < 0.33)
vario = 0.33;
animactive5 = 2;
variofirst = (variofirst -1);
}
 
// return 1;

Regards,
JMW
 
Try it with a state machine, your solution has no way to tell how far it should travel to stop. The simplest implementation, I see is defining a integer for which 5° increment you currently use, as well as telling the direction of travel, and then just cycle through the positions.

Positions would be:
0° down
5° down
10° down
15° up
10° up
5° up

With the up and down telling you the direction for the next transition.
 
More help please

I have a working animation now, as per below:
Code:
// Variable Geometry 
 
if( animactive5 ) {PlayVesselWave3(MySoundID,BRAKE,NOLOOP,255);
if( animactive5 == 1 ) {
vario += 0.006;
if( vario > 1.0 ) {
vario = 1.0;
animactive5 = 0;
}
}
else {
vario -= 0.006;
if( vario < 0.0 ) {
vario = 0.0;
animactive5 = 0;
}
}
SetAnimation( anim_vario, vario );
SetAnimation( anim_vario1, vario );
SetAnimation( anim_variolever, vario );
}

Code:
case OAPI_KEY_V:// Variable geometry fully up/down
 
 
if( vario > 0.5 )
animactive5 = 2;
else
if (GetAirspeed() <139)//safe speed 
animactive5 = 1;
 
return 1;
 
////////////////////////////////
 
case OAPI_KEY_C: // Geom Down 5 deg
if (GetAirspeed() <139)//safe speed
vario += 0.3333333333;
if( vario > 1.0 ) {
vario = 1.0;
}
{
PlayVesselWave3(MySoundID,BRAKE,NOLOOP,255);
} 
SetAnimation( anim_vario, vario );
SetAnimation( anim_vario1, vario );
SetAnimation( anim_variolever, vario );
 
varioexproc = vario;
variofirst = (variofirst +1);
 
 
 
return 1;
/////////////////////////////////////
 
case OAPI_KEY_N: // Geom Up 5 deg
 
vario -= 0.3333333333;
if( vario < 0.0 ) {
vario = 0.0;
}
{
PlayVesselWave3(MySoundID,BRAKE,NOLOOP,255);
} 
SetAnimation( anim_vario, vario );
SetAnimation( anim_vario1, vario );
SetAnimation( anim_variolever, vario );
 
varioexproc = vario;
variofirst = (variofirst -1);
 
 
 
return 1;

but how can I get the transitions to be smooth as it is for the full up or down transition? (At the moment it just jerks from 0 - 5, 5-10 degrees etc.)
Thanks,
JMW
 
Back
Top