void FPS::prepare() { if (!displayed()) return; ++loop_count; double curtime = time_of_day(); // force a redraw.... need_matrix_recalc(); // but don't redraw indicator more than twice per second if (curtime - last_update < 0.5) return; double rate = loop_count / (curtime - last_update); last_update = curtime; loop_count = 0; reset_disp_list(); append(DMATERIALOFF); float asp = disp->aspect(); float poscale = 1.2f; float pos[3]; pos[0] = asp * poscale; pos[1] = poscale; pos[2] = 0; DispCmdColorIndex cmdColor; cmdColor.putdata(usecolor, cmdList); DispCmdText cmdText; char buf[20]; sprintf(buf, "%5.2f", rate); cmdText.putdata(pos, buf, 1.0f, cmdList); }
void Displayable::set_rot(const Matrix4 &m) { if (fixed()) return; // only transform unfixed objects // do trans for all children as well for (int i=0; i < num_children; i++) child(i)->set_rot(m); if (!rotating()) return; rotm = m; need_matrix_recalc(); }
void Displayable::set_cent_trans(float x, float y, float z) { // do trans for all children as well for (int i=0; i < num_children; i++) child(i)->set_cent_trans(x, y, z); if (!cent_translating()) return; centt[0] = x; centt[1] = y; centt[2] = z; need_matrix_recalc(); }
void Displayable::mult_scale(float s) { if (fixed()) return; // only transform unfixed objects // do trans for all children as well for (int i=0; i < num_children; i++) child(i)->mult_scale(s); if (!scaling()) return; scale *= s; need_matrix_recalc(); }
// reset the transformation to the identity matrix void Displayable::reset_transformation(void) { // only reset if we're not fixed and given operations are allowed if (scaling()) scale=1; if (rotating()) { rotm.identity(); } if (glob_translating()) globt[0] = globt[1] = globt[2] = 0; if (cent_translating()) centt[0] = centt[1] = centt[2] = 0; need_matrix_recalc(); // do reset for all children as well for (int i=0; i < num_children; i++) child(i)->reset_transformation(); }
void Displayable::add_glob_trans(float x, float y, float z) { if (fixed()) return; // only transform unfixed objects // do trans for all children as well for (int i=0; i < num_children; i++) child(i)->add_glob_trans(x, y, z); if (!glob_translating()) return; globt[0] += x; globt[1] += y; globt[2] += z; need_matrix_recalc(); }
void Displayable::set_rot(float x, char axis) { if (fixed()) return; // only transform unfixed objects // do trans for all children as well for (int i=0; i < num_children; i++) child(i)->set_rot(x, axis); if (!rotating()) return; // apply rotation to identity, and then multiply this by old rot matrix rotm.identity(); rotm.rot(x,axis); need_matrix_recalc(); }
// redraw all the representations void DrawMolecule::force_recalc(int reason) { int numcomp = components(); for (int i=0; i<numcomp; i++) { component(i)->force_recalc(reason); } // The preceding loop updates all the DrawMolItem reps, but other children // of DrawMolecule (i.e. DrawForce) need to know about the update as well. // Calling need_matrix_recalc sets the _needUpdate flag for this purpose. need_matrix_recalc(); app->commandQueue->runcommand(new CmdAnimNewFrame); // MOL_REGEN or SEL_REGEN implies our scale factor may have changed. if (reason & (DrawMolItem::MOL_REGEN | DrawMolItem::SEL_REGEN)) invalidate_cov_scale(); }
void Displayable::add_rot(float x, char axis) { if (fixed()) return; // only transform unfixed objects // do trans for all children as well for (int i=0; i < num_children; i++) child(i)->add_rot(x, axis); if (!rotating()) return; // Need to apply the new rotation first Matrix4 mat; mat.rot(x, axis); mat.multmatrix(rotm); rotm = mat; need_matrix_recalc(); }