Пример #1
0
        public void ComplexRender()
        {
            // Create scene
            var camera = new PerspectiveCamera(new Size(120, 120));

            camera.Transform = Transformation.Offset(new Vec3(0, -5, 0));
            var scene = new Scene();

            // Set the skybox
            camera.Skybox = new GradientSkybox(Color.FromArgb(255, 58, 58, 82), Color.FromArgb(255, 2, 1, 17));

            // Create objects
            var helper = new AxisHelper();

            var planet        = new Geometry.Primitives.Sphere(radius: 1, centre: Vec3.Zero, horizontalResolution: 32, verticalResolution: 32);
            var planetTexture = LoadImage("assets/planet.png");

            var satellite        = new Geometry.Primitives.Sphere(radius: 0.2, centre: Vec3.Zero, horizontalResolution: 12, verticalResolution: 12);
            var satelliteTexture = LoadImage("assets/moon.png");

            var hierarchy = new SceneNode();

            scene.Add(hierarchy);

            var planetObj = new MeshRenderer(mesh: planet, uv: UV.Spherical(planet), material: new UnlitTexture(planetTexture));

            hierarchy.Add(planetObj);

            var satelliteObj = new MeshRenderer(mesh: satellite, uv: UV.Spherical(satellite), material: new UnlitTexture(satelliteTexture));

            satelliteObj.Transform = Transformation.Offset(new Vec3(-1.6, 1.6, 0.1));
            hierarchy.Add(satelliteObj);

            helper.Transform = Transformation.Scale(Vec3.One * 1.3);
            helper.XLabel    = "X";
            helper.YLabel    = "Y";
            helper.ZLabel    = "Z";
            hierarchy.Add(helper);

            // Render
            SaveAnimation("render.complex", SpinAnimation(camera, hierarchy, frames: 64));
        }
Пример #2
0
        private void SelectionRequested(SelectionFrustum obj)
        {
            if (_pos == null)
            {
                return;
            }

            // The user has interactively edited the constrained sections -> propagate the information to the simulation core
            List <int>     indices = new List <int>();
            List <Double3> pos     = _pos.GetList();

            Double4x4 trafo = _gl.SceneGraph.AbsoluteTransformation;
            //trafo.Invert();


            Double3 center = Double3.Zero;

            for (int i = 0; i < pos.Count; ++i)
            {
                double d;
                if (obj.IsPointInside(trafo.TransformPoint(pos[i]), out d))
                {
                    indices.Add(i);
                    center += pos[i];
                }
            }

            if (indices.Count > 0)
            {
                center /= indices.Count;

                SceneNode n = new SceneNode();
                n.RelativeTranslation = center;

                CoordinateSystemSceneNode cs = new CoordinateSystemSceneNode();
                //cs.RelativeTranslation = center;

                cs.Call <SceneNode>(m => m.Overlay = true);

                n.Add(cs);


                _gl.SceneGraph.Add(n);


                _sim.AddConstraint(new ConstrainedSection(cs, indices));
                _sim.UpdateConstraintConfiguration();
            }
        }