Author Topic: strange movement  (Read 2621 times)

Offline theFALCO

  • byte
  • *
  • Posts: 39
    • View Profile
strange movement
« on: December 29, 2006, 10:52:56 am »
first I do the gravity
Code: [Select]
       SimpleVector theG = cube.checkForCollisionEllipsoid(GRAVITY, CUBE_SIZE, 1);
        moveResultant.add(theG);

then I "move" (actually at this point I only set the resultant vector) the cube according to pressed keys
Code: [Select]
       boolean movinDaC = false;

        cube.rotateY(MX*0.01f);

        if(left && moveResultant.x>-3) {
            SimpleVector a = cube.getXAxis();
            a.scalarMul(-BASESPEED);
            moveResultant.add(a);
            movinDaC=true;
        }
        if(right && moveResultant.x<3) {
            SimpleVector d = cube.getXAxis();
            d.scalarMul(BASESPEED);
            moveResultant.add(d);
            movinDaC=true;
        }
        if(forward && moveResultant.z<3) {
            SimpleVector w = cube.getZAxis();
            w.scalarMul(BASESPEED);
            moveResultant.add(w);
            movinDaC=true;
        }
        if(back && moveResultant.z>-3) {
            SimpleVector s = cube.getZAxis();
            s.scalarMul(-BASESPEED);
            moveResultant.add(s);
            movinDaC=true;
        }
        if(MX!=0) {
            camRot+=MX*0.01f;
        }
        if(MY!=0) {
            CAMANGLE-=MY*0.01f;
        }

then comes the translaition
Code: [Select]
       moveResultant = cube.checkForCollisionEllipsoid(moveResultant, CUBE_SIZE, 1);
        cube.translate(moveResultant);

        moveResultant.x=Math.round(moveResultant.x*10)/10f;
        moveResultant.y=Math.round(moveResultant.y*10)/10f;
        moveResultant.z=Math.round(moveResultant.z*10)/10f;

and if no keys are pressed I do the velocity loss
Code: [Select]
       if(!movinDaC) {
            if(moveResultant.x>FRICTION) {
                moveResultant.x-=FRICTION;
            } else if(moveResultant.x<-FRICTION) {
                moveResultant.x+=FRICTION;
            } else {
                moveResultant.x=0f;
            }
            if(moveResultant.y>FRICTION) {
                moveResultant.y-=FRICTION;
            } else if(moveResultant.y<-FRICTION) {
                moveResultant.y+=FRICTION;
            } else {
                moveResultant.y=0f;
            }
            if(moveResultant.z>FRICTION) {
                moveResultant.z-=FRICTION;
            } else if(moveResultant.z<-FRICTION) {
                moveResultant.z+=FRICTION;
            } else {
                moveResultant.z=0f;
            }
        }


the SimpleVector CUBE_SIZE is achieved by
Code: [Select]
       float b[] = cube.getMesh().getBoundingBox();
        CUBE_SIZE.x = (Math.abs(b[0])+Math.abs(b[1]))/2f;
        CUBE_SIZE.y = (Math.abs(b[2])+Math.abs(b[3]))/2f;
        CUBE_SIZE.z = (Math.abs(b[4])+Math.abs(b[5]))/2f;


The problem is that if I move forwads it's cool but when I rotate 45 degrees (so it's positioned "diagonally" to global axis) the cube moves very slowly, like ten times slower.
Any ideas what might cause it?

Offline eye1

  • int
  • **
  • Posts: 68
    • View Profile
strange movement
« Reply #1 on: December 29, 2006, 11:05:52 am »
How are you rendering? Do you use full processing time (no sleep)?

If you do, than it is possible that when you rotate it, more objects needs to be rendered or something like that and that causes that movement is much slower. Since one rendering loop takes longer.

Offline theFALCO

  • byte
  • *
  • Posts: 39
    • View Profile
strange movement
« Reply #2 on: December 29, 2006, 11:27:07 am »
no, it's a test with 2 objects only... a cube as moving object and a plane as a map (small, whole visible all the time)

I'm wondering if the cube.getZAxis() doesn't do it

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11748
    • View Profile
    • http://www.jpct.net
strange movement
« Reply #3 on: December 29, 2006, 09:30:23 pm »
What's the purpose of this section:

Code: [Select]

moveResultant.x=Math.round(moveResultant.x*10)/10f;
moveResultant.y=Math.round(moveResultant.y*10)/10f;
moveResultant.z=Math.round(moveResultant.z*10)/10f;


It does reduce accuracy by a good amount. Anything else?

Offline theFALCO

  • byte
  • *
  • Posts: 39
    • View Profile
strange movement
« Reply #4 on: December 29, 2006, 09:45:43 pm »
damn, after commenting it out everything is cool :/

in my old DirectX game i used such thing to round to the second number after the comma so that I don't have someting like 0.0000000000001...
that's why I added it as soos as I added the "resultant vector movement" technique

thanks