Page 1 of 2 12 LastLast
Results 1 to 20 of 21
  1. #1
    DrPepperMan85 is offline Member
    Join Date
    Dec 2008
    Posts
    13
    Rep Power
    0

    Default Java 3D API question for a model

    Hi there,

    I am looking to create a Java application to re-create flocking behaviour in bats using the Java 3D API. But I have a few questions before I start.

    • Is it possible to define an area like a cube for my agents?
    • Is it fesaible to model a flock of bats using the boids algorithm using the Java 3D API?
    • And if it is could I put the behaviour in the "behaviour" part of the Java 3D API or would I have to add this additionaly outside the behaviour section?
    • Is it possible to work out the distance between the agents? And could this be like a grid like structure to calculate distances etc to allow me to work out poteinal fields etc?


    Thanks for any help/advice.

  2. #2
    Nicholas Jordan's Avatar
    Nicholas Jordan is offline Senior Member
    Join Date
    Jun 2008
    Location
    Southwest
    Posts
    1,018
    Rep Power
    8

    Lightbulb yes, these things can be done

    • Yes, a matter of mathematica of spaces, I saw a code demonstration in Java from a Prof at UC Berkely where a 2-d space was shown to be a 3-d space with one line of mathematics. I do not have the skills to know what it it is but yes it can be done.
    • This has been done, it can be done.
    • This is a design issue, no simple answer. What matters is to write code you can understand.
    • This is a math vector space reduction. Not hard to do, nor computationally infeasible. Actually is one line of code for 2-d vector space - 3-d is just a matter of implementin class Point as having three values.
    Introduction to Programming Using Java.
    Cybercartography: A new theoretical construct proposed by D.R. Fraser Taylor

  3. #3
    DrPepperMan85 is offline Member
    Join Date
    Dec 2008
    Posts
    13
    Rep Power
    0

    Default

    Quote Originally Posted by Nicholas Jordan View Post
    • Yes, a matter of mathematica of spaces, I saw a code demonstration in Java from a Prof at UC Berkely where a 2-d space was shown to be a 3-d space with one line of mathematics. I do not have the skills to know what it it is but yes it can be done.
    • This has been done, it can be done.
    • This is a design issue, no simple answer. What matters is to write code you can understand.
    • This is a math vector space reduction. Not hard to do, nor computationally infeasible. Actually is one line of code for 2-d vector space - 3-d is just a matter of implementin class Point as having three values.
    Many thanks for your help. Sorry I couldn't reply sooner.

    I have had found a program similar to the one I want to make.

    I am trying to get the program running from the "Killer Game Programming" O'reilly book.

    The code I am try to run is the Chapter 22 code "Flocking3d"

    When I perform a javac *.java on the folder containing the files from the book I get 100 errors.

    I have everything installed including Java3D.

    I can post some of the errors if it helps.

    Some of the errors are below:

    Java Code:
    ^
    CheckerFloor.java:11: package javax.media.j3d does not exist
    import javax.media.j3d.*;
    ^
    CheckerFloor.java:12: package com.sun.j3d.utils.geometry does not exist
    import com.sun.j3d.utils.geometry.Text2D;
                                     ^
    CheckerFloor.java:13: package javax.vecmath does not exist
    import javax.vecmath.*;
    ^
    CheckerFloor.java:22: cannot find symbol
    symbol  : class Color3f
    location: class CheckerFloor
      private final static Color3f blue = new Color3f(0.0f, 0.1f, 0.4f);
                           ^
     
                           ^
    PreyBoid.java:16: package javax.media.j3d does not exist
    import javax.media.j3d.*;
    ^
    PreyBoid.java:17: package javax.vecmath does not exist
    import javax.vecmath.*;
    ^
    PreyBoid.java:22: cannot find symbol
    symbol  : class Color3f
    location: class PreyBoid
      private final static Color3f orange = new Color3f(1.0f,0.75f,0.0f);
    My folder where my .java files for the flocking3d program is:

    C:\Flocking3D

    And my Java3D folder is:

    C:\Program Files\Java\Java3D\1.5.2

    this folder has the following sub folders:

    bin
    lib

    What would I need to type to tell my compiler where to find the java3D classes?

    Many thanks.

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    I think that your problem may be fixed by adding the Java3D folder directory to the classpath when compiling.
    Last edited by Fubarable; 01-17-2009 at 09:03 PM.

  5. #5
    DrPepperMan85 is offline Member
    Join Date
    Dec 2008
    Posts
    13
    Rep Power
    0

    Default

    Quote Originally Posted by Fubarable View Post
    I think that your problem may be fixed by adding the Java3D folder directory to the classpath when compiling.

    Thanks I have managed to sort that problem out.

    I have a problem running the file that the book states to run the whole application (Flocking3d.java)

    I get the following errors:

    C:\Flocking3D>java flocking3d
    Exception in thread "main" java.lang.NoClassDefFoundError: flocking3d
    Caused by: java.lang.ClassNotFoundException: flocking3d
    at java.net.URLClassLoader$1.run(URLClassLoader.java: 200)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.j ava:188)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:3 07)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launche r.java:301)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:2 52)
    at java.lang.ClassLoader.loadClassInternal(ClassLoade r.java:320)
    Could not find the main class: flocking3d. Program will exit.

    C:\Flocking3D>

    It seems weird that these errors appear due to the fact that the zipped code was provided by the authors website. With now mention of any problems.

    The readme in the folder reads as follows:

    Chapter 23. Flocking Boids

    From:
    Killer Game Programming in Java
    Andrew Davison
    O'Reilly, May 2005
    ISBN: 0-596-00730-2
    Killer Game Programming in Java | O'Reilly Media[

    Contact Address:
    Dr. Andrew Davison
    Dept. of Computer Engineering
    Prince of Songkla University
    Hat Yai, Songkhla 90112, Thailand



    If you use this code, please mention my name, and include a link
    to the book's Web site.

    Thanks,
    Andrew


    ============================
    Flocking3D.java


    -----
    Compilation

    $ javac *.java
    // you must have Java 3D installed for the compilation to succeed;
    // if you get "Warning" messages, please see the note below


    Java 3D is available from


    -----
    Execution:

    Use the Flocking3D.bat batch file.

    There can be up to three arguments which set the number of
    predators, prey, and obstacles. Usually, we have no arguments
    (then the default values are used) or set all three.

    BNF format for the arguments:

    $ Flocking3D [ NumPredators [ NumPrey [NumObstacles] ] ]

    The [ ...] brackets means the "..." is optional.
    e.g.

    $ Flocking3D
    - means use the defaults, 40 predators, 160 prey, 20 obstacles


    $ Flocking3D 10 200 15
    - means 10 predators, 200 prey, 15 obstacles


    $ Flocking3D 1 30
    - means use 1 predator, 30 prey (and 20 obstacles)


    -----------
    Note on "unchecked or unsafe operation" Warnings

    As explained in chapter 3, I have not used J2SE 5.0's type-safe
    collections, so that this code will compile in early versions of
    J2SE (e.g. version 1.4).

    The warning messages are always related to my use of collections
    (e.g. ArrayList) without specifying a type for the objects they will
    contain at run time.

    No. of Warnings generated in J2SE 5.0 for the examples:
    /Flocking3D: 18 warnings

    ---------
    Last updated: 19th April 2005




  6. #6
    Nicholas Jordan's Avatar
    Nicholas Jordan is offline Senior Member
    Join Date
    Jun 2008
    Location
    Southwest
    Posts
    1,018
    Rep Power
    8

    Default

    This pretty common, I once became involved in a discussion with someone....

    Uh, people who do not realize how this works ( fails to work ) have never been a book author .....


    Sounds like either manifest.mf or there actually is no main()

    Either way, this is the normal way.
    Introduction to Programming Using Java.
    Cybercartography: A new theoretical construct proposed by D.R. Fraser Taylor

  7. #7
    DrPepperMan85 is offline Member
    Join Date
    Dec 2008
    Posts
    13
    Rep Power
    0

    Default

    Quote Originally Posted by Nicholas Jordan View Post
    This pretty common, I once became involved in a discussion with someone....

    Uh, people who do not realize how this works ( fails to work ) have never been a book author .....


    Sounds like either manifest.mf or there actually is no main()

    Either way, this is the normal way.
    I've been looking at the flocking3d class and there is no main() which leaves me rather puzzled.

    Java Code:
    Could not find the main class: flocking3d. Program will exit.
    Java Code:
    public class Flocking3D extends JFrame
    {
      // constants for the numbers of predators, prey, and obstacles
      private static final int NUM_PREDATORS = 40;
      private static final int NUM_PREY = 160;
      private static final int NUM_OBSTACLES = 20;
    
    
      public Flocking3D(String[] args) 
      {
        super("Flocking Predator and Prey Boids");
    
        int numPreds = NUM_PREDATORS;
        int numPrey = NUM_PREY;
        int numObstacles = NUM_OBSTACLES;
    
        // simple extraction of command line args.
        if (args.length >= 1) {
          try 
          { numPreds = Integer.parseInt( args[0] ); 
            numPrey = numPreds;    // same number of predators and prey
          }
          catch(NumberFormatException e)
          { System.out.println("Illegal number of predators"); }
        }
    
        if (args.length >= 2) {
          try 
          { numPrey = Integer.parseInt( args[1] ); }
          catch(NumberFormatException e)
          { System.out.println("Illegal number of prey"); }
        }
    
        if (args.length == 3) {
          try 
          { numObstacles = Integer.parseInt( args[2] ); }
          catch(NumberFormatException e)
          { System.out.println("Illegal number of obstacles"); }
        }
    
        Container c = getContentPane();
        c.setLayout( new BorderLayout() );
        WrapFlocking3D w3d = 
    		new WrapFlocking3D(numPreds, numPrey, numObstacles);
        c.add(w3d, BorderLayout.CENTER);
    
        setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
        pack();
        setResizable(false);    // fixed size display
        setVisible(true);
      } // end of Flocking3D()
    
    
    // -----------------------------------------
    
      public static void main(String[] args)
      { new Flocking3D(args); }
    
    } // end of Flocking3D class

  8. #8
    DrPepperMan85 is offline Member
    Join Date
    Dec 2008
    Posts
    13
    Rep Power
    0

    Default

    I suppose I could run it as an applet? Since no main() is needed in an applet.

    Would it be hard to turn the application into an applet?

  9. #9
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    This looks like a main method to me:
    Java Code:
      public static void main(String[] args)
      { new Flocking3D(args); }

  10. #10
    DrPepperMan85 is offline Member
    Join Date
    Dec 2008
    Posts
    13
    Rep Power
    0

    Default

    Quote Originally Posted by Fubarable View Post
    This looks like a main method to me:
    Java Code:
      public static void main(String[] args)
      { new Flocking3D(args); }
    I have tried to run flocking3d trying to invoke the main method with no luck. Any tips?

    Thanks

  11. #11
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Not really since with the amount of data presented here, I have no idea what your problem is. You may wish to post any error messages that occur if you have any. Post the whole message though, don't paraphrase it. Also when you try to run it, you capitalize the first letter of Flocking3D, right?

  12. #12
    DrPepperMan85 is offline Member
    Join Date
    Dec 2008
    Posts
    13
    Rep Power
    0

    Default

    Quote Originally Posted by Fubarable View Post
    Not really since with the amount of data presented here, I have no idea what your problem is. You may wish to post any error messages that occur if you have any. Post the whole message though, don't paraphrase it. Also when you try to run it, you capitalize the first letter of Flocking3D, right?
    Thanks for the help,

    It does seem weird that the code doesn't work straight "out of the box" due to the fact that the code was taken from the authors web site.

    fivedots.coe.psu.ac.th/~ad/jg/ch13/index.html

  13. #13
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    But again, exactly what errors are you recieving if you try to compile and run this?

  14. #14
    DrPepperMan85 is offline Member
    Join Date
    Dec 2008
    Posts
    13
    Rep Power
    0

    Default

    Quote Originally Posted by Fubarable View Post
    But again, exactly what errors are you recieving if you try to compile and run this?
    Java Code:
    C:\Flocking3D>java Flocking3D
    Exception in thread "main" java.lang.NoClassDefFoundError: Flocking3D
    Caused by: java.lang.ClassNotFoundException: Flocking3D
            at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
            at java.security.AccessController.doPrivileged(Native Method)
            at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
            at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
            at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
            at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
            at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
    Could not find the main class: Flocking3D.  Program will exit.

    And when I run javac *.java like the readme.txt states I get this:

    Java Code:
    C:\Flocking3D>javac *.java
    BoidShape.java:19: package javax.media.j3d does not exist
    import javax.media.j3d.*;
    ^
    BoidShape.java:20: package javax.vecmath does not exist
    import javax.vecmath.*;
    ^
    BoidShape.java:23: cannot find symbol
    symbol: class Shape3D
    public class BoidShape extends Shape3D
                                   ^
    BoidShape.java:27: cannot find symbol
    symbol  : class Color3f
    location: class BoidShape
      private static final Color3f purple = new Color3f(0.5f, 0.2f, 0.8f);
                           ^
    BoidShape.java:30: cannot find symbol
    symbol  : class Color3f
    location: class BoidShape
      public BoidShape(Color3f col)
                       ^
    BoidsList.java:20: cannot access Boid
    bad class file: .\Boid.java
    file does not contain class Boid
    Please remove or make sure it appears in the correct subdirectory of the classpa
    th.
      synchronized public Boid getBoid(int i)
                          ^
    
    C:\Flocking3D>

  15. #15
    DrPepperMan85 is offline Member
    Join Date
    Dec 2008
    Posts
    13
    Rep Power
    0

    Default

    I don't understand some of the errors in that parts like the;

    BoidShape.java:19: package javax.media.j3d does not exist
    import javax.media.j3d.*;
    ^

    I have double checked, yet I have made sure that javax.media.j3d.*; has been imported.

  16. #16
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    But again, it's not on the classpath.

  17. #17
    DrPepperMan85 is offline Member
    Join Date
    Dec 2008
    Posts
    13
    Rep Power
    0

    Default

    My vecmath jar file for me is at

    C:\Program Files\Java\Java3D\1.5.2\lib\ext

    However I already have a value in my classpath directory which is:

    .;C:\Program Files\Java\jre1.5.0_05\lib\ext\QTJava.zip

  18. #18
    Nicholas Jordan's Avatar
    Nicholas Jordan is offline Senior Member
    Join Date
    Jun 2008
    Location
    Southwest
    Posts
    1,018
    Rep Power
    8

    Question ?...

    Quote Originally Posted by DrPepperMan85 View Post
    My vecmath jar file for me is at

    C:\Program Files\Java\Java3D\1.5.2\lib\ext

    However I already have a value in my classpath directory which is:

    .;C:\Program Files\Java\jre1.5.0_05\lib\ext\QTJava.zip
    don't understand some of the errors in that parts like the;

    Java Code:
    BoidShape.java:19: package javax.media.j3d does not exist
    import javax.media.j3d.*;
    ^
    Java Code:
    if(new String("QTJava.zip").equals(new String("vecmath.jar")))
    {System.print("new algorithm invented, special deal for you");}
    else
    {System.print("non-maximal suppression and the technique for gradient computation"+System.getProperty("line.separator")+"allows flocking over aluminum foil surfaces"+System.getProperty("line.separator")+"see babbling Billie at rednecks-r-us to order your dead-bird attractor");}
    Introduction to Programming Using Java.
    Cybercartography: A new theoretical construct proposed by D.R. Fraser Taylor

  19. #19
    DrPepperMan85 is offline Member
    Join Date
    Dec 2008
    Posts
    13
    Rep Power
    0

    Default

    Quote Originally Posted by Fubarable View Post
    But again, it's not on the classpath.
    I have changed my CLASSPATH to "C:\Program Files\Java\Java3D\1.5.2\lib\ext" yet still get the same errors:


    Java Code:
    C:\Flocking3D>javac *.java
    BoidShape.java:19: package javax.media.j3d does not exist
    import javax.media.j3d.*;
    ^
    BoidShape.java:20: package javax.vecmath does not exist
    import javax.vecmath.*;
    ^
    BoidShape.java:23: cannot find symbol
    symbol: class Shape3D
    public class BoidShape extends Shape3D
                                   ^
    BoidShape.java:27: cannot find symbol
    symbol  : class Color3f
    location: class BoidShape
      private static final Color3f purple = new Color3f(0.5f, 0.2f, 0.8f);
                           ^
    BoidShape.java:30: cannot find symbol
    symbol  : class Color3f
    location: class BoidShape
      public BoidShape(Color3f col)
                       ^
    BoidsList.java:20: cannot access Boid
    bad class file: .\Boid.java
    file does not contain class Boid
    Please remove or make sure it appears in the correct subdirectory of the classpa
    th.
      synchronized public Boid getBoid(int i)
                          ^
    And when I try to run the Flocking3D file I get:

    Java Code:
    C:\Flocking3D>java Flocking3D
    Exception in thread "main" java.lang.NoClassDefFoundError: Flocking3D
    Caused by: java.lang.ClassNotFoundException: Flocking3D
            at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
            at java.security.AccessController.doPrivileged(Native Method)
            at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
            at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
            at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
            at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
            at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
    Could not find the main class: Flocking3D.  Program will exit.
    
    C:\Flocking3D>
    And yet there is a main() and I have tried different classpath values. I seem to be going round in circles with this one. :s

  20. #20
    DrPepperMan85 is offline Member
    Join Date
    Dec 2008
    Posts
    13
    Rep Power
    0

    Default

    Right abit of an update. I have gone through various guide on installing java3d and have managed to eliminate all but one error when I type

    Java Code:
    javac *.java
    The the point where the only error I get is:

    Java Code:
    C:\Flocking3D>javac *.java
    BoidsList.java:20: cannot access Boid
    bad class file: .\Boid.java
    file does not contain class Boid
    Please remove or make sure it appears in the correct subdirectory of the classpa
    th.
      synchronized public Boid getBoid(int i)
    So I have managed to solve the Java3D problems. But still get the:

    Java Code:
    C:\Flocking3D>java Flocking3D
    Exception in thread "main" java.lang.NoClassDefFoundError: Flocking3D
    Caused by: java.lang.ClassNotFoundException: Flocking3D
            at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
            at java.security.AccessController.doPrivileged(Native Method)
            at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
            at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
            at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
            at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
            at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
    Could not find the main class: Flocking3D.  Program will exit.
    When I try running the program.

Page 1 of 2 12 LastLast

Similar Threads

  1. Table model
    By Manfizy in forum NetBeans
    Replies: 4
    Last Post: 11-08-2008, 02:19 AM
  2. Model View Controller with Java
    By chopram in forum New To Java
    Replies: 8
    Last Post: 06-07-2008, 09:18 PM
  3. EJB, classes Model
    By Felissa in forum Enterprise JavaBeans (EJB)
    Replies: 1
    Last Post: 07-06-2007, 03:17 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •