protected void addChildTo(ModelRenderer child,ModelRenderer parent){
  float distance=(float)Math.sqrt(Math.pow((child.rotationPointZ - parent.rotationPointZ),2) + Math.pow((child.rotationPointY - parent.rotationPointY),2));
  float oldRotateAngleX=parent.rotateAngleX;
  float parentToChildAngle=(float)Math.atan((child.rotationPointZ - parent.rotationPointZ) / (child.rotationPointY - parent.rotationPointY));
  float childRelativeRotation=parentToChildAngle - parent.rotateAngleX;
  float newRotationPointY=(float)(distance * (Math.cos(childRelativeRotation)));
  float newRotationPointZ=(float)(distance * (Math.sin(childRelativeRotation)));
  parent.rotateAngleX=0F;
  child.setRotationPoint(child.rotationPointX - parent.rotationPointX,newRotationPointY,newRotationPointZ);
  parent.addChild(child);
  parent.rotateAngleX=oldRotateAngleX;
  child.rotateAngleX-=parent.rotateAngleX;
  child.rotateAngleY-=parent.rotateAngleY;
  child.rotateAngleZ-=parent.rotateAngleZ;
}

protected void addChildTo ( ModelRenderer child , ModelRenderer parent ) { float distance = ( float ) Math . sqrt ( Math . pow ( ( child . rotationPointZ - parent . rotationPointZ ) , 2 ) + Math . pow ( ( child . rotationPointY - parent . rotationPointY ) , 2 ) ) ; float oldRotateAngleX = parent . rotateAngleX ; float parentToChildAngle = ( float ) Math . atan ( ( child . rotationPointZ - parent . rotationPointZ ) / ( child . rotationPointY - parent . rotationPointY ) ) ; float childRelativeRotation = parentToChildAngle - parent . rotateAngleX ; float newRotationPointY = ( float ) ( distance * ( Math . cos ( childRelativeRotation ) ) ) ; float newRotationPointZ = ( float ) ( distance * ( Math . sin ( childRelativeRotation ) ) ) ; parent . rotateAngleX = 0F ; child . setRotationPoint ( child . rotationPointX - parent . rotationPointX , newRotationPointY , newRotationPointZ ) ; parent . addChild ( child ) ; parent . rotateAngleX = oldRotateAngleX ; child . rotateAngleX -= parent . rotateAngleX ; child . rotateAngleY -= parent . rotateAngleY ; child . rotateAngleZ -= parent . rotateAngleZ ; }
calculates the relative positions and rotations easily . < p / > note : when parenting a chain of boxes , such as a head to a neck to a body , the end of the chain should start first . in this case the head should be parented to the neck before parenting the neck to the body . < p / > some corrections and adjustments to the rotation point may be needed .
