- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/UIElements/Views/Qt4/Qt3D/GLMoleculeObject_atom.cpp
r9eb71b3 r897a01 50 50 #include "Element/element.hpp" 51 51 #include "Element/periodentafel.hpp" 52 #include "LinearAlgebra/Line.hpp" 52 53 #include "LinearAlgebra/Vector.hpp" 53 54 #include "UIElements/Views/Qt4/Qt3D/GLMoleculeObject_bond.hpp" … … 57 58 GLMoleculeObject_atom::GLMoleculeObject_atom( 58 59 QGLSceneNode *mesh[], 60 QGLSceneNode *mesharrow[], 59 61 QObject *parent, 60 62 QtObservedAtom::ptr &_ObservedAtom) : 61 63 GLMoleculeObject(mesh, parent), 64 GLMoleculeObjectVelocity(mesharrow, this), 65 GLMoleculeObjectForce(mesharrow, this), 62 66 ObservedAtom(_ObservedAtom) 63 67 { … … 69 73 setObjectId(_id); 70 74 resetPosition(); 75 resetVelocity(); 76 resetForce(); 71 77 resetElement(); 78 79 GLMoleculeObjectVelocity.setMaterial(GLMoleculeObject::m_velocityMaterial); 80 GLMoleculeObjectForce.setMaterial(GLMoleculeObject::m_forceMaterial); 72 81 73 82 m_selected = ObservedAtom->getAtomSelected(); … … 77 86 connect( ObservedAtom.get(), SIGNAL(elementChanged()), this, SLOT(resetElement())); 78 87 connect( ObservedAtom.get(), SIGNAL(positionChanged()), this, SLOT(resetPosition())); 88 connect( ObservedAtom.get(), SIGNAL(velocityChanged()), this, SLOT(resetVelocity())); 89 connect( ObservedAtom.get(), SIGNAL(forceChanged()), this, SLOT(resetForce())); 79 90 connect( ObservedAtom.get(), SIGNAL(selectedChanged()), this, SLOT(resetSelected())); 80 91 } … … 95 106 } 96 107 108 static void setArrow( 109 const Vector &_position, 110 const Vector &_arrow, 111 const double _offset, 112 GLMoleculeObject &_obj) 113 { 114 // set position (cylinder offset is in its barymetric center) 115 Vector OneFourth(_position + (_offset/_arrow.Norm()+.75) * _arrow); 116 _obj.setPosition(QVector3D(OneFourth[0], OneFourth[1], OneFourth[2])); 117 } 118 97 119 void GLMoleculeObject_atom::resetPosition() 98 120 { … … 100 122 LOG(4, "INFO: GLMoleculeObject_atom::resetPosition() - new position is "+toString(Position)+"."); 101 123 setPosition(QVector3D(Position[0], Position[1], Position[2])); 124 setArrow(Position, 10.*ObservedAtom->getAtomVelocity(), scaleX(), GLMoleculeObjectVelocity); 125 setArrow(Position, 10.*ObservedAtom->getAtomForce(), scaleX(), GLMoleculeObjectForce); 126 } 127 128 static void alignArrow( 129 const Vector &_arrow, 130 GLMoleculeObject &_obj) 131 { 132 if (_arrow.IsZero()) { 133 _obj.setScaleZ(0.); 134 return; 135 } 136 // calculate position 137 Vector Z(unitVec[2]); // cylinder are initially aligned along the Z axis 138 Vector b; 139 Vector OtherAxis; 140 double alpha; 141 // construct rotation axis 142 b = -1.*_arrow; 143 b.VectorProduct(Z); 144 Line axis(zeroVec, b); 145 // calculate rotation angle 146 alpha = _arrow.Angle(Z); 147 // construct other axis to check right-hand rule 148 OtherAxis = b; 149 OtherAxis.VectorProduct(Z); 150 // assure right-hand rule for the rotation 151 if (_arrow.ScalarProduct(OtherAxis) < MYEPSILON) 152 alpha = M_PI-alpha; 153 // check 154 Vector a_rotated = axis.rotateVector(_arrow, alpha); 155 LOG(5, "DEBUG: Aligning arrow " << _arrow << " to " << a_rotated 156 << " around " << b << " by " << alpha/M_PI*180. << "."); 157 158 _obj.setScaleZ(10.*_arrow.Norm()); 159 _obj.setRotationVector(QVector3D(b[0], b[1], b[2])); 160 _obj.setRotationAngle(alpha/M_PI*180.); 161 } 162 163 void GLMoleculeObject_atom::resetVelocity() 164 { 165 const Vector Velocity = ObservedAtom->getAtomVelocity(); 166 LOG(4, "INFO: GLMoleculeObject_atom::resetVelocity() - new velocity is "+toString(Velocity)+"."); 167 alignArrow(Velocity, GLMoleculeObjectVelocity); 168 // GLMoleculeObjectForce.setScaleZ(Velocity.Norm()); 169 } 170 171 void GLMoleculeObject_atom::resetForce() 172 { 173 const Vector Force = ObservedAtom->getAtomForce(); 174 LOG(4, "INFO: GLMoleculeObject_atom::resetForce() - new force is "+toString(Force)+"."); 175 alignArrow(Force, GLMoleculeObjectForce); 176 // GLMoleculeObjectForce.setScaleZ(Force.Norm()); 102 177 } 103 178 … … 144 219 // call old hook to do the actual paining 145 220 GLMoleculeObject::draw(painter, cameraPlane); 221 GLMoleculeObjectVelocity.draw(painter, cameraPlane); 222 GLMoleculeObjectForce.draw(painter, cameraPlane); 146 223 } 147 224
Note:
See TracChangeset
for help on using the changeset viewer.