Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (522)
Games in Android Showcase (127)
games submitted by our members
Games in WIP (590)
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 1253 times)
0 Members and 1 Guest are viewing this topic.
Offline 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  Smiley
Offline Riven
« League of Dukes »

« JGO Overlord »


Medals: 835
Projects: 4
Exp: 16 years


Hand over your head.


« 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
Offline Riven
« League of Dukes »

« JGO Overlord »


Medals: 835
Projects: 4
Exp: 16 years


Hand over your head.


« 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!
Legends of Yore - The Casual Retro Roguelike
Offline Riven
« League of Dukes »

« JGO Overlord »


Medals: 835
Projects: 4
Exp: 16 years


Hand over your head.


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

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

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Offline 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.
Offline Riven
« League of Dukes »

« JGO Overlord »


Medals: 835
Projects: 4
Exp: 16 years


Hand over your head.


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

http://www.google.com/search?q=normalize+vector

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
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.

trollwarrior1 (32 views)
2014-11-22 12:13:56

xFryIx (73 views)
2014-11-13 12:34:49

digdugdiggy (52 views)
2014-11-12 21:11:50

digdugdiggy (46 views)
2014-11-12 21:10:15

digdugdiggy (40 views)
2014-11-12 21:09:33

kovacsa (64 views)
2014-11-07 19:57:14

TehJavaDev (69 views)
2014-11-03 22:04:50

BurntPizza (67 views)
2014-11-03 18:54:52

moogie (82 views)
2014-11-03 06:22:04

CopyableCougar4 (82 views)
2014-11-01 23:36:41
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06
java-gaming.org 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‑gaming.org
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!