void CreateScene() { Input.SubscribeToTouchEnd(OnTouched); var cache = ResourceCache; scene = new Scene(); octree = scene.CreateComponent <Octree>(); plotNode = scene.CreateChild(); var cameraNode = scene.CreateChild("camera"); camera = cameraNode.CreateComponent <Camera>(); cameraNode.Position = new Vector3(20, 30, 20) / 1.75f; cameraNode.Rotation = new Quaternion(-0.121f, 0.878f, -0.305f, -0.35f); plotNode.Rotate(new Quaternion(2f, -90, 0), 0); Node lightNode = cameraNode.CreateChild(name: "light"); var light = lightNode.CreateComponent <Light>(); light.LightType = LightType.Point; light.Range = 100; light.Brightness = 0.7f; int size = 3; int values = 4; float maxY = 10; for (int i = 0; i < values; i++) { var sectionX = plotNode.CreateChild().CreateChild(); var planeX = sectionX.CreateComponent <StaticModel>(); planeX.Model = ResourceCache.GetModel("Models/Box.mdl"); sectionX.Position = new Vector3(size * size * (-1) + size - 0.8f, (maxY / values) * i + (maxY / values / 2), 0); sectionX.Scale = new Vector3(maxY / values, 0.2f, 8); sectionX.Rotate(new Quaternion(0, 0, -90), 0); planeX.SetMaterial(cache.GetMaterial("Materials/Wall.xml").Clone("")); } var deltaColor = new Color(RandomHelper.NextRandom(), RandomHelper.NextRandom(), RandomHelper.NextRandom(), 1); deltas = new List <DeltaBox>(); bars = new List <Bar>(size * size); cylinders = new List <Cylinder>(size * size); barValues = new List <float>(); for (int i = 0; i < 9; i++) { float barValue = RandomHelper.NextRandom(1.0f, 5.0f); barValues.Add(barValue); var boxNode = plotNode.CreateChild(); boxNode.Position = new Vector3(size / 2f - i * 1.5f + size * size * 0.5f, 0, size / 4f); boxNode.Rotate(new Quaternion(0, 180, 0), 0); var box = new Bar(new Color(RandomHelper.NextRandom(), RandomHelper.NextRandom(), RandomHelper.NextRandom(), 0.5f)); boxNode.AddComponent(box); box.SetValueWithAnimation(barValue); bars.Add(box); var sectionY = plotNode.CreateChild().CreateChild(); var planeY = sectionY.CreateComponent <StaticModel>(); planeY.Model = ResourceCache.GetModel("Models/Box.mdl"); planeY.SetMaterial(cache.GetMaterial("Materials/Wall.xml").Clone("")); sectionY.Position = new Vector3(boxNode.Position.X, 0, 0); sectionY.Scale = new Vector3(boxNode.Scale.X + 0.5f, 0.2f, 8); for (int j = 0; j < values; j++) { var sectionZ = plotNode.CreateChild().CreateChild(); var planeZ = sectionZ.CreateComponent <StaticModel>(); planeZ.Model = ResourceCache.GetModel("Models/Box.mdl"); sectionZ.Position = new Vector3(boxNode.Position.X, (maxY / values) * j + (maxY / values) / 2, sectionY.Scale.Z / 2 + 0.1f); sectionZ.Scale = new Vector3(sectionY.Scale.X, maxY / values, 0.2f); planeZ.SetMaterial(cache.GetMaterial("Materials/Wall.xml").Clone("")); } if (i != 0) { var valueNode = plotNode.CreateChild(); valueNode.Position = new Vector3(boxNode.Position.X + boxNode.Scale.X, 0, size); valueNode.Scale = new Vector3(1.5f, 1, 1); valueNode.Rotate(new Quaternion(0, 180, 0), 0); var valueBox = new DeltaBar(deltaColor); valueNode.AddComponent(valueBox); var deltaNode = plotNode.CreateChild(); var deltaBox = new DeltaBox(deltaColor); if (i == 1) { deltaBox.SetValues(barValues[i], barValues[i - 1]); } else { deltaBox.SetValues(barValues[i], deltas[i - 2].leftValue); } DeltaHelper.AdjustDelta(deltaNode, deltaBox, valueBox); deltaBox.bar = valueBox; deltas.Add(deltaBox); } var cylinderNode = plotNode.CreateChild(); cylinderNode.Position = new Vector3(size / 2f - i * 1.5f + size * size * 0.5f, 0, size / 4f - 2); cylinderNode.Rotate(new Quaternion(0, 180, 0), 0); var cylinder = new Cylinder(new Color(RandomHelper.NextRandom(), RandomHelper.NextRandom(), RandomHelper.NextRandom(), 0.5f)); cylinderNode.AddComponent(cylinder); cylinder.SetValueWithAnimation(barValue); cylinders.Add(cylinder); bars[bars.Count - 1].Cylinder = cylinder; } for (int i = 0; i < 9; i++) { if (i > 0 && i < 8) { bars [i].SetDeltas(deltas [i], deltas [i - 1]); } if (i == 0) { bars [i].SetDeltas(deltas [i], null); } if (i == 8) { bars [i].SetDeltas(null, deltas [i - 1]); } } SelectedBar = bars.First(); SelectedBar.Select(); movementsEnabled = true; }
public static void AdjustDelta(Node deltaNode, DeltaBox deltaBox, DeltaBar valueBox) { var valueNode = valueBox.Node; if (deltaBox.leftValue > deltaBox.rightValue) { deltaNode.Position = new Vector3(valueNode.Position.X, deltaBox.rightValue - deltaNode.Scale.Y, valueNode.Position.Z); valueBox.SetValueWithAnimation(deltaBox.rightValue - deltaNode.Scale.Y / 4); } else { deltaNode.Position = new Vector3(valueNode.Position.X, deltaBox.leftValue - deltaNode.Scale.Y, valueNode.Position.Z); valueBox.SetValueWithAnimation(deltaBox.leftValue - deltaNode.Scale.Y / 4); } deltaNode.AddComponent(deltaBox); if (deltaBox.valueDifference < 1.0f) { var height = (1 - deltaBox.deltaNode.Scale.Y) / 3 * 2; if (deltaBox.valueDifference < 1 && deltaBox.valueDifference > 0.2f) { valueBox.SetValueWithAnimation(deltaBox.Node.Position.Y + 0.15f); } if (deltaBox.valueDifference <= 0.5f) { deltaNode.Position = new Vector3(deltaNode.Position.X, deltaNode.Position.Y + height, deltaNode.Position.Z); valueBox.SetValueWithAnimation(deltaBox.Node.Position.Y + 0.02f); } valueBox.Node.Position = new Vector3(valueBox.Node.Position.X, valueBox.Node.Position.Y + 0.1f, valueBox.Node.Position.Z); } if (deltaBox.valueDifference > 1.0f) { var height = (deltaBox.deltaNode.Scale.Y - 1) / (-1); if (deltaBox.valueDifference <= 2f) { height = (deltaBox.deltaNode.Scale.Y / 2); valueBox.SetValueWithAnimation(deltaNode.Position.Y + height); } else { if (deltaBox.valueDifference >= 3) { deltaBox.Node.Position = new Vector3(deltaBox.Node.Position.X, deltaBox.Node.Position.Y - (3 - deltaBox.valueDifference) * (-0.5f), deltaBox.Node.Position.Z); } if (deltaBox.valueDifference >= 4) { deltaBox.Node.Position = new Vector3(deltaBox.Node.Position.X, deltaBox.Node.Position.Y - (3 - deltaBox.valueDifference) * (-0.5f), deltaBox.Node.Position.Z); } valueBox.SetValueWithAnimation(deltaNode.Position.Y + deltaNode.Scale.Y / 3 * 2 + 0.2f); } } if (Math.Round(deltaBox.valueDifference) == 1) { var height = (1 - deltaBox.deltaNode.Scale.Y) / 3 * 2; deltaNode.Position = new Vector3(deltaNode.Position.X, deltaNode.Position.Y + height, deltaNode.Position.Z); valueBox.SetValueWithAnimation(deltaNode.Position.Y + 0.2f); valueBox.Node.Position = new Vector3(valueBox.Node.Position.X, valueBox.Node.Position.Y + 0.1f, valueBox.Node.Position.Z); } }
public static void ChangeDelta(DeltaBox deltaBox, DeltaBar valueBox) { var deltaNode = deltaBox.Node; var valueNode = valueBox.Node; valueBox.Node.Position = new Vector3(valueBox.Node.Position.X, 0, valueBox.Node.Position.Z); if (deltaBox.leftValue > deltaBox.rightValue) { deltaNode.Position = new Vector3(valueNode.Position.X, deltaBox.rightValue - deltaNode.Scale.Y, valueNode.Position.Z); valueBox.SetValueWithAnimation(deltaBox.rightValue - deltaNode.Scale.Y / 4); } else { deltaNode.Position = new Vector3(valueNode.Position.X, deltaBox.leftValue - deltaNode.Scale.Y, valueNode.Position.Z); valueBox.SetValueWithAnimation(deltaBox.leftValue - deltaNode.Scale.Y / 4); } if (deltaBox.valueDifference < 1.0f) { var height = (1 - deltaBox.deltaNode.Scale.Y) / 3 * 2; if (deltaBox.valueDifference < 1 && deltaBox.valueDifference > 0.2f) { valueBox.SetValueWithAnimation(deltaBox.Node.Position.Y + 0.15f); } if (deltaBox.valueDifference <= 0.5f && deltaBox.valueDifference >= 0.2f) { deltaNode.Position = new Vector3(deltaNode.Position.X, deltaNode.Position.Y + height, deltaNode.Position.Z); valueBox.SetValueWithAnimation(deltaBox.Node.Position.Y + 0.02f); } else if (deltaBox.valueDifference < 0.2f) { deltaNode.Position = new Vector3(deltaNode.Position.X, deltaNode.Position.Y + height - 0.05f, deltaNode.Position.Z); valueBox.SetValueWithAnimation(deltaBox.Node.Position.Y + 0.02f); } if (deltaBox.valueDifference < 0.7f) { valueBox.SetValueWithAnimation(deltaBox.Node.Position.Y - 0.04f); } valueBox.Node.Position = new Vector3(valueBox.Node.Position.X, valueBox.Node.Position.Y + 0.1f, valueBox.Node.Position.Z); } if (deltaBox.valueDifference > 1.0f) { var height = (deltaBox.deltaNode.Scale.Y - 1) / (-1); if (deltaBox.valueDifference <= 2f) { height = (deltaBox.deltaNode.Scale.Y / 2); valueBox.SetValueWithAnimation(deltaNode.Position.Y + height + 0.15f); if (deltaBox.valueDifference == 1.7f) { valueBox.SetValueWithAnimation(deltaNode.Position.Y + 0.15f); } } else { if (deltaBox.valueDifference >= 3) { deltaBox.Node.Position = new Vector3(deltaBox.Node.Position.X, deltaBox.Node.Position.Y - (3 - deltaBox.valueDifference) * (-0.5f), deltaBox.Node.Position.Z); } valueBox.SetValueWithAnimation(deltaNode.Position.Y + deltaNode.Scale.Y / 3 * 2 + 0.2f); } } if (Math.Round(deltaBox.valueDifference) == 1) { var height = (1 - deltaBox.deltaNode.Scale.Y) / 3 * 2; deltaNode.Position = new Vector3(deltaNode.Position.X, deltaNode.Position.Y + height, deltaNode.Position.Z); valueBox.SetValueWithAnimation(deltaNode.Position.Y + 0.2f); valueBox.Node.Position = new Vector3(valueBox.Node.Position.X, valueBox.Node.Position.Y + 0.1f, valueBox.Node.Position.Z); } }
public void SetDeltas(DeltaBox left, DeltaBox right) { rightDelta = right; leftDelta = left; }