Results 1 to 20 of 21
Thread: Java 3D API question for a model
- 12-20-2008, 10:45 PM #1
Member
- Join Date
- Dec 2008
- Posts
- 13
- Rep Power
- 0
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.
- 12-21-2008, 04:55 PM #2
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
- 01-17-2009, 08:43 PM #3
Member
- Join Date
- Dec 2008
- Posts
- 13
- Rep Power
- 0
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:
My folder where my .java files for the flocking3d program is: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);
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.
-
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.
- 01-17-2009, 09:11 PM #5
Member
- Join Date
- Dec 2008
- Posts
- 13
- Rep Power
- 0
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
- 01-17-2009, 11:24 PM #6
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
- 01-18-2009, 01:34 AM #7
Member
- Join Date
- Dec 2008
- Posts
- 13
- Rep Power
- 0
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
- 01-18-2009, 12:19 PM #8
Member
- Join Date
- Dec 2008
- Posts
- 13
- Rep Power
- 0
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?
-
This looks like a main method to me:
Java Code:public static void main(String[] args) { new Flocking3D(args); }
- 01-18-2009, 05:21 PM #10
Member
- Join Date
- Dec 2008
- Posts
- 13
- Rep Power
- 0
-
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?
- 01-18-2009, 05:37 PM #12
Member
- Join Date
- Dec 2008
- Posts
- 13
- Rep Power
- 0
-
But again, exactly what errors are you recieving if you try to compile and run this?
- 01-18-2009, 05:46 PM #14
Member
- Join Date
- Dec 2008
- Posts
- 13
- Rep Power
- 0
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>
- 01-18-2009, 06:43 PM #15
Member
- Join Date
- Dec 2008
- Posts
- 13
- Rep Power
- 0
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.
-
But again, it's not on the classpath.
- 01-18-2009, 08:15 PM #17
Member
- Join Date
- Dec 2008
- Posts
- 13
- Rep Power
- 0
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
- 01-18-2009, 08:54 PM #18
?...
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
- 01-19-2009, 12:16 AM #19
Member
- Join Date
- Dec 2008
- Posts
- 13
- Rep Power
- 0
I have changed my CLASSPATH to "C:\Program Files\Java\Java3D\1.5.2\lib\ext" yet still get the same errors:
And when I try to run the Flocking3D file I get: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 yet there is a main() and I have tried different classpath values. I seem to be going round in circles with this one. :sJava 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>
- 01-19-2009, 02:06 AM #20
Member
- Join Date
- Dec 2008
- Posts
- 13
- Rep Power
- 0
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
The the point where the only error I get is:Java Code:javac *.java
So I have managed to solve the Java3D problems. But still get the: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)
When I try running the program.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.
Similar Threads
-
Table model
By Manfizy in forum NetBeansReplies: 4Last Post: 11-08-2008, 02:19 AM -
Model View Controller with Java
By chopram in forum New To JavaReplies: 8Last Post: 06-07-2008, 09:18 PM -
EJB, classes Model
By Felissa in forum Enterprise JavaBeans (EJB)Replies: 1Last Post: 07-06-2007, 03:17 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks