Java-Gaming.org Hi !
 Featured games (90) games approved by the League of Dukes Games in Showcase (753) Games in Android Showcase (228) games submitted by our members Games in WIP (842) games currently in development
 News: Read the Java Gaming Resources, or peek at the official Java tutorials
Pages: [1]
 ignore  |  Print
 Code request. static Path Object and iterator on it for 2D  (Read 3493 times) 0 Members and 1 Guest are viewing this topic.
alesky

Junior Devvie

Medals: 3
Exp: 15 years

mmm....

 « Posted 2012-10-19 00:36:39 »

Becouse i need in my project
if someone can share with my his obejct that define
static path and
iterator on it to get the varoius poin to follow

Thanks!!!
theagentd
 « Reply #1 - Posted 2012-10-19 00:45:56 »

An ArrayList<Point2D.Float> and a for-loop?

Myomyomyo.
DrHalfway
 « Reply #2 - Posted 2012-10-19 00:52:53 »

I'm assuming you have a set of points in 2D space and you simply want to move from one point to the other? Doing this is fairly straightforward, however there is one problem, finding weather or not the object has reached its current point so that it can move towards a new point. This is only a problem for floating point numbers.

You will need this support function.

 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  26  27  28 `// destination as a Point in X-Y plane (the destination)// current as a Point in X-Y plane (the current position)// direction as a Normalized Vector of the current direction (can be computed from destination - current vectors if needed// function will return a boolean true/false if the current point has reached its destination.// 2D versionpublic static boolean isInFront2(final Vector destination,       final Vector current,       final Vector direction) {   float product = (current.getX() - destination.getX()) * direction.getX() +         (current.getY() - destination.getY()) * direction.getY();         return (product > 0.0f);}// 3D versionpublic static boolean isInFront3(final Vector destination,       final Vector current,       final Vector direction) {   float product = (current.getX() - destination.getX()) * direction.getX() +         (current.getY() - destination.getY()) * direction.getY() +         (current.getZ() - destination.getZ()) * direction.getZ();         return (product > 0.0f);}`

hope that helps

Danny02
 « Reply #3 - Posted 2012-10-19 08:18:10 »

when you don't need something like bezier cuves just use a collection of points which define a path

I for example just use this code:
https://github.com/Danny02/DarwinsBox/blob/master/Util/src/main/java/darwin/util/math/composits/Path.java
alesky

Junior Devvie

Medals: 3
Exp: 15 years

mmm....

 « Reply #4 - Posted 2012-10-19 11:50:12 »

thanks Danny!

this is something close to what i'm looking for!

a class Path that implement an Iterator interface

the implementation can be good as basic, but i have to add some functionality becouse
i need also to calculate the rotation of the sprite so i will need to avaluate the derivate to the point where i'm arrived
and use it to rotate the sprite

anyway i can start from this chunk of code

thanks again!

i will post the code when will be complete

alesky

Junior Devvie

Medals: 3
Exp: 15 years

mmm....

 « Reply #5 - Posted 2012-10-22 17:19:13 »

thanks for you help guys

i create my  iplementation that is shared always in this section of the forum