private static SceneNode recursiveGetSceneNodeByGameObject(SceneNode currentSceneNode, IGameObject gameObject) { IGameObject currentGameObject = currentSceneNode.getSceneNodeGameObject(); if (SceneNode.equals(currentGameObject, gameObject)) { return currentSceneNode; } else { SceneNode sceneNodeCandidate = null; foreach (SceneNode childSceneNode0 in currentSceneNode.getChildList()) { sceneNodeCandidate = SceneNode.recursiveGetSceneNodeByGameObject(childSceneNode0, gameObject); if (sceneNodeCandidate != null) { break; } } return sceneNodeCandidate; } }
/// <summary> /// /// </summary> /// <param name="sceneNode"></param> private void recursiveRemoveGameObject(SceneNode sceneNode) { if (sceneNode.getSceneNodeGameObject() != null) { this.deleteGameObject(sceneNode.getSceneNodeGameObject(), this.gameObjectListMapByTag); this.deleteGameObject(sceneNode.getSceneNodeGameObject(), this.collidableGameObjectListMapByTag); } foreach (SceneNode childSceneNode0 in sceneNode.getChildList()) { this.recursiveRemoveGameObject(childSceneNode0); } sceneNode.getParent().removeChild(sceneNode); }
/// <summary> /// /// </summary> /// <param name="sceneNode"></param> /// <param name="transformGroup"></param> /// <param name="zIndex"></param> private void recursiveApplyTranslation(SceneNode sceneNode, double xOffset, double yOffset, bool propagateToChild) { IGameObject gameObject = sceneNode.getSceneNodeGameObject(); gameObject.setPosition(gameObject.getXPosition() + xOffset, gameObject.getYPosition() + yOffset); if (gameObject.getBoundingBoxGeometry() != null) { gameObject.getBoundingBoxGeometry().Transform = new TranslateTransform(gameObject.getXPosition(), gameObject.getYPosition()); } if (propagateToChild) { foreach (SceneNode childSceneNode0 in sceneNode.getChildList()) { this.recursiveApplyTranslation(childSceneNode0, xOffset, yOffset, propagateToChild); } } }
/// <summary> /// /// </summary> /// <param name="sceneNode"></param> /// <param name="xScale"></param> /// <param name="yScale"></param> /// <param name="xCenter"></param> /// <param name="yCenter"></param> /// <param name="propagateToChild"></param> private void recursiveApplyScale(SceneNode sceneNode, double xScale, double yScale, double xCenter, double yCenter, bool propagateToChild) { IGameObject gameObject = sceneNode.getSceneNodeGameObject(); ScaleTransform scaleTransform = new ScaleTransform(xScale, yScale, xCenter, yCenter); if (gameObject.getImage() != null) { TransformGroup transformGroup = new TransformGroup(); transformGroup.Children.Add(scaleTransform); transformGroup.Children.Add(gameObject.getImage().RenderTransform); gameObject.getImage().RenderTransform = transformGroup; } if (gameObject.getBoundingBoxGeometry() != null) { TransformGroup geometryTransformGroup = new TransformGroup(); geometryTransformGroup.Children.Add(scaleTransform); geometryTransformGroup.Children.Add(gameObject.getBoundingBoxGeometry().Transform); gameObject.getBoundingBoxGeometry().Transform = geometryTransformGroup; } if (propagateToChild) { foreach (SceneNode childSceneNode0 in sceneNode.getChildList()) { this.recursiveApplyScale(childSceneNode0, xScale, yScale, xCenter, yCenter, propagateToChild); } } }
/// <summary> /// /// </summary> /// <param name="targetSceneNode"></param> /// <param name="clockwiseDegreeAngle"></param> /// <param name="xRotationCenter"></param> /// <param name="yRotationCenter"></param> public void recursiveApplyRotation(SceneNode sceneNode, double clockwiseDegreeAngle, double xRotationCenter, double yRotationCenter, bool affectBoundingBox, bool propagateToChild) { IGameObject gameObject = sceneNode.getSceneNodeGameObject(); RotateTransform rotateTransform = new RotateTransform(clockwiseDegreeAngle, xRotationCenter, yRotationCenter); { // transform image TransformGroup transformGroup = new TransformGroup(); transformGroup.Children.Add(rotateTransform); if (gameObject.getImage().RenderTransform != null) { transformGroup.Children.Add(gameObject.getImage().RenderTransform); } gameObject.getImage().RenderTransform = transformGroup; } // transform geometry if (affectBoundingBox && gameObject.getBoundingBoxGeometry() != null) { TransformGroup transformGroup = new TransformGroup(); transformGroup.Children.Add(rotateTransform); transformGroup.Children.Add(gameObject.getBoundingBoxGeometry().Transform); gameObject.getBoundingBoxGeometry().Transform = transformGroup; } foreach (SceneNode childSceneNode0 in sceneNode.getChildList()) { double xRotationRelativeToChild = xRotationCenter - (childSceneNode0.getSceneNodeGameObject().getXPosition() - gameObject.getXPosition()); double yRotationRelativeToChild = yRotationCenter - (childSceneNode0.getSceneNodeGameObject().getYPosition() - gameObject.getYPosition()); this.recursiveApplyRotation(childSceneNode0, clockwiseDegreeAngle, xRotationRelativeToChild, yRotationRelativeToChild, affectBoundingBox, propagateToChild); } }