Featured games (79)
games approved by the League of Dukes
Games in Showcase (476)
Games in Android Showcase (106)
games submitted by our members
Games in WIP (533)
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  
  Code request. static Path Object and iterator on it for 2D  (Read 1481 times)
0 Members and 1 Guest are viewing this topic.
Offline alesky

Junior Member

Medals: 2


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

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

Thanks!!!   Roll Eyes
Offline theagentd
« Reply #1 - Posted 2012-10-19 02:45:56 »

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

Offline DrHalfway
« Reply #2 - Posted 2012-10-19 02: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.

// 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 version
public 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 version
public 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

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Danny02
« Reply #3 - Posted 2012-10-19 10: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:
Offline alesky

Junior Member

Medals: 2


« Reply #4 - Posted 2012-10-19 13: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

Offline alesky

Junior Member

Medals: 2


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

thanks for you help guys

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

this is the link
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 (22 views)
2014-07-24 01:59:36

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

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

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

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

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

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

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

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

Riven (52 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 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‑
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!