Parent/child coding help

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,755
Reaction score
2,738
Points
203
Location
Dallas, TX
:(I am having an issue adding another child to an existing parent. I get a CTD when the vessel is loaded.
Code:
{

       static UINT EGrp20[4] = {22,23,156,117};// mount
       static UINT EGrp21[2] = {0,95}; //laser and rings
       static UINT EGrp22[1] = {189};//laserbeam ray
   static MGROUP_ROTATE TURRET (0,EGrp20, 4, _V(0,1.183,-1.707), _V(0,1,0), (float)(360*RAD));
    
   GUN = new MGROUP_ROTATE(0,EGrp21, 2, _V(0,1.864,-1.707), _V(1,0,0), (float)(-60*RAD));
   BEAM = new  MGROUP_TRANSLATE(0,EGrp22, 1, _V(0,0,30));
ANIMATIONCOMPONENT_HANDLE parent,  parent2;
    
anim_TURRET = CreateAnimation (0.0);
parent = AddAnimationComponent (anim_TURRET, 0, 1, &TURRET);
anim_gun = CreateAnimation (0.0);
AddAnimationComponent (anim_gun, 0, 1, GUN, parent);
anim_beam = CreateAnimation (0.0);
AddAnimationComponent (anim_beam, 0, 1, BEAM, parent2);
in the h file
Code:
MGROUP_TRANSFORM *TURRENT, *GUN, *BEAM;
 

Xantcha

Addon Developer
Addon Developer
Joined
Mar 26, 2008
Messages
203
Reaction score
0
Points
0
Code:
	static UINT EGrp20[4] = {22,23,156,117};// mount
	static UINT EGrp21[2] = {0,95}; //laser and rings
	static UINT EGrp22[1] = {189};//laserbeam ray

static MGROUP_ROTATE TURRET (0,EGrp20, 4, _V(0,1.183,-1.707), _V(0,1,0), (float)(360*RAD));   
	GUN = new MGROUP_ROTATE(0,EGrp21, 2, _V(0,1.864,-1.707), _V(1,0,0), (float)(-60*RAD));
	BEAM = new  MGROUP_TRANSLATE(0,EGrp22, 1, _V(0,0,30));


	ANIMATIONCOMPONENT_HANDLE [COLOR="Blue"]parent[/COLOR],  [COLOR="Red"]parent2[/COLOR];

	anim_TURRET = CreateAnimation (0.0);
	[COLOR="Blue"]parent[/COLOR] = AddAnimationComponent (anim_TURRET, 0, 1, &TURRET);

	anim_gun = CreateAnimation (0.0);
	AddAnimationComponent (anim_gun, 0, 1, GUN, [COLOR="Blue"]parent[/COLOR]);

	anim_beam = CreateAnimation (0.0);
	AddAnimationComponent (anim_beam, 0, 1, BEAM, [b][COLOR="Red"]parent2[/COLOR][/b]);

parent2 was not created, when it was tried to be used.

Code:
MGROUP_TRANSFORM *TURRENT, *GUN, *BEAM;
Just curios, what is TURRENT?

Also, I'm bad at c++. Are 1 element arrays legal?
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,755
Reaction score
2,738
Points
203
Location
Dallas, TX
Thanks. I changed it to this:
void LASER2::DefineAnimations(void)
{

static UINT EGrp20[4] = {22,23,156,117};
static UINT EGrp21[2] = {0,95};
static UINT EGrp22[1] = {186};
static MGROUP_ROTATE TURRET (0,EGrp20, 4, _V(0,1.183,-1.707), _V(0,1,0), (float)(360*RAD));

GUN = new MGROUP_ROTATE(0,EGrp21, 2, _V(0,1.864,-1.707), _V(1,0,0), (float)(-60*RAD));
BEAM = new MGROUP_TRANSLATE(0,EGrp22, 1, _V(0,0,5));
ANIMATIONCOMPONENT_HANDLE parent;

anim_TURRET = CreateAnimation (0.0);
parent = AddAnimationComponent (anim_TURRET, 0, 1, &TURRET);
anim_gun = CreateAnimation (0.0);
AddAnimationComponent (anim_gun, 0, 1, GUN, parent);
anim_beam = CreateAnimation (0.0);
AddAnimationComponent (anim_beam, 0, 1, BEAM, parent);


No ctd but beam translateS. Turrent should be turret. But EGrp 22 doesn't move with the parent
 
Last edited:

Xantcha

Addon Developer
Addon Developer
Joined
Mar 26, 2008
Messages
203
Reaction score
0
Points
0
Try to give less ambigous code, please.:mad:

Is the mentioned code part of clbkConsumeBufferedKey method of your class? Is LASER property of your class?
Hope I guessed it right. If so than it could works like this:

you press "W": LASER sets to 1, clbkConsumeBufferedKey returns 1 and stops here.
you press "W" again: LASER resets to 1, clbkConsumeBufferedKey returns 1 and stops here once more.
you press nothing: clbkConsumeBufferedKey not called, nothing happens.
you press anykey other than "W" - can't help you there, too litle information on your problem.

If not then it's not me to blame, try give more details
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,755
Reaction score
2,738
Points
203
Location
Dallas, TX
Thanks. I got the beam to translate. But Now I am back to why it will not move at the same rate as Turret-the parent. Gun and Beam should be child. the beam is the purple piece and although it moves with the gun part it moves at a different rate. At the start the purple ray is inside of the gun piece.
f_laserm_fcd484c.jpg

Code:
void LASER2::DefineAnimations(void)
{

       static UINT EGrp20[4] = {22,23,156,117};//turret
       static UINT EGrp21[3] = {0,95};//gun
       static UINT EGrp22[1] = {186};//beam
   static MGROUP_ROTATE TURRET (0,EGrp20, 4, _V(0,1.183,-1.707), _V(0,1,0), (float)(360*RAD));
 
   GUN = new MGROUP_ROTATE(0,EGrp21, 3, _V(0,1.864,-1.707), _V(1,0,0), (float)(-60*RAD));
   BEAM = new MGROUP_TRANSLATE(0,EGrp22, 1, _V(0,0,2));
ANIMATIONCOMPONENT_HANDLE parent, parent2;
    
anim_TURRET = CreateAnimation (0.0);
parent = AddAnimationComponent (anim_TURRET, 0, 1, &TURRET);
anim_gun = CreateAnimation (0.0);
AddAnimationComponent (anim_gun, 0, 1, GUN, parent);
parent2 = AddAnimationComponent (anim_gun, 0, 1, GUN, parent);
anim_beam = CreateAnimation (0.0);
AddAnimationComponent (anim_beam, 0, 1, BEAM, parent2);
 
Last edited:

Xantcha

Addon Developer
Addon Developer
Joined
Mar 26, 2008
Messages
203
Reaction score
0
Points
0
static UINT EGrp21[3] = {0,95};//gun
Why declare array of size of 3?

But other than that, can't see anything wrong here, may be I'm missing something :-/


Also - You don't have to make animation for beam - you can simply make that meshgroup (in)visible when you need.

You can get MESHGROUP pointer with oapiMeshGroup (MESHHANDLE hMesh, DWORD idx) function. Then set it's UsrFlag to 3 for hiding meshgroup, and to 1 for showing it again. (check 3dmodel.pdf in orbiterdk\doc for more details)
To get MESHHANDLE, use GetMesh (VISHANDLE vis, UINT idx), and for aquiring visual handle use oapiObjectVisualPtr (OBJHANDLE hObject).

P.S.
oh my here it is
Code:
void LASER2::DefineAnimations(void)
{

       static UINT EGrp20[4] = {22,23,156,117};//turret
       static UINT EGrp21[3] = {0,95};//gun
       static UINT EGrp22[1] = {186};//beam
   static MGROUP_ROTATE TURRET (0,EGrp20, 4, _V(0,1.183,-1.707), _V(0,1,0), (float)(360*RAD));
 
   GUN = new MGROUP_ROTATE(0,EGrp21, 3, _V(0,1.864,-1.707), _V(1,0,0), (float)(-60*RAD));
   BEAM = new MGROUP_TRANSLATE(0,EGrp22, 1, _V(0,0,2));
ANIMATIONCOMPONENT_HANDLE parent, parent2;
    
anim_TURRET = CreateAnimation (0.0);
parent = AddAnimationComponent (anim_TURRET, 0, 1, &TURRET);
anim_gun = CreateAnimation (0.0);
[color='red']          AddAnimationComponent (anim_gun, 0, 1, GUN, parent);
parent2 = AddAnimationComponent (anim_gun, 0, 1, GUN, parent);[/color]
anim_beam = CreateAnimation (0.0);
AddAnimationComponent (anim_beam, 0, 1, BEAM, parent2);
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,755
Reaction score
2,738
Points
203
Location
Dallas, TX
Thanks. Since I can't get the material of the beam to change I might look at the meshgroup item. I see you have in in red but not sure what to change.
static UINT EGrp21[3] = {0,95};//gun
Why declare array of size of 3?

But other than that, can't see anything wrong here, may be I'm missing something :-/


Also - You don't have to make animation for beam - you can simply make that meshgroup (in)visible when you need.

You can get MESHGROUP pointer with oapiMeshGroup (MESHHANDLE hMesh, DWORD idx) function. Then set it's UsrFlag to 3 for hiding meshgroup, and to 1 for showing it again. (check 3dmodel.pdf in orbiterdkdoc for more details)
To get MESHHANDLE, use GetMesh (VISHANDLE vis, UINT idx), and for aquiring visual handle use oapiObjectVisualPtr (OBJHANDLE hObject).

P.S.
oh my here it is
Code:
void LASER2::DefineAnimations(void)
{

       static UINT EGrp20[4] = {22,23,156,117};//turret
       static UINT EGrp21[3] = {0,95};//gun
       static UINT EGrp22[1] = {186};//beam
   static MGROUP_ROTATE TURRET (0,EGrp20, 4, _V(0,1.183,-1.707), _V(0,1,0), (float)(360*RAD));
 
   GUN = new MGROUP_ROTATE(0,EGrp21, 3, _V(0,1.864,-1.707), _V(1,0,0), (float)(-60*RAD));
   BEAM = new MGROUP_TRANSLATE(0,EGrp22, 1, _V(0,0,2));
ANIMATIONCOMPONENT_HANDLE parent, parent2;
    
anim_TURRET = CreateAnimation (0.0);
parent = AddAnimationComponent (anim_TURRET, 0, 1, &TURRET);
anim_gun = CreateAnimation (0.0);
[COLOR=red]          AddAnimationComponent (anim_gun, 0, 1, GUN, parent);
parent2 = AddAnimationComponent (anim_gun, 0, 1, GUN, parent);[/COLOR]
anim_beam = CreateAnimation (0.0);
AddAnimationComponent (anim_beam, 0, 1, BEAM, parent2);
 

Xantcha

Addon Developer
Addon Developer
Joined
Mar 26, 2008
Messages
203
Reaction score
0
Points
0
anim_TURRET = CreateAnimation (0.0); //turret animation
parent = AddAnimationComponent (anim_TURRET, 0, 1, &TURRET); //component for turret animation, saving value (to use it as parent for gun animation)

anim_gun = CreateAnimation (0.0); //gun animation
AddAnimationComponent (anim_gun, 0, 1, GUN, parent); //what is this for?
parent2 = AddAnimationComponent (anim_gun, 0, 1, GUN, parent); //component for gun animation, saving value (to use it as parent for beam animation)

anim_beam = CreateAnimation (0.0); //component for laser beam
AddAnimationComponent (anim_beam, 0, 1, BEAM, parent2); //component for laser beam animation, not saving value (as it is not used anywhere else)


You have added animation component for gun twice, so when you rotate gun it is updated twice for each component, hence different rotation rate.
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,755
Reaction score
2,738
Points
203
Location
Dallas, TX
Thanks I don't know what is causing this:

The grey turret piece is elevating with the gun and beam but the orange piece is not. This is mesh grp # 22. and on the rotation the orange piece is not rotating at the same speed. the orange piece is mesh grp # 156.
Turret is should be the parent and beam and gun should child
here is the code:
Code:
void LASER2::DefineAnimations(void)
{

       static UINT EGrp20[4] = {22,23,156,117};//turret
       static UINT EGrp21[2] = {0,95};//gun
       static UINT EGrp22[1] = {187};//beam
   static MGROUP_ROTATE TURRET (0,EGrp20, 4, _V(0,1.183,-1.707), _V(0,1,0), (float)(360*RAD));
 
   GUN = new MGROUP_ROTATE(0,EGrp21, 2, _V(0,1.864,-1.707), _V(1,0,0), (float)(-60*RAD));
   BEAM = new MGROUP_TRANSLATE(0,EGrp22, 1, _V(0,0,2));
ANIMATIONCOMPONENT_HANDLE parent, parent2;
    
anim_TURRET = CreateAnimation (0.0);
parent = AddAnimationComponent (anim_TURRET, 0, 1, &TURRET);
anim_gun = CreateAnimation (0.0);
parent2 = AddAnimationComponent (anim_gun, 0, 1, GUN, parent);
anim_beam = CreateAnimation (0.0);
AddAnimationComponent (anim_beam, 0, 1, BEAM, parent2);
f_08052905473m_90c78f9.jpg


f_08052905494m_4a82a4b.jpg
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,755
Reaction score
2,738
Points
203
Location
Dallas, TX
I fixed one thing. But now the ray, gun, and turrent all rotate but the gun only elevates not the ray piece.
static UINT EGrp20[4] = {22,23,156,117};//turret
static UINT EGrp21[2] = {0,95};//gun
static UINT EGrp22[1] = {187};//beam
static MGROUP_ROTATE TURRET (0,EGrp20, 4, _V(0,1.183,-1.707), _V(0,1,0), (float)(360*RAD));

GUN = new MGROUP_ROTATE(0,EGrp21, 2, _V(0,1.864,-1.707), _V(1,0,0), (float)(-60*RAD));
BEAM = new MGROUP_TRANSLATE(0,EGrp22, 1, _V(0,0,2));
ANIMATIONCOMPONENT_HANDLE parent, parent2;

anim_TURRET = CreateAnimation (0.0);
parent = AddAnimationComponent (anim_TURRET, 0, 1, &TURRET);
anim_gun = CreateAnimation (0.0);
AddAnimationComponent (anim_gun, 0, 1, GUN, parent);
anim_beam = CreateAnimation (0.0);
AddAnimationComponent (anim_beam, 0, 1, BEAM, parent);
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,755
Reaction score
2,738
Points
203
Location
Dallas, TX
CAn you have 1 parent and more than 1 child?
if so how is it coded?
 

Xantcha

Addon Developer
Addon Developer
Joined
Mar 26, 2008
Messages
203
Reaction score
0
Points
0
Code in post #10 works as it should - both Beam and Gun animation are childs of turret and rotate with it. Them are independent of each other so when Gun pitchs up/down nothing happens with beam.

But I have no idea why code in post #9 worked like you have described - is it all relevant code, arent those meshgroups used anywhere else?
 

Urwumpe

Not funny anymore
Addon Developer
Donator
Joined
Feb 6, 2008
Messages
37,661
Reaction score
2,382
Points
203
Location
Wolfsburg
Preferred Pronouns
Sire
CAn you have 1 parent and more than 1 child?
if so how is it coded?


Just have all childs have the same parent. of course it goes.

Is a translation ("movement") of the beam by 2m enough or do you want to have a higher range?
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,755
Reaction score
2,738
Points
203
Location
Dallas, TX
The code from Post #10 gives this result. All groups rotate. ok
but on elevations the beam doesn't move. It will translate.
But the gun and beam both should elevate.
f_laserm_8e95269.jpg
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,755
Reaction score
2,738
Points
203
Location
Dallas, TX
On the translation. Yes. I just what the beam to extend beyond the tip of the grey gun. I have it extend and retract several times. like a pulse.

I have both the beam and gun set as child to the parent turret:
anim_TURRET = CreateAnimation (0.0);
parent = AddAnimationComponent (anim_TURRET, 0, 1, &TURRET);
anim_gun = CreateAnimation (0.0);
AddAnimationComponent (anim_gun, 0, 1, GUN, parent);
anim_beam = CreateAnimation (0.0);
AddAnimationComponent (anim_beam, 0, 1, BEAM, parent);


I am wondering if I am to deleting part of it?







Just have all childs have the same parent. of course it goes.

Is a translation ("movement") of the beam by 2m enough or do you want to have a higher range?
 

Urwumpe

Not funny anymore
Addon Developer
Donator
Joined
Feb 6, 2008
Messages
37,661
Reaction score
2,382
Points
203
Location
Wolfsburg
Preferred Pronouns
Sire
If your beam should not elevate with the gun, yes. But actually, you want to beam to be child of the gun animation.

So, you should remember the animation component handle of the gun animation for use as parent for the beam.
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,755
Reaction score
2,738
Points
203
Location
Dallas, TX
So the gun is a parent also? and a child? Because the gun and beam need to be child of the turret(Parent) for rotational purposes.


If your beam should not elevate with the gun, yes. But actually, you want to beam to be child of the gun animation.
 

Urwumpe

Not funny anymore
Addon Developer
Donator
Joined
Feb 6, 2008
Messages
37,661
Reaction score
2,382
Points
203
Location
Wolfsburg
Preferred Pronouns
Sire
You can imagine the animations of a spacecraft as trees:

You start with one root animation, which can have 0 or more childs.

Each of these childs can also be parent of 0 or more childs... etc.

Like the branches of a tree.
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,755
Reaction score
2,738
Points
203
Location
Dallas, TX
So like this:
anim_TURRET = CreateAnimation (0.0);
parent = AddAnimationComponent (anim_TURRET, 0, 1, &TURRET);
anim_gun = CreateAnimation (0.0);
AddAnimationComponent (anim_gun, 0, 1, GUN, parent); I deleted this line and it works, yeah
anim_beam = CreateAnimation (0.0);
parent2 = AddAnimationComponent (anim_gun, 0, 1, GUN, parent);
AddAnimationComponent (anim_beam, 0, 1, BEAM, parent2);


 
Last edited:
Top