void SpacePlane::anim(double dt){ WarSpace *ws = *w; if(!ws){ st::anim(dt); return; } if(bbody && !warping){ const btTransform &tra = bbody->getCenterOfMassTransform(); pos = btvc(tra.getOrigin()); rot = btqc(tra.getRotation()); velo = btvc(bbody->getLinearVelocity()); } /* forget about beaten enemy */ if(enemy && (enemy->getHealth() <= 0. || enemy->w != w)) enemy = NULL; Mat4d mat; transform(mat); if(0 < health){ Entity *collideignore = NULL; if(ai){ if(ai->control(this, dt)){ ai->unlink(this); ai = NULL; } if(!w) return; } else if(task == sship_undock){ if(undocktime < 0.){ inputs.press &= ~PL_W; task = sship_idle; } else{ inputs.press |= PL_W; undocktime -= dt; } } else if(controller){ } else if(!enemy && task == sship_parade){ Entity *pm = mother ? mother->e : NULL; if(mother){ if(paradec == -1) paradec = mother->enumParadeC(mother->Frigate); Vec3d target, target0(1.5, -1., -1.); Quatd q2, q1; target0[0] += paradec % 10 * 300.; target0[2] += paradec / 10 * -300.; target = pm->rot.trans(target0); target += pm->pos; Vec3d dr = this->pos - target; if(dr.slen() < .10 * .10){ q1 = pm->rot; inputs.press &= ~PL_W; // parking = 1; this->velo += dr * (-dt * .5); q2 = Quatd::slerp(this->rot, q1, 1. - exp(-dt)); this->rot = q2; } else{ // p->throttle = dr.slen() / 5. + .01; steerArrival(dt, target, pm->velo, 1. / 10., 1.); } } else task = sship_idle; } else if(task == sship_idle){ if(race != 0 /*RandomSequence((unsigned long)this + (unsigned long)(w->war_time() / .0001)).nextd() < .0001*/){ command(&DockCommand()); } inputs.press = 0; } else{ inputs.press = 0; } } else{ this->w = NULL; return; } st::anim(dt); // inputs.press is filtered in st::anim, so we put tefpol updates after it. for(int i = 0; i < engines.size(); i++) if(pf[i]){ pf[i]->move(mat.vp3(engines[i]), avec3_000, cs_orangeburn.t, !(inputs.press & PL_W)); } // engineHeat = approach(engineHeat, direction & PL_W ? 1.f : 0.f, dt, 0.); // Exponential approach is more realistic (but costs more CPU cycles) engineHeat = direction & PL_W ? engineHeat + (1. - engineHeat) * (1. - exp(-dt)) : engineHeat * exp(-dt); #if 0 if(p->pf){ int i; avec3_t pos, pos0[numof(p->pf)] = { {.0, -.003, .045}, }; for(i = 0; i < numof(p->pf); i++){ MAT4VP3(pos, mat, pos0[i]); MoveTefpol3D(p->pf[i], pos, avec3_000, cs_orangeburn.t, 0); } } #endif }