Exemple #1
0
void TorsionAngleContrib::getGrad(double *pos, double *grad) const {
  PRECONDITION(dp_forceField, "no owner");
  PRECONDITION(pos, "bad vector");
  PRECONDITION(grad, "bad vector");

  RDGeom::Point3D iPoint(pos[3 * d_at1Idx], pos[3 * d_at1Idx + 1],
                         pos[3 * d_at1Idx + 2]);
  RDGeom::Point3D jPoint(pos[3 * d_at2Idx], pos[3 * d_at2Idx + 1],
                         pos[3 * d_at2Idx + 2]);
  RDGeom::Point3D kPoint(pos[3 * d_at3Idx], pos[3 * d_at3Idx + 1],
                         pos[3 * d_at3Idx + 2]);
  RDGeom::Point3D lPoint(pos[3 * d_at4Idx], pos[3 * d_at4Idx + 1],
                         pos[3 * d_at4Idx + 2]);
  double *g[4] = {&(grad[3 * d_at1Idx]), &(grad[3 * d_at2Idx]),
                  &(grad[3 * d_at3Idx]), &(grad[3 * d_at4Idx])};

  RDGeom::Point3D r[4] = {iPoint - jPoint, kPoint - jPoint, jPoint - kPoint,
                          lPoint - kPoint};
  RDGeom::Point3D t[2] = {r[0].crossProduct(r[1]), r[2].crossProduct(r[3])};
  double d[2] = {t[0].length(), t[1].length()};
  if (isDoubleZero(d[0]) || isDoubleZero(d[1])) {
    return;
  }
  t[0] /= d[0];
  t[1] /= d[1];
  double cosPhi = t[0].dotProduct(t[1]);
  clipToOne(cosPhi);
  double sinPhiSq = 1.0 - cosPhi * cosPhi;
  double sinPhi = ((sinPhiSq > 0.0) ? sqrt(sinPhiSq) : 0.0);
  double sin2Phi = 2.0 * sinPhi * cosPhi;
  double sin3Phi = 3.0 * sinPhi - 4.0 * sinPhi * sinPhiSq;
  // dE/dPhi is independent of cartesians:
  double dE_dPhi =
      0.5 * (-(d_V1)*sinPhi + 2.0 * d_V2 * sin2Phi - 3.0 * d_V3 * sin3Phi);
#if 0
      if(dE_dPhi!=dE_dPhi){
        std::cout << "\tNaN in Torsion("<<d_at1Idx<<","<<d_at2Idx<<","<<d_at3Idx<<","<<d_at4Idx<<")"<< std::endl;
        std::cout << "sin: " << sinPhi << std::endl;
        std::cout << "cos: " << cosPhi << std::endl;
      }

#endif
  // FIX: use a tolerance here
  // this is hacky, but it's per the
  // recommendation from Niketic and Rasmussen:
  double sinTerm =
      -dE_dPhi * (isDoubleZero(sinPhi) ? (1.0 / cosPhi) : (1.0 / sinPhi));

  Utils::calcTorsionGrad(r, t, d, g, sinTerm, cosPhi);
}
Exemple #2
0
double TorsionAngleContrib::getEnergy(double *pos) const {
  PRECONDITION(dp_forceField, "no owner");
  PRECONDITION(pos, "bad vector");

  RDGeom::Point3D iPoint(pos[3 * d_at1Idx], pos[3 * d_at1Idx + 1],
                         pos[3 * d_at1Idx + 2]);
  RDGeom::Point3D jPoint(pos[3 * d_at2Idx], pos[3 * d_at2Idx + 1],
                         pos[3 * d_at2Idx + 2]);
  RDGeom::Point3D kPoint(pos[3 * d_at3Idx], pos[3 * d_at3Idx + 1],
                         pos[3 * d_at3Idx + 2]);
  RDGeom::Point3D lPoint(pos[3 * d_at4Idx], pos[3 * d_at4Idx + 1],
                         pos[3 * d_at4Idx + 2]);

  return Utils::calcTorsionEnergy(
      d_V1, d_V2, d_V3,
      Utils::calcTorsionCosPhi(iPoint, jPoint, kPoint, lPoint));
}
Exemple #3
0
void OopBendContrib::getGrad(double *pos, double *grad) const {
  PRECONDITION(dp_forceField, "no owner");
  PRECONDITION(pos, "bad vector");
  PRECONDITION(grad, "bad vector");

  RDGeom::Point3D iPoint(pos[3 * d_at1Idx], pos[3 * d_at1Idx + 1],
                         pos[3 * d_at1Idx + 2]);
  RDGeom::Point3D jPoint(pos[3 * d_at2Idx], pos[3 * d_at2Idx + 1],
                         pos[3 * d_at2Idx + 2]);
  RDGeom::Point3D kPoint(pos[3 * d_at3Idx], pos[3 * d_at3Idx + 1],
                         pos[3 * d_at3Idx + 2]);
  RDGeom::Point3D lPoint(pos[3 * d_at4Idx], pos[3 * d_at4Idx + 1],
                         pos[3 * d_at4Idx + 2]);
  double *g1 = &(grad[3 * d_at1Idx]);
  double *g2 = &(grad[3 * d_at2Idx]);
  double *g3 = &(grad[3 * d_at3Idx]);
  double *g4 = &(grad[3 * d_at4Idx]);

  RDGeom::Point3D rJI = iPoint - jPoint;
  RDGeom::Point3D rJK = kPoint - jPoint;
  RDGeom::Point3D rJL = lPoint - jPoint;
  double dJI = rJI.length();
  double dJK = rJK.length();
  double dJL = rJL.length();
  if (isDoubleZero(dJI) || isDoubleZero(dJK) || isDoubleZero(dJL)) {
    return;
  }
  rJI /= dJI;
  rJK /= dJK;
  rJL /= dJL;

  RDGeom::Point3D n = (-rJI).crossProduct(rJK);
  n /= n.length();
  double const c2 = MDYNE_A_TO_KCAL_MOL * DEG2RAD * DEG2RAD;
  double sinChi = rJL.dotProduct(n);
  clipToOne(sinChi);
  double cosChiSq = 1.0 - sinChi * sinChi;
  double cosChi = std::max(((cosChiSq > 0.0) ? sqrt(cosChiSq) : 0.0), 1.0e-8);
  double chi = RAD2DEG * asin(sinChi);
  double cosTheta = rJI.dotProduct(rJK);
  clipToOne(cosTheta);
  double sinThetaSq = std::max(1.0 - cosTheta * cosTheta, 1.0e-8);
  double sinTheta =
      std::max(((sinThetaSq > 0.0) ? sqrt(sinThetaSq) : 0.0), 1.0e-8);

  double dE_dChi = RAD2DEG * c2 * d_koop * chi;
  RDGeom::Point3D t1 = rJL.crossProduct(rJK);
  RDGeom::Point3D t2 = rJI.crossProduct(rJL);
  RDGeom::Point3D t3 = rJK.crossProduct(rJI);
  double term1 = cosChi * sinTheta;
  double term2 = sinChi / (cosChi * sinThetaSq);
  double tg1[3] = {(t1.x / term1 - (rJI.x - rJK.x * cosTheta) * term2) / dJI,
                   (t1.y / term1 - (rJI.y - rJK.y * cosTheta) * term2) / dJI,
                   (t1.z / term1 - (rJI.z - rJK.z * cosTheta) * term2) / dJI};
  double tg3[3] = {(t2.x / term1 - (rJK.x - rJI.x * cosTheta) * term2) / dJK,
                   (t2.y / term1 - (rJK.y - rJI.y * cosTheta) * term2) / dJK,
                   (t2.z / term1 - (rJK.z - rJI.z * cosTheta) * term2) / dJK};
  double tg4[3] = {(t3.x / term1 - rJL.x * sinChi / cosChi) / dJL,
                   (t3.y / term1 - rJL.y * sinChi / cosChi) / dJL,
                   (t3.z / term1 - rJL.z * sinChi / cosChi) / dJL};
  for (unsigned int i = 0; i < 3; ++i) {
    g1[i] += dE_dChi * tg1[i];
    g2[i] += -dE_dChi * (tg1[i] + tg3[i] + tg4[i]);
    g3[i] += dE_dChi * tg3[i];
    g4[i] += dE_dChi * tg4[i];
  }
}
Exemple #4
0
//UI
void SetupUI()
{
	DBOXUIPROPERTIES props = {0};
	props.BaseWidth = 1280;
	props.BaseHeight = 1024;
	props.eng2d = Engine2D;
	props.FontColor = 0xffdddddd;
	props.hWnd = App->GetWindowHandle();
	props.pDevice = Engine3D->GetDevice();
	props.inp = Input;
	props.FontFace = "Arial Black";
	props.TextureKeyColor = 0xffff00ff;
	props.TextureName = "UI.png";
	props.LabelWordSize = 85;

	props.BtnRects[0] = lRect(0,0 , 386,139);
	props.BtnRects[1] = lRect(0,140 , 386,279);
	props.BtnRects[2] = lRect(0,280 , 386,419);

	props.TextboxRect = lRect(0,420 , 589,559);

	UIm.Create(props);
	//select profile
	UIm.Pages["prof"]["Hello Label"] = DBOXUICreateLabel(&UIm , lRect(0, 90,  1280 , 400) , "Impossible Game for PC(beta)\n\rOriginal game by : flukedude.com\n\rThe remake by K.Petkov\n\rSelect your profile...");
	UIm.Pages["prof"]["prof1"] = DBOXUICreateButton(&UIm , Profiles::profiles[0].Name , lPoint(1280/4 - 387/2 - 90, 500)); 
	UIm.Pages["prof"]["prof2"] = DBOXUICreateButton(&UIm , Profiles::profiles[1].Name , lPoint(1280/2 - 387/2 , 500)); 
	UIm.Pages["prof"]["prof3"] = DBOXUICreateButton(&UIm , Profiles::profiles[2].Name , lPoint(1920/2 - 387/2 + 90 , 500)); 
	UIm.Pages["prof"]["ok"] = DBOXUICreateButton(&UIm , "OK" , lPoint(740, 800)); 
	UIm.Pages["prof"]["tb"] = DBOXUICreateTextbox(&UIm , 9 , lPoint(120 , 800) , "profile");
	UIm.Pages["prof"]["Name Label"] = DBOXUICreateLabel(&UIm , lRect(0, 670,  1280 , 100) , "Enter your name ...");
	//main
	UIm.Pages["main"]["Hello Label"] = DBOXUICreateLabel(&UIm , lRect(0, 0,  1280 , 100) , "Hello ");
	UIm.Pages["main"]["Start"] = DBOXUICreateButton(&UIm , "Start" , lPoint(1280/2 - 387/2 , 350));
	UIm.Pages["main"]["Settings"] = DBOXUICreateButton(&UIm , "Settings" , lPoint(1280/2 - 387 - 1, 500));
	UIm.Pages["main"]["Controls"] = DBOXUICreateButton(&UIm , "Controls" , lPoint(1280/2 + 1, 500));
	UIm.Pages["main"]["Stats"] = DBOXUICreateButton(&UIm , "Stats" , lPoint(1280/2 - 387 - 1, 650));
	UIm.Pages["main"]["Profiles"] = DBOXUICreateButton(&UIm , "Profiles" , lPoint(1280/2 + 1 , 650));
	UIm.Pages["main"]["Exit"] = DBOXUICreateButton(&UIm , "Exit" , lPoint(1280/2 - 387/2  , 800));
	UIm.Pages["main"]["Controls"]->InfoState.Locked = UIm.Pages["main"]["Stats"]->InfoState.Locked = true;
	//settings
	UIm.Pages["settings"]["ResolutionSelect"] = DBOXUICreateLabel(&UIm , lRect(0, 100,  1280 , 100) , "Select your screen resolution ..");
	UIm.Pages["settings"]["640x480"] = DBOXUICreateButton(&UIm , "640x480" , lPoint(1280/2 - 387 - 10, 270)); 
	UIm.Pages["settings"]["800x600"] = DBOXUICreateButton(&UIm , "800x600", lPoint(1280/2  + 10 , 270)); 
	UIm.Pages["settings"]["1024x768"] = DBOXUICreateButton(&UIm , "1024x768" , lPoint(1280/2 - 387 - 10, 420)); 
	UIm.Pages["settings"]["1280x1024"] = DBOXUICreateButton(&UIm , "1280x1024" , lPoint(1280/2  + 10 , 420)); 
	UIm.Pages["settings"]["Toggle"] = DBOXUICreateButton(&UIm , "Fullscreen" , lPoint(1280/2 - 387 - 10 , 570)); 
	//
	UIm.Pages["settings"]["Toggle"]->InfoState.Locked = true;
	UIm.Pages["settings"]["Back"] = DBOXUICreateButton(&UIm , "Back" , lPoint(1280/2  + 10 , 570)); 
	//select level
	UIm.Pages["level"]["l1"] = DBOXUICreateButton(&UIm , "Level 1" , lPoint(1280/2 - 387/2 , 350)); 
	UIm.Pages["level"]["l2"] = DBOXUICreateButton(&UIm , "Level 2" , lPoint(1280/2 - 387/2 , 500)); 
	UIm.Pages["level"]["l3"] = DBOXUICreateButton(&UIm , "Level 3" , lPoint(1280/2 - 387/2 , 650)); 
	UIm.Pages["level"]["Back"] = DBOXUICreateButton(&UIm , "Menu" , lPoint(1920/2 - 387/2 + 90 , 800)); 

	UIm.Pages["ingame"]["Menu"] = DBOXUICreateButton(&UIm , "Menu" , lPoint(1920/2 - 387/2 + 110 , 830));
	UIm.Pages["paused"]["Resume"] = DBOXUICreateButton(&UIm , "Resume" , lPoint(1280/2 - 387/2 , 500)); 
	UIm.Pages["paused"]["Leave"] = DBOXUICreateButton(&UIm , "Leave" , lPoint(1280/2 - 387/2  , 650)); 
	UIm.Pages["lcompleate"]["Menu"] = DBOXUICreateButton(&UIm , "Menu" , lPoint(1280/2 - 387/2  , 650));
	UIm.Pages["lcompleate"]["label"] = DBOXUICreateLabel(&UIm , lRect(0 , 400 , 1280 , 400) , "Level clear !!!");
	UIm.ActivePage = "prof";
}
Exemple #5
0
    void TorsionAngleContrib::getGrad(double *pos, double *grad) const
    {
      PRECONDITION(dp_forceField,"no owner");
      PRECONDITION(pos,"bad vector");
      PRECONDITION(grad,"bad vector");

      RDGeom::Point3D iPoint(pos[3 * this->d_at1Idx],
        pos[3 * this->d_at1Idx + 1], pos[3 * this->d_at1Idx + 2]);
      RDGeom::Point3D jPoint(pos[3 * this->d_at2Idx],
        pos[3 * this->d_at2Idx + 1], pos[3 * this->d_at2Idx + 2]);
      RDGeom::Point3D kPoint(pos[3 * this->d_at3Idx],
        pos[3 * this->d_at3Idx + 1], pos[3 * this->d_at3Idx + 2]);
      RDGeom::Point3D lPoint(pos[3 * this->d_at4Idx],
        pos[3 * this->d_at4Idx + 1], pos[3 * this->d_at4Idx + 2]);
      double *g1 = &(grad[3 * this->d_at1Idx]);
      double *g2 = &(grad[3 * this->d_at2Idx]);
      double *g3 = &(grad[3 * this->d_at3Idx]);
      double *g4 = &(grad[3 * this->d_at4Idx]);

      RDGeom::Point3D r1 = iPoint - jPoint;
      RDGeom::Point3D r2 = kPoint - jPoint;
      RDGeom::Point3D r3 = jPoint - kPoint;
      RDGeom::Point3D r4 = lPoint - kPoint;
      RDGeom::Point3D t1 = r1.crossProduct(r2);
      RDGeom::Point3D t2 = r3.crossProduct(r4);
      double d1 = t1.length();
      t1 /= d1;
      double d2 = t2.length();
      t2 /= d2;
      if (isDoubleZero(d1) || isDoubleZero(d2)) {
        return;
      }
      double cosPhi = t1.dotProduct(t2);
      double sinPhiSq = 1.0 - cosPhi * cosPhi;
      double sinPhi = ((sinPhiSq > 0.0) ? sqrt(sinPhiSq) : 0.0);
      double sin2Phi = 2.0 * sinPhi * cosPhi;
      double sin3Phi = 3.0 * sinPhi - 4.0 * sinPhi * sinPhiSq;
      // dE/dPhi is independent of cartesians:
      double dE_dPhi = 0.5 * (-(this->d_V1) * sinPhi + 2.0
        * this->d_V2 * sin2Phi - 3.0 * this->d_V3 * sin3Phi);
#if 0
      if(dE_dPhi!=dE_dPhi){
        std::cout << "\tNaN in Torsion("<<this->d_at1Idx<<","<<this->d_at2Idx<<","<<this->d_at3Idx<<","<<this->d_at4Idx<<")"<< std::endl;
        std::cout << "sin: " << sinPhi << std::endl;
        std::cout << "cos: " << cosPhi << std::endl;
      } 
      
#endif
      
      // -------
      // dTheta/dx is trickier:
      double dCos_dT1 = 1.0 / d1 * (t2.x - cosPhi * t1.x);
      double dCos_dT2 = 1.0 / d1 * (t2.y - cosPhi * t1.y);
      double dCos_dT3 = 1.0 / d1 * (t2.z - cosPhi * t1.z);
                                                    
      double dCos_dT4 = 1.0 / d2 * (t1.x - cosPhi * t2.x);
      double dCos_dT5 = 1.0 / d2 * (t1.y - cosPhi * t2.y);
      double dCos_dT6 = 1.0 / d2 * (t1.z - cosPhi * t2.z);
    
      // FIX: use a tolerance here
      // this is hacky, but it's per the
      // recommendation from Niketic and Rasmussen:
      double sinTerm = -dE_dPhi * (isDoubleZero(sinPhi)
        ? (1.0 / cosPhi) : (1.0 / sinPhi));

      g1[0] += sinTerm * (dCos_dT3 * r2.y - dCos_dT2 * r2.z);
      g1[1] += sinTerm * (dCos_dT1 * r2.z - dCos_dT3 * r2.x);
      g1[2] += sinTerm * (dCos_dT2 * r2.x - dCos_dT1 * r2.y);

      g2[0] += sinTerm * (dCos_dT2 * (r2.z - r1.z)
        + dCos_dT3 * (r1.y - r2.y) + dCos_dT5 * (-1.0 * r4.z) + dCos_dT6 * (r4.y));
      g2[1] += sinTerm * (dCos_dT1 * (r1.z - r2.z)
        + dCos_dT3 * (r2.x - r1.x) + dCos_dT4 * (r4.z) + dCos_dT6 * (-1.0 * r4.x));
      g2[2] += sinTerm * (dCos_dT1 * (r2.y - r1.y)
        + dCos_dT2 * (r1.x - r2.x) + dCos_dT4 * (-1.0 * r4.y) + dCos_dT5 * (r4.x));

      g3[0] += sinTerm * (dCos_dT2 * (r1.z) + dCos_dT3 * (-1.0 * r1.y) +
        dCos_dT5 * (r4.z - r3.z) + dCos_dT6 * (r3.y - r4.y));
      g3[1] += sinTerm * (dCos_dT1 * (-1.0 * r1.z) + dCos_dT3 * (r1.x) +
        dCos_dT4 * (r3.z - r4.z) + dCos_dT6 * (r4.x - r3.x));
      g3[2] += sinTerm * (dCos_dT1 * (r1.y) + dCos_dT2 * (-1.0 * r1.x) +
        dCos_dT4 * (r4.y - r3.y) + dCos_dT5 * (r3.x - r4.x));

      g4[0] += sinTerm * (dCos_dT5 * r3.z - dCos_dT6 * r3.y);
      g4[1] += sinTerm * (dCos_dT6 * r3.x - dCos_dT4 * r3.z);
      g4[2] += sinTerm * (dCos_dT4 * r3.y - dCos_dT5 * r3.x);
    }