00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <math.h>
00022 #include <string.h>
00023 #include "PickModeCenter.h"
00024 #include "Pickable.h"
00025 #include "VMDApp.h"
00026 #include "MoleculeList.h"
00027
00028 PickModeCenter::PickModeCenter(VMDApp *vmdapp) : app(vmdapp) {}
00029
00030 void PickModeCenter::pick_molecule_start(DrawMolecule *, DisplayDevice *,
00031 int, int tag, const int * cell, int dim, const float *pos) {
00032 pAtom = tag;
00033 memcpy(pPos, pos, dim*sizeof(float));
00034 memcpy(pCell, cell, 3L*sizeof(int));
00035 needName = TRUE;
00036 }
00037
00038 void PickModeCenter::pick_molecule_move(DrawMolecule *, DisplayDevice *,
00039 int, int dim, const float *pos) {
00040 if(needName) {
00041 float mvdist = 0.0;
00042 for(int i=0; i < dim; i++)
00043 mvdist += (float) fabs(pPos[i] - pos[i]);
00044 if(mvdist > 0.02 )
00045 needName = FALSE;
00046 }
00047 }
00048
00049 void PickModeCenter::pick_molecule_end(DrawMolecule *mol, DisplayDevice *) {
00050 if (!needName) return;
00051
00052 const Timestep *ts = mol->current();
00053 const float *coord = ts->pos + pAtom * 3L;
00054 float tcoord[3];
00055 Matrix4 mat;
00056 ts->get_transform_from_cell(pCell, mat);
00057 mat.multpoint3d(coord, tcoord);
00058
00059
00060
00061 DrawMolecule *m;
00062 for (int m_id = 0; m_id < app->moleculeList->num(); m_id++) {
00063 m = app->moleculeList->molecule(m_id);
00064 if (m->active) {
00065 m->change_center(tcoord[0], tcoord[1], tcoord[2]);
00066 }
00067 }
00068 }
00069