bool SIMPLEAPI ExpandResponseFiles(CVector<CUniString>& args, CUniString& strError)
{
	for (int i=0; i<args.GetSize(); i++)
	{
		const wchar_t* pszFile=args[i];

		// Commented switch
		if (pszFile[0]=='#')
		{
			args.RemoveAt(i);
			i--;
			continue;
		}

		// Response file?
		if (pszFile[0]=='@')
		{
			pszFile++;

			bool bOptional=false;
			if (pszFile[0]=='@')
			{
				bOptional++;
				pszFile++;
			}

			// Load response file
			CUniString strResponseText;
			if (!LoadTextFile<wchar_t>(pszFile, strResponseText))
			{
				args.RemoveAt(i);
				i--;
				if (bOptional)
					continue;

				strError=Format(L"Failed to load response file '%s'", pszFile);
				return false;
			}

			// Parse args
			CVector<CUniString> vecFile;
			SplitCommandLine(strResponseText, vecFile);

			args.RemoveAt(i);
			args.InsertAt(i, vecFile);
			i--;
		}
	}

	return true;
}
RawDataInput_M CellInitHelper::generateRawInput_M() {
	RawDataInput_M rawData;
	rawData.simuType = simuType;
	vector<CVector> insideCellCenters;
	vector<CVector> outsideBdryNodePos;
	std::string bdryInputFileName = globalConfigVars.getConfigValue(
			"Bdry_InputFileName").toString();

	GEOMETRY::MeshGen meshGen;

	GEOMETRY::UnstructMesh2D mesh = meshGen.generateMesh2DFromFile(
			bdryInputFileName);

	std::vector<GEOMETRY::Point2D> insideCenterCenters =
			mesh.getAllInsidePoints();

	uint initCellCt = insideCenterCenters.size();

	for (uint i = 0; i < initCellCt; i++) {
		insideCellCenters.push_back(
				CVector(insideCenterCenters[i].getX(),
						insideCenterCenters[i].getY(), 0));
	}

	double randNum;
	double progDivStart =
			globalConfigVars.getConfigValue("GrowthPrgrCriVal").toDouble();
	for (uint i = 0; i < initCellCt; i++) {
		randNum = (double) rand() / ((double) RAND_MAX + 1) * progDivStart;
		//std::cout << "rand init growth progress = " << randNum << std::endl;
		rawData.cellGrowProgVec.push_back(randNum);
	}

	std::cout << "Printing initial cell center positions ......" << std::endl;
	for (unsigned int i = 0; i < insideCellCenters.size(); i++) {
		CVector centerPos = insideCellCenters[i];
		rawData.initCellCenters.push_back(centerPos);
		std::cout << "    ";
		centerPos.Print();
	}

	generateCellInitNodeInfo_v3(rawData.initCellCenters,
			rawData.cellGrowProgVec, rawData.initMembrNodePoss,
			rawData.initIntnlNodePoss);

	//std::cout << "finished generate raw data" << std::endl;
	//std::cout.flush();

	rawData.isStab = true;
	return rawData;
}
Exemple #3
0
void CMapGridPainter::AddRegion (const CVector &vCenter, Metric rWidth, Metric rHeight)

//	AddRegion
//
//	Adds a rectangular region to paint. We combine this appropriately with any
//	previously added regions.

	{
	int x, y;

	Metric rHalfWidth = 0.5 * rWidth;
	Metric rHalfHeight = 0.5 * rHeight;

	int xFrom = (int)floor((vCenter.GetX() - rHalfWidth) / GRID_SIZE);
	int xTo = (int)floor((vCenter.GetX() + rHalfWidth) / GRID_SIZE);
	int yFrom = (int)floor((vCenter.GetY() - rHalfHeight) / GRID_SIZE);
	int yTo = (int)floor((vCenter.GetY() + rHalfHeight) / GRID_SIZE);

	//	Null case

	if (xFrom == xTo || yFrom == yTo)
		return;

	//	Start with vertical lines

	TArray<SLine> NewLines;
	for (x = xFrom; x <= xTo; x++)
		{
		SLine *pNewLine = NewLines.Insert();
		pNewLine->xyKey = x;
		pNewLine->xyFrom = yFrom;
		pNewLine->xyTo = yTo;
		}

	AddLines(NewLines, &m_VertLines);

	//	Add horizontal lines

	NewLines.DeleteAll();
	for (y = yFrom; y <= yTo; y++)
		{
		SLine *pNewLine = NewLines.Insert();
		pNewLine->xyKey = y;
		pNewLine->xyFrom = xFrom;
		pNewLine->xyTo = xTo;
		}

	AddLines(NewLines, &m_HorzLines);

	m_bRecalcNeeded = true;
	}
