Java-Gaming.org    
Featured games (91)
games approved by the League of Dukes
Games in Showcase (581)
games submitted by our members
Games in WIP (500)
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  
  [SOLVED] Collision Detection Problems  (Read 1919 times)
0 Members and 1 Guest are viewing this topic.
Offline Conzar

Junior Member




There is nothing common about common sense


« Posted 2006-04-09 18:38:59 »

Hello all.  I have a been working on a collision detection algo and I think I've got something wrong.  I have been going off of the tutorial from j3d.org with some modifications. 

Here is the code for detecting if a collision happened.
curTrans is the current position of the object.
nextTrans is the position we are checking for a collision with.  Meaning, if we move the object to this position, will there be a collision.
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
public void detect(Transform3D curTrans, Transform3D nextTrans){
    curTrans.get(locationVector);
    nextTrans.get(collisionVector);
    locationPoint.set(locationVector);
    locationEndPoint.set(collisionVector);
    cylinderPicker.set(locationPoint, locationEndPoint,0.01);

    SceneGraphPath[] closest = collidables.pickAllSorted(cylinderPicker);

    if((closest == null) || (closest.length == 0)){
       // break out b/c we didn't hit anything (code left out for simplicity)
   }
    length = (float)collisionVector.length();

    for(int i = 0; (i < closest.length); i++){
        Transform3D local_tx = closest[i].getTransform();
        Shape3D i_shape = (Shape3D)closest[i].getObject();
        PickResult pr = new PickResult(i_shape,local_tx,cylinderPicker);
        PickIntersection pis = pr.getClosestIntersection(locationPoint);
        if(pis != null){
             //we found a collision so we can stop for now
            // notify engine code goes here (left out for simplicity)
       }
    }
}


This is the code that calls the function.
We basically need to get the world coordinates, so thats what most of this code does.
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
TransformGroup currentTransG;    // holds the current transform information
Transform3D nextTrans;            // Is the next position for the object to travel to

// these variables get set along the way

// get the World Coordinates of the current position and the next position
Transform3D t1 = new Transform3D();
currentTransG.getLocalToVworld(t1);
Transform3D tempT = new Transform3D();
currentTransG.getTransform(tempT);
t1.mul(tempT);

Transform3D t2 = new Transform3D();
currentTransG.getLocalToVworld(t2);
currentTransG.mul(nextTrans);

// detect if there was a collision
detect(t1,t2);


Anyone have any suggestions on what I need to fix?

Thanks

Ubuntu
Offline Breakfast

Senior Member




for great justice!


« Reply #1 - Posted 2006-04-09 21:34:42 »

Assuming we're too lazy to build and implement your code, what are the symptoms of the problem?
Offline Conzar

Junior Member




There is nothing common about common sense


« Reply #2 - Posted 2006-04-11 01:59:44 »

Check out the attachment. 
Basically, when I shoot the lasers, the detection algo is indicating that they hit in-between the balls.  It also picks up that it hits the balls too.  In the image, collisions are indicated by the swerly round things and the laser is the cylindrical red thing.  When I shoot away from the balls, the lasers fly as they should and don't hit anything.

Let me know if you need more info.  Thanks!!!

Ubuntu
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Breakfast

Senior Member




for great justice!


« Reply #3 - Posted 2006-04-11 16:24:02 »

That makes things a lot clearer...

I'm not really a picking expert, but I would make a bit of a guess that it could be picking based on bounds rather than polygon collisions?

Try changing the appearance of the object being hit when it is hit- that way you can tell what shape Java3D thinks you are hitting when you think you are shooting in between them.
Offline Conzar

Junior Member




There is nothing common about common sense


« Reply #4 - Posted 2006-04-12 00:08:53 »

Yea, that would make sense except that my algorithm makes sure that we really hit a shape3d object.  Unless something is wrong with the code below...
Also, what do u mean by change the apperance?

Thanks

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
   for(int i = 0; (i < closest.length); i++){
        Transform3D local_tx = closest[i].getTransform();
        Shape3D i_shape = (Shape3D)closest[i].getObject();
        PickResult pr = new PickResult(i_shape,local_tx,cylinderPicker);
        PickIntersection pis = pr.getClosestIntersection(locationPoint);
        if(pis != null){
             //we found a collision so we can stop for now
            // notify engine code goes here (left out for simplicity)
       }
    }

