Problem Animating mesh group based on Throttle position (level)

Grev77

New member
Joined
Jun 25, 2008
Messages
3
Reaction score
0
Points
0
Location
New Orleans, La
I have been going round and round but still cannot rotate an external part of my ship based on the level of the main throttle.
So far I have set a key press to trigger the animation which tells me that that the animation is working. However, I cant seem to get the part rotate using the main engine level to determine the angle, ie: more throttle = larger angle.

here's the code:
Code:
[SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]void[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#000000] Pegasus::AnimateEnginePart (PartStatus action)[/COLOR][/SIZE]
[SIZE=2]{[/SIZE]
[SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]for[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] ([/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]int[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] i = 0; i < 2; i++)[/SIZE]
[SIZE=2]{[/SIZE]
[SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]double[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] level = GetThrusterLevel (th_main);[/SIZE]
[SIZE=2]UINT pos = (UINT) (level *500.0);[/SIZE]
[SIZE=2]SetAnimation(anim_enginepart, level);[/SIZE]
[SIZE=2]}[/SIZE]
[SIZE=2]}[/SIZE]

I also tried the following code in the same area (with no luck):
Code:
[SIZE=2][COLOR=#008000][SIZE=2][COLOR=#008000]if (pos != engsliderpos)[/COLOR][/SIZE]
[SIZE=2][COLOR=#008000]{[/COLOR][/SIZE]
[SIZE=2][COLOR=#008000]SetAnimation(anim_enginepart, level);[/COLOR][/SIZE]
[SIZE=2][COLOR=#008000]engsliderpos = pos;[/COLOR][/SIZE]
[SIZE=2][COLOR=#008000]}[/COLOR][/SIZE]
[/COLOR][/SIZE]

And this is what I have in the clbkPostStep area. I placed this so I can test if the enginePart animation works, and it does:
Code:
[SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#000000] (part_status >= PART_CLOSING) [/COLOR][/SIZE][SIZE=2][COLOR=#008000][SIZE=2][COLOR=#008000]// Animate Engine part[/COLOR][/SIZE]
[/COLOR][/SIZE][SIZE=2]{[/SIZE]
[SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]double[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] da = simdt * PART_ROT_SPEED;[/SIZE]
[SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] (part_status == PART_CLOSING) [/SIZE]
[SIZE=2]{ [/SIZE]
[SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] (part_proc > 0.0) part_proc = max (0.0, part_proc-da);[/SIZE]
[SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]else[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] part_status = PART_CLOSED;[/SIZE]
[SIZE=2]} [/SIZE]
[SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]else[/COLOR][/SIZE][/COLOR][/SIZE]
[SIZE=2]{ [/SIZE]
[SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] (part_proc < 1.0) part_proc = min (1.0, part_proc+da);[/SIZE]
[SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]else[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] part_status = PART_OPEN;[/SIZE]
[SIZE=2]}[/SIZE]
[SIZE=2]SetAnimation (anim_enginepart, part_proc);[/SIZE]
[SIZE=2][COLOR=#008000][SIZE=2][COLOR=#008000]//AnimateEnginePart (part_proc);[/COLOR][/SIZE]
[/COLOR][/SIZE][SIZE=2]}[/SIZE]

And finally, the DefineAnimation code:
Code:
[SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]static[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#000000] UINT EnginePartGRP1[1]={2};[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]static[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] MGROUP_ROTATE EnginePart1 (0,EnginePartGRP1,1,_V(5.1826,-0.516f,5.405f),_V(0,0,-0.393),([/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]float[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2])PI);[/SIZE]
[SIZE=2]anim_enginepart = CreateAnimation (0.0);[/SIZE]
[SIZE=2]AddAnimationComponent (anim_enginepart, 0.0f, 1.0f, &EnginePart1);[/SIZE]


Any suggestions would be great as I have come upon a bit of a roadblock.

Again, what I'm trying to do is animate (rotate) an external part of the ship based on the thrust level of the main engine

Thanx
Grev
 

martins

Orbiter Founder
Orbiter Founder
Joined
Mar 31, 2008
Messages
2,448
Reaction score
462
Points
83
Website
orbit.medphys.ucl.ac.uk
This code contains so many inconsistencies that it is difficult to say what it is supposed to do and what it actually does:

  • The loop in AnimateEnginePart doesn't seem to do anything other than run the same code twice.
  • The pos variable in AnimateEnginePart doesn't seem to be used (although it is used in the second code fragment, in a rather convouted way). It isn't quite clear how the two parts fit together.
  • The action argument is never used in AnimateEnginePart. When the function is called from clbkPreStep, (the commented line, which presumably is not commented when you are testing the function) the argument is (probably) a double, but is interpreted as PartStatus by AnimateEnginePart
  • The AnimateEnginePart call is inside the part_status >= PART_CLOSING test, but it isn't obvious why, or if this was done only temporarily for testing purposes.
I would just throw away the whole code and simply do
Code:
engine_level = GetThrusterLevel(thmain);
if (engine_level != saved_engine_level) {
   SetAnimation(anim_enginepart,engine_level);
   saved_engine_level = engine_level;
}
In general, it is much easier to just run your code in a debugger and see exactly what is happening, rather than us trying to second-guess what the code is supposed to do. :thumbup:
 
Top