void Integration::TemporalIteration(Config *config, Structure *structure){

  double epsilon = 1e-6;

  /*--- Prediction phase ---*/
  qddot->Reset();

  a->Reset();
  *a += ScalVecProd(alpha_f/(1-alpha_m),qddot_n);
  *a -= ScalVecProd(alpha_m/(1-alpha_m),a_n);

  *q = *q_n;
  *q += ScalVecProd(deltaT,qdot_n);
  *q += ScalVecProd((0.5-beta)*deltaT*deltaT,a_n);
  *q += ScalVecProd(deltaT*deltaT*beta,a);

  *qdot = *qdot_n;
  *qdot += ScalVecProd((1-gamma)*deltaT,a_n);
  *qdot += ScalVecProd(deltaT*gamma,a);

  /*--- Tangent operator and corrector computation ---*/
  CVector* res;
  CVector* Deltaq;
  CMatrix* St;
  res = new CVector(qddot->GetSize(),double(0));
  Deltaq = new CVector(qddot->GetSize(),double(0));
  St = new CMatrix(qddot->GetSize(),qddot->GetSize(),double(0));
  ComputeResidual(structure->GetM(),structure->GetC(),structure->GetK(),res);
  while (res->norm() >= epsilon){
    St->Reset();
    ComputeTangentOperator(structure,St);
    SolveSys(St,res);
    //*res -= ScalVecProd(double(2),res); //=deltaq
    *Deltaq += ScalVecProd(-1,res);
    *q += *Deltaq;
    *qdot += ScalVecProd(gammaPrime,Deltaq);
    *qddot += ScalVecProd(betaPrime,Deltaq);
    res->Reset();
    Deltaq->Reset();
    ComputeResidual(structure->GetM(),structure->GetC(),structure->GetK(),res);
  }
  //cout << (*q)[0] << endl;
  *a += ScalVecProd((1-alpha_f)/(1-alpha_m),qddot);

  delete res;
  delete Deltaq;
  delete St;
  Deltaq = NULL;
  res = NULL;
  St = NULL;
}
Exemple #5
0
void VectorToTile (const CVector &vPos, int *retx, int *rety)

//	VectorToTile
//
//	Converts from a vector to space environment tile coordinates

	{
	//	This algorithm is designed for only two levels; change
	//	if seaScale changes.
	ASSERT(seaScale == 1);

	*retx = (int)(((vPos.GetX() / g_KlicksPerPixel) / seaTileSize) + (seaArraySize * seaArraySize / 2));
	*rety = (int)(((-vPos.GetY() / g_KlicksPerPixel) / seaTileSize) + (seaArraySize * seaArraySize / 2));
	}
