コード例 #1
0
BigInteger Karatsuba3Multiplication::Mult(const BigInteger&A, const BigInteger&B){

    int s1=A.GetSize();
    int s2=B.GetSize();

    int n,k;
    //for(n=1, m=0; n<s1 || n<s2; n*=3,++m); k=n/3;
    if(s1>s2) n=s1; else n=s2;
    k=n/3;


    if(n<100) return Multiplies::Mult(A,B);

    BigInteger A1 = A, A2 = A>>k, A3=A>>(2*k);
    A1.Resize(k);
    A1.ClearFirstZeros();
    A2.Resize(k);
    A2.ClearFirstZeros();

    BigInteger B1 = B, B2 = B>>k, B3=B>>(2*k);
    B1.Resize(k);
    B1.ClearFirstZeros();
    B2.Resize(k);
    B2.ClearFirstZeros();

    BigInteger A1B1 = Mult(A1,B1);
    BigInteger A2B2 = Mult(A2,B2);
    BigInteger A3B3 = Mult(A3,B3);

    BigInteger AB=A1B1+  (( Mult(A1+A2,B1+B2)-(A1B1+A2B2))<<k)+  (( Mult(A1+A3,B1+B3)-(A1B1+A3B3)+A2B2)<<2*k) + (( Mult(A2+A3,B2+B3)-(A2B2+A3B3))<<3*k) + (A3B3<<4*k);

    AB.ClearFirstZeros();
    return AB;
};
コード例 #2
0
ファイル: ss.c プロジェクト: hbhdytf/secshare
void Combine( int Positions[], FILE *InputFiles[], int NumberInputs )
{
    int OddNibble ;
    BOOLEAN Odd ;
    int i ;
    int j ;
    G13 C[15] ;
    G13 c ;
    G13 Y[15] ;
    BOOLEAN FillNibbles( G13 *Nibbles, FILE *InputFiles[], int NumberInputs );

    setmode( fileno( stdout ), O_BINARY ) ;

    /* Compute the coefficients by which the nibbles from the
     * various input files can be combined to produce the output
     * file.
     *     If X(i) is the "position" of the ith input file, and
     * Y(i) is the value of a particular nibble in the ith file,
     * we will find coefficients C(i) such that
     * 
     *     p = C(1) * Y(1) + C(2) * Y(2) + ...
     * 
     * where p is the appropriate nibble for the output file.
     * 
     *     The formula for the Cs is:
     * 
     *     C(i) = product of (   X(j) / ( X(i) - X(j) )   ) for all j != i .
     * 
     * 
     */

    for ( i = 0; i < NumberInputs; i++ )
    {
     c = 1 ;
     for ( j = 0; j < NumberInputs; j++ )
         if ( j != i )
          c = Mult( c,
               Div( Positions[j], Positions[i] ^ Positions[j] ) ) ;
     C[i] = c ;
    }

    /*
     *  Now, process the input files:
     */

    Odd = TRUE ;
    while ( FillNibbles( Y, InputFiles, NumberInputs ) )
    {
     c = 0 ;
     for ( i = 0; i < NumberInputs; i++ )
         c ^= Mult( C[i], Y[i] ) ;

     if ( Odd )
         OddNibble = c ;
     else
         putchar( ( OddNibble << 4 ) | c ) ;

     Odd = !Odd ;
    }
}
コード例 #3
0
ファイル: lab4-4.c プロジェクト: Grulfen/tsbk07
void display(void)
{
	// clear the screen
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	
	GLfloat modelView[16], camMatrix[16], cam_Matrix_skybox[16], total[16];
	
	printError("pre display");
	
	check_keys();

        t += 1;

	glUseProgram(program);

	// Build matrix
	
	lookAt(&cam_pos, &obj_pos, up.x, up.y, up.z, camMatrix);
        CopyMatrix(camMatrix, cam_Matrix_skybox);
        cam_Matrix_skybox[3] = 0;
        cam_Matrix_skybox[7] = 0;
        cam_Matrix_skybox[11] = 0;
        cam_Matrix_skybox[15] = 1;
        // disable z-buffer for skybox
        glDisable(GL_DEPTH_TEST);

	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
        // Draw skybox
        // Set the skybox variable 
        glUniform1i(glGetUniformLocation(program, "skybox"), 1);
        T(0,-0.5,0,modelView);
        Mult(cam_Matrix_skybox, modelView, total);
        glUniformMatrix4fv(glGetUniformLocation(program, "mdlMatrix"), 1, GL_TRUE, total);
        glBindTexture(GL_TEXTURE_2D, skytex);
        DrawModel(skybox, program, "inPosition", "inNormal", "inTexCoord");

        glUniform1i(glGetUniformLocation(program, "skybox"), 0);
        glEnable(GL_DEPTH_TEST);
        // Bind terrain
	IdentityMatrix(modelView);
	Mult(camMatrix, modelView, total);
	glUniformMatrix4fv(glGetUniformLocation(program, "mdlMatrix"), 1, GL_TRUE, total);
	// Bind Our Texture tex1
	glBindTexture(GL_TEXTURE_2D, tex1);		
	DrawModel(tm, program, "inPosition", "inNormal", "inTexCoord");

        // Draw sphere
        sphere_pos = update_sphere(t, total);
        sphere_pos.y = calculate_height(sphere_pos.x, sphere_pos.z, ttex.width, vertexArray);
        T(sphere_pos.x, sphere_pos.y, sphere_pos.z, trans);
        Mult(camMatrix, trans, total);
        //Ry(0.01*t, roty);
	glUniformMatrix4fv(glGetUniformLocation(program, "mdlMatrix"), 1, GL_TRUE, total);
	glBindTexture(GL_TEXTURE_2D, spheretex);		
	DrawModel(sphere, program, "inPosition", "inNormal", "inTexCoord");

	printError("display 2");
	
	glutSwapBuffers();
}
コード例 #4
0
ファイル: 1876.cpp プロジェクト: AiHaibara/acm-icpc
	void Work(void) {
		int64 P[5] = {1, 2};
		while (!Zero(a) && !Zero(b)) {
			bool Odda = a[1] & 1, Oddb = b[1] & 1;
			if (Odda && Oddb) {
				Decreas(a, b);
			}else
			if (!Odda && !Oddb) {
				Div(a);
				Div(b);
				Mult(delta, P);
			}else
			if (Odda && !Oddb) {
				Div(b);
			}else
			if (!Odda && Oddb) {
				Div(a);
			}
		}
		if (Zero(a)) {
			Mult(b, delta);
			Print(b);
		}
		else {
			Mult(a, delta);
			Print(a);
		}
	}
コード例 #5
0
ファイル: PlanetManager.c プロジェクト: Krowded/Planet
/*
 *	Takes care of orbit and rotation
 */
void UpdatePlanetMovement(GLint t)
{
	GLuint i;
	mat4 ModelToWorld;
	for(i = 0; i < numberOfPlanets; i++)
	{
		t = glutGet(GLUT_ELAPSED_TIME) -  planetsList[i].timeOfCreation;

		vec3 arbAxis = {0,1,0};
		ModelToWorld = ArbRotate(planetsList[i].rotationalAxis, planetsList[i].rotationalSpeed*(GLfloat)t); //IdentityMatrix(); //Rotation around own axis
		ModelToWorld = Mult(T(planetsList[i].startingPosition.x, planetsList[i].startingPosition.y, planetsList[i].startingPosition.z), ModelToWorld); //Offset

		if(!(planetsList[i].startingPosition.x == planetsList[0].startingPosition.x 
		  && planetsList[i].startingPosition.y == planetsList[0].startingPosition.y 
		  && planetsList[i].startingPosition.z == planetsList[0].startingPosition.z )) //Dont try to orbit when already at 0
		{	
			if(fabs(planetsList[i].startingPosition.x) - arbAxis.x + 
			   fabs(planetsList[i].startingPosition.y) - arbAxis.y + 
			   fabs(planetsList[i].startingPosition.z) - arbAxis.z == 0)
				arbAxis = SetVector(1,0,0);

			arbAxis = Normalize(CrossProduct(VectorSub(planetsList[i].startingPosition, planetsList[0].startingPosition), arbAxis));

			ModelToWorld = Mult(T(planetsList[0].center.x, planetsList[0].center.y, planetsList[0].center.z), ModelToWorld);
			ModelToWorld = Mult(ArbRotate(arbAxis, planetsList[i].orbitalSpeed*(GLfloat)t), ModelToWorld); //Orbit
			ModelToWorld = Mult(T(-planetsList[0].center.x, -planetsList[0].center.y, -planetsList[0].center.z), ModelToWorld);
		}
		planetsList[i].ModelToWorldMatrix = ModelToWorld;
	}
}
コード例 #6
0
static void createInstanceTransforms(mat4 *transforms, float time) {
	for (int x = 0; x < count; x++) {
		for (int y = 0; y < count; y++) {
			for (int z = 0; z < count; z++) {
				int index = x + y * count + z * count * count;
				vec3 rand = (vec3){randoms[index], randoms[index + 1], randoms[index + 2]};
				float particleSize = .15f;
				vec3 volumeSize = (vec3){4.2f, 4.2f, 12.0f};

				float fallOffset = time * 25.0f;

				mat4 translation = T(
						(x - count/2) * volumeSize.x / particleSize + (0.5f - rand.x) * volumeSize.x * 6.0f,
					-fmodf((y - count/2) * volumeSize.y / particleSize + (0.5f - rand.y) * volumeSize.y * 6.0f + fallOffset, 200.0f),
						-fmodf((z - count/2) * volumeSize.z / particleSize + (0.5f - rand.z) * volumeSize.z * 6.0f + fallOffset * 0.5, volumeSize.z * 25.0));
				// mat4 rotation = Mult(Rx(time * 2.5 * rand.y), Rz(time * 2.0 * rand.x));
				mat4 rotation = Rx(.5f);
				mat4 scale = S(particleSize, particleSize, particleSize);


				transforms[index] = Transpose(Mult(Mult(scale, translation), rotation));
			}
		}
	}
}
コード例 #7
0
ファイル: lab3-3.c プロジェクト: jonatanolofsson/tsbk07
void draw_windmill(windmill_t* w, float dt)
{
    glUseProgram(programs[WINDMILL_PROGRAM]);

	// Send in additional params
	glUniformMatrix4fv(glGetUniformLocation(programs[WINDMILL_PROGRAM], "projectionMatrix"), 1, GL_TRUE, projectionMatrix);
	glUniformMatrix4fv(glGetUniformLocation(programs[WINDMILL_PROGRAM], "camMatrix"), 1, GL_TRUE, camMatrix);

    glUniformMatrix4fv(glGetUniformLocation(programs[WINDMILL_PROGRAM], "lightSourcesColors"), 1, GL_FALSE, lightSourcesColors);
    glUniformMatrix4fv(glGetUniformLocation(programs[WINDMILL_PROGRAM], "lightSourcesDirections"), 1, GL_FALSE, lightSourcesDirections);

    float camera_position[3]; camera_position[0] = position.x;  camera_position[1] = position.y;  camera_position[2] = position.z;
	glUniform3fv(glGetUniformLocation(programs[WINDMILL_PROGRAM], "camera_position"), 1, camera_position);

    w->bladeangle += dt*windspeed/3;

	Rz(w->bladeangle, w->bladerotationMatrix);
    GLfloat bladeBaseMatrix[16];
    Mult(w->windmillMDLMatrix[WINDMILL_BASE], w->bladecenterMatrix, work[0]);
    Mult(work[0], w->bladerotationMatrix, bladeBaseMatrix);

    {
        glActiveTexture(GL_TEXTURE0);
        glBindTexture(GL_TEXTURE_2D, billboards[WOOD_TEXTURE]);
        glActiveTexture(GL_TEXTURE1);
        glBindTexture(GL_TEXTURE_2D, billboards[WOOD_TEXTURE]);

        glUniform1i(glGetUniformLocation(programs[WINDMILL_PROGRAM], "firstTexUnit"), 0);
        glUniform1i(glGetUniformLocation(programs[WINDMILL_PROGRAM], "secondTexUnit"), 1);
        glUniformMatrix4fv(glGetUniformLocation(programs[WINDMILL_PROGRAM], "baseMatrix"), 1, GL_TRUE, bladeBaseMatrix);
        int i = 0;
        for(i = 0; i < 4; ++i) {
            glUniformMatrix4fv(glGetUniformLocation(programs[WINDMILL_PROGRAM], "mdlMatrix"), 1, GL_TRUE, w->bladeMDLMatrix[i]);
            DrawModel(w->blades[i]);
        }
    }

    {
        glUniformMatrix4fv(glGetUniformLocation(programs[WINDMILL_PROGRAM], "baseMatrix"), 1, GL_TRUE, w->windmillMDLMatrix[WINDMILL_BASE]);
        int i = 0;

        for(i = 1; i < 3; ++i) {
            glUniformMatrix4fv(glGetUniformLocation(programs[WINDMILL_PROGRAM], "mdlMatrix"), 1, GL_TRUE, w->windmillMDLMatrix[i]);
            DrawModel(w->windmill[i]);
        }

        glActiveTexture(GL_TEXTURE0);
        glBindTexture(GL_TEXTURE_2D, billboards[BRICK_TEXTURE]);
        glActiveTexture(GL_TEXTURE1);
        glBindTexture(GL_TEXTURE_2D, billboards[BRICK_CRACK_TEXTURE]);

        glUniformMatrix4fv(glGetUniformLocation(programs[WINDMILL_PROGRAM], "mdlMatrix"), 1, GL_TRUE, w->windmillMDLMatrix[WALLS]);
        DrawModel(w->windmill[WALLS]);
    }

	//printError("display windmill");
}
コード例 #8
0
ファイル: naj.cpp プロジェクト: AiHaibara/acm-icpc
	inline Int64 Pow(Int64 a, Int64 n, Int64 p) {
		Int64 r = 1;
		while (n) {
			if (n&1) r = Mult(r, a, p);
			n >>= 1;
			a = Mult(a, a, p);
		}
		return r;
	}
