Java-Gaming.org Hi !
 Featured games (91) games approved by the League of Dukes Games in Showcase (755) Games in Android Showcase (229) 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
 Home Help Search Login Register
Pages: [1]
 ignore  |  Print
 Can anyone convert 4 lines of C++ for me?  (Read 2166 times) 0 Members and 1 Guest are viewing this topic.
ataris

Senior Newbie

 « Posted 2007-07-30 21:29:58 »

Hi guys,

I am just looking into some ai behaviours and am struggling to get my head around this at the moment. Want to get this simple Seek behaviour to work but can only find a code sample in c++. Anyone able to change it into Java so i can understand it better?

Vector2D SteeringBehaviors::Seek(Vector2D TargetPos)
{
Vector2D DesiredVelocity = Vec2DNormalize(TargetPos m_pVehicle->Pos())
* m_pVehicle->MaxSpeed();

return (DesiredVelocity m_pVehicle->Velocity());
}

First the desired velocity is calculated. This is the velocity the agent would need to reach the target position in an ideal world. It represents the vector from the agent to the target, scaled to be the length of the maximum possible speed of the agent.

The steering force returned by this method is the force required, which when added to the agent's current velocity vector gives the desired velocity. To achieve this you simply subtract the agent's current velocity from the desired velocity. See Figure 3.2.

Thanks in advance if anyone can help! Or better yet, if anyone knows any Java Artificial intelligence sites that would be so helpful
Riven

« JGO Overlord »

Medals: 1340
Projects: 4
Exp: 16 years

 « Reply #1 - Posted 2007-07-30 22:12:04 »

In Java you don't have operator overloading, so you'll have to write your own methods to handle vector-math.

 1  2  3  4  5  6 `Vec add(Vec a, Vec b) {  Vec c = new Vec();  c.x = a.x + b.x;  c.y = a.y + b.y;  return c;}`

I don't see any other problems you'd have with that code. If this really troubles you this much, you might want to study Java a bit more, before you dive into AI

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings!
Riven

« JGO Overlord »

Medals: 1340
Projects: 4
Exp: 16 years

 « Reply #2 - Posted 2007-07-30 22:27:51 »

There is absolutely nothing hard in the C++, nothing really requires a 'math-lib' (only subtraction, multiplication & normalize), so that's why I suggested you looked more into the basics.

Oh well.

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings!
 Games published by our own members! Check 'em out!
Riven

« JGO Overlord »

Medals: 1340
Projects: 4
Exp: 16 years

 « Reply #3 - Posted 2007-07-30 22:28:41 »

Hm... you removed you post I replied to.

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings!
ataris

Senior Newbie

 « Reply #4 - Posted 2007-07-30 22:29:49 »

Yea, its just the vector normalization part i didnt understand what was happening in there.
Riven

« JGO Overlord »

Medals: 1340
Projects: 4
Exp: 16 years

 « Reply #5 - Posted 2007-07-30 22:35:01 »