src/proto2/Physics.cc
changeset 84 3cb862028a24
parent 83 cbba9729e92b
child 85 351cb6b69c04
equal deleted inserted replaced
83:cbba9729e92b 84:3cb862028a24
    41     
    41     
    42     // Go trough every force in the queue
    42     // Go trough every force in the queue
    43     // TODO: It might be possible to optimize by adding forces together
    43     // TODO: It might be possible to optimize by adding forces together
    44     std::queue<Force> newfq;
    44     std::queue<Force> newfq;
    45     Force tmpf;
    45     Force tmpf;
       
    46     Force total;
    46     posAfterTick = position;
    47     posAfterTick = position;
    47     velAfterTick = velocity;
    48     velAfterTick = velocity;
    48     while (!forceq.empty()) {
    49     while (!forceq.empty()) {
    49         tmpf = forceq.front();
    50         tmpf = forceq.front();
    50         if (tmpf.dt <= PHYSICS_TICK_MS) { // Force affects only one tick
    51         if (tmpf.dt <= PHYSICS_TICK_MS) { // Force affects only one tick
    51             integrate(tmpf.force, tmpf.dt);
    52             total.force += tmpf.force;
    52         } else { // Add remaining time to next tick
    53         } else { // Add remaining time to next tick
    53             newfq.push(Force(tmpf.force, tmpf.dt - PHYSICS_TICK_MS));
    54             newfq.push(Force(tmpf.force, tmpf.dt - PHYSICS_TICK_MS));
    54             integrate(tmpf.force, PHYSICS_TICK_MS);
    55             total.force += tmpf.force;
    55         }
    56         }
    56         forceq.pop();
    57         forceq.pop();
    57         //        Engine::log(DEBUG, "PhysicsObject.updatePosition") << "Current position: " << posAfterTick;
    58         //        Engine::log(DEBUG, "PhysicsObject.updatePosition") << "Current position: " << posAfterTick;
    58     }
    59     }
       
    60     integrate(total.force, PHYSICS_TICK_MS);
    59     forceq = newfq;
    61     forceq = newfq;
    60 
    62 
    61     Vector newPosition = posAfterTick + (velAfterTick * PHYSICS_TICK_MS)/1000;
    63     Vector newPosition = posAfterTick /*+ (velAfterTick * PHYSICS_TICK_MS)/1000*/;
    62     this->velocity = velAfterTick;
    64     this->velocity = velAfterTick;
    63     Engine::log(DEBUG, "PhysicsObject.updatePosition") << "Nopeus: "<<this->velocity;
    65     Engine::log(DEBUG, "PhysicsObject.updatePosition") << "Nopeus: "<<this->velocity;
    64     /*
    66     /*
    65     this->velocity += world.gravity * (PHYSICS_TICK_MS / 1000.0);
    67     this->velocity += world.gravity * (PHYSICS_TICK_MS / 1000.0);
    66 
    68