Accessing shapes in ILPanel and ILCamera

260 Views Asked by At

I have three question regarding ILPanel in ILNumerics:

  1. How can I disable the double click interaction of ILPanel to reset the view.
  2. How can I increase the speed of panning using right click and drag. The panning is very slow especially when the shape is vary large.
  3. How can access the elements that I add to a camera and modify them.

Here is a simple example. Two spheres are added to a camera and a ILLable, "Hello", is on top of one of them (the blue one). I want the "Hello" label to jump on top of the green sphere if I rotate the scene with mouse and the green sphere become closer to the camera and visa verse. And, how can I change the color of the spheres say by clicking a button?

 private void ilPanel1_Load(object sender, EventArgs e)
 {
        var scene = new ILScene();
        var cam = scene.Camera;
        var Sphere1 = new ILSphere();
        Sphere1.Wireframe.Visible = true;
        Sphere1.Fill.Color = Color.Blue;
        Sphere1.Wireframe.Color = Color.Blue;
        Sphere1.Transform = Matrix4.Translation(0, 0, 0);
        var Sphere2 = new ILSphere();
        Sphere2.Wireframe.Visible = true;
        Sphere2.Transform = Matrix4.Translation(2, 0, 0);
        cam.Add(Sphere1);
        cam.Add(Sphere2);
        cam.Add(new ILLabel("Hello")
        {
            Font = new System.Drawing.Font(FontFamily.GenericSansSerif, 8),
            Position = new Vector3(0, 0, 1.1),
            Anchor = new PointF(0, 1),
        });
        ilPanel1.Scene = scene;
 }

enter image description here

1

There are 1 best solutions below

2
On BEST ANSWER

Create a label, which is always on top of other 3D objects

cam.Add(
        new ILScreenObject() {
            Location = new PointF(0.5f, 0.5f),
            Children = {
                new ILLabel("Hello") 
            }
        });

See also: http://ilnumerics.net/world3d-and-screen2d-nodes.html

Regarding your "jumping sphere" example: if your want your label to jump to another group (spheres are groups actually) at runtime, you will have to implement that logic into a function which is called at runtime. ilPanel1.BeginRenderFrame might be a good place to check for such updates.

Disable default behavior for the first camera:

scene.Camera.MouseDoubleClick += (_, arg) => {
    arg.Cancel = true;
};

See: http://ilnumerics.net/mouse-events.html

React on a button press:

button1.Click += (_,args) => {
    ilPanel1.Scene.First<ILSphere>().Fill.Color = Color.Red; 
    ilPanel1.Refresh(); 
};

Finding objects in the scene: see: http://ilnumerics.net/nodes-accessing-managing.html

Controlling the panning speed:

There is no easy way to configure the speed currently. The best way would be to implement the corresponding mouse handler on your own:

  1. Override MouseMove for the camera node.

  2. Implement the panning similar to the way it was done in ILNumerics (see: ILCamera.OnMouseMove in the sources).

  3. Increase the scale factor.

  4. Dont forget to cancel the event processing at the end of your handler.