Exemple #6
0
void CAcmUdp::GetAllDomains(CVector<uint32> &oDomains)
{
	oDomains.Clear();
	CRbTreeNode* pEnd = g_oUdpTable.End();
	g_oMutex.Enter();
	CRbTreeNode* pIt = g_oUdpTable.First();
	for(uint32 nIdx=0; pIt!=pEnd; pIt=g_oUdpTable.GetNext(pIt))
	{
		uint32 nDomain = g_oUdpTable.GetKey(pIt);
		oDomains.Insert(nIdx, nDomain);
		++nIdx;
	}
	g_oMutex.Leave();
}
Exemple #7
0
void CLine::project(const CVector &inV,CVector &outV)
{
	CVector seg = V1 - V0;
	float n = seg.sqrnorm();
	if (n == 0.f)
	{
		outV = V0;
	}
	else
	{
		float dp = (inV - V0) * seg;
		outV = V0 + (dp /  n) * seg;
	}
}
Exemple #8
0
//===================================================================================
//	Compute intersection of a line and a plane
//	Line is defined by the points PA and PB
//	Plane is defined by the normal vector NP and a point PP
//===================================================================================
void CIntersector::GetLineToPlane()
{	rc	= 0;														// No intersection
	CVector U = *PB - *PA;
	CVector W = *PA -  PP;
	double  N = -NP.DotProduct(W);
	double  D =  NP.DotProduct(U);
	if (fabs(D) < DBL_EPSILON)	return;
	//---- Compute intersection ------------------
	double  S = N / D;
	U.Times(S);
	PR.Sum(*PA,U);
	rc = (S > 0)?(1):(2);
	return;
}
Exemple #9
0
// The 1/exp function for vectors
CVector &Exp_1(CVector &vec) {
  CVector *pvecExp;
  if(! vec.Defined()) {throw ELENotDefined; }
  
  pvecExp = new CVector(vec.m_pnDimSize[0]);		// Make a deep copy of the original
  pvecExp->SetAllocated(true);		// We allocated the memory space
  
  for(int i=0; i<vec.m_pnDimSize[0]; i++) {
    (*pvecExp)[i] = exp(0.0-double(vec[i]));
  }

  if(vec.Allocated()) {delete &vec; } // This should call for the destructor
  return *pvecExp;
} // Exp_1
Exemple #10
0
void CGnomon::MakeNewStartConditions(Earth::CEarth &Mod)
{
	// храним посчитанную часть года на будущее
	earthPosition_Day.add_toEnd(Mod.getResult());

	// Подготовка второго этапа
	CVector forStart;
	forStart = Mod.getLastResult();
	forStart.pop_back();	// вырезали время из вектора
	Mod.clearResult();	// очистили контейнер результатов перед вторым этапом

	Mod.setStart(forStart);
	Mod.set_t0(Mod.get_t1());
}
Exemple #11
0
//register_native(const name[], const handler[])
static cell AMX_NATIVE_CALL register_native(AMX *amx, cell *params)
{
	if (!g_Initialized)
		amxx_DynaInit((void *)(amxx_DynaCallback));

	g_Initialized = true;

	int len;
	char *name = get_amxstring(amx, params[1], 0, len);
	char *func = get_amxstring(amx, params[2], 1, len);

	int idx, err;
	if ( (err=amx_FindPublic(amx, func, &idx)) != AMX_ERR_NONE)
	{
		LogError(amx, err, "Function \"%s\" was not found", func);
		return 0;
	}

	regnative *pNative = new regnative;
	pNative->amx = amx;
	pNative->func = idx;
	
	//we'll apply a safety buffer too
	//make our function
	int size = amxx_DynaCodesize();
#if defined(_WIN32)
	DWORD temp;
	pNative->pfn = new char[size + 10];
	VirtualProtect(pNative->pfn, size+10, PAGE_EXECUTE_READWRITE, &temp);
#elif defined(__GNUC__)
# if defined(__APPLE__)
	pNative->pfn = (char *)valloc(size+10);
# else
	pNative->pfn = (char *)memalign(sysconf(_SC_PAGESIZE), size+10);
# endif
	mprotect((void *)pNative->pfn, size+10, PROT_READ|PROT_WRITE|PROT_EXEC);
#endif

	int id = (int)g_RegNatives.size();
	
	amxx_DynaMake(pNative->pfn, id);
	pNative->func = idx;
	pNative->style = params[3];

	g_RegNatives.push_back(pNative);

	pNative->name.assign(name);

	return 1;
}
Exemple #12
0
// The arcsin function for vectors
CVector &Fabs(CVector &vec) {
  CVector *pvecArcSin;
  if(! vec.Defined()) {throw ELENotDefined; }
  
  pvecArcSin = new CVector(vec.m_pnDimSize[0]);		// Make a deep copy of the original
  pvecArcSin->SetAllocated(true);		// We allocated the memory space

  for(int i=0; i<vec.m_pnDimSize[0]; i++) {
    (*pvecArcSin)[i] = fabs(double(vec[i]));
  }

  if(vec.Allocated()) {delete &vec; } // This should call for the destructor
  return *pvecArcSin;
} // Fabs
void CAniRoundedRect::GetSpacingRect (RECT *retrcRect)

