Java-Gaming.org Hi !
 Featured games (83) games approved by the League of Dukes Games in Showcase (580) Games in Android Showcase (162) games submitted by our members Games in WIP (632) games currently in development
 News: Read the Java Gaming Resources, or peek at the official Java tutorials
Pages: [1]
 ignore  |  Print
 shapes around view :)  (Read 1756 times) 0 Members and 1 Guest are viewing this topic.
aNt

Senior Devvie

AFK

 « Posted 2004-02-22 18: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
silverklyph

Senior Newbie

Java games rock!

 « Reply #1 - Posted 2004-02-22 21: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 eyePoint3f oLoc = ... // Location of the objectfloat 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/
Yuri Vl. Gushchin

Senior Devvie

Speak Java!

 « Reply #2 - Posted 2004-02-23 09: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
aNt

Senior Devvie

AFK

 « Reply #3 - Posted 2004-02-23 10: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
Yuri Vl. Gushchin

Senior Devvie

Speak Java!

 « Reply #4 - Posted 2004-02-23 13: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
aNt

Senior Devvie

AFK

 « Reply #5 - Posted 2004-02-23 13: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.
EBTTRT

Senior Newbie

 « Reply #6 - Posted 2004-02-27 14: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?
Yuri Vl. Gushchin

Senior Devvie

Speak Java!

 « Reply #7 - Posted 2004-02-27 16: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
EBTTRT

Senior Newbie

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

Thanks

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

Senior Devvie

Speak Java!

 « Reply #9 - Posted 2004-02-28 07: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
EBTTRT

Senior Newbie

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

Thanks

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

Pages: [1]
 ignore  |  Print

You cannot reply to this message, because it is very, very old.

 Waterwolf (21 views) 2015-05-20 15:01:45 chrislo27 (25 views) 2015-05-20 03:42:21 BurntPizza (59 views) 2015-05-10 15:53:18 FrozenShade (45 views) 2015-05-07 09:11:21 TheLopais (208 views) 2015-05-06 13:36:48 TheLopais (192 views) 2015-05-06 13:35:14 TheLopais (198 views) 2015-05-06 13:33:39 TheLopais (214 views) 2015-05-06 13:32:48 TheLopais (214 views) 2015-05-06 13:31:28 ClaasJG (236 views) 2015-04-30 20:33:25
 Spasi 31x BurntPizza 16x theagentd 13x DavidBVal 13x ra4king 12x EgonOlsen 11x Husk 10x KevinWorkman 9x princec 8x scanevaro 8x KaiHH 7x opiop65 6x revers 6x Riven 6x HeroesGraveDev 5x MrPork 5x
 List of Learning Resources2015-05-05 10:20:32How to: JGO Wikiby Mac702015-02-17 20:56:162D Dynamic Lighting2015-01-01 20:25:42How do I start Java Game Development?by gouessej2014-12-27 19:41:21Resources for WIP gamesby kpars2014-12-18 10:26:14Understanding relations between setOrigin, setScale and setPosition in libGdx2014-10-09 22:35:00Definite guide to supporting multiple device resolutions on Android (2014)2014-10-02 22:36:02List of Learning Resources2014-08-16 10:40:00
 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