コード例 #1
0
ファイル: generic.cpp プロジェクト: Antipina/OpenBabel-BFGS
 //
 // member functions for OBUnitCell class
 //
 OBUnitCell::OBUnitCell():
   OBGenericData("UnitCell", OBGenericDataType::UnitCell),
   _mOrtho(matrix3x3()),
   _mOrient(matrix3x3()),
   _offset(vector3()),
   _spaceGroupName(""), _spaceGroup( NULL ),
   _lattice(Undefined)
 {  }
コード例 #2
0
ファイル: generic.cpp プロジェクト: Antipina/OpenBabel-BFGS
 //! Implements <a href="http://qsar.sourceforge.net/dicts/blue-obelisk/index.xhtml#calculateOrthogonalisationMatrix">blue-obelisk:calculateOrthogonalisationMatrix</a>
 void OBUnitCell::SetData(const double a, const double b, const double c,
                          const double alpha, const double beta, const double gamma)
 {
   _mOrtho.FillOrth(alpha, beta, gamma, a, b, c);
   _mOrient = matrix3x3(1);
   _spaceGroup = NULL;
   _spaceGroupName = "";
   _lattice = OBUnitCell::Undefined;
 }
コード例 #3
0
ファイル: rendermodel.cpp プロジェクト: FanMist/Faned-Server
void rdlimitrot(int *t1, int *t2, float *maxangle, float *qx, float *qy, float *qz, float *qw)
{
    checkragdoll;
    ragdollskel::rotlimit &r = ragdoll->rotlimits.add();
    r.tri[0] = *t1;
    r.tri[1] = *t2;
    r.maxangle = *maxangle * RAD;
    r.middle = matrix3x3(quat(*qx, *qy, *qz, *qw));
}
コード例 #4
0
ファイル: rendermodel.cpp プロジェクト: Blarget2/OF-Engine
void rdlimitrot(int t1, int t2, float maxangle, float qx, float qy, float qz, float qw)
{
    checkragdoll;
    ragdollskel::rotlimit &r = ragdoll->rotlimits.add();
    r.tri[0] = t1;
    r.tri[1] = t2;
    r.maxangle = maxangle * RAD;
    r.middle = matrix3x3(quat(qx, qy, qz, qw));
}
コード例 #5
0
void SceneGraph::set_local_rotation(TransformInstance i, const Quaternion& rot)
{
	_data.local[i.i].rotation = matrix3x3(rot);
	set_local(i);
}
コード例 #6
0
ファイル: Matrix.cpp プロジェクト: ServerGame/GameEngine
/**
 ****************************************************************************************************
	\fn			void UnitTest( void )
	\brief		The unit test of Matrix class
	\param		NONE
	\return		NONE
 ****************************************************************************************************
*/
void GameEngine::Math::Matrix::UnitTest( void )
{
	FUNCTION_START;

	Matrix matrix2x2( 2, 2 );

	// Check creation
	for( UINT8 i = 0; i < 2; ++i )
	{
		for( UINT8 j = 0; j < 2; ++j )
			assert( matrix2x2(i, j) == 0 );
	}

	// Check matrix identity
	matrix2x2(0, 0) = 1;
	matrix2x2(0, 1) = 2;
	matrix2x2(1, 0) = 3;
	matrix2x2(1, 1) = 4;
	Matrix identityMatrix( 2, 2 );
	identityMatrix(0, 0) = 1;
	identityMatrix(1, 1) = 1;
	Matrix m( 2, 2 );
	m = matrix2x2.Identity();
	assert( matrix2x2.Identity() == identityMatrix );

	// Check matrix transpose
	Matrix matrix2x3( 2, 3 );
	matrix2x3( 0, 0 ) = 1;
	matrix2x3( 0, 1 ) = 2;
	matrix2x3( 0, 2 ) = 3;
	matrix2x3( 1, 0 ) = 4;
	matrix2x3( 1, 1 ) = 5;
	matrix2x3( 1, 2 ) = 6;
	matrix2x3.Transpose();
	Matrix matrix3x2( 3, 2 );
	matrix3x2( 0, 0 ) = 1;
	matrix3x2( 0, 1 ) = 4;
	matrix3x2( 1, 0 ) = 2;
	matrix3x2( 1, 1 ) = 5;
	matrix3x2( 2, 0 ) = 3;
	matrix3x2( 2, 1 ) = 6;
	assert( matrix2x3 == matrix3x2 );

	// Check matrix 3x3 inverse
	Matrix matrix3x3( 3, 3 );
	matrix3x3( 0, 0 ) = 2;
	matrix3x3( 0, 1 ) = -1;
	matrix3x3( 0, 2 ) = 3;
	matrix3x3( 1, 0 ) = 1;
	matrix3x3( 1, 1 ) = 6;
	matrix3x3( 1, 2 ) = -4;
	matrix3x3( 2, 0 ) = 5;
	matrix3x3( 2, 1 ) = 0;
	matrix3x3( 2, 2 ) = 8;
	Matrix matrix3x3Inverse( 3, 3 );
	Matrix3Inverse( matrix3x3, matrix3x3Inverse );
	assert( (matrix3x3 * matrix3x3Inverse) == matrix3x3.Identity() );

	// Check matrix 4x4 inverse
	Matrix matrix4x4( 4, 4 );
	matrix4x4( 0, 0 ) = 2;
	matrix4x4( 0, 1 ) = 3;
	matrix4x4( 0, 2 ) = 4;
	matrix4x4( 0, 3 ) = 5;
	matrix4x4( 1, 0 ) = 5;
	matrix4x4( 1, 1 ) = 7;
	matrix4x4( 1, 2 ) = 9;
	matrix4x4( 1, 3 ) = 9;
	matrix4x4( 2, 0 ) = 5;
	matrix4x4( 2, 1 ) = 8;
	matrix4x4( 2, 2 ) = 7;
	matrix4x4( 2, 3 ) = 4;
	matrix4x4( 3, 0 ) = 4;
	matrix4x4( 3, 1 ) = 3;
	matrix4x4( 3, 2 ) = 3;
	matrix4x4( 3, 3 ) = 2;
	Matrix matrix4x4Inverse( 4, 4 );
	Matrix4Inverse( matrix4x4, matrix4x4Inverse );
	Matrix matrix4x4Result( 4, 4 );
	matrix4x4Result = matrix4x4 * matrix4x4Inverse;
	assert( (matrix4x4 * matrix4x4Inverse) == matrix4x4.Identity() );

	FUNCTION_FINISH;
}
コード例 #7
0
ファイル: r_particle.cpp プロジェクト: XashDev/XashXT
AURSTATE CParticleSystem :: UpdateSystem( float frametime )
{
	if( m_pEntity != NULL )
	{
		// don't update if the system is outside the player's PVS.
		if( m_pEntity->curstate.messagenum != r_currentMessageNum )
		{
			// but always update rocket particles
			if( !FBitSet( m_pEntity->curstate.effects, EF_NUKE_ROCKET ))
				return AURORA_INVISIBLE;
		}

		// time-based particle system
		if( m_fLifeTime != 0.0f )
		{
			enable = (m_fLifeTime >= RI.refdef.time) ? true : false;
		}
		else
		{
			enable = (m_pEntity->curstate.renderfx == kRenderFxAurora) ? true : false;
		}

		// check for contents to remove
		if( m_iKillCondition == POINT_CONTENTS( m_pEntity->origin ))
          	{
			m_pEntity = NULL;
          		enable = false;
          	}
	}
	else
	{
		enable = false;
	}

	if( m_pEntity != NULL )
	{
		Vector angles = m_pEntity->angles;

		// get the system entity matrix
		if( m_iEntAttachment && m_pEntity->model->type == mod_studio )
			entityMatrix.FromVector( R_StudioAttachmentDir( m_pEntity, m_iEntAttachment - 1 ));
		else entityMatrix = matrix3x3( angles );
	}

	if( m_pMainParticle == NULL )
	{
		if( enable )
		{
			CParticleType *pType = m_pMainType;

			if( pType )
			{
				m_pMainParticle = pType->CreateParticle( this );

				if( m_pMainParticle )
				{
					// first origin initialize
					if( m_iEntAttachment && m_pEntity->model->type == mod_studio )
						m_pMainParticle->origin = R_StudioAttachmentPos( m_pEntity, m_iEntAttachment - 1 );
					else m_pMainParticle->origin = m_pEntity->origin;

					m_pMainParticle->m_pEntity = m_pEntity;
					m_pMainParticle->age_death = -1.0f; // never die
				}
			}
		}
	}
	else if( !enable )
	{
		MarkForDeletion();
	}

	// last particle is died, allow to remove partsystem
	if( !m_pEntity && !m_pActiveParticle )
		return AURORA_REMOVE;

	CParticle	*pParticle = m_pActiveParticle;
	CParticle	*pLast = NULL;

	while( pParticle )
	{
		if( UpdateParticle( pParticle, frametime ))
		{
			pLast = pParticle;
			pParticle = pParticle->nextpart;
		}
		else
		{
			// deactivate it
			if( pLast )
			{
				pLast->nextpart = pParticle->nextpart;
				pParticle->nextpart = m_pFreeParticle;
				m_pFreeParticle = pParticle;
				pParticle = pLast->nextpart;
			}
			else
			{
				// deactivate the first CParticle in the list
				m_pActiveParticle = pParticle->nextpart;
				pParticle->nextpart = m_pFreeParticle;
				m_pFreeParticle = pParticle;
				pParticle = m_pActiveParticle;
			}
		}
	}

	return AURORA_DRAW;
}
コード例 #8
0
ファイル: pwscfformat.cpp プロジェクト: Reinis/openbabel
  bool PWscfFormat::ReadMolecule(OBBase* pOb, OBConversion* pConv)
  {
    OBMol* pmol = pOb->CastAndClear<OBMol>();
    if(pmol==NULL)
      return false;

    //Define some references so we can use the old parameter names
    istream &ifs = *pConv->GetInStream();

    char buffer[BUFF_SIZE], tag[BUFF_SIZE];
    double x,y,z;
    double alat = 1.0;
    vector<string> vs;
    matrix3x3 ortho;
    int atomicNum;
    OBUnitCell *cell = new OBUnitCell();
    bool hasEnthalpy=false;
    double enthalpy, pv;

    pmol->BeginModify();

    while (ifs.getline(buffer,BUFF_SIZE)) {

      // Older version of pwscf may use this for alat
      if (strstr(buffer, "lattice parameter (a_0)")) {
        tokenize(vs, buffer);
        alat = atof(vs.at(4).c_str());
      }

      // Newer versions will use this for alat instead
      if (strstr(buffer, "lattice parameter (alat)")) {
        tokenize(vs, buffer);
        alat = atof(vs.at(4).c_str());
      }

      // Unit cell info
      // Newer versions will also say "CELL_PARAMETERS" to complain that no
      // units were specified
      if (strstr(buffer, "CELL_PARAMETERS") &&
          !strstr(buffer, "no units specified in CELL_PARAMETERS card")) {
        // Discover units
        double conv = 1.0;
        tokenize(vs, buffer);

        if (strstr(vs[1].c_str(), "alat")) {
          conv = alat * BOHR_TO_ANGSTROM;
        }
        else if (strstr(vs[1].c_str(), "bohr")) {
          conv = BOHR_TO_ANGSTROM;
        }
        // Add others if needed

        double v11, v12, v13,
          v21, v22, v23,
          v31, v32, v33;

        ifs.getline(buffer,BUFF_SIZE); // v1
        tokenize(vs, buffer);
        v11 = atof(vs.at(0).c_str()) * conv;
        v12 = atof(vs.at(1).c_str()) * conv;
        v13 = atof(vs.at(2).c_str()) * conv;

        ifs.getline(buffer,BUFF_SIZE); // v2
        tokenize(vs, buffer);
        v21 = atof(vs.at(0).c_str()) * conv;
        v22 = atof(vs.at(1).c_str()) * conv;
        v23 = atof(vs.at(2).c_str()) * conv;

        ifs.getline(buffer,BUFF_SIZE); // v3
        tokenize(vs, buffer);
        v31 = atof(vs.at(0).c_str()) * conv;
        v32 = atof(vs.at(1).c_str()) * conv;
        v33 = atof(vs.at(2).c_str()) * conv;

        // Build unit cell
        cell->SetData(vector3(v11,v12,v13),
                      vector3(v21,v22,v23),
                      vector3(v31,v32,v33));
      }

      // Unit cell info (for non-variable cell calcs)
      if (strstr(buffer, "crystal axes: (cart. coord. in units of a_0)") ||
          strstr(buffer, "crystal axes: (cart. coord. in units of alat)")) {
        double conv = alat * BOHR_TO_ANGSTROM;
        double v11, v12, v13,
          v21, v22, v23,
          v31, v32, v33;

        ifs.getline(buffer,BUFF_SIZE); // v1
        tokenize(vs, buffer);
        v11 = atof(vs.at(3).c_str()) * conv;
        v12 = atof(vs.at(4).c_str()) * conv;
        v13 = atof(vs.at(5).c_str()) * conv;

        ifs.getline(buffer,BUFF_SIZE); // v2
        tokenize(vs, buffer);
        v21 = atof(vs.at(3).c_str()) * conv;
        v22 = atof(vs.at(4).c_str()) * conv;
        v23 = atof(vs.at(5).c_str()) * conv;

        ifs.getline(buffer,BUFF_SIZE); // v3
        tokenize(vs, buffer);
        v31 = atof(vs.at(3).c_str()) * conv;
        v32 = atof(vs.at(4).c_str()) * conv;
        v33 = atof(vs.at(5).c_str()) * conv;

        // Build unit cell
        cell->SetData(vector3(v11,v12,v13),
                      vector3(v21,v22,v23),
                      vector3(v31,v32,v33));
      }

      // Atoms info
      if (strstr(buffer, "ATOMIC_POSITIONS")) {
        // Clear old atoms from pmol
        vector<OBAtom*> toDelete;
        FOR_ATOMS_OF_MOL(a, *pmol)
          toDelete.push_back(&*a);
        for (size_t i = 0; i < toDelete.size(); i++)
          pmol->DeleteAtom(toDelete.at(i));


        // Discover units
        matrix3x3 conv (1);
        tokenize(vs, buffer);

        if (strstr(vs[1].c_str(), "alat")) {
          conv *= (alat * BOHR_TO_ANGSTROM);
        }
        else if (strstr(vs[1].c_str(), "crystal")) {
          // Set to the zero matrix and test below.
          conv = matrix3x3 (0.0);
        }
        // Add others if needed

        // Load new atoms from molecule
        ifs.getline(buffer,BUFF_SIZE); // First entry
        tokenize(vs, buffer);
        int size = vs.size();
        while (size == 4) {
          atomicNum = OBElements::GetAtomicNum(vs[0].c_str());
          x = atof((char*)vs[1].c_str());
          y = atof((char*)vs[2].c_str());
          z = atof((char*)vs[3].c_str());
          // Add atom
          OBAtom *atom = pmol->NewAtom();
          atom->SetAtomicNum(atomicNum);
          vector3 coords (x,y,z);
          if (conv.determinant() == 0.0) { // Fractional coords
            atom->SetVector(cell->FractionalToCartesian(coords));
          }
          else {
            atom->SetVector(conv * coords);
          }

          // Reset vars
          ifs.getline(buffer,BUFF_SIZE); // First entry
          tokenize(vs, buffer);
          size = vs.size();
        }
      }

      // Free energy
      if (strstr(buffer, "Final energy =")) {
        tokenize(vs, buffer);
        pmol->SetEnergy(atof(vs[3].c_str()) * RYDBERG_TO_KCAL_PER_MOL);
      }

      // H - PV = U energy
      if (strstr(buffer, "!    total energy              =")) {
        tokenize(vs, buffer);
        pmol->SetEnergy(atof(vs[4].c_str()) * RYDBERG_TO_KCAL_PER_MOL);
      }

      // Enthalphy
      if (strstr(buffer, "Final enthalpy =")) {
        tokenize(vs, buffer);

        hasEnthalpy = true;
        enthalpy = atof(vs.at(3).c_str()) * RYDBERG_TO_KCAL_PER_MOL;
        pv = enthalpy - pmol->GetEnergy();
      }
    }

    // set final unit cell
    pmol->SetData(cell);

    // Set enthalpy
    if (hasEnthalpy) {
      OBPairData *enthalpyPD = new OBPairData();
      OBPairData *enthalpyPD_pv = new OBPairData();
      OBPairData *enthalpyPD_eV = new OBPairData();
      OBPairData *enthalpyPD_pv_eV = new OBPairData();
      enthalpyPD->SetAttribute("Enthalpy (kcal/mol)");
      enthalpyPD_pv->SetAttribute("Enthalpy PV term (kcal/mol)");
      enthalpyPD_eV->SetAttribute("Enthalpy (eV)");
      enthalpyPD_pv_eV->SetAttribute("Enthalpy PV term (eV)");
      double en_kcal_per_mole = enthalpy;
      double pv_kcal_per_mole = pv;
      double en_eV = enthalpy / EV_TO_KCAL_PER_MOL;
      double pv_eV = pv / EV_TO_KCAL_PER_MOL;
      snprintf(tag, BUFF_SIZE, "%f", en_kcal_per_mole);
      enthalpyPD->SetValue(tag);
      snprintf(tag, BUFF_SIZE, "%f", pv_kcal_per_mole);
      enthalpyPD_pv->SetValue(tag);
      snprintf(tag, BUFF_SIZE, "%f", en_eV);
      enthalpyPD_eV->SetValue(tag);
      snprintf(tag, BUFF_SIZE, "%f", pv_eV);
      enthalpyPD_pv_eV->SetValue(tag);
      pmol->SetData(enthalpyPD);
      pmol->SetData(enthalpyPD_pv);
      pmol->SetData(enthalpyPD_eV);
      pmol->SetData(enthalpyPD_pv_eV);
    }

    pmol->EndModify();

    return true;
  }