Exemplo n.º 1
0
        private void RightVolumeControllerStandRadius_ValueChanged(object sender, EventArgs e)
        {
            var value = (double)RightVolumeControllerStandRadius.Value;

            if (value != currentObject.Basis1CylinderRadius)
            {
                currentObject.Basis1CylinderRadius = value;
                currentObject.UpdateObject();
            }
        }
Exemplo n.º 2
0
        // XML импорт сцены из файла
        private void ImportScene_Click(object sender, EventArgs e)
        {
            if (ImportDialog.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    IFormatProvider format = new System.Globalization.CultureInfo("en-us");

                    XDocument document = XDocument.Load(ImportDialog.FileName);

                    XElement scene = document.Element("scene");

                    var mode = scene.Attribute("ViewMode").Value;
                    if (mode == "WIREFRAME")
                    {
                        Scene.Mode             = (Scene.MODE.WIREFRAME);
                        ViewType.SelectedIndex = 0;
                    }
                    else
                    {
                        Scene.Mode             = (Scene.MODE.SOLID);
                        ViewType.SelectedIndex = 1;
                    }


                    Scene.Camera = new Camera();
                    Scene.ResetCamera();

                    var cameraElement = scene.Element("camera");
                    Scene.Camera.IsCentralProjection = bool.Parse(cameraElement.Element("central-projection").Value);

                    XElement position = cameraElement.Element("position");
                    Scene.Camera.Position = new Point3DSpherical(new Point3D(
                                                                     double.Parse(position.Attribute("x").Value, format),
                                                                     double.Parse(position.Attribute("y").Value, format),
                                                                     double.Parse(position.Attribute("z").Value, format)
                                                                     ));

                    XElement target = cameraElement.Element("target");
                    Scene.Camera.Target = new Point3DSpherical(new Point3D(
                                                                   double.Parse(target.Attribute("x").Value, format),
                                                                   double.Parse(target.Attribute("y").Value, format),
                                                                   double.Parse(target.Attribute("z").Value, format)
                                                                   ));

                    Scene.Camera.MoveCameraLeftRight(0);
                    Scene.Camera.MoveCameraUpDown(0);

                    var lightElement = scene.Element("light");

                    XElement lightPosition = lightElement.Element("position");
                    Scene.Light.X = double.Parse(lightPosition.Attribute("x").Value, format);
                    Scene.Light.Y = double.Parse(lightPosition.Attribute("y").Value, format);
                    Scene.Light.Z = double.Parse(lightPosition.Attribute("z").Value, format);


                    Scene.Objects.Clear();
                    ObjectsList.Items.Clear();
                    ObjectViewPanel.Visible = ObjectViewPanel.Enabled = ObjectSpacePanel.Visible = ObjectSpacePanel.Enabled = false;

                    foreach (XElement objectElement in scene.Element("objects").Elements("Telescope"))
                    {
                        var radioName = objectElement.Attribute("name").Value;
                        var tel       = new TelescopeObject(radioName);

                        XElement objectPosition = objectElement.Element("position");
                        tel.BasePoint = new Point3D(
                            double.Parse(objectPosition.Attribute("x").Value, format),
                            double.Parse(objectPosition.Attribute("y").Value, format),
                            double.Parse(objectPosition.Attribute("z").Value, format)
                            );

                        XElement rotate = objectElement.Element("rotate");
                        tel.AngleX = int.Parse(rotate.Attribute("x").Value);
                        tel.AngleY = int.Parse(rotate.Attribute("y").Value);
                        tel.AngleZ = int.Parse(rotate.Attribute("z").Value);

                        XElement scale = objectElement.Element("scale");
                        tel.SetScale(
                            double.Parse(scale.Attribute("x").Value, format),
                            double.Parse(scale.Attribute("y").Value, format),
                            double.Parse(scale.Attribute("z").Value, format)
                            );

                        tel.Basis1CylinderRadius = double.Parse(objectElement.Element("Basis1CylinderRadius").Value, format);
                        tel.PrimaryLegsLength    = double.Parse(objectElement.Element("PrimaryLegsLength").Value, format);
                        tel.Basis2CylinderRadius = double.Parse(objectElement.Element("Basis2CylinderRadius").Value, format);
                        tel.Basis3CylinderRadius = double.Parse(objectElement.Element("Basis3CylinderRadius").Value, format);
                        tel.LenseRadius          = double.Parse(objectElement.Element("LenseRadius").Value, format);
                        tel.SecondaryLegsLength  = double.Parse(objectElement.Element("SecondaryLegsLength").Value, format);
                        tel.PrimaryLegsCount     = double.Parse(objectElement.Element("PrimaryLegsCount").Value, format);
                        tel.SecondaryLegsCount   = double.Parse(objectElement.Element("SecondaryLegsCount").Value, format);
                        tel.HandsCount           = int.Parse(objectElement.Element("HandsCount").Value, format);
                        tel.HandsRadius          = int.Parse(objectElement.Element("HandsRadius").Value, format);

                        tel.UpdateObject();

                        Scene.AddObject(tel);
                        ObjectsList.Items.Add(tel.ObjectName);
                    }

                    // if there are no objects, the user will see it.
                    ObjectsList.SelectedIndex = -1;
                    if (Scene.Objects.Count > 0)
                    {
                        ObjectsList.SelectedIndex = 0;
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Не получается импортировать сцену!", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }