Example #1
0
void richness(double *v, int *prow, int *pcolumn)
{

    int i,j,k;
    int row, column;
	double tmp;
    double **m;

    row = *prow;
    column = *pcolumn;

    m = vectomat(v,row,column);

    GetRNGstate();
    for(i=0;i<row;i++)
    {
        for (j=0;j<column;j++)
        {
            k=intrand(column);//choose another column (species) at random
            tmp = m[i][j];
            m[i][j] = m[i][k];
            m[i][k] = tmp;
		}
    }
    mattovec(v,m,row,column);
    PutRNGstate();
}
Example #2
0
void frequency(double *v, int *prow, int *pcolumn)
{

    int i,j,k;
    int row, column;
	double tmp;
    double **m;

    row = *prow;
    column = *pcolumn;

    m = vectomat(v,row,column);

    GetRNGstate();
    for(i=0;i<column;i++)
    {
        for (j=0;j<row;j++)
        {
            k=intrand(row);//choose another row (sample) at random
            tmp = m[j][i];
            m[j][i] = m[k][i];
            m[k][i] = tmp;
		}
    }
    mattovec(v,m,row,column);
    PutRNGstate();
}
Example #3
0
bool KX_TrackToActuator::Update(double curtime, bool frame)
{
	bool result = false;
	bool bNegativeEvent = IsNegativeEvent();
	RemoveAllEvents();

	if (bNegativeEvent)
	{
		// do nothing on negative events
	}
	else if (m_object)
	{
		KX_GameObject* curobj = (KX_GameObject*) GetParent();
		MT_Vector3 dir = curobj->NodeGetWorldPosition() - ((KX_GameObject*)m_object)->NodeGetWorldPosition();
		MT_Matrix3x3 mat;
		MT_Matrix3x3 oldmat;

		mat = vectomat(dir, m_trackflag, m_upflag, m_allow3D);
		oldmat = curobj->NodeGetWorldOrientation();
		
		/* erwin should rewrite this! */
		mat = matrix3x3_interpol(oldmat, mat, m_time);
		
		/* check if the model is parented and calculate the child transform */
		if (m_parentobj) {
				
			MT_Point3 localpos;
			localpos = curobj->GetSGNode()->GetLocalPosition();
			// Get the inverse of the parent matrix
			MT_Matrix3x3 parentmatinv;
			parentmatinv = m_parentobj->NodeGetWorldOrientation().inverse();
			// transform the local coordinate system into the parents system
			mat = parentmatinv * mat;
			// append the initial parent local rotation matrix
			mat = m_parentlocalmat * mat;

			// set the models tranformation properties
			curobj->NodeSetLocalOrientation(mat);
			curobj->NodeSetLocalPosition(localpos);
			//curobj->UpdateTransform();
		}
		else {
			curobj->NodeSetLocalOrientation(mat);
		}

		result = true;
	}

	return result;
}
Example #4
0
void independentswap(double *v, int *pintervals, int *prow, int *pcolumn)
{
    long int swap;
    int swapped;
    int i,j,k,l;
    int row, column;
    int intervals;
	double tmp;
    double **m;

    row = *prow;
    column = *pcolumn;
    intervals = *pintervals;

    m = vectomat(v,row,column);

    GetRNGstate();
    for(swap=0;swap<intervals;swap++)
    {
        swapped = 0;
        while(swapped==0) {
            i=intrand(row);//Choose a random row
            while((j=intrand(row))==i);//make sure that you do not randomly choose the same row as before
            k=intrand(column);//Choose a random column
            while((l=intrand(column))==k);//make sure that you do not randomly choose the same column as before
            if((m[i][k]>0.0 && m[j][l]>0.0 && m[i][l]+m[j][k]==0.0)||(m[i][k]+m[j][l]==0.0 && m[i][l]>0.0 && m[j][k]>0.0))
            {
                //currently swaps abundances within columns (=species)
                //should have a switch to swap abundances within rows, columns, or random
                tmp = m[i][k];
                m[i][k] = m[j][k];
                m[j][k] = tmp;
                tmp = m[i][l];
                m[i][l] = m[j][l];
                m[j][l] = tmp;
                swapped = 1;
            }
        }
    }
    mattovec(v,m,row,column);
    PutRNGstate();
}