Topic
  • 5 replies
  • Latest Post - ‏2013-02-05T19:08:40Z by TomBanks
EvanWorley
EvanWorley
11 Posts

Pinned topic getVelocity depends on JBox2D

‏2013-02-05T15:59:32Z |
Hello, 
 
I have two questions about the getVelocity method. The first question is that it appears it returns a Vec2 type, which is a type exposed from JBox2D, yet JBox2D isn't included in the plugin. Is this missing? The second question is how to use the Vec2 to determine the MPH. It appears to be a 2 dimensional vector, so are we expected to compute the hypotenuse our self?
 
Thanks, 
Evan 
Updated on 2013-02-05T19:08:40Z at 2013-02-05T19:08:40Z by TomBanks
  • TomBanks
    TomBanks
    66 Posts

    Re: getVelocity depends on JBox2D

    ‏2013-02-05T16:57:42Z  
     Hi Evan,
     
    You are correct that JBox2D isn't added to the classpath by default. To convert from the Vec2 to a speed you can call normalize() on the Vec2 object from getVelocity() - this negates the need to import JBox2D and the float you get back from the normalize method is the speed of your car in MPH. 
     
    Example code: 
    float speedInMPH = getCar().getVelocity().normalize();
  • EvanWorley
    EvanWorley
    11 Posts

    Re: getVelocity depends on JBox2D

    ‏2013-02-05T18:05:46Z  
    • TomBanks
    • ‏2013-02-05T16:57:42Z
     Hi Evan,
     
    You are correct that JBox2D isn't added to the classpath by default. To convert from the Vec2 to a speed you can call normalize() on the Vec2 object from getVelocity() - this negates the need to import JBox2D and the float you get back from the normalize method is the speed of your car in MPH. 
     
    Example code: 
    float speedInMPH = getCar().getVelocity().normalize();
     Ah I see, thanks for the tip. You might consider returning normalize() from the API method since the docs say it returns the speed in MPH. The workaround will work well for now though, cheers.
     
    - Evan 
  • TomBanks
    TomBanks
    66 Posts

    Re: getVelocity depends on JBox2D

    ‏2013-02-05T18:43:31Z  
     Ah I see, thanks for the tip. You might consider returning normalize() from the API method since the docs say it returns the speed in MPH. The workaround will work well for now though, cheers.
     
    - Evan 
     We do have a policy of not changing existing APIs other than for bug fixes so it is unlikely that we will change the return on getVelocity, however I may look into adding a getSpeedInMph method which does exactly that :)
  • EvanWorley
    EvanWorley
    11 Posts

    Re: getVelocity depends on JBox2D

    ‏2013-02-05T18:58:14Z  
    • TomBanks
    • ‏2013-02-05T18:43:31Z
     We do have a policy of not changing existing APIs other than for bug fixes so it is unlikely that we will change the return on getVelocity, however I may look into adding a getSpeedInMph method which does exactly that :)
     I see. Well maybe the javadoc for getVelocity could be updated then? Also in general I think it's a poor design to have the method return an object with a type that the user does not have in their environment. It's not user friendly, although it is usable when you told me about the workaround.
  • TomBanks
    TomBanks
    66 Posts

    Re: getVelocity depends on JBox2D

    ‏2013-02-05T19:08:40Z  
     I see. Well maybe the javadoc for getVelocity could be updated then? Also in general I think it's a poor design to have the method return an object with a type that the user does not have in their environment. It's not user friendly, although it is usable when you told me about the workaround.
     Yes I agree the javadoc needs updating. It looks like a method that slipped past our review for the car API and should not have been released as-is (but since it has been we won't want to step on people's toes who have written code to take advantage of it).