Problem rotating parent then rotating children

Hi there,

The code I have supplied below allows a selected part and all its child parts to rotate around a pre-determined axis without a problem,
but when I then select one of the child parts to further rotate, it first moves back to its original position before the rotation works.
I hope that makes sense. Please help because I’ve been at it for a few days and don’t know what to do.

for itemNo := 0 to length(frmSetup.ParentChildArray) - 1 do // Loop for number of parts in object
glPushMatrix;
glTranslatef( frmSetup.PartsTranslationArray[ itemNo, 0 ],
frmSetup.PartsTranslationArray[ itemNo, 1 ],
frmSetup.PartsTranslationArray[ itemNo, 2 ]);

	if itemNo = frmSetup.objSelectList.ItemIndex then	// Selected part (from a list box) to be rotated
	begin
		XValue1	:= frmSetup.ControlVertArray[ frmSetup.ControlAxisArray[ itemNo, ZFace ] - 1, XVert ];
		YValue1 := frmSetup.ControlVertArray[ frmSetup.ControlAxisArray[ itemNo, ZFace ] - 1, YVert ];
		ZValue1 := frmSetup.ControlVertArray[ frmSetup.ControlAxisArray[ itemNo, ZFace ] - 1, ZVert ];
	end;

	glTranslatef( XValue1, YValue1, ZValue1 );

	glRotatef(frmSetup.PartsRotationArray[ itemNo, 0 ], 1.0, 0.0, 0.0);
	glRotatef(frmSetup.PartsRotationArray[ itemNo, 1 ], 0.0, 1.0, 0.0);
	glRotatef(frmSetup.PartsRotationArray[ itemNo, 2 ], 1.0, 0.0, 1.0);

	glTranslatef( XValue1*-1.0, YValue1*-1.0, ZValue1*-1.0 );

	glBegin( frmSetup.DisplayModeArr[ frmSetup.DisplayMode.ItemIndex ] );
		for I := frmSetup.ControlPartArray[ itemNo, 1 ] - 1 to frmSetup.ControlPartArray[ itemNo + 1, 1 ] - 2 do
		begin
			makeGLFace( I, itemNo );	// output glVertex3f
		end;
	glEnd;
glPopMatrix;

end;

From what I see, you are making a new layer on the modelview stack for each object you draw. It makes a layer, draws the parent, removes it’s layer, makes another layer, draws a child, removes the layer, makes a layer, draws a child, removes the layer, etc…

Try translating/rotating the child objects by their respective amounts, PLUS the parent’s amount. This will cause the effect you desire.

Danny
anitox@subdimension.com