//	GetSpacingRect
//
//	Returns the size

	{
	CVector vScale = m_Properties[INDEX_SCALE].GetVector();

	retrcRect->left = 0;
	retrcRect->top = 0;
	retrcRect->right = (int)vScale.GetX();
	retrcRect->bottom = (int)vScale.GetY();
	}
Exemple #14
0
void SphereForce::evalRepulsiveForce(Cell & c1, const Sphere & s)
{
    float overlap=fmax(((c1.getCoord().distanceTo(s.getCentroid())+c1.getRadius())-s.getRadius()),0.0f);
    CVector cv;
    if(overlap==0.0f) {
        this->setValueXyz(cv);
        return;
    }
    std::cout<<c1.getID()<<"---"<<overlap<<std::endl;
    //cv=(c1.getCoord()/fmax(c1.getCoord().getAbsoluteMax(),1))*overlap;
    cv=c1.getCoord();
    cv = cv/sqrt(pow(cv.getX(),2)+pow(cv.getY(),2)+pow(cv.getZ(),2));
    //cv=cv*(overlap/(c1.getCoord().distanceTo(s.getCentroid())+c1.getRadius())); // utiliser fraction de la distance pour scaler
    cv.reverseSign();
    c1.resetBoxCol();
    /*if(strcmp(c1.getID().c_str(),"4")==1){

    	std::cout<<c1.getID().c_str()<<"overlap :"<<overlap<<"--"<<c1.getCoord().distanceTo(s.getCentroid())<<"\n fact : "<<(overlap/(c1.getCoord().distanceTo(s.getCentroid())+c1.getRadius()))<<"\nVecteur : "<<std::endl;
    	cv.print();
    	c1.getCoord().print();
    }*/
    if(cv.getX()>0.0f) c1.setWl(true);
    if(cv.getX()<0.0f) c1.setWr(true);
    if(cv.getY()>0.0f) c1.setHl(true);
    if(cv.getY()<0.0f) c1.setHr(true);
    if(cv.getZ()>0.0f) c1.setDl(true);
    if(cv.getZ()<0.0f) c1.setDr(true);
    this->setValueXyz((cv*overlap*REPULSIVE_CONST));
}
void CBitPatternTreeMethod::getUnsetBitIndexes(const CStepMatrixColumn * pColumn,
    CVector< size_t > & indexes) const
{
  mpStepMatrix->getUnsetBitIndexes(pColumn, indexes);

  // Apply the QR pivot
  size_t * pIndex = indexes.array();
  size_t * pIndexEnd = pIndex + indexes.size();

  for (; pIndex != pIndexEnd; ++pIndex)
    {
      *pIndex = mReactionPivot[*pIndex];
    }
}
void CAniRoundedRect::GetContentRect (RECT *retrcRect)

//	GetContentRect
//
//	Returns a RECT of the content area (relative to the rect itself)

	{
	CVector vScale = m_Properties[INDEX_SCALE].GetVector();

	retrcRect->left = PADDING_LEFT;
	retrcRect->top = PADDING_TOP;
	retrcRect->right = (int)vScale.GetX() - PADDING_RIGHT;
	retrcRect->bottom = (int)vScale.GetY() - PADDING_BOTTOM;
	}
void SpringForceGenerator::Update( double timelapse )
{
	CVector springVecToOther = F::VECTOR::GetVectorFromAToB(p1->position, p2->position);
	double currSpringLenght = springVecToOther.Length();
	springVecToOther.Normalise();

	double springLenghtDiff = currSpringLenght - restLenght;

	if((springLenghtDiff < 0) && noPush)
		return;

	double tempEk = elasticityKoef;
	double tempDk = dampingKoef;

	if(springLenghtDiff>0)
	{
		//dampingKoef = 300;
		//elasticityKoef = 400;
	}

	CVector force = elasticityKoef*springLenghtDiff*springVecToOther;



	//////////////////////////////////////////////////////

	CLine springBearing(springVecToOther);

	CVector p1VelocityComponentToSpring = F::VECTOR::GetVectorComponentToLine(springBearing, p1->velocity);
	CVector p2VelocityComponentToSpring = F::VECTOR::GetVectorComponentToLine(springBearing, p2->velocity);
	CVector dampingForce = F::VECTOR::GetVectorFromAToB(p1VelocityComponentToSpring,p2VelocityComponentToSpring);
	dampingForce*= dampingKoef;

	//////////////////////////////////////////
	if(workMode == 0)
	{
		p1->AddForce(force + dampingForce);
		p2->AddForce(-force - dampingForce);
	//	return;
	}
	
	if(workMode == 1)
		p1->AddForce(force);

	if(workMode == 2)
		p1->AddForce(-force);

	elasticityKoef = tempEk;
	dampingKoef = tempDk;
}
Exemple #18
0
//-----------------------------------------------
// currentView :
// Set the user position.
//-----------------------------------------------
CVector CView::currentView() const
{
	if(_RearView)
	{
		CVector v;
		v.x = -UserEntity->front().x;
		v.y = -UserEntity->front().y;
		v.z = 0.0f;
		v.normalize();
		return v;
	}
	else
		return _View;
}// currentView //
Exemple #19
0
void CServerDlg::OnTimer()
{
    CVector<CHostAddress> vecHostAddresses;
    CVector<QString>      vecsName;
    CVector<int>          veciJitBufNumFrames;
    CVector<int>          veciNetwFrameSizeFact;

    ListViewMutex.lock();
    {
        pServer->GetConCliParam ( vecHostAddresses,
                                  vecsName,
                                  veciJitBufNumFrames,
                                  veciNetwFrameSizeFact );

        // we assume that all vectors have the same length
        const int iNumChannels = vecHostAddresses.Size();

        // fill list with connected clients
        for ( int i = 0; i < iNumChannels; i++ )
        {
            if ( !( vecHostAddresses[i].InetAddr == QHostAddress ( (quint32) 0 ) ) )
            {
                // IP, port number
                vecpListViewItems[i]->setText ( 0,
                    vecHostAddresses[i].toString ( CHostAddress::SM_IP_PORT ) );

                // name
                vecpListViewItems[i]->setText ( 1, vecsName[i] );

                // jitter buffer size (polling for updates)
                vecpListViewItems[i]->setText ( 2,
                    QString().setNum ( veciJitBufNumFrames[i] ) );

                // out network block size
                vecpListViewItems[i]->setText ( 3,
                    QString().setNum ( static_cast<double> (
                    veciNetwFrameSizeFact[i] * SYSTEM_BLOCK_DURATION_MS_FLOAT
                    ), 'f', 2 ) );

                vecpListViewItems[i]->setHidden ( false );
            }
            else
            {
                vecpListViewItems[i]->setHidden ( true );
            }
        }
    }
    ListViewMutex.unlock();
}
Exemple #20
0
void CClientSound::Process3D ( CVector vecPosition, CVector vecLookAt )
{
    if ( !m_b3D ) return;

    // Update our position/rotation if we're attached
    DoAttaching ();

    if ( m_pSound )
    {
        // Pan
        CVector vecLook = vecLookAt - vecPosition;
        CVector vecSound = m_vecPosition - vecPosition;
        vecLook.fZ = vecSound.fZ = 0.0f;
        vecLook.Normalize ();
        vecSound.Normalize ();

        vecLook.CrossProduct ( &vecSound );
        // The length of the cross product (which is simply fZ in this case)
        // is equal to the sine of the angle between the vectors
        float fPan = vecLook.fZ;
        if ( fPan < -1.0f + SOUND_PAN_THRESHOLD )
            fPan = -1.0f + SOUND_PAN_THRESHOLD;
        else if ( fPan > 1.0f - SOUND_PAN_THRESHOLD )
            fPan = 1.0f - SOUND_PAN_THRESHOLD;

        m_pSound->setPan ( fPan );

        // Volume
        float fDistance = DistanceBetweenPoints3D ( vecPosition, m_vecPosition );
        float fSilenceDistance = m_fMinDistance * 20.0f;
        float fVolume = 1.0;

        if ( fDistance <= m_fMinDistance )
        {
            fVolume = 1.0f;
        }
        else if ( fDistance >= fSilenceDistance )
        {
            fVolume = 0.0f;
        }
        else
        {
            float fLinear = (fSilenceDistance - fDistance) / fSilenceDistance;
            fVolume = sqrt ( fLinear ) * fLinear;
        }

        m_pSound->setVolume ( m_fVolume * fVolume );
    }
}
RawDataInput CellInitHelper::generateRawInput_stab() {
	RawDataInput rawData;
	rawData.simuType = simuType;
	vector<CVector> insideCellCenters;
	vector<CVector> outsideBdryNodePos;
	std::string bdryInputFileName = globalConfigVars.getConfigValue(
			"Bdry_InputFileName").toString();

	GEOMETRY::MeshGen meshGen;

	GEOMETRY::UnstructMesh2D mesh = meshGen.generateMesh2DFromFile(
			bdryInputFileName);

	std::vector<GEOMETRY::Point2D> insideCenterPoints =
			mesh.getAllInsidePoints();

	double fine_Ratio =
			globalConfigVars.getConfigValue("StabBdrySpacingRatio").toDouble();

	for (uint i = 0; i < insideCenterPoints.size(); i++) {
		insideCellCenters.push_back(
				CVector(insideCenterPoints[i].getX(),
						insideCenterPoints[i].getY(), 0));
	}

	mesh = meshGen.generateMesh2DFromFile(bdryInputFileName, fine_Ratio);

	std::vector<GEOMETRY::Point2D> bdryPoints = mesh.getOrderedBdryPts();

	for (uint i = 0; i < bdryPoints.size(); i++) {
		outsideBdryNodePos.push_back(
				CVector(bdryPoints[i].getX(), bdryPoints[i].getY(), 0));
	}

	for (unsigned int i = 0; i < insideCellCenters.size(); i++) {
		CVector centerPos = insideCellCenters[i];
		rawData.MXCellCenters.push_back(centerPos);
		centerPos.Print();
	}

	for (uint i = 0; i < outsideBdryNodePos.size(); i++) {
		rawData.bdryNodes.push_back(outsideBdryNodePos[i]);
	}

	generateCellInitNodeInfo_v2(rawData.initCellNodePoss);

	rawData.isStab = true;
	return rawData;
}
Exemple #22
0
bool CClientCamera::ProcessFixedCamera ( CCam* pCam )
{
    // The purpose of this handler function is changing the Source, Front and Up vectors in CCam
    // when called by GTA. This is called when we are in fixed camera mode.

    CClientCamera* pThis = g_pClientGame->GetManager ()->GetCamera ();

    // Make sure we actually want to apply our custom camera position/lookat
    // (this handler could also be called from cinematic mode)
    if ( !pThis->m_bFixed )
        return false;

    const CVector& vecPosition = pThis->m_vecFixedPosition;
    const CVector& vecTarget = pThis->m_vecFixedTarget;

    // Set the position in the CCam interface
    *pCam->GetSource () = vecPosition;

    // Calculate the front vector, target - position. If its length is 0 we'll get problems
    // (i.e. if position and target are the same), so make a new vector then looking horizontally
    CVector vecFront = vecTarget - vecPosition;
    if ( vecFront.Length () < FLOAT_EPSILON )
        vecFront = CVector ( 0.0, 1.0f, 0.0f );
    else
        vecFront.Normalize ();

    *pCam->GetFront () = vecFront;

    // Grab the right vector
    CVector vecRight = CVector ( vecFront.fY, -vecFront.fX, 0 );
    if ( vecRight.Length () < FLOAT_EPSILON )
        vecRight = CVector ( 1.0f, 0.0f, 0.0f );
    else
        vecRight.Normalize ();

    // Calculate the up vector from this
    CVector vecUp = vecRight;
    vecUp.CrossProduct ( &vecFront );
    vecUp.Normalize ();

    // Apply roll if needed
    if ( pThis->m_fRoll != 0.0f )
    {
        float fRoll = ConvertDegreesToRadiansNoWrap ( pThis->m_fRoll );
        vecUp = vecUp*cos(fRoll) - vecRight*sin(fRoll);
    }

    *pCam->GetUp () = vecUp;

    // Set the zoom
    pCam->SetFOV ( pThis->m_fFOV );

    return true;
}
//-------------------------------------------------------------------------------------
HRESULT CIsochartMesh::InitializeLSCMEquation(
    CSparseMatrix<double>& A,
    CVector<double>& B,
    CVector<double>& U,
    uint32_t dwBaseVertId1,
    uint32_t dwBaseVertId2)
{
    HRESULT hr = S_OK;
    CSparseMatrix<double> orgA;
    CSparseMatrix<double> M;
    CVector<double> orgB;

    if (!orgA.resize(2*m_dwFaceNumber, (m_dwVertNumber-2)*2))
    {
        return E_OUTOFMEMORY;
    }
    if (!M.resize(2*m_dwFaceNumber, 2*2))
    {
        return E_OUTOFMEMORY;
    }
    
    for (uint32_t ii=0; ii<m_dwFaceNumber; ii++)
    {
        FAILURE_RETURN(
            AddFaceWeight(ii, orgA, M, dwBaseVertId1, dwBaseVertId2));
    }

    // b = -M*u
    if (!CSparseMatrix<double>::Mat_Mul_Vec(orgB, M, U))
    {
        return E_OUTOFMEMORY;
    }
    assert(orgB.size() == 2*m_dwFaceNumber);
    CVector<double>::scale(orgB, orgB, static_cast<double>(-1));

    // A' = A^T * A
    if (!CSparseMatrix<double>::Mat_Trans_MUL_Mat(A, orgA))
    {
        return E_OUTOFMEMORY;
    }

    // B' = A^T * b
    if (!CSparseMatrix<double>::Mat_Trans_Mul_Vec(B, orgA, orgB))
    {
        return E_OUTOFMEMORY;
    }
    
    return hr;
}
Exemple #24
0
C2DCurveData::C2DCurveData(const CVector< C_FLOAT64 > & x, const CVector< C_FLOAT64 > & y, size_t size):
  QwtData(),
  mpX(x.array()),
  mpY(y.array()),
  mSize(size),
  mMaxSize(x.size()),
  mLastRectangle(0),
  mMinX(std::numeric_limits<double>::quiet_NaN()),
  mMaxX(std::numeric_limits<double>::quiet_NaN()),
  mMinY(std::numeric_limits<double>::quiet_NaN()),
  mMaxY(std::numeric_limits<double>::quiet_NaN())
{
  assert(x.size() == y.size());
  assert(mSize <= mMaxSize);
}
Exemple #25
0
void CCamera::CamShake(float shakeFactor, float shakeX, float shakeY, float shakeZ)
{
    CVector shake(shakeX, shakeY, shakeZ);
    CVector ds = this->cams[this->activeCam].Source - shake;
    float force = Clamp(0.0f, sqrt(ds.z * ds.z + ds.Magnitude2DSquared()), 100.0f);
    v15 = 1.0 - force / 100.0f;
    v12 = (this->fCameraSpeedSoFar - (CTimer::GetCurrentTimeMs() - this->m_uiCamShakeStart) / 1000.0f) * v15;
  
    v13 = v15 * shakeFactor * 0.35;
    if (v13 > Clamp<float>(0.0f, v12, 2.0f))
    {
        this->fCameraSpeedSoFar = v13;
        this->m_uiCamShakeStart = CTimer::GetCurrentTimeMs();
    }
}
Exemple #26
0
// *********************************************************
void CPrimRender::updateEdge(NL3D::UInstance edge,const NLMISC::CVector &start, const NLMISC::CVector &end)
{
	//H_AUTO(R2_CPrimRender_updateEdge)
	CVector I = end - start;
	CVector INormed = I.normed();
	CVector K = (CVector::K - (CVector::K * INormed) * INormed).normed();
	CVector J = K ^ INormed;
	CMatrix connectorMat;
	static volatile float scale =0.5f;
	connectorMat.setRot(I, scale * J, scale * K);
	connectorMat.setPos(start);
	edge.setTransformMode(UTransform::DirectMatrix);
	edge.setMatrix(connectorMat);
	edge.show();
}
Exemple #27
0
void Box::generateRandomCells(int nbcells,float radius){
	// instantiate new cells
	CVector coord;
	for(int i=0;i<nbcells;i++){
		MainWindow::addLog(("Instantiate cells..."+to_string(i+1)).c_str());
		coord.setX(rand()%(int)getWidth());
		coord.setY(rand()%(int)getHeight());
		coord.setZ(rand()%(int)getDepth());
		Cell* aCell=new Cell(to_string(i+1));
		aCell->setCoord(coord);
		aCell->setRadius(radius);
		addCell(aCell);
		MainWindow::uiStat->ProcessProgressBar->setValue((MainWindow::uiStat->ProcessProgressBar->value())+1);
	}
}
Exemple #28
0
void CBeam::ComputeOffsets (void)

//	ComputeOffsets
//
//	Computes offsets

{
    Metric rLength = LIGHT_SPEED * g_SecondsPerUpdate / g_KlicksPerPixel;
    CVector vFrom = PolarToVector(m_iRotation, -rLength);

    m_xFromOffset = (int)(vFrom.GetX() + 0.5);
    m_yFromOffset = -(int)(vFrom.GetY() + 0.5);
    m_xToOffset = 0;
    m_yToOffset = 0;
}
Exemple #29
0
void CAniRect::GetContentRect (RECT *retrcRect)

//	GetContentRect
//
//	Returns a RECT of the content area (relative to the rect itself)

	{
	CVector vScale = m_Properties[INDEX_SCALE].GetVector();
	int iPadding = m_Properties[INDEX_LINE_PADDING].GetInteger();

	retrcRect->left = iPadding + PADDING_LEFT;
	retrcRect->top = iPadding + PADDING_TOP;
	retrcRect->right = (int)vScale.GetX() - (iPadding + PADDING_RIGHT);
	retrcRect->bottom = (int)vScale.GetY() - (iPadding + PADDING_BOTTOM);
	}
Exemple #30
0
//This behavior accepts a list of other entities, called the peers list, and
//creates a steering force that attempts to move this entity away from
//any of those peers that might be invading his personal space.
bool Entity::Separate(vector<Entity *> & peers, float weight, float FrameTime)
{
    CVector force = 0.0;       //This vector will be used to accumulate the individual repellant
    //forces between this entity and each of its peers

    for (int e=0; e<peers.size(); e++)
    {
        if (peers[e] == this) continue; //if this entity is in his own peers list, ignore it

        CVector pos1 = GetPos();              //pos of this entity
        CVector pos2 = peers[e]->GetPos();    //pos of the current peer

        float distance = sqrt(pow(pos2.x-pos1.x,2) + pow(pos2.y-pos1.y,2));

        if (distance == 0)  continue; //if they are right on top of eachother, something
        //is wrong elsewhere in the sim, so ignore this peer

        if ((distance <= (viewradius + peers[e]->radius))) //if peer is within proximity
        {
            CVector Velocity = GetLinearVel();

            CVector Tempv = Velocity;
            CVector temptarget = pos2 - pos1;

            if (distance) temptarget.Normalize();
            if (Tempv.Length()) Tempv.Normalize();

            float dprod = temptarget.DotProduct(Tempv);

            float diffangle = acosf(dprod);

            //if the peer is not within the clipping portion of the proximity radius
            if ( (diffangle*(180/PI)) < viewclip )
            {
                force += temptarget;     //accumulate all individual separating forces
            }

        }//end if within proximity

    }//end for each peer

    if (!force.Length()) return false; //no peers were close enough to consider, nothing will be changed

    force.Normalize();   //normalize our accumulated force

    CVector DesiredVel = -force * Speed ;  //find the Desired velocity

    //create a steering force by taking the difference between the actual velocity
    //and the desired velocity.
    SteeringForce += (DesiredVel - GetLinearVel()) * weight * FrameTime;

    return true;
}