Ubuntu
Offline Jeff

JGO Coder




Got any cats?


« Reply #5 - Posted 2006-04-12 02:21:25 »

Make sure you are setting it to pick by triangle data

Also make sure your Shape3Ds are set to allow such a pick

Got a question about Java and game programming?  Just new to the Java Game Development Community?  Try my FAQ.  Its likely you'll learn something!

http://wiki.java.net/bin/view/Games/JeffFAQ
Offline Herkules

Senior Member




Friendly fire isn't friendly!


« Reply #6 - Posted 2006-04-12 10:44:53 »

Just hint, here is an example how FlyingGuns uses picking to detect cannon hits (look for method evalCannonHits()):

http://cvs.sourceforge.net/viewcvs.py/drts/projects/flyingguns/core/client/java/com/flyingguns/scene/Vehicle.java?view=markup

HARDCODE    --     DRTS/FlyingGuns/JPilot/JXInput  --    skype me: joerg.plewe
Offline Conzar

Junior Member




There is nothing common about common sense


« Reply #7 - Posted 2006-04-12 23:28:49 »

So I found this in the collisions function.

1  
2  
3  
4  
mShotAnalysis.setup( m3DModel.getTransformGroup() );
mShotAnalysis.mPicker.setShapeCylinderRay( mShotAnalysis.mCenter, mShotAnalysis.mAhead, 0.5 );

PickResult result = mShotAnalysis.mPicker.pickClosest();


The problem is, I can't find Vehicle.shotanalyis which is what mShotAnalysis is. 
Thats where the meat of the collision detection takes place.  I use the PickResult the same way those guys use it.
So I am thinknig however they first get the bounds of their collisions is where they differ for me.

But I can't tell that until I get at their code.

Ubuntu
Offline Herkules

Senior Member




Friendly fire isn't friendly!


« Reply #8 - Posted 2006-04-13 08:18:36 »

Scroll a bit upwards Smiley


(I admit that Vehicle.java is a bit messy ... refactoring is planned)

HARDCODE    --     DRTS/FlyingGuns/JPilot/JXInput  --    skype me: joerg.plewe
Offline Conzar

Junior Member




There is nothing common about common sense


« Reply #9 - Posted 2006-04-18 00:32:29 »

Hey.
   Just wanted to let everyone know that I got collision detection working on my lasers as well as running into stuff.
From looking through Flying Guns, I was able to get the following routine to work.  Thanks a bunch.  Now I just need to figure out how to better deal with collisions from the ship that you are flying -- sometime you get stuck which is bad bad bad.


1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
        curTrans.get(locationVector);
        nextTrans.get(collisionVector);

        locationPoint.set(locationVector);
        locationEndPoint.set(collisionVector);

        cylinderPicker.set(locationPoint, locationEndPoint,0.5);
        PickTool mPicker = new PickTool(collidables);
        mPicker.setMode( PickTool.GEOMETRY_INTERSECT_INFO );
        mPicker.setShapeCylinderSegment(locationPoint,locationEndPoint,0.05);
        PickResult result = mPicker.pickClosest();
        if(result == null) // we didn't hit anything
       // else we hit something so do hit routine

Ubuntu
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.

xsi3rr4x (53 views)
2014-04-15 18:08:23

BurntPizza (51 views)
2014-04-15 03:46:01

UprightPath (65 views)
2014-04-14 17:39:50

UprightPath (48 views)
2014-04-14 17:35:47

Porlus (65 views)
2014-04-14 15:48:38

tom_mai78101 (89 views)
2014-04-10 04:04:31

BurntPizza (149 views)
2014-04-08 23:06:04

tom_mai78101 (245 views)
2014-04-05 13:34:39

trollwarrior1 (203 views)
2014-04-04 12:06:45

CJLetsGame (210 views)
2014-04-01 02:16:10
List of Learning Resources
by SHC
2014-04-18 03:17:39

List of Learning Resources
by Longarmx
2014-04-08 03:14:44

Good Examples
by matheus23
2014-04-05 13:51:37

Good Examples
by Grunnt
2014-04-03 15:48:46

Good Examples
by Grunnt
2014-04-03 15:48:37

Good Examples
by matheus23
2014-04-01 18:40:51

Good Examples
by matheus23
2014-04-01 18:40:34

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:22:30
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!