void CKeyframe::Update (double timestep, CControl *ctrl) { if (!loaded) return; double frac; TVector3 pos; CCharShape *shape = Char.GetShape (g_game.char_id); if (!active) return; keytime += timestep; if (keytime >= frames[keyidx]->val[0]) { keyidx++; keytime = 0; } if (keyidx >= numFrames-1 || numFrames < 2) { active = false; return; } if (fabs (frames[keyidx]->val[0]) < 0.0001) frac = 1.0; else frac = (frames[keyidx]->val[0] - keytime) / frames[keyidx]->val[0]; pos.x = interp (frac, frames[keyidx]->val[1], frames[keyidx+1]->val[1]) + refpos.x; pos.z = interp (frac, frames[keyidx]->val[3], frames[keyidx+1]->val[3]) + refpos.z; pos.y = interp (frac, frames[keyidx]->val[2], frames[keyidx+1]->val[2]); pos.y += Course.FindYCoord (pos.x, pos.z); shape->ResetRoot (); shape->ResetJoints (); Players.GetCtrl (g_game.player_id)->cpos = pos; double disp_y = pos.y + TUX_Y_CORR + heightcorr; shape->ResetNode (0); shape->TranslateNode (0, MakeVector (pos.x, disp_y, pos.z)); InterpolateKeyframe (keyidx, frac, shape); }
void CKeyframe::Init (const TVector3& ref_position, double height_correction) { if (!loaded) return; CCharShape *shape = Char.GetShape (g_game.char_id); shape->ResetNode ("head"); shape->ResetNode ("neck"); refpos = ref_position; heightcorr = height_correction; active = true; keyidx = 0; keytime = 0; }
void CKeyframe::Update(float timestep) { if (!loaded) return; if (!active) return; keytime += timestep; if (keytime >= frames[keyidx].val[0]) { keyidx++; keytime = 0; } if (keyidx >= frames.size()-1 || frames.size() < 2) { active = false; return; } double frac; TVector3d pos; CCharShape *shape = g_game.character->shape; if (std::fabs(frames[keyidx].val[0]) < 0.0001) frac = 1.0; else frac = (frames[keyidx].val[0] - keytime) / frames[keyidx].val[0]; pos.x = interp(frac, frames[keyidx].val[1], frames[keyidx+1].val[1]) + refpos.x; pos.z = interp(frac, frames[keyidx].val[3], frames[keyidx+1].val[3]) + refpos.z; pos.y = interp(frac, frames[keyidx].val[2], frames[keyidx+1].val[2]); pos.y += Course.FindYCoord(pos.x, pos.z); shape->ResetRoot(); shape->ResetJoints(); g_game.player->ctrl->cpos = pos; double disp_y = pos.y + TUX_Y_CORR + heightcorr; shape->ResetNode(0); shape->TranslateNode(0, TVector3d(pos.x, disp_y, pos.z)); InterpolateKeyframe(keyidx, frac, shape); }