Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (106)
games submitted by our members
Games in WIP (533)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  shapes around view :)  (Read 1467 times)
0 Members and 1 Guest are viewing this topic.
Offline aNt

Senior Member




AFK


« Posted 2004-02-22 19:48:56 »

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.



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 Smiley
Offline silverklyph

Senior Newbie




Java games rock!


« Reply #1 - Posted 2004-02-22 22:25:49 »

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

1  
2  
3  
4  
5  
6  
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/
Offline Yuri Vl. Gushchin

Senior Member




Speak Java!


« Reply #2 - Posted 2004-02-23 10:36:23 »

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:

1  
2  
3  
4  
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 Vl. Gushchin
JProof Group
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline aNt

Senior Member




AFK


« Reply #3 - Posted 2004-02-23 11:46:02 »

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
Offline Yuri Vl. Gushchin

Senior Member




Speak Java!


« Reply #4 - Posted 2004-02-23 14:15:52 »

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

Yuri Vl. Gushchin
JProof Group
Offline aNt

Senior Member




AFK


« Reply #5 - Posted 2004-02-23 14:45:19 »

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.
Offline EBTTRT

Senior Newbie





« Reply #6 - Posted 2004-02-27 15:22:47 »

Sorry newbie Question...

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


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:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
      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? Sad
Offline Yuri Vl. Gushchin

Senior Member




Speak Java!


« Reply #7 - Posted 2004-02-27 17:38:44 »

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:

1  
2  
3  
4  
5  
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

Yuri Vl. Gushchin
JProof Group
Offline EBTTRT

Senior Newbie





« Reply #8 - Posted 2004-02-27 21:11:40 »

Thanks  Smiley

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

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
//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.


Thanks again.
Offline Yuri Vl. Gushchin

Senior Member




Speak Java!


« Reply #9 - Posted 2004-02-28 08:31:36 »

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

Yuri Vl. Gushchin
JProof Group
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline EBTTRT

Senior Newbie





« Reply #10 - Posted 2004-02-28 09:48:33 »

Thanks Smiley

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 Smiley

Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

pw (26 views)
2014-07-24 01:59:36

Riven (25 views)
2014-07-23 21:16:32

Riven (20 views)
2014-07-23 21:07:15

Riven (22 views)
2014-07-23 20:56:16

ctomni231 (51 views)
2014-07-18 06:55:21

Zero Volt (46 views)
2014-07-17 23:47:54

danieldean (37 views)
2014-07-17 23:41:23

MustardPeter (40 views)
2014-07-16 23:30:00

Cero (56 views)
2014-07-16 00:42:17

Riven (55 views)
2014-07-14 18:02:53
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!