Exemple #1
0
void ObjectRenderer::setupProjection()
{
	glViewport (0,0, 960, 640);
    Size size(960,640);
    float zeye = 640/1.1566f;

    Mat4 matrixPerspective, matrixLookup;

    loadIdentityMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION);

#if CC_TARGET_PLATFORM == CC_PLATFORM_WP8
    //if needed, we need to add a rotation for Landscape orientations on Windows Phone 8 since it is always in Portrait Mode
    GLView* view = getOpenGLView();
    if(getOpenGLView() != nullptr)
    {
        multiplyMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION, getOpenGLView()->getOrientationMatrix());
    }
#endif
    // issue #1334
    Mat4::createPerspective(60, (GLfloat)size.width/size.height, 1, zeye+size.height/2, &matrixPerspective);

    multiplyMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION, matrixPerspective);

    Vec3 eye(size.width/2, size.height/2, zeye), center(size.width/2, size.height/2, 0.0f), up(0.0f, 1.0f, 0.0f);
    Mat4::createLookAt(eye, center, up, &matrixLookup);
    multiplyMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION, matrixLookup);

    loadIdentityMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
}
/*
double Cos(double angle)
{
	float temp = 0;
	temp = 1 - angle*angle/(1*2) + angle*angle*angle*angle/(1*2*3*4);
	return temp;	
}

double Sin(double angle)
{
	float temp = 0;
	temp = angle - angle*angle*angle/(1*2*3) + angle*angle*angle*angle*angle/(1*2*3*4*5); 
	return temp;	
}

*/
void demo_transform(float rz, Vector tr, Vector* v, Vector* tv)
{
	double  angle;
	double  c;
	double  s;
	float  matID[16];
	float  matTR[16];
	float  matRZ[16];
	float  mat[16];
	float  mat2[16];
	int    i;


	// Affine transformation done in software (NOT optimized).
	angle = PI * rz / 180.0f;
	c     = (float)cos(angle);
	s     = (float)sin(angle);
	loadIdentityMatrix(matID);
	loadTranslationMatrix(matTR, tr);
	loadZRotationMatrix(matRZ, c, s);
	multMatrix(mat, matTR, matID);
	multMatrix(mat2, matRZ, mat);
	// Linear combination of source data and transformation matrix (z computation disabled).
	for (i = 0; i < 4; i++) {
		tv[i].x = v[i].x * mat2[ 0] + v[i].y * mat2[ 4] + mat2[12];// + v[i].z * mat2[ 8];
		tv[i].y = v[i].x * mat2[ 1] + v[i].y * mat2[ 5] + mat2[13];// + v[i].z * mat2[ 9];
	}
}
void loadUKL1(structMatrix UKL1,float time, float (*waveSpeedFunction)(int,float)) {
		float fDelta[3];
		fDelta[X_AXIS] = MESH_HLENGTH/N_HNODES;
		fDelta[Y_AXIS] = MESH_VLENGTH/N_VNODES;

		loadIdentityMatrix(UKL1);

		// Load indexes for inner nodes
		for(int i=1;i<(N_HNODES-1);i++) {
			for(int j=1;j<(N_VNODES-1);j++) {
				int index = i*N_HNODES+j;
				UKL1->matrix[index][index] = (1/(pow(fDelta[X_AXIS],2)) + 1/(pow(fDelta[Y_AXIS],2)) + 1/(pow(waveSpeedFunction(index,time),2)*pow(DELTA_TIME,2)));
				UKL1->matrix[index][index-1] = UKL1->matrix[index][index+1] = -1/(2*pow(fDelta[X_AXIS],2));
				UKL1->matrix[index][index-N_HNODES] = UKL1->matrix[index][index+N_HNODES] = -1/(2*pow(fDelta[Y_AXIS],2));
			}
		}
}
//----------------------------------------------------------
void ofGLRenderer::setupScreenOrtho(float width, float height, float nearDist, float farDist) {

	ofRectangle currentViewport = getCurrentViewport();

	float viewW = currentViewport.width;
	float viewH = currentViewport.height;

	ofMatrix4x4 ortho;

	ortho = ofMatrix4x4::newOrthoMatrix(0, viewW, 0, viewH, nearDist, farDist);

	matrixMode(OF_MATRIX_PROJECTION);
	loadMatrix(ortho); // make ortho our new projection matrix.

	matrixMode(OF_MATRIX_MODELVIEW);
	loadIdentityMatrix();

}
Exemple #5
0
/*
 * Problems...
 * ------
 * Computer problem 4.2 #1
 */
void problem42_1()
{
  // variables
  struct matrix a,ai,aai,im;
  struct lu lu;

  // setup
  a.size = NUM10;
  ai.size = NUM10;
  aai.size = NUM10;
  im.size = NUM10;

  // print
  printf("Problem 4.2 #1\n");
  printf("Algorithm for inverting an nxn lower triangular matrix A.\n");
  printf("Testing on matrix whose elements are aij = (i+j)^2 when i >= j.\n");
  printf("Use n = 10. Form AA^-1 as test.\n");

  // do the work
  a.m10 = loadMatrix42_1();
  im = loadIdentityMatrix(NUM10);
  lu = luDecomposition(a);
  ai.m10 = evaluateLu(lu.lu10,im.m10);
  aai = multiplyMatrix(a,ai);

  // Original matrix
  printf("\nOriginal Matrix: A\n");
  printMatrix(a);
  // Identity matrix
  printf("\nIdentity Matrix: I\n");
  printMatrix(im);
  // LU decomposition
  printf("\nLU decomposition:\n");
  printLu10(lu.lu10);
  // Inverted matrix
  printf("\nInverted Matrix: A^-1\n");
  printMatrix(ai);
  // Product of A and A^-1
  printf("\nProduct of AA^-1 Matrix\n");
  printMatrix(aai);
  printf("\n");
  return;
}