Picking

Is there a sensible way to generate a non axis aligned bounding box for a node.

I am making a 3d scroll bar. Previously it was axis aligned as well so this wasn't an issue. I would simply cast a ray, find its intersection and translate the selector to this new location.

Now it is attached to the HUD so is seldom axis aligned and thus is not an option.



I could project the world co-ordinates of the edges to the screen co-ordinates and map it that way but it seems silly.

Anyone here done anything similar?

I decided to create a box around my gui element. Then project the facing side to screen co-ords after converting them to world co-ords.

Then I normalise the mouse position and check where I pick.



Here is the code:


{// Floating bounding box.
         attachChild(new Box("box", new Vector3f(5, 5, lengthOfSlideBar / 2f), new Vector3f(-5, -5,
               -lengthOfSlideBar / 2f)) {
            @ Override
            public void draw( final Renderer r ) {
            };
         });
      }



and...


final Box box = (Box) getChild("box");
      
      final Vector3f[] corners = box.computeVertices();
      
      final Vector3f tl = display.getScreenCoordinates(box.localToWorld(corners[0], corners[1]));
      
      final Vector3f bl = display.getScreenCoordinates(box.localToWorld(corners[3], corners[1]));
      
      final Vector3f tr = display.getScreenCoordinates(box.localToWorld(corners[5], corners[1]));
      
      final Vector3f br = display.getScreenCoordinates(box.localToWorld(corners[7], corners[1]));
      
      final Vector3f mouse = new Vector3f(screenPos.x, screenPos.y, 0);
      
      {// Check and translate
         if (mouse.x > tl.x && mouse.x < tr.x)
            if (mouse.y > bl.y && mouse.y < tl.y) {
               final float normal = tr.x - tl.x;
               alpha = 1 + (mouse.x - tl.x - normal) / normal;
               setAlpha(alpha);
            }
      }



Not what I wanted but works a treat.