Changeset b40b9d for src


Ignore:
Timestamp:
Oct 6, 2011, 12:08:30 PM (13 years ago)
Author:
Frederik Heber <heber@…>
Branches:
Action_Thermostats, Add_AtomRandomPerturbation, Add_FitFragmentPartialChargesAction, Add_RotateAroundBondAction, Add_SelectAtomByNameAction, Added_ParseSaveFragmentResults, AddingActions_SaveParseParticleParameters, Adding_Graph_to_ChangeBondActions, Adding_MD_integration_tests, Adding_ParticleName_to_Atom, Adding_StructOpt_integration_tests, AtomFragments, Automaking_mpqc_open, AutomationFragmentation_failures, Candidate_v1.5.4, Candidate_v1.6.0, Candidate_v1.6.1, ChangeBugEmailaddress, ChangingTestPorts, ChemicalSpaceEvaluator, CombiningParticlePotentialParsing, Combining_Subpackages, Debian_Package_split, Debian_package_split_molecuildergui_only, Disabling_MemDebug, Docu_Python_wait, EmpiricalPotential_contain_HomologyGraph, EmpiricalPotential_contain_HomologyGraph_documentation, Enable_parallel_make_install, Enhance_userguide, Enhanced_StructuralOptimization, Enhanced_StructuralOptimization_continued, Example_ManyWaysToTranslateAtom, Exclude_Hydrogens_annealWithBondGraph, FitPartialCharges_GlobalError, Fix_BoundInBox_CenterInBox_MoleculeActions, Fix_ChargeSampling_PBC, Fix_ChronosMutex, Fix_FitPartialCharges, Fix_FitPotential_needs_atomicnumbers, Fix_ForceAnnealing, Fix_IndependentFragmentGrids, Fix_ParseParticles, Fix_ParseParticles_split_forward_backward_Actions, Fix_PopActions, Fix_QtFragmentList_sorted_selection, Fix_Restrictedkeyset_FragmentMolecule, Fix_StatusMsg, Fix_StepWorldTime_single_argument, Fix_Verbose_Codepatterns, Fix_fitting_potentials, Fixes, ForceAnnealing_goodresults, ForceAnnealing_oldresults, ForceAnnealing_tocheck, ForceAnnealing_with_BondGraph, ForceAnnealing_with_BondGraph_continued, ForceAnnealing_with_BondGraph_continued_betteresults, ForceAnnealing_with_BondGraph_contraction-expansion, FragmentAction_writes_AtomFragments, FragmentMolecule_checks_bonddegrees, GeometryObjects, Gui_Fixes, Gui_displays_atomic_force_velocity, ImplicitCharges, IndependentFragmentGrids, IndependentFragmentGrids_IndividualZeroInstances, IndependentFragmentGrids_IntegrationTest, IndependentFragmentGrids_Sole_NN_Calculation, JobMarket_RobustOnKillsSegFaults, JobMarket_StableWorkerPool, JobMarket_unresolvable_hostname_fix, MoreRobust_FragmentAutomation, ODR_violation_mpqc_open, PartialCharges_OrthogonalSummation, PdbParser_setsAtomName, PythonUI_with_named_parameters, QtGui_reactivate_TimeChanged_changes, Recreated_GuiChecks, Rewrite_FitPartialCharges, RotateToPrincipalAxisSystem_UndoRedo, SaturateAtoms_findBestMatching, SaturateAtoms_singleDegree, StoppableMakroAction, Subpackage_CodePatterns, Subpackage_JobMarket, Subpackage_LinearAlgebra, Subpackage_levmar, Subpackage_mpqc_open, Subpackage_vmg, Switchable_LogView, ThirdParty_MPQC_rebuilt_buildsystem, TrajectoryDependenant_MaxOrder, TremoloParser_IncreasedPrecision, TremoloParser_MultipleTimesteps, TremoloParser_setsAtomName, Ubuntu_1604_changes, stable
Children:
47812b
Parents:
29daad
git-author:
Frederik Heber <heber@…> (08/12/11 15:16:28)
git-committer:
Frederik Heber <heber@…> (10/06/11 12:08:30)
Message:

FIX: Bonds are now displayed correctly.

  • using Vector::VectorProduct() to correctly create normal vectors and fixed therewith GLMoleculeView::makeCylinder().
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/UIElements/Views/Qt4/GLMoleculeView.cpp

    r29daad rb40b9d  
    2828
    2929#include <iostream>
     30#include <boost/shared_ptr.hpp>
    3031
    3132#include "LinearAlgebra/Line.hpp"
     
    229230  float blueMaterial[] = { 255./(float)color[0], 255./(float)color[1], 255./(float)color[2], 1 };  // need to recast from [0,255] with integers into [0,1] with floats
    230231  GLUquadricObj* q = gluNewQuadric ();
     232  gluQuadricOrientation(q, GLU_OUTSIDE);
    231233
    232234  std::cout << "Setting sphere at " << x << " with color r"
     
    254256  float blueMaterial[] = { 255./(float)color[0], 255./(float)color[1], 255./(float)color[2], 1 };
    255257  GLUquadricObj* q = gluNewQuadric ();
     258  gluQuadricOrientation(q, GLU_OUTSIDE);
    256259  Vector a,b;
     260  Vector OtherAxis;
    257261  double alpha;
    258   a = x - b;
    259   b.GetOneNormalVector(a);
    260   b.MakeNormalTo(Z);
     262  a = x - y;
     263  // construct rotation axis
     264  b = a;
     265  b.VectorProduct(Z);
     266  Line axis(zeroVec, b);
     267  // calculate rotation angle
    261268  alpha = a.Angle(Z);
    262   if (fabs(a[2]) > MYEPSILON)   // I have no idea why I need to check this, but this fixes the sign problem of the rotation angle
     269  // construct other axis to check right-hand rule
     270  OtherAxis = b;
     271  OtherAxis.VectorProduct(Z);
     272  // assure right-hand rule for the rotation
     273  if (a.ScalarProduct(OtherAxis) < MYEPSILON)
    263274    alpha = M_PI-alpha;
    264   Line axis(zeroVec, b);
    265   a = axis.rotateVector(a, alpha);
    266   std::cout << "Setting cylinder from " << x << " to " << a << " with color r"
     275  // check
     276  Vector a_rotated = axis.rotateVector(a, alpha);
     277  std::cout << "Setting cylinder from "// << x << " to " << y
     278      << a << " to " << a_rotated << " around " << b << " by " << alpha/M_PI*180. << ", respectively, "
     279      << " with color r"
    267280      << (int)color[0] << ",g" << (int)color[1] << ",b" << (int)color[2] << "." << endl;
    268281
     
    307320        // create atom
    308321        const element *ptr = (*atomiter)->getType();
    309         molecule::const_iterator moliter = (*Runner)->begin();
    310         Position = (*atomiter)->getPosition() - (*moliter)->getPosition();
     322        boost::shared_ptr<Vector> MolCenter((*Runner)->DetermineCenterOfGravity());
     323        Position = (*atomiter)->getPosition() - *MolCenter;
    311324        const unsigned char* color = NULL;
    312325        if ((World::getInstance().isSelected(*atomiter)) || (World::getInstance().isSelected((*Runner))))
     
    322335            ++bonditer) {
    323336          if ((*bonditer)->leftatom->getId() == (*atomiter)->getId()) {
    324             Position = (*bonditer)->leftatom->getPosition() - (*moliter)->getPosition();
    325             OtherPosition = (*bonditer)->rightatom->getPosition() - (*moliter)->getPosition();
     337            Position = (*bonditer)->leftatom->getPosition() - *MolCenter;
     338            OtherPosition = (*bonditer)->rightatom->getPosition() - *MolCenter;
    326339            const double distance = sqrt(Position.DistanceSquared(OtherPosition))/2.;
    327340            const unsigned char *color1 = (*bonditer)->leftatom->getType()->getColor();
Note: See TracChangeset for help on using the changeset viewer.