Adding Scene Elements to Scene Control

Mar 18, 2012 at 8:41 PM

I am trying to use the HitTestSample so I can select the object I have clicked on, but I cannot add my own object to the Scene.

My object is of class BSpline, which is basically a set of control points and knots, and the error i get is:


Error    2    Argument 1: cannot convert from 'SharpGLWinformsApplication1.BSpline' to 'SharpGL.SceneGraph.Core.SceneElement'    ...

Error    1    The best overloaded method match for 'SharpGL.SceneGraph.Core.SceneElement.AddChild(SharpGL.SceneGraph.Core.SceneElement)' has some invalid arguments    ...



How do I add the BSpline object as a SceneElement to the SceneControl?

Mar 19, 2012 at 9:06 AM

Have you derived SharpGLWinformsApplication1.BSpline from SharpGL.SceneGraph.Core.SceneElement?

Unless the class is derived from SceneElement, SharpGL won't know how to treat it :)

If you cannot derive from it (e.g. it's third party), create a SceneElement class called 'BSplineWrapper' or something like that - include the BSpline in the class and then render it after implementing the IRenderable interface.

Good luck and let me know how it goes!

Mar 19, 2012 at 5:54 PM
Edited Mar 19, 2012 at 9:33 PM

OK, done that.

But I obviously have to do a lot more if I want my object to be selected.

From what I understand, my class must also implement the IVolumeBound interface, but I dont understand how to implement it. This didnt work:

public BoundingVolume BoundingVolume()
   // compute bounding box somehow

   // return it somehow

the error now is

Error    2    'SharpGLWinformsApplication1.BSpline' does not implement interface member 'SharpGL.SceneGraph.Core.IVolumeBound.BoundingVolume'  ...

Mar 20, 2012 at 5:09 PM

I still havent found out how to implement the interface member IVolumeBound.BoundingVolume

This is what I found so far:

namespace SharpGL.SceneGraph.Core
    public interface IVolumeBound
        BoundingVolume BoundingVolume { get; }

but i dont know how to implement it in my class!

Mar 26, 2012 at 9:31 AM

Hi Kyriazis,


OK let me explain to you. To make an object be able to participate in hit testing, you do indeed have to implement IVolumeBound, just as you have discovered. What happens in hit testing is that rather than drawing the entire object, just a cuboid of roughly the same shape as the object. So for example, if we have a sphere, then the bounding volume is just a cube that encompasses the sphere. It's much faster to hit test cuboids rather than complex geometry :). However, this means that for a custom object, the responsibility is yours to come up with the bounding volume! So here's some hints:

  1. The bounding volume is a cuboid (i.e. a 3D rectangle).
  2. It should encompass your object.
  3. For testing, turn the 'DrawBoundingVolumes' property of the scene on - it'll show bounding volumes in red.
  4. Bounding Volumes are in object space - i.e. they don't need to take account of translations and so on.

If you have a 2D bezier spline, then basically create a cuboid from it's topmost/leftmost point and bottommost/rightmost points, then give it a small thickness, say 0.1 and you should be fine. If you're having problems, send the class over and I'll take a look.