Author Topic: Understanding Problems with translate  (Read 808 times)

Offline dandee

  • byte
  • *
  • Posts: 7
    • View Profile
Understanding Problems with translate
« on: November 12, 2012, 09:41:38 am »
Good Morning jpct-Masters,

I'am having some problems to undesrstand how translate works.

I have two simple planes which shall move to the direction of each other plane (see the picture). For that I use an own class to translate both planes to move one plane to the top and one plane to the bottom. Both planes shall stop in the middle of the screen.

To manipulate the speed of planes moving to each other I played around with my var roundtripStep (0.01f, 0.001f, 0.1f). Everytime I change that var the planes stop moving in a different position. If setting roundtripStep to 0.01f and stop moving if var rounttrip reaches 1.4f works for me and both planes stop moving where they should (see picture). But if ein change roundtripStep to 0.001f the planes stop moving in a totally different place.

I would expect that both planes are still stopping where they should but move a little bit slower when I change roundtripStep to 0.001f.

Am I overlook something?

Thanks and kind regards

Code: [Select]
class WorldModifierAssembleGameBoard {

    boolean BoardAssembled = false;
    boolean run = true;
    float roundtrip = 1;
    float roundtripStep = 0.01f;
    boolean runModifier(World world, int secCounter, TextureManager tm, int DisplayHeight, int DisplayWidth) {
        Logger.log("Run: AssembleGameBoard");
        if(this.run) {
           
            world.getObjectByName("top1").translate(0, roundtrip, 0);
            world.getObjectByName("bottom1").translate(0, -roundtrip, 0);
            this.roundtrip = this.roundtrip+roundtripStep;
            Logger.log("Roundtrip = " + this.roundtrip);
           
            if (this.roundtrip >= 1.4f) {
                this.run = false;
            }
           
        }   
        return this.run;
    }   
    void setRun(boolean run) {
        this.run = run;
    }
   
}

[attachment deleted by admin]

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11983
    • View Profile
    • http://www.jpct.net
Re: Understanding Problems with translate
« Reply #1 on: November 12, 2012, 10:47:16 am »
Your approach ignores that translations are cumulative. You don't translate by 0.x in each iteration but by 0.x/0.x*2/0.x*3/0.x*y... If you want to do it that way, add a clearTranslation() before calling translate or adjust your logic.

Offline dandee

  • byte
  • *
  • Posts: 7
    • View Profile
Re: Understanding Problems with translate
« Reply #2 on: November 12, 2012, 11:05:23 am »
 :-X

Right! Damn...  :-[ Thank you!