shapes around view :)

what would be the best way in xith3d to obtain all the nodes around a given radias of my view.

so if i have a number of shapes around my moveing camrea- i could lookup the node locations of my shape within a give redius around my camera.

http://www.topresultmate.com/xith3d/area.jpg

not sure if i should be using the collision stuff. or if thats just over kill for what i want to do. Thing is, i may have lots and lots of shapes in my world- and i dont want to check on all of my shapes if the sg is doing it anyways.

so a return of the shapes around the view world be grand. in a list or whatever :slight_smile:

I believe what you do is, you have two Point3f objects, one representing the view and one representing the object.



Point3f vLoc = ... // Location of eye
Point3f oLoc = ... // Location of the object

float radius = cuberoot( Math.pow(vLoc.x - oLoc.x, 2),
                                      Math.pow(vLoc.y - oLoc.y, 2),
                                      Math.pow(vLoc.z - oLoc.z, 2));

There is a cuberoot function in 1.5 beta, but using one in 1.4.2 I am not QUITE sure how to do it. You could probably google for it, as I am sure that there is a formula for cubic equations that would be able to solve this, but its really complex.

EDIT : http://www.math.vanderbilt.edu/~schectex/courses/cubic/

SG is doing a bounds-check, it uses Bounding Sphere.
I can not give you step-by-step example, but can tell you that SG uses Classifiers in a way something like:

Classifier.Classification classify = frustum.classify(node.getVworldBounds());

if (classify == Classifier.OUTSIDE)  
  ****

So you may be interested in classes from com.xith3d.spatial.bounds.*;

Yuri

Yuri more info on that would be tops! i just need to now what models are around the view within a given radius.

messing with :

Frustum frustum = new Frustum();
view.extractFrustum(frustum, canvas);

Classifier.Classification classify = frustum.classify(view.getVworldBounds());

if(classify …

nothing seems to happen… what should i expect?
tip tip tops

Hi,

No, this is a wrong use.

Classifier can classify if bounds are inside/outside/intersect classifying shape.

For your case, you I guess should use Sphere to classify (because of we speak about Radius), traverse scenegraph and classify every shape of your interest.

I can imagine that scenegraph traversal is what you wanted to avoid, but AFAIK there is no direct way in Xith3D how to get a list of classified shapes - View does this via traversal…

Yuri

maybe i should be using Collision Detection? with in the:
com.xith3d.scenegraph.behavior

? going to have more of a look into this, need it so i can tell what objects are around the camera. and i need this to be fast- because i may have alot of objects in the scene. like alot.

Sorry newbie Question…

[quote]Classifier can classify if bounds are inside/outside/intersect classifying shape.
[/quote]
Given this is how Classifier works, & given that I have a moving view (with a BoundingSphere) & a cube (with a BoundingSphere) how would I sense when the view enters that particular cube?

For example:


      public void detectCol()
      {
            //viewBounds is BoundingSphere with the view &
            //Cube1Bounds is the BoundingSphere with the cube
            Classifier.Classification classifyCube1 = viewBounds.classify(cube1Bounds);
            Classifier.Classification classifyCube2 = viewBounds.classify(cube2Bounds);

            if ( ( classifyCube1 == Classifier.INSIDE ) ) { 
                  System.out.println("collision shape1");
            }

            if ( ( classifyCube2 == Classifier.INSIDE ) ) { 
                  System.out.println("collision shape2");
            }

The method is called in my render loop to check for the collision.

Please what am I doing wrong? :frowning:

First, all of coordinates should be in the same coordinate space. This means that you have to use Virtual World bounds instead of local Bounds. You can obtain Virtual World bounds for shape by call to getVWorldBounds() and passing them to the classifier.

Next, you have to adjust classifier volume for current location of your viewing region (aka camera location, aka view frustum). The easiest way to do this is to let Xith3D core to construct Classifier object for you by calling view.extractFrustum(Frustum, Canvas3D) and passing new frustum object and your Canvas3D of interest. This will give you a frustum which describes currently visible volume. If you need another classification shape (sphere etc.) you should construct it yourself basing on View projection and transform matices.

Then you do actual classification:

Classifier.Classification classify = frustum.classify(node.getVworldBounds());
if (classify == Classifier.INSIDE)  
{ 
   ...do my code... 
}

For more details, take a look for View.java in Xith3D source tree - it performs frustum culling to avoid rendering of definitely invisible objects.

Yuri

Thanks :slight_smile:

So instead if I wanted to find out if my view collides /intersects with a shape I would say something like:


//dummyView & shape1 are Shape3D's with BoundingSpheres
if (dummyView.getVworldBounds().sphereIntersection(shape1.getVworldBounds()))
            {
                  System.out.println("collision shape1");
            }

            else if (dummyView.getVworldBounds().sphereIntersection(shape2.getVworldBounds()))
            {
                  System.out.println("collision shape2");
            }

But if I add another shape (shape2 above) & look to see if my view collides with this new one nothing seems to register with println()s - presumably because both shapes are in my frustum.

Do I need to somehow culling everything I have apart from the intersection I’m testing for?
Is this what you mean by:

[quote]take a look for View.java in Xith3D source tree - it performs frustum culling to avoid rendering of definitely invisible objects.
[/quote]
Thanks again.

The example above can not detect that two collisions happened simultaneously - you have to replace “else if” with “if”.

My suggestion si that you print out the bounds and check manually if they are intersecting.

Yuri

Thanks :slight_smile:

It kind of works now - I can detect a collision when I’m moving in a certain direction at my cubes.

It seems if both cubes are in the frustum they seem detectable but not if they they aren’t. I probably need to do some testing to see what is exactly happening. I do have collision attached to everything + I’m using terrain.

I couldn’t see any methods to detect/test if Collision Nodes intersect/hit each other - that is why I’m trying to do it this way.

I’m a bit further forward - thanks again :slight_smile: