Esempio n. 1
0
void BuildXiwMatrix(GzCamera *camera)
{
	IdentityMatrix(camera->Xiw);

	GzCoord right;
	GzCoord look;

	// build look-vector
	look[0] = camera->lookat[0] - camera->position[0];
	look[1] = camera->lookat[1] - camera->position[1];
	look[2] = camera->lookat[2] - camera->position[2];
	NormalizeVector(look, look);

	// build up-vector
	float upDotZ = DotProduct(camera->worldup, look);
	camera->worldup[0] = camera->worldup[0] - upDotZ * look[0];
	camera->worldup[1] = camera->worldup[1] - upDotZ * look[1];
	camera->worldup[2] = camera->worldup[2] - upDotZ * look[2];
	NormalizeVector(camera->worldup, camera->worldup);

	// build right-vector
	CrossProduct(camera->worldup, look, right);
	NormalizeVector(right, right);

	// build matrix
	camera->Xiw[0][0] = right[0];
	camera->Xiw[0][1] = right[1];
	camera->Xiw[0][2] = right[2];

	camera->Xiw[1][0] = camera->worldup[0];
	camera->Xiw[1][1] = camera->worldup[1];
	camera->Xiw[1][2] = camera->worldup[2];

	camera->Xiw[2][0] = look[0];
	camera->Xiw[2][1] = look[1];
	camera->Xiw[2][2] = look[2];

	// build upper right column
	GzCoord tRight = {-right[0], -right[1], -right[2]};
	GzCoord tUp = {-camera->worldup[0], -camera->worldup[1], -camera->worldup[2]};
	GzCoord tLook = {-look[0], -look[1], -look[2]};
	
	//up - (up . Z)Z 
	camera->Xiw[0][3] = DotProduct(tRight, camera->position);
	camera->Xiw[1][3] = DotProduct(tUp, camera->position);
	camera->Xiw[2][3] = DotProduct(tLook, camera->position);
	
	/*fprintf(outf, "Camera vectors\n");
	fprintf(outf, "  right: "); PrintGzCoord(right);
	fprintf(outf, "  up:    "); PrintGzCoord(camera->worldup);
	fprintf(outf, "  look:  "); PrintGzCoord(look);
	fprintf(outf, "  pos:   "); PrintGzCoord(camera->position);*/
}
//The the rotation elements in an identity matrix
void MakeYRotatationMatrix(D3DRMMATRIX4D* mat, float angle)
{
	float c, s;

	c = (float) cos(angle);	
	s = (float) sin(angle);

	IdentityMatrix(mat);

	(*mat)[0][0] = c; (*mat)[0][2] = -s;
	(*mat)[2][0] = s; (*mat)[2][2] = c;
}
Esempio n. 3
0
/*************
 * DESCRIPTION:   sets an orientation matrix
 * INPUT:         ox,oy,oz    orientation
 * OUTPUT:        none
 *************/
void MATRIX::SetOMatrix(const VECTOR *ox, const VECTOR *oy, const VECTOR *oz)
{
    IdentityMatrix();
    m[ 5] = ox->x;
    m[ 9] = ox->y;
    m[13] = ox->z;
    m[ 6] = oy->x;
    m[10] = oy->y;
    m[14] = oy->z;
    m[ 7] = oz->x;
    m[11] = oz->y;
    m[15] = oz->z;
}
Esempio n. 4
0
	mat4 Rz(GLfloat a)
	{
		mat4 m;
		m = IdentityMatrix();
		m.m[0] = cos(a);
		if (transposed)
			m.m[4] = -sin(a);
		else
			m.m[4] = sin(a);
		m.m[1] = -m.m[4]; //sin(a);
		m.m[5] = m.m[0]; //cos(a);
		return m;
	}
Esempio n. 5
0
	mat4 Ry(GLfloat a)
	{
		mat4 m;
		m = IdentityMatrix();
		m.m[0] = (GLfloat)cos(a);
		if (transposed)
			m.m[8] = (GLfloat)sin(a); // Was flipped
		else
			m.m[8] = (GLfloat)-sin(a);
		m.m[2] = -m.m[8]; //sin(a);
		m.m[10] = m.m[0]; //cos(a);
		return m;
	}
void setTextureMatrix(mat4 currentModelMatrix){
    mat4 scaleBiasMatrix;

    IdentityMatrix(textureMatrix);

// Scale and bias transform, moving from unit cube [-1,1] to [0,1]
    scaleBiasMatrix = Mult(T(0.5, 0.5, 0.0), S(0.5, 0.5, 1.0));
    textureMatrix = Mult(Mult(scaleBiasMatrix, projectionMatrix), Mult(lightViewMatrix,currentModelMatrix));


    //  textureMatrix = Mult(Mult(scaleBiasMatrix, projectionMatrix), modelViewMatrix);
    // Multiply modelview and transformation matrices
}
Esempio n. 7
0
	mat4 Rx(GLfloat a)
	{
		mat4 m;
		m = IdentityMatrix();
		m.m[5] = (GLfloat)cos(a);
		if (transposed)
			m.m[9] = (GLfloat)-sin(a);
		else
			m.m[9] = (GLfloat)sin(a);
		m.m[6] = -m.m[9]; //sin(a);
		m.m[10] = m.m[5]; //cos(a);
		return m;
	}
void ScaleMatrix(D3DRMMATRIX4D* mat, float fX, float fY, float fZ)
{
	D3DRMMATRIX4D scalemat;

	IdentityMatrix(&scalemat);

	scalemat[0][0] = fX; 
	scalemat[1][1] = fY; 
	scalemat[2][2] = fZ;

	PostMultiplyMatrix(mat, &scalemat);

}
Esempio n. 9
0
Matrix *Matrix::Power(Matrix *m, int pow)
{
	if (pow == 0)
	{
		return IdentityMatrix(m->rows, m->cols);
	}
	if (pow == 1)
	{
		return m->Duplicate();
	}
	if (pow == -1)
	{
		return m->Invert();
	}

	Matrix *x;
	if (pow < 0)
	{
		x = m->Invert();
		pow *= -1;
	}
	else
	{
		x = m->Duplicate();
	}

	Matrix *ret = IdentityMatrix(m->rows, m->cols);
	while (pow != 0)
	{
		if ((pow & 1) == 1)
		{
			ret = ret->Multiply(x);
		}
		x = x->Multiply(x);
		pow >>= 1;
	}
	return ret;
}
Esempio n. 10
0
void moHueSatIntMatrix::Update(MOfloat p_int, MOfloat p_sat, MOfloat p_hue)
{
	m_int = m_min_int + p_int * (m_max_int - m_min_int);
	m_sat = m_min_sat + p_sat * (m_max_sat - m_min_sat);
	m_hue = m_min_hue + p_hue * (m_max_hue - m_min_hue);

	m_int = momax(1e-3, m_int);

	IdentityMatrix();
	IntensityMatrix();
	SaturateMatrix();
	if (m_PreserveLuminance) HueRotateMatrix();
	else SimpleHueRotateMatrix();
}
Esempio n. 11
0
int GzTrxMat(GzCoord translate, GzMatrix mat)
{
// Create translation matrix
// Pass back the matrix using mat value
	GzMatrix m;

	IdentityMatrix(m);
	m[0][3] = translate[0];
	m[1][3] = translate[1];
	m[2][3] = translate[2];

	memcpy((GzMatrix*)mat, (GzMatrix*)m, sizeof(GzMatrix));

	return GZ_SUCCESS;
}
Esempio n. 12
0
/* correspond to the vectors given.                        */
CMatrix GenRotation(const CVector3D& x, const CVector3D& y, const CVector3D& z) {
 CMatrix M = IdentityMatrix();

  M._matrix[0] = x._vector[X];
  M._matrix[4] = x._vector[Y];
  M._matrix[8] = x._vector[Z];
  M._matrix[1] = y._vector[X];
  M._matrix[5] = y._vector[Y];
  M._matrix[9] = y._vector[Z];
  M._matrix[2] = z._vector[X];
  M._matrix[6] = z._vector[Y];
  M._matrix[10] = z._vector[Z];

  return M;
}
Esempio n. 13
0
int GzScaleMat(GzCoord scale, GzMatrix mat)
{
// Create scaling matrix
// Pass back the matrix using mat value
	GzMatrix m;

	IdentityMatrix(m);
	m[0][0] = scale[0];
	m[1][1] = scale[1];
	m[2][2] = scale[2];	

	memcpy((GzMatrix*)mat, (GzMatrix*)m, sizeof(GzMatrix));

	return GZ_SUCCESS;
}
Esempio n. 14
0
/*************
 * DESCRIPTION:   sets a scale orientation translate matrix
 * INPUT:         s           scale factors
 *                ox,oy,oz    orientation
 *                d           translation values
 * OUTPUT:        none
 *************/
void MATRIX::SetSOTMatrix(const VECTOR *s, const VECTOR *ox, const VECTOR *oy, const VECTOR *oz, const VECTOR *d)
{
    IdentityMatrix();
    m[ 1] = d->x;
    m[ 2] = d->y;
    m[ 3] = d->z;
    m[ 5] = ox->x * s->x;
    m[ 9] = ox->y * s->x;
    m[13] = ox->z * s->x;
    m[ 6] = oy->x * s->y;
    m[10] = oy->y * s->y;
    m[14] = oy->z * s->y;
    m[ 7] = oz->x * s->z;
    m[11] = oz->y * s->z;
    m[15] = oz->z * s->z;
}
Esempio n. 15
0
void FnirtFileWriter::common_coef_construction(const string&            fname, 
                                               const basisfield&        fieldx,
                                               const basisfield&        fieldy,
                                               const basisfield&        fieldz,
                                               const Matrix&            aff)
{
  volume4D<float>       coefs(fieldx.CoefSz_x(),fieldx.CoefSz_y(),fieldx.CoefSz_z(),3);
  vector<float>         ksp(3,1.0);
  try {
    const splinefield& f = dynamic_cast<const splinefield& >(fieldx);
    ksp[0] = float(f.Ksp_x()); ksp[1] = float(f.Ksp_y()); ksp[2] = float(f.Ksp_z());
    if (f.Order() == 2) coefs.set_intent(FSL_QUADRATIC_SPLINE_COEFFICIENTS,f.Vxs_x(),f.Vxs_y(),f.Vxs_z());
    else if (f.Order() == 3) coefs.set_intent(FSL_CUBIC_SPLINE_COEFFICIENTS,f.Vxs_x(),f.Vxs_y(),f.Vxs_z());
  }
  catch (...) {  
    try {
      const dctfield& f = dynamic_cast<const dctfield& >(fieldx);
      coefs.set_intent(FSL_DCT_COEFFICIENTS,f.Vxs_x(),f.Vxs_y(),f.Vxs_z());
      throw FnirtFileWriterException("common_coef_construction: Saving of DCT coefficients not yet implemented");
    }
    catch (...) {
      throw FnirtFileWriterException("common_coef_construction: Unknown field type");
    }
  } 
  coefs.setxdim(ksp[0]); coefs.setydim(ksp[1]); coefs.setzdim(ksp[2]);
  Matrix  qform(4,4); 
  qform = IdentityMatrix(4);
  qform(1,4) = fieldx.FieldSz_x(); 
  qform(2,4) = fieldx.FieldSz_y(); 
  qform(3,4) = fieldx.FieldSz_z();
  coefs.set_qform(NIFTI_XFORM_SCANNER_ANAT,qform);
  coefs.set_sform(NIFTI_XFORM_SCANNER_ANAT,aff);
  vector<shared_ptr<ColumnVector> > coefp(3);
  coefp[0]=fieldx.GetCoef(); coefp[1]=fieldy.GetCoef(); coefp[2]=fieldz.GetCoef();  
  for (unsigned int v=0; v<3; v++) {
    ColumnVector  c = *(coefp[v]);
    for (unsigned int k=0, vindx=0; k<fieldx.CoefSz_z(); k++) {
      for (unsigned int j=0; j<fieldx.CoefSz_y(); j++) {
        for (unsigned int i=0; i<fieldx.CoefSz_x(); i++) {
          coefs(i,j,k,v) = c.element(vindx++);
	}
      }
    }
  }

  save_orig_volume4D(coefs,fname);
}
Esempio n. 16
0
void render_windmill(struct Windmill* windmill, GLuint program, float time)
{
	mat4 rot, trans, scale, total;

	scale = S(1, 1, 1);
	rot = Rx(-time * 4);
	rot = IdentityMatrix();
	trans = T(windmill->position.x, windmill->position.y, windmill->position.z);
	total = Mult(scale, rot);
	total = Mult(trans, total);
	glUniformMatrix4fv(glGetUniformLocation(program, "mdlMatrix"), 1, GL_TRUE, total.m);	// Upload matrix

	// Draw the windmill
	DrawModel(windmill->balcony, program, "in_Position", "in_Normal", "inTexCoord");
	DrawModel(windmill->walls, program, "in_Position", "in_Normal", "inTexCoord");
	DrawModel(windmill->roof, program, "in_Position", "in_Normal", "inTexCoord");

	// Draw the blades
	trans = T(windmill->position.x+5, windmill->position.y+10, windmill->position.z);

	// 1
	rot = Rx(0 + time);
	total = Mult(trans, rot);
	glUniformMatrix4fv(glGetUniformLocation(program, "mdlMatrix"), 1, GL_TRUE, total.m);	// Upload matrix
	DrawModel(windmill->blade, program, "in_Position", "in_Normal", "inTexCoord");

	// 2
	rot = Rx(3.14f/2.0f + time);
	total = Mult(trans, rot);
	glUniformMatrix4fv(glGetUniformLocation(program, "mdlMatrix"), 1, GL_TRUE, total.m);	// Upload matrix
	DrawModel(windmill->blade, program, "in_Position", "in_Normal", "inTexCoord");

	// 3
	rot = Rx(3.14f + time);
	total = Mult(trans, rot);
	glUniformMatrix4fv(glGetUniformLocation(program, "mdlMatrix"), 1, GL_TRUE, total.m);	// Upload matrix
	DrawModel(windmill->blade, program, "in_Position", "in_Normal", "inTexCoord");

	// 3
	rot = Rx(-3.14f/2.0f + time);
	total = Mult(trans, rot);
	glUniformMatrix4fv(glGetUniformLocation(program, "mdlMatrix"), 1, GL_TRUE, total.m);	// Upload matrix
	DrawModel(windmill->blade, program, "in_Position", "in_Normal", "inTexCoord");

}
Esempio n. 17
0
int GzRotZMat(float degree, GzMatrix mat)
{
// Create rotate matrix : rotate along z axis
// Pass back the matrix using mat value
	GzMatrix m;
	float cd = cos(degree * PIOVER180);
	float sd = sin(degree * PIOVER180);

	IdentityMatrix(m);
	m[0][0] = cd;
	m[1][0] = sd;
	m[0][1] = -sd;
	m[1][1] = cd;

	memcpy((GzMatrix*)mat, (GzMatrix*)m, sizeof(GzMatrix));

	return GZ_SUCCESS;
}
Esempio n. 18
0
	mat4 T(GLfloat tx, GLfloat ty, GLfloat tz)
	{
		mat4 m;
		m = IdentityMatrix();
		if (transposed)
		{
			m.m[12] = tx;
			m.m[13] = ty;
			m.m[14] = tz;
		}
		else
		{
			m.m[3] = tx;
			m.m[7] = ty;
			m.m[11] = tz;
		}
		return m;
	}
Esempio n. 19
0
Boid::Boid()
{
  //Construtor for leader. Maybe make a class of it because it does not need all that a boid needs
  position = vec3(0,0,0);
  averagePosition = vec3(0.0, 0.0, 0.0);
  
  speed = vec3(0,0,0); //vec3(1.0, 0.2, 0.8);
  speedDifference = vec3(0.0, 0.0, 0.0);
  
  avoidanceVector = vec3(0.0, 0.0, 0.0);
  cohesionVector = vec3(0.0, 0.0, 0.0);
  alignmentVector = vec3(0.0, 0.0, 0.0);

  forward = vec3(0,0,-1); //Or vec3(0,0,1)?; According to blender: -1 in z
  up = vec3(0,1,0);
  //side = vec3(1,0,0);, needed?

  rotationMatrix = IdentityMatrix();
}
Esempio n. 20
0
void display(void)
{
	// clear the screen
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	
	mat4 total, modelView, camMatrix;
	
	printError("pre display");
	
	glUseProgram(program);

	// Build matrix
	lookAtPoint = VectorAdd(cam, camDir);
	camMatrix = lookAt(cam.x, cam.y, cam.z,
                       lookAtPoint.x, lookAtPoint.y, lookAtPoint.z,
                       0.0, 1.0, 0.0);

    calculateCullingFrustum(camMatrix);
    
	modelView = IdentityMatrix();
	total = Mult(camMatrix, modelView);
	glUniformMatrix4fv(glGetUniformLocation(program, "model"), 1, GL_TRUE, total.m);

    glUniform3f(glGetUniformLocation(program, "camPos"), cam.x, cam.y, cam.z);

	glBindTexture(GL_TEXTURE_2D, tex1);		// Bind Our Texture tex1
	DrawModel(tm, program, "inPosition", "inNormal", "inTexCoord");

    /*

    mat4 foobar = Mult(modelView, camMatrix);
    */
    GLfloat ballY = GetMapHeight(tm,ttex.width, ttex.height, ballX, ballZ);
    if (sphereInFrustum((vec3) {ballX, ballY, ballZ}, 10.0f)) {
        modelView = T(ballX, ballY, ballZ);
        total = Mult(camMatrix, modelView);
        glUniformMatrix4fv(glGetUniformLocation(program, "model"), 1, GL_TRUE, total.m);
        DrawModel(m2, program, "inPosition", "inNormal", "inTexCoord");
        printf("foo\n");
    }
	printError("display 2");
	glutSwapBuffers();
}
Esempio n. 21
0
void display(void)
{
    // clear the screen
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    mat4 total, modelView, camMatrix;

    printError("pre display");

    glUseProgram(program);

    // Build matrix
    lookAtPoint = VectorAdd(cam, camDir);
    camMatrix = lookAt(cam.x, cam.y, cam.z,
                       lookAtPoint.x, lookAtPoint.y, lookAtPoint.z,
                       0.0, 1.0, 0.0);
    modelView = IdentityMatrix();
    total = Mult(camMatrix, modelView);
    glUniformMatrix4fv(glGetUniformLocation(program, "model"), 1, GL_TRUE, total.m);

    glUniform3f(glGetUniformLocation(program, "camPos"), cam.x, cam.y, cam.z);

    glBindTexture(GL_TEXTURE_2D, tex1);         // Bind Our Texture tex1



    DrawModel(tm, program, "inPosition", "inNormal", "inTexCoord");

    /*modelView = T(10.f, 30.f, 10.f);
    glUniformMatrix4fv(glGetUniformLocation(program, "model"), 1, GL_TRUE, modelView.m);
    DrawModel(m, program, "inPosition", "inNormal", "inTexCoord");*/

    if (sphereInFrustum((vec3) {-10.f, 30.f, 10.f}, 10.f)) {
        modelView = T(-10.f, 30.f, 10.f);
        glUniformMatrix4fv(glGetUniformLocation(program, "model"), 1, GL_TRUE, modelView.m);
        DrawModel(m2, program, "inPosition", "inNormal", "inTexCoord");
        printf("foo\n");
    }

    printError("display 2");
    glutSwapBuffers();
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
void
DAF::LightsOutSolver::ReduceGameMatrix()
{
    _vbElementaryOperationMatrix = IdentityMatrix();
    _vbReducedGameMatrix = GameMatrix();
    
    const std::size_t kuGameDimension = _uDimension * _uDimension;
    
    std::size_t uNextRow = 0;
    for (std::size_t uColumn = 0; uColumn < kuGameDimension; ++uColumn)
    {
        for (std::size_t uRow = uNextRow; uRow < kuGameDimension; ++uRow)
        {
            const std::size_t kuLinearIndex = ConvertToLinearIndex(kuGameDimension, uRow, uColumn);
            if ( _vbReducedGameMatrix[kuLinearIndex] )
            {
                SwapRows(kuGameDimension, _vbElementaryOperationMatrix, uNextRow, uRow);
                SwapRows(kuGameDimension, _vbReducedGameMatrix, uNextRow, uRow);
                
                for (size_t uClearRow = 0; uClearRow < kuGameDimension; ++uClearRow)
                {
                    if ( uClearRow == uNextRow )
                        continue;
                    
                    const size_t kuClearLinearIndex = ConvertToLinearIndex(kuGameDimension, uClearRow, uColumn);
                    if ( _vbReducedGameMatrix[kuClearLinearIndex] )
                    {
                        AddRowToRow(kuGameDimension, _vbElementaryOperationMatrix, uNextRow, uClearRow);
                        AddRowToRow(kuGameDimension, _vbReducedGameMatrix, uNextRow, uClearRow);
                    }
                }
                
                ++uNextRow;
                
                break;
            }
        }
    }
    
    FindNullSpaceBasis();
}
void	FSsAnimeDecoder::UpdateMatrix(FSsPart* part , FSsPartAnime* anime , FSsPartState* state)
{

	IdentityMatrix( state->Matrix );

	if (state->Parent)
	{
		memcpy( state->Matrix , state->Parent->Matrix , sizeof( float ) * 16 );
	}

	// アンカー
	if ( state->Parent )
	{
		const FVector2D& parentSize = state->Parent->Size;
		state->Position.X = state->Position.X + state->Parent->Size.X * state->Anchor.X;
		state->Position.Y = state->Position.Y + state->Parent->Size.Y * state->Anchor.Y;
	}

	TranslationMatrixM( state->Matrix , state->Position.X, state->Position.Y, state->Position.Z );//
	RotationXYZMatrixM( state->Matrix , FMath::DegreesToRadians(state->Rotation.X) , FMath::DegreesToRadians(state->Rotation.Y) , FMath::DegreesToRadians( state->Rotation.Z) );
	ScaleMatrixM(  state->Matrix , state->Scale.X, state->Scale.Y, 1.0f );
}
Esempio n. 24
0
Boid::Boid(vec3 pos)
{
  position = pos;
  averagePosition = vec3(0.0, 0.0, 0.0);
  
  speed = vec3(0,0,0); //vec3(1.0, 0.2, 0.8);
  speedDifference = vec3(0.0, 0.0, 0.0);
  
  avoidanceVector = vec3(0.0, 0.0, 0.0);
  cohesionVector = vec3(0.0, 0.0, 0.0);
  alignmentVector = vec3(0.0, 0.0, 0.0);

  forward = vec3(0,0,-1); //Or vec3(0,0,1)?;
  up = vec3(0,1,0);
  //side = vec3(1,0,0);, needed?

  rotationMatrix = IdentityMatrix();

  uint max = 40;
  uint min = 0;
  animationIndex = rand()%(max-min + 1) + min;
}
Esempio n. 25
0
Matrix Matrix::Inverse() const {
	if (!IsSquare()) {
		throw "Exception : Not a square matrixe.\n";
		exit(EXIT_FAILURE);
	}

	Matrix m = Clone();
	const int N = Row();
	Matrix e = IdentityMatrix(N);
	for (int i = 0; i < N; i++) {
		for (int j = i + 1; j < N; j++) {
			if (abs(m(i, i)) < abs(m(j, i))) {
				m.SwapRow(i, j);
			}
		}
		double aii = m(i, i);
		if (aii == 0.0) {
			throw "Exception : Can not calculate.\n";
			exit(EXIT_FAILURE);
		}

		for (int j = 0; j < N; j++) {
			m(i, j) /= aii;
			e(i, j) /= aii;
		}
		for (int j = 0; j < N; j++) {
			if (i == j) {
				continue;
			}
			double aji = m(j, i);
			for (int k = 0; k < N; k++) {
				m(j, k) -= m(i, k) * aji;
				e(j, k) -= m(i, k) * aji;
			}
		}
	}
	return e;
}
Esempio n. 26
0
void CParam::initizalize(CData &Data, int nComp, CFeasibilityMap &FM, Uniform &randUnif, int n_simul){
  // Set the minimum value of (no. of correct records)/(no. of all records)
  toolarge_nout = (1-min_Prob_A)/min_Prob_A * Data.n_sample ;

  n_var = Data.n_var;
  n_var_independent = n_var - Data.n_balance_edit;
  K = nComp;
  n_sample = Data.n_sample;

  alpha = 1.0 ;
  Phi = IdentityMatrix(n_var_independent) * 5.0;
  init_pi();
  init_sigmamu(Data);
  init_Y_in(Data);
  init_z_in();

  S_Mat = Data.initial_S_Mat.t();
  init_logUnif_y_tilde(Data,FM,randUnif,n_simul);

  n_z = ColumnVector(K); n_z = 0 ;
  Sigma_k_inv_ll = Matrix(K,n_var_independent);  Sigma_k_inv_ll=0.0;
  X_bar= Matrix(n_var_independent,K); X_bar = 0.0 ;
  CalculateInitProbA(Data);
}
Esempio n. 27
0
void initParticleSystem()
{
    srand((unsigned int)time(NULL));

    int i;
    float max = 2, max2 = 1;
    for(i = 0; i < MAX_PARTICLES; i++)
    {
    	par_sys[i].mMatrix = IdentityMatrix();

    	par_sys[i].mMatrix.m[3] = max * ((float)rand()/(float)RAND_MAX - 0.5);  //x
        par_sys[i].mMatrix.m[7] = max2 * ((float)rand()/(float)RAND_MAX - 0.1); //y
        par_sys[i].mMatrix.m[11] = max * ((float)rand()/(float)RAND_MAX - 0.5); //z

        par_sys[i].position = SetVector(par_sys[i].mMatrix.m[3], par_sys[i].mMatrix.m[7], par_sys[i].mMatrix.m[11]);

        particlePositionData[16 * i + 0] = par_sys[i].mMatrix.m[0]; 	//0,0
        particlePositionData[16 * i + 1] = par_sys[i].mMatrix.m[4]; 	//0,1
        particlePositionData[16 * i + 2] = par_sys[i].mMatrix.m[8]; 	//0,2
        particlePositionData[16 * i + 3] = par_sys[i].mMatrix.m[12]; 	//0,3
        particlePositionData[16 * i + 4] = par_sys[i].mMatrix.m[1]; 	//1,0
        particlePositionData[16 * i + 5] = par_sys[i].mMatrix.m[5]; 	//1,1
        particlePositionData[16 * i + 6] = par_sys[i].mMatrix.m[9]; 	//1,2
        particlePositionData[16 * i + 7] = par_sys[i].mMatrix.m[13]; 	//1,3
        particlePositionData[16 * i + 8] = par_sys[i].mMatrix.m[2]; 	//2,0
        particlePositionData[16 * i + 9] = par_sys[i].mMatrix.m[6]; 	//2,1
        particlePositionData[16 * i + 10] = par_sys[i].mMatrix.m[10]; 	//2,2
        particlePositionData[16 * i + 11] = par_sys[i].mMatrix.m[14]; 	//2,3
        particlePositionData[16 * i + 12] = par_sys[i].mMatrix.m[3]; 	//3,0
        particlePositionData[16 * i + 13] = par_sys[i].mMatrix.m[7]; 	//3,1
        particlePositionData[16 * i + 14] = par_sys[i].mMatrix.m[11]; 	//3,2
        particlePositionData[16 * i + 15] = par_sys[i].mMatrix.m[15]; 	//3,3

    }

}
Esempio n. 28
0
const bool Test_Matrix_IdentityMatrix()
{
	const TMatrix4d kA4d{	1.0, 0.0, 0.0, 0.0,
							0.0, 1.0, 0.0, 0.0,
							0.0, 0.0, 1.0, 0.0,
							0.0, 0.0, 0.0, 1.0};

	const TMatrix4f kA4f{	1.0f, 0.0f, 0.0f, 0.0f,
							0.0f, 1.0f, 0.0f, 0.0f,
							0.0f, 0.0f, 1.0f, 0.0f,
							0.0f, 0.0f, 0.0f, 1.0f};


	const TMatrix3d kA3d{	1.0, 0.0, 0.0,
							0.0, 1.0, 0.0,
							0.0, 0.0, 1.0};

	const TMatrix3f kA3f{	1.0f, 0.0f, 0.0f,
							0.0f, 1.0f, 0.0f,
							0.0f, 0.0f, 1.0f};


	const TMatrix2d kA2d{	1.0, 0.0,
							0.0, 1.0};

	const TMatrix2f kA2f{	1.0f, 0.0f,
							0.0f, 1.0f};

	const bool kbPass4d = Equal(IdentityMatrix(TMatrix4d()), kA4d, s_kdEpsilon);
	const bool kbPass4f = Equal(IdentityMatrix(TMatrix4f()), kA4f, s_kfEpsilon);
	const bool kbPass3d = Equal(IdentityMatrix(TMatrix3d()), kA3d, s_kdEpsilon);
	const bool kbPass3f = Equal(IdentityMatrix(TMatrix3f()), kA3f, s_kfEpsilon);
	const bool kbPass2d = Equal(IdentityMatrix(TMatrix2d()), kA2d, s_kdEpsilon);
	const bool kbPass2f = Equal(IdentityMatrix(TMatrix2f()), kA2f, s_kfEpsilon);

	return(		kbPass4d
			&&	kbPass4f
			&&	kbPass3d
			&&	kbPass3f
			&&	kbPass2d
			&&	kbPass2f);
}
Esempio n. 29
0
const bool Test_Matrix_ScalarMultiply()
{
	const TMatrix4d kA4d{	2.0, 0.0, 0.0, 0.0,
							0.0, 2.0, 0.0, 0.0,
							0.0, 0.0, 2.0, 0.0,
							0.0, 0.0, 0.0, 2.0};

	const TMatrix4f kA4f{	2.0f, 0.0f, 0.0f, 0.0f,
							0.0f, 2.0f, 0.0f, 0.0f,
							0.0f, 0.0f, 2.0f, 0.0f,
							0.0f, 0.0f, 0.0f, 2.0f};


	const TMatrix3d kA3d{	2.0, 0.0, 0.0,
							0.0, 2.0, 0.0,
							0.0, 0.0, 2.0};

	const TMatrix3f kA3f{	2.0f, 0.0f, 0.0f,
							0.0f, 2.0f, 0.0f,
							0.0f, 0.0f, 2.0f};


	const TMatrix2d kA2d{	2.0, 0.0,
							0.0, 2.0};

	const TMatrix2f kA2f{	2.0f, 0.0f,
							0.0f, 2.0f};

	const bool kbPass4d = Equal(ScalarMultiply(TMatrix4d(), IdentityMatrix(TMatrix4d()), 2.0), kA4d, s_kdEpsilon);
	const bool kbPass4f = Equal(ScalarMultiply(TMatrix4f(), IdentityMatrix(TMatrix4f()), 2.0f), kA4f, s_kfEpsilon);
	const bool kbPass3d = Equal(ScalarMultiply(TMatrix3d(), IdentityMatrix(TMatrix3d()), 2.0), kA3d, s_kdEpsilon);
	const bool kbPass3f = Equal(ScalarMultiply(TMatrix3f(), IdentityMatrix(TMatrix3f()), 2.0f), kA3f, s_kfEpsilon);
	const bool kbPass2d = Equal(ScalarMultiply(TMatrix2d(), IdentityMatrix(TMatrix2d()), 2.0), kA2d, s_kdEpsilon);
	const bool kbPass2f = Equal(ScalarMultiply(TMatrix2f(), IdentityMatrix(TMatrix2f()), 2.0f), kA2f, s_kfEpsilon);

	return(		kbPass4d
			&&	kbPass4f
			&&	kbPass3d
			&&	kbPass3f
			&&	kbPass2d
			&&	kbPass2f);
}
Esempio n. 30
0
void display(void)
{
	if(wIsDown) 
	{
		if(nearTree()) player->playerHitTree();
		player->goForward();
		
	}
	else
		player->stop();
	if(sIsDown)
	{
			player->goBackwards();
	}
	if(qIsDown) 
	{
		mapAngle-=0.02;	
	}
	if(eIsDown)
	{
			mapAngle+=0.02;
	}
	if(jumping)
	{
			player->jump();
	}
	player->heightUpdate();
	if(player->isNextControl())
	{
		
		//punshControl(map);
		controlIsFound = true;
			
		player->setNextControl(world->getControlPos(player->getPunshedControls()));		

	}
	

	// clear the screen
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);	
	
	printError("pre display");

	mat4 total, modelView, translate;
	modelView= IdentityMatrix();


	//Draw Sky box

	glUseProgram(skyProgram);
	glDisable(GL_DEPTH_TEST);
	mat4 camMatrix2 = player->getCamMatrix();

	camMatrix2.m[3] = 0;
	camMatrix2.m[7] = 0;
	camMatrix2.m[11] = 0;	

	mat4 modelView2 = modelView;

	mat4 translate2 = T(0,-0.5,0);
	modelView2 = Mult(modelView2,translate2);

	glUniformMatrix4fv(glGetUniformLocation(skyProgram, "mdlMatrix"), 1, GL_TRUE, modelView2.m);
	glUniformMatrix4fv(glGetUniformLocation(skyProgram, "camMatrix"), 1, GL_TRUE, camMatrix2.m);

	glActiveTexture(GL_TEXTURE5);
	glBindTexture(GL_TEXTURE_2D, skyTex);
	glUniform1i(glGetUniformLocation(skyProgram, "tex1"), 5);

	DrawModel(sky, skyProgram, "inPosition", NULL, "inTexCoord");
	
	glEnable(GL_DEPTH_TEST);
	
	glUseProgram(program);


	//Draw world
	glUniformMatrix4fv(glGetUniformLocation(program, "mdlMatrix"), 1, GL_TRUE, modelView.m);
	glUniformMatrix4fv(glGetUniformLocation(program, "camMatrix"), 1, GL_TRUE, player->getCamMatrix().m);
	
	glActiveTexture(GL_TEXTURE1);
	glBindTexture(GL_TEXTURE_2D, tex1);
	glActiveTexture(GL_TEXTURE2);
	glBindTexture(GL_TEXTURE_2D, tex2);
	glActiveTexture(GL_TEXTURE3);
	glBindTexture(GL_TEXTURE_2D, tex4);
	glUniform1i(glGetUniformLocation(program, "tex1"), 1);
	glUniform1i(glGetUniformLocation(program, "tex2"), 2);
	glUniform1i(glGetUniformLocation(program, "tex3"), 3);
	DrawModel(tm, program, "inPosition", "inNormal", "inTexCoord");


	//Draw trees
	glUseProgram(billBoardProgram);
	glEnable(GL_ALPHA_TEST);
	glActiveTexture(GL_TEXTURE4);
	glBindTexture(GL_TEXTURE_2D, treeTex);
	glUniform1i(glGetUniformLocation(billBoardProgram, "tex1"), 4);

	for(int x=2; x<254; x=x+3)
	{
		for(int z=2; z<254; z=z+3)
		{
			if(posIsTree[x][z]){
				DrawBillboard(bill,x,z,modelView);
			}
		}
	}	

	//Draw controls
	glDisable(GL_CULL_FACE);
	drawControl(110,72);
	drawControl(50,151);
	drawControl(106,233);
	drawControl(179,103);
	drawControl(226,111);
	glEnable(GL_CULL_FACE);
	//Draw map
	glActiveTexture(GL_TEXTURE6);
	glBindTexture(GL_TEXTURE_2D, mapTex);
	glUniform1i(glGetUniformLocation(billBoardProgram, "tex1"), 6);

	if(showMap)
	{
			DrawMap(map,compass,modelView); 
	}

	//Check if near control
	if(player->getPunshedControls() <=4){
		glActiveTexture(GL_TEXTURE7);
		glBindTexture(GL_TEXTURE_2D, punshTex);
		glUniform1i(glGetUniformLocation(billBoardProgram, "tex1"), 7);
	
		if(controlIsFound)
		{
				punshControl(punsh, modelView);
				controlPunshedFor++;
		}
		if(controlPunshedFor>100){
			controlIsFound = false;
			controlPunshedFor = 0;
		}
	}
	else
	{
		glActiveTexture(GL_TEXTURE7);
		glBindTexture(GL_TEXTURE_2D, goalTex);
		glUniform1i(glGetUniformLocation(billBoardProgram, "tex1"), 7);
		punshControl(punsh, modelView);

	}
	glDisable(GL_ALPHA_TEST);
	
	glutSwapBuffers();
	
}