Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (107)
games submitted by our members
Games in WIP (534)
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  
  Why this collision detection code don't work?  (Read 1511 times)
0 Members and 1 Guest are viewing this topic.
Offline oldmao_2001

Senior Newbie





« Posted 2005-12-04 03:23:37 »

i define a viewplatform and add it to a transformGroup,and I and the tansformGroup to a branchgroup.I create a collisionBehavior class to detect the collision between view and the 3ds model,I import a 3ds model and add 3ds model to another branchgroup
the code of collisionBehavior is below:
public class collisionBehavior extends Behavior {
    private MyTransformGroup collisionObject;
    private WakeupOnCollisionEntry wEnter;
    private WakeupOnCollisionExit wExit;   
    public collisionBehavior(MyTransformGroup shape,ViewPlatform viewPlat) {
        // super();
        collisionObject = shape;
    }
    public void initialize() {
        wEnter = new WakeupOnCollisionEntry(collisionObject,WakeupOnCollisionEntry.USE_GEOMETRY);
        wExit = new WakeupOnCollisionExit(collisionObject,WakeupOnCollisionEntry.USE_GEOMETRY);
        wakeupOn(wEnter);
    }   
    public void processStimulus(Enumeration criteria) {
        WakeupCriterion wakeup;
        while (criteria.hasMoreElements()) {
   wakeup = (WakeupCriterion) criteria.nextElement();
   if (wakeup instanceof WakeupOnCollisionEntry) {
                         System.out.println("CollisionEntry..");
           wakeupOn(wExit);/* change the wakeup condition */
   } else if (wakeup instanceof WakeupOnCollisionExit) {
           collisionObject.setCollision(false);
           System.out.println("CollisionExit..");
           wakeupOn(wEnter);/* change the wakeup condition */
   }
        }
    }
}
the question is why i move the view and cross the wall,but nothing happen...
Offline Jeff

JGO Coder




Got any cats?


« Reply #1 - Posted 2005-12-04 04:56:58 »

Well there maybe other problems but first and foremost you will *never* get notification on time by doing a wakeup on *anything* but WakeupOnFrame(0).  The collision wake-up  conditions are totally useless for what I believe you are trying to do.

Only WakeupOnFrame(0) has a guaranteed wakeup time (one call per frame.)  Any other wakeup opccurs at some unspecified time AFTER the wakeup confiditon has ocurred.  For anything that is timing critical you cannot wait for J3D to wakeup your behavior but must waker up every frame and manually check the critical condition yourself.

Take a look at how JNWN uses behaviors to see more examples of the kind of thing you need to do....

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 oldmao_2001

Senior Newbie





« Reply #2 - Posted 2005-12-05 07:01:11 »

Thank u Jeff,But I can't find WakeupOnFrame in java3d api,I only find WakeupOnElapsedFrames.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline oldmao_2001

Senior Newbie





« Reply #3 - Posted 2005-12-05 09:25:52 »

By the way ,could u tell me the different between WakeupOnCollisionEntry and WakeupOnCollisionMovement?
Offline Jeff

JGO Coder




Got any cats?


« Reply #4 - Posted 2005-12-05 09:43:51 »

Thank u Jeff,But I can't find WakeupOnFrame in java3d api,I only find WakeupOnElapsedFrames.
Thats it,  I was writing from memory Smiley

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 Jeff

JGO Coder




Got any cats?


« Reply #5 - Posted 2005-12-05 09:45:11 »

By the way ,could u tell me the different between WakeupOnCollisionEntry and WakeupOnCollisionMovement?

Beats me.  NONE of the Java3D collision code is useful for games so I've never bothered to learn the details.

If you really need to know I could take a look at the docs and or ask one of the Java3D team...

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 Jeff

JGO Coder




Got any cats?


« Reply #6 - Posted 2005-12-05 09:46:28 »

Btw...

In general if you are having trouble with a  behavior not seeming to run, check to make sure your activation bounds for the behavior encompass your current camera position.  Incorrect activation bounds (or totally missing activation bounds) are a common cause of behavior problems.

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 oldmao_2001

Senior Newbie





« Reply #7 - Posted 2005-12-05 09:54:17 »

I change the code like this:
public class collisionBehavior extends Behavior {
    private MyTransformGroup collisionObject;
    private WakeupOnCollisionEntry wEnter;
    private private WakeupOnElapsedFrames frame;
    private WakeupCriterion criterionArray[] = new WakeupCriterion[3];
    private WakeupCondition wakeupCondition = null; 
    public collisionBehavior(MyTransformGroup shape) {
        super();
        collisionObject = shape;
    }
    public void initialize() {
        wEnter = new WakeupOnCollisionEntry(collisionObject,WakeupOnCollisionEntry.USE_GEOMETRY);       
        frame = new WakeupOnElapsedFrames(0);
        criterionArray[0] = wEnter;
        criterionArray[1] = frame;
        wakeupCondition = new WakeupOr(criterionArray);      
        wakeupOn(wakeupCondition);
    }   
    public void processStimulus(Enumeration criteria) {
        WakeupCriterion wakeup;
        while (criteria.hasMoreElements()) {
             wakeup = (WakeupCriterion) criteria.nextElement();
             if (wakeup instanceof WakeupOnCollisionEntry) {
                   System.out.println("CollisionEntry..");
             } else if (wakeup instanceof WakeupOnElapsedFrames) {                   
                   System.out.println("WakeupOnElapsedFrames..");
             }
        }
        wakeupOn(wakeupCondition)
    }
}
but it dose not work...
Could u give me more hint? thank u...
Offline Jeff

JGO Coder




Got any cats?


« Reply #8 - Posted 2005-12-05 22:25:45 »

Well, to begin with, your two wakeup conditions make no sense together?

What are you trying to do?  if you are trying to detect wall collision to avoid walking through walls you CANNOT use Java3Ds collision dection at all.  It just doesnt do what you want.  You need to WakeUp OnElapsed Frame(0) and then do your OWN collision tests.

Seperately, how are you using thsi behavior? show me the code thata dds it to your scenegraph and sets its activation bounds...

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
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 (35 views)
2014-07-24 01:59:36

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

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

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

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

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

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

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

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

Riven (56 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!