コード例 #9
0
ファイル: VectorUtils3.c プロジェクト: Grodaaa/TSBK03
// Rotation around arbitrary axis (rotation only)
mat4 ArbRotate(vec3 axis, GLfloat fi)
{
	vec3 x, y, z;
	mat4 R, Rt, Raxel, m;

// Check if parallel to Z
	if (axis.x < 0.0000001) // Below some small value
	if (axis.x > -0.0000001)
	if (axis.y < 0.0000001)
	if (axis.y > -0.0000001)
	{
		if (axis.z > 0)
		{
			m = Rz(fi);
			return m;
		}
		else
		{
			m = Rz(-fi);
			return m;
		}
	}

	x = Normalize(axis);
	z = SetVector(0,0,1); // Temp z
	y = Normalize(CrossProduct(z, x)); // y' = z^ x x'
	z = CrossProduct(x, y); // z' = x x y

	if (transposed)
	{
		R.m[0] = x.x; R.m[4] = x.y; R.m[8] = x.z;  R.m[12] = 0.0;
		R.m[1] = y.x; R.m[5] = y.y; R.m[9] = y.z;  R.m[13] = 0.0;
		R.m[2] = z.x; R.m[6] = z.y; R.m[10] = z.z;  R.m[14] = 0.0;

		R.m[3] = 0.0; R.m[7] = 0.0; R.m[11] = 0.0;  R.m[15] = 1.0;
	}
	else
	{
		R.m[0] = x.x; R.m[1] = x.y; R.m[2] = x.z;  R.m[3] = 0.0;
		R.m[4] = y.x; R.m[5] = y.y; R.m[6] = y.z;  R.m[7] = 0.0;
		R.m[8] = z.x; R.m[9] = z.y; R.m[10] = z.z;  R.m[11] = 0.0;

		R.m[12] = 0.0; R.m[13] = 0.0; R.m[14] = 0.0;  R.m[15] = 1.0;
	}

	Rt = Transpose(R); // Transpose = Invert -> felet ej i Transpose, och det Šr en ortonormal matris

	Raxel = Rx(fi); // Rotate around x axis

	// m := Rt * Rx * R
	m = Mult(Mult(Rt, Raxel), R);
	
	return m;
}
コード例 #10
0
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
}
コード例 #11
0
ファイル: lab4-4.c プロジェクト: Grulfen/tsbk07
Point3D update_sphere(float t, GLfloat* total)
{
        Point3D sphere_pos;
        sphere_pos.x = 0;
        sphere_pos.y = 0;
        sphere_pos.z = 0;
        T(60,0,0, trans);
        Ry(0.01*t, roty);
        Mult(roty, trans, total);
        T(125,0,125, trans);
        Mult(trans, total, total);
        MatrixMultPoint3D(total, &sphere_pos, &sphere_pos);
        return sphere_pos;
}
char* Mult(int **s, int i, int j) {
    if(i < j) {
        char *retVal = (char*) malloc(10);
        char *a = Mult(s, i, s[i][j]);
        char *b = Mult(s, s[i][j] + 1, j);
        sprintf(retVal, "(%s*%s)\0", a, b);
        return retVal;
    }
    else {
        char *retVal = (char *) malloc(3);
        sprintf(retVal, "A%d\0", i);
        return retVal;
    }
}
コード例 #13
0
ファイル: lab2-3.c プロジェクト: Nicsi918/Labs
void display(void)
{
	printError("pre display");
	
	GLfloat t = (GLfloat)glutGet(GLUT_ELAPSED_TIME);
    mat4 transMatrix = T(0.0f, 1.0f, -3.0f);
    mat4 rotMatrix = Ry(0.1f);
    mat4 total = Mult(rotMatrix, transMatrix);
    //total = Mult(projectionMatrix, total);
    
   glUniformMatrix4fv(glGetUniformLocation(program, "projectionMatrix"), 1, GL_TRUE, projectionMatrix);
   //glUniformMatrix4fv(glGetUniformLocation(program, "transMatrix"), 1, GL_TRUE, transMatrix.m);
   glUniformMatrix4fv(glGetUniformLocation(program, "totMatrix"), 1, GL_TRUE, total.m);
   //glUniformMatrix4fv(glGetUniformLocation(program, "rotMatrix3"), 1, GL_TRUE, rotMatrix3);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	// clear the screen
	
	glBindVertexArray(bunnyVertexArrayObjID);    // Select VAO
   glDrawElements(GL_TRIANGLES, m->numIndices, GL_UNSIGNED_INT, 0L);

	
	printError("display");
	
	glutSwapBuffers();
}
コード例 #14
0
status_t _GlBinaryOp2d::Process(	const GlPlanes* src, GlPlanes& dest,
									GlProcessStatus* status)
{
	if (dest.size < 1) return B_OK;

	GlAlgo2d*		lh = Algo2dAt(_LH_INDEX);
	GlAlgo2d*		rh = Algo2dAt(_RH_INDEX);

	if (lh && rh) {
		GlPlanes*	c = dest.Clone();
		if (c && c->size == dest.size) {
			lh->Process(src, dest, status);
			rh->Process(src, *c, status);
			if (mOp == GL_ADD_BINARY_SRF_KEY) Add(dest, *c);
			else if (mOp == GL_SUB_BINARY_SRF_KEY) Sub(dest, *c);
			else if (mOp == GL_MULT_BINARY_SRF_KEY) Mult(dest, *c);
			else if (mOp == GL_DIV_BINARY_SRF_KEY) Div(dest, *c);
			else if (mOp == GL_MIN_BINARY_SRF_KEY) Min(dest, *c);
			else if (mOp == GL_MAX_BINARY_SRF_KEY) Max(dest, *c);
			else ArpASSERT(false);
		}
		delete c;
	} else if (lh) {
		lh->Process(src, dest, status);
	} else if (rh) {
		rh->Process(src, dest, status);
	}
	return B_OK;
}
コード例 #15
0
ファイル: TpIFT6150-1-Ae.c プロジェクト: smdarry/tiaut2010
/*------------------------------------------------*/
int main(int argc,char **argv)
{
    int i,j,k;
    int length,width,tailleCarre;
    float** MatriceImgR;
    float** MatriceImgI;
    float** MatriceImgM;

    // Generation d'une image carre blanc sur fond noir
    length = 128;
    width = 128;

    printf("Veuillez entrer la taille du carre: ");
    scanf("%d", &tailleCarre);

    MatriceImgR = squareImage(length, width, tailleCarre);

    // Sauvegarde de MatriceImgR sous forme d'image pgm
    SaveImagePgm(NAME_IMG_OUT,MatriceImgR,length,width);

    // Allocation memoire pour la FFT
    MatriceImgI=fmatrix_allocate_2d(length,width);
    MatriceImgM=fmatrix_allocate_2d(length,width);

    // Initialisation a zero de toutes les matrices
    for(i=0;i<length;i++) 
    {
        for(j=0;j<width;j++) 
        {
	        MatriceImgI[i][j]=0.0;
	        MatriceImgM[i][j]=0.0;
        }
    }

    // Decalage de l'image pour obtenir un spectre au centre
    shiftSpatial(MatriceImgR,length,width);
  
    // FFT
    FFTDD(MatriceImgR,MatriceImgI,length,width);

    // Module
    Mod(MatriceImgM,MatriceImgR,MatriceImgI,length,width);

    // Pour visu
    //RecalLog(MatriceImgM,length,width);
    Recal(MatriceImgM,length,width);
    Mult(MatriceImgM,20,length,width);
  
    // Sauvegarde de MatriceImgM sous forme d'image pgm
    SaveImagePgm(NAME_SPC_OUT,MatriceImgM,length,width);

    // Liberation memoire pour les matrices
    free_fmatrix_2d(MatriceImgR);
    free_fmatrix_2d(MatriceImgI); 
    free_fmatrix_2d(MatriceImgM);

    // Retour sans probleme
    printf("\n C'est fini ... \n\n\n");
    return 0; 	 
}
コード例 #16
0
ファイル: lab4-2.c プロジェクト: hansfilipelo/TSBK07
void display(void)
{
	handle_keyboard(&cam, &lookAtPoint, &upVector, &movement_speed);

	// clear the screen
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	mat4 total, modelView, camMatrix;

	printError("pre display");

	glUseProgram(program);

	// Build matrix
	camMatrix = lookAtv(cam,lookAtPoint,upVector);

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

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

	printError("display 2");

	glutSwapBuffers();
}
コード例 #17
0
ファイル: lab4-1.c プロジェクト: lragnarsson/TSBK07-Labs
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, "mdlMatrix"), 1, GL_TRUE, total.m);

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

    printError("display 2");

    glutSwapBuffers();
}
コード例 #18
0
ファイル: lab3-4.c プロジェクト: Nicsi918/Labs
void UploadObjectMatricesArbRot(float x, float y, float z, vec3 rAxis, float rAngle, mat4 view, mat4 projection, GLuint prg)
{
	mat4 transMatrix = T(x,y,z);
   mat4 invTransMatrix = T(-x,-y,-z);
   mat4 rotMatrix = ArbRotate(rAxis, rAngle);
   mat4 total = Mult(transMatrix, rotMatrix);
   total = Mult(total, invTransMatrix);
   total = Mult(total, transMatrix);
   mat3 normalMatrix = mat4tomat3(total);
   
   glUniformMatrix4fv(glGetUniformLocation(prg, "viewMatrix"), 1, GL_TRUE, view.m);
   glUniformMatrix3fv(glGetUniformLocation(prg, "normalMatrix"), 1, GL_TRUE, normalMatrix.m);
   glUniformMatrix4fv(glGetUniformLocation(prg, "mdlMatrix"), 1, GL_TRUE, total.m);
   glUniformMatrix4fv(glGetUniformLocation(prg, "projectionMatrix"), 1, GL_TRUE, projection.m);

}
コード例 #19
0
ファイル: game.cpp プロジェクト: PONT-MAX/TSBK07
void Game::duck_cam_controll(){
    
    //obstacle positions
    mat4 obstacle_total = maze->get_total();
    obstacle_x_pos = maze->obstacle_x_pos;
    
    mat4 obstacle_pos = T(obstacle_x_pos, 0, 4.5);
    obstacle_total = Mult(obstacle_total, obstacle_pos);
    
    obstacle_x_pos = obstacle_total.m[3];
    
    
    int cam_x_pos = -15;
    int diff_x = abs(obstacle_x_pos - cam_x_pos);
    
    if (obstacle_x_pos < -15) {
        duck_camera = false;
        
    }
    
    if (diff_x > 20){
        duck_camera = false;
    }
    
    
}
コード例 #20
0
ファイル: lab2-3.c プロジェクト: Grulfen/tsbk07
void display(void)
{
	printError("pre display");

        // Update rotation matrix
        t = (GLfloat)glutGet(GLUT_ELAPSED_TIME);

        T(0,0,-3, trans);
        Ry(0.001*t, rot);
        Mult(trans, rot, total);

	// clear the screen
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

        glBindVertexArray(bunnyVertexArrayObjID);    // Select VAO
        glDrawElements(GL_TRIANGLES, m->numIndices, GL_UNSIGNED_INT, 0L);
        
        // Upload the Matrices
        glUniformMatrix4fv(glGetUniformLocation(program, "projectionMatrix"), 1, GL_TRUE, projectionMatrix);
        glUniformMatrix4fv(glGetUniformLocation(program, "mdlMatrix"), 1, GL_TRUE, total);
        
        // Upload texture unit
        glUniform1i(glGetUniformLocation(program, "texUnit"), 0); // Texture unit 0
	
	printError("display");
	
	//glFlush();
	glutSwapBuffers();
}
コード例 #21
0
ファイル: Operatii.c プロジェクト: ratza128/App_Parser
void PrelucrareArbore(struct TNod *lel){

	char * a=lel->info;
	lel->rez = (double*)malloc(sizeof(double));  
	
	if(strcmp(a,"+")==0){
		Add(lel->st,lel->dr,lel);
	}else if(strcmp(a,"-")==0){
		Sub(lel->st,lel->dr,lel);
	}else if(strcmp(a,"*")==0){
		Mult(lel->st, lel->dr,lel);
	}else if(strcmp(a,"/")==0){
		Divi(lel->st, lel->dr,lel);
	}else if(strcmp(a,"sum")==0){
		Sum(lel);
		//printf("PrelArb %lf\n",*(lel->rez));
	}else if(strcmp(a,"prod")==0){
		Prod(lel);
	}else if(strcmp(a,"sqrt")==0){
		SqrtCalc(lel->st,lel->dr,lel);
	}else if(strcmp(a,"pow")==0){
		PowCalc(lel->st, lel->dr,lel);
	}else{
		*(lel->rez) = (double)atoi(a);
		//printf("ATOI %lf\n",*(lel->rez));
	}
}
コード例 #22
0
ファイル: matrix.cpp プロジェクト: jbongard/cords
void MATRIX::Mult(double val) {

	for (int i=0;i<length;i++)

		for (int j=0;j<width;j++)

			Mult(i,j,val);
}
コード例 #23
0
ファイル: lab3-2.c プロジェクト: LordStraider/TSBK07
void display(void) {
	printError("pre display");

	/* clear the screen*/
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	GLfloat t = (GLfloat)glutGet(GLUT_ELAPSED_TIME);
	SetVector(xValue, 0.0, (zValue+3), &p);
	lookAt(&p, &l, 0.0, 1.0, 0.0, &cam);


	glUniformMatrix4fv(glGetUniformLocation(program, "camMatrix"), 1, GL_TRUE, cam);

    T(-3.9, -7.4, 0, trans);
    S(0.8, 0.8, 0.8, shear);
    Mult(trans, shear, total);
	glUniformMatrix4fv(glGetUniformLocation(program, "mdlMatrix"), 1, GL_TRUE, total);
    DrawModel(windmillRoof, program, "inPosition", "inNormal", "inTexCoord");

    T(-3.9, -7.4, 0, trans);
    S(0.8, 0.8, 0.8, shear);
    Mult(trans, shear, total);
	glUniformMatrix4fv(glGetUniformLocation(program, "mdlMatrix"), 1, GL_TRUE, total);
    DrawModel(windmillBalcony, program, "inPosition", "inNormal", "inTexCoord");

    T(-3.9, -7.4, 0, trans);
    S(0.8, 0.8, 0.8, shear);
    Mult(trans, shear, total);
	glUniformMatrix4fv(glGetUniformLocation(program, "mdlMatrix"), 1, GL_TRUE, total);    
	DrawModel(windmillWalls, program, "inPosition", "inNormal", "inTexCoord");

	int i;
	for (i = 0; i < 4; i++) {
	    T(0, 0, 0, trans);
	    S(0.5, 0.5, 0.5, shear);
	    Mult(trans, shear, total);
		Rx(i * PI / 2 + t/1000, rot);
	    Mult(rot, total, total);
		glUniformMatrix4fv(glGetUniformLocation(program, "mdlMatrix"), 1, GL_TRUE, total);
	    DrawModel(blade, program, "inPosition", "inNormal", "inTexCoord");
	}

	printError("display");

	glutSwapBuffers();
}
コード例 #24
0
ファイル: Starter.cpp プロジェクト: hento581/OProject2
void DrawMap(Model* map, Model* compass, mat4 view)
{
		vec3 mapNorm = vec3(0,0,1);
		vec3 camPos = VectorAdd(player->getPos(),vec3(0,2.0,0));
		vec3 mapToCam = VectorSub(player->getPos(),player->getLook());

		//Put map in front of the cam
		vec3 mapPos = VectorSub(camPos,mapToCam);
		mat4 translate=  T(mapPos.x,mapPos.y,mapPos.z);
		view = Mult(view, translate);

		//Rotate in around Y-axis
		vec3 mapToCamXZ = mapToCam;
		mapToCamXZ.y = 0;
		mapToCamXZ = Normalize(mapToCamXZ);
		vec3 upVec = CrossProduct(mapNorm, mapToCamXZ);
		GLfloat angle = acos(DotProduct(mapNorm, mapToCamXZ));
		mat4 billRotMat = ArbRotate(upVec, angle);
		view = Mult(view,billRotMat);

		//Rotate in around XZ-axis
		mapToCam = Normalize(mapToCam);
		angle = acos(DotProduct(mapToCamXZ,mapToCam));
		
		if (mapToCam.y < 0)
			billRotMat = ArbRotate(vec3(1,0,0), angle);	
		else
			billRotMat = ArbRotate(vec3(-1,0,0), angle);

		view = Mult(view,billRotMat);
		
		//Rotate map 
		mat4 viewCompass = view;
		view = Mult(view,ArbRotate(vec3(0,0,1), mapAngle));		

		view = Mult(view,T(0,0,-0.1));
		glUniformMatrix4fv(glGetUniformLocation(billBoardProgram, "camMatrix"), 1, GL_TRUE, player->getCamMatrix().m);
		glUniformMatrix4fv(glGetUniformLocation(billBoardProgram, "mdlMatrix"), 1, GL_TRUE, view.m);
		DrawModel(map, billBoardProgram, "inPosition",  NULL, "inTexCoord"); 
		
		//Kompass
		viewCompass = Mult(viewCompass,T(-0.35,-0.3,0.1));
		GLfloat compassAngle = acos(DotProduct(vec3(0,0,1),mapToCamXZ));
		if (mapToCam.x < 0)
			viewCompass = Mult(viewCompass,ArbRotate(vec3(0,0,1), compassAngle));
		else
			viewCompass = Mult(viewCompass,ArbRotate(vec3(0,0,-1), compassAngle));
		
		glActiveTexture(GL_TEXTURE5);
		glBindTexture(GL_TEXTURE_2D, compassTex);
		glUniform1i(glGetUniformLocation(billBoardProgram, "tex1"), 5);

		glUniformMatrix4fv(glGetUniformLocation(billBoardProgram, "mdlMatrix"), 1, GL_TRUE, viewCompass.m);
		DrawModel(compass, billBoardProgram, "inPosition",  NULL, "inTexCoord");

}
コード例 #25
0
//==========================================================================*
// 2D: Result := CosAlpha(LHS-C,RHS-C)
//--------------------------------------------------------------------------*
Tdble CosAlpha(const TV2D &LHS, const TV2D &RHS, const TV2D &C)
{
  TV2D DLHS, DRHS;

  DLHS = Sub(LHS,C);
  DRHS = Sub(RHS,C);
  return Mult(DLHS,DRHS) / (Len(DLHS) * Len(DRHS));
};
コード例 #26
0
ファイル: Matrix4x4.cpp プロジェクト: AaronMK/Meega
	mat4x4 operator*(float f, const mat4x4 &M)
	{
		vec4 Mult(f);

		return mat4x4(Mult*M.Cols[0],
		              Mult*M.Cols[1],
		              Mult*M.Cols[2],
		              Mult*M.Cols[3]);
	}
コード例 #27
0
ファイル: lab3-4.c プロジェクト: Nicsi918/Labs
void drawSkybox(mat4 view, mat4 projection)
{
	glDisable(GL_DEPTH_TEST);
	glDisable(GL_CULL_FACE);
	glUseProgram(skyboxProgram);
	//mat4 totMatrix = mat3tomat4(mat4tomat3(view));
	//totMatrix = Mult(projection, totMatrix);
	mat4 transMatrix = T(p.x, p.y - 0.1, p.z);
	mat4 rotMatrix = mat3tomat4(mat4tomat3(view));
	mat4 totMatrix = transMatrix; //Mult(rotMatrix, transMatrix);
	//mat4 totMatrix = Mult(rotMatrix, transMatrix);
	totMatrix = Mult(view, totMatrix);
	totMatrix = Mult(projection, totMatrix);
	glUniformMatrix4fv(glGetUniformLocation(skyboxProgram, "totMatrix"), 1, GL_TRUE, totMatrix.m);
	DrawModel(skybox, skyboxProgram, "in_Position", "in_Normal", "inTexCoord");
	glEnable(GL_DEPTH_TEST);
	glEnable(GL_CULL_FACE);
}
コード例 #28
0
ファイル: lab2-5.c プロジェクト: simplerr/TSBK07
void OnTimer(int value)
{
	static float e = 0;

	mat4 rot, trans, scale, total;

	scale = S(6, 6, 6);
	rot = Ry(e);
	trans = T(0, 0, 0);
	total = Mult(trans, rot);
	total = Mult(total, scale);

	glUniformMatrix4fv(glGetUniformLocation(program, "mdlMatrix"), 1, GL_TRUE, total.m);	// // Upload matrix
	e += 0.01;
	
	glutPostRedisplay();
	glutTimerFunc(20, &OnTimer, value);
}
コード例 #29
0
ファイル: Boid.cpp プロジェクト: CStejmar/birdSim
void Boid::draw(mat4 cameraMatrix, GLuint* shader, Model* model, GLuint* texture)
{
  mat4 translationMatrix = T(position.x, position.y, position.z);
  mat4 transformationMatrix = Mult(translationMatrix, rotationMatrix);
  glUseProgram(*shader);
  glUniformMatrix4fv(glGetUniformLocation(*shader, "mdl2World"), 1, GL_TRUE, transformationMatrix.m);
  glUniformMatrix4fv(glGetUniformLocation(*shader, "world2View"), 1, GL_TRUE, cameraMatrix.m);
  glBindTexture(GL_TEXTURE_2D, *texture);	
  DrawModel(model, *shader, "inPosition", "inNormal", "inTexCoord");
}
コード例 #30
0
ファイル: SpriteLight.c プロジェクト: Rovanion/TSBK03
void DrawSprite(SpritePtr sp)
{
	mat4 trans, rot, scale, m;
	
	glUseProgram(program);
	// Update matrices
	scale = S((float)sp->face->width/gWidth * 2, (float)sp->face->height/gHeight * 2, 1);
//	trans = T(sp->position.h/gWidth, sp->position.v/gHeight, 0);
	trans = T(sp->position.h/gWidth * 2 - 1, sp->position.v/gHeight * 2 - 1, 0);
	rot = Rz(sp->rotation * 3.14 / 180);
	m = Mult(trans, Mult(scale, rot));
	
	glUniformMatrix4fv(glGetUniformLocation(program, "m"), 1, GL_TRUE, m.m);
	glBindTexture(GL_TEXTURE_2D, sp->face->texID);
	
	// Draw
	glBindVertexArray(vertexArrayObjID);	// Select VAO
	glDrawArrays(GL_TRIANGLES, 0, 6);	// draw object
}