Пример #1
0
/// Computes lighting for the entire scene
void computeLighting()
{
    for (auto &ridge : mountains)
    {
        for (int i=0; i < ridge.meshVertices.size(); i = i+3)
        {
            // Compute for our (single) light
            Vec3Df vertexpos = Vec3Df(ridge.meshVertices[i],
                                      ridge.meshVertices[i+1],
                                      ridge.meshVertices[i+2]);
            Vec3Df normal = Vec3Df(ridge.meshNormals[i],
                                   ridge.meshNormals[i+1],
                                   ridge.meshNormals[i+2]);
            Vec3Df lighting = computeLighting(vertexpos, normal, DIFFUSE_LIGHTING);
            
            // Pass computed values to Ridge
            ridge.meshColors[i] = lighting[0];
            ridge.meshColors[i+1] = lighting[1];
            ridge.meshColors[i+2] = lighting[2];
        }
    }
	
	if (toggleBoss) {
		std::vector<Vertex> vertices = boss.getMesh().vertices;
		std::vector<Vec3Df> meshColors = std::vector<Vec3Df>(vertices.size());

		auto rotMat = matrixMultiplication(
			rotateMatrixY(boss.angleHeadY*M_PI / 180),
			rotateMatrixX(boss.angleHeadZ*M_PI / 180)
			);

		for (int i = 0; i < vertices.size(); i++)
		{
			// Compute for our (single) light
			Vertex vertex = vertices[i];
			Vec3Df vec = vertex.p;
			vec = calculateMatrix(rotMat, vec);
			vec = vec + boss.translation;
			vec = vec * boss.scale;
			vec = vec + boss.position;

			Vec3Df nor = vertex.n;
			nor = calculateMatrix(rotMat, nor);
			nor = nor + boss.translation;
			nor = nor * boss.scale;
			nor = nor + boss.position;

			Vec3Df lighting = computeLighting(vec, nor, PHONG_LIGHTNING);

			meshColors[i] = lighting;
		}
		boss.getMesh().meshColor = meshColors;
	}
}
Пример #2
0
//take input file from fortran code and convert into format which can be processed by this code, so we can check if equivalent
int convert(int mat[SIZE1][SIZE2],char *infile,char *outfile,int * numbers)
{
	printf("reading in data file \n"); 
	int swit2,count,n,val;
	struct entry bob; 
	FILE * fpin;
	FILE * fpout;  
	char text [1000]; 
	fpin=fopen(infile,"r"); 
	fpout=fopen(outfile,"w");
	(*numbers)=0; //we don't know how many results we are reading in

	fgets(&text[0],1000,fpin); //get first two lines
        fgets(&text[0],1000,fpin);  
	swit2=0; 
	while(1)
	{
		//code for locating set of values from line and extracting
		count=0; 
		while(count<SIZE1)
		{
                        //second method for simpler output format
                        fscanf(fpin,"%d",&val); 
                        if(feof(fpin)) //end of file indicator, read in all words which are part of matrices
			{	
				swit2=1; 
				break;
			} 
			//printf("%d \n",val); 
        		bob.rows[count]=val;
			//printf("%d \n",bob.rows[count]);  
			count++; 
		}	
                if(swit2==1)
		{
			break;
		}
		if(count==SIZE1)  //if there are SIZE1 components read in, print out matrix to outfile              
		{
			calculateMatrix(bob,mat); 
			//displayentry(bob,NULL); 
			displaymatrix(mat,fpout);
			(*numbers)++; 
			fgets(&text[0],1000,fpin); //go to next line
		}
	}
	//printdata(data,size1,(*numbers)); 
	printf("read data in \n"); 
	printf("numbers %d \n",(*numbers)); 
	
	fclose(fpin); 
	fclose(fpout); 
	
	return 0; 
}
Пример #3
0
void ModifiedPatankarRK(int dim_matrix, double oldvalue[], double dt, double newvalue[], recomb_t *thisRecombRates, cell_t *thisCell){
	double intervalue[dim_matrix];
	double oldvalue_local[dim_matrix];
	double newvalue_local[dim_matrix];
	double destr_rate[dim_matrix][dim_matrix];
	double inter_destr_rate[dim_matrix][dim_matrix];
	double matrix[dim_matrix][dim_matrix];

	initializeVector(dim_matrix, oldvalue_local, oldvalue);
	initializeVector(dim_matrix, newvalue_local, oldvalue);
	
// 	printf("oldvalue_local[0] = %e\toldvalue_local[1] = %e\n", oldvalue_local[0], oldvalue_local[1]);

// 	First Runge Kutta step
	initializeVector(dim_matrix, oldvalue_local, newvalue_local);	//oldvalue = x

	create_rate_functions(dim_matrix, destr_rate, oldvalue_local, thisRecombRates, thisCell);	//calculate destruction rates

	calculateMatrix(dim_matrix, dt, matrix, destr_rate, oldvalue_local);	//calculate matrix for destr_rate and oldvalue

	solveSetOfEquations(dim_matrix, matrix, oldvalue_local, intervalue);	//Solve set of equations for intervalue

	checkVector(dim_matrix,intervalue);

// 	Second Runge Kutta step
	initializeVector(dim_matrix, oldvalue_local, oldvalue);		//oldvalue = newvalue

	create_rate_functions(dim_matrix, inter_destr_rate, intervalue, thisRecombRates, thisCell);	//calculate new destruction rates from intervalue

	add_rate_functions(dim_matrix, inter_destr_rate, destr_rate);	//add rate functions destr_rate and interdestr_rate, output on interdestr_rate

	calculateMatrix(dim_matrix, dt*0.5, matrix, inter_destr_rate, intervalue);	//calculate matrix for interdestr_rate and intervalue

	solveSetOfEquations(dim_matrix, matrix, oldvalue_local, newvalue_local);	//solve set of equations for newvalue

	checkVector(dim_matrix, newvalue_local);

	initializeVector(dim_matrix, newvalue, newvalue_local);
}
Пример #4
0
//Генерация узлов
bool Environment::generateNodes(int nodeCount)
{
    const int maxAttemps = 9999;
    int attemps = 0;

    this->nodeCount = nodeCount;

    cout << "Инициализация узлов\n\n";
    cout << "Размер области: " << xSize << " x "<< ySize << "\n\n";
    cout << "Запрет на передачу при приеме ";
    if (Simulator::getInstance().mode == DisableTransmittingMode_RTS) cout <<"RTS\n\n";
    else cout << "CTS\n\n";

    generateNodesAttempt();

    //проверяем связность сети
    while ((!(isNetworkConnected()))&&(attemps < maxAttemps))
    {
        attemps++;
        this->clear();
        Simulator::getInstance().getEventQueue()->clear();
//        cout << "Сеть несвязна, перегенерируем координаты узлов "<<1+attemps<<" раз\n";
        generateNodesAttempt();
    }

     calculateMatrix();

    if (isNetworkConnected())
    {
        for (int nodeMac = 0; nodeMac < nodeCount; nodeMac++)
        {
            BSSNode* node = nodes[nodeMac];
            cout<<"Узел P"<<nodeMac<<" добавлен: X="<<node->getX()<<" Y="<<node->getY()<<", момент включения = "<<node->getTimeOn()<<"\n";
        }
//        printMatrix();
        return true;
    }
    else
        return false;
}
Пример #5
0
int sort(char * fname, int counts, int mat[SIZE1][SIZE2])
{
	FILE * fp; 
	int n,n1,n2, inti,max,start,maxdiff;
	struct fullentry * matrices;
	int minsidelobes [MAXONES]; 
	fp=fopen(fname,"r");
	matrices=(struct fullentry *)calloc(counts,sizeof(struct fullentry)); 
	printf("Beginning to sort results \n");
	max=0;
 
	for(n=0; n<MAXONES; n++)
	{
		minsidelobes[n]=100;	
	}
	for(n=0; n<counts; n++)
	{
		for(n2=0; n2<SIZE2; n2++)
		{				
			for(n1=0; n1<SIZE1; n1++)
			{
				fscanf(fp,"%d ",&inti); 
				mat[n1][n2]=inti;
			}
			fscanf(fp,"\n ",&inti); 
		}
		lexleast(mat,1);  
		calculateFullEntry(mat,&matrices[n]);
		//displayentry(matrices[n].intrep,NULL); 
		if(matrices[n].ones>max)
			max=matrices[n].ones;
		if(minsidelobes[matrices[n].ones]>matrices[n].peaksidelobe)
			minsidelobes[matrices[n].ones]=matrices[n].peaksidelobe;   
	}
	fclose(fp);
	printf("Maximum ones reached in search is %d \n",max);
	printf("optimal sidelobe for each level \n"); 
	start=-1; 
	//
	//printf("minones %d max %d \n",MINONES,max);
	int min=100; 
	//need to be careful here, get start of range and minimum sidelobe independently
	for(n=MINONES; n<=max; n++)
	{
		//printf("%d \n",minsidelobes[n]); 
		if(minsidelobes[n]<min)
		{
			min=minsidelobes[n]; 
		}
		if(start==-1 && minsidelobes[n]!=100)
			start=n; 
		if(start!=-1)
			printf("%d ",minsidelobes[n]); 
	} 
	printf(" \n"); 
	//create matrix for storing sidelobe and length statistics, if find lower sidelobe, need to also break down by sidelobe		 
	int * counttype=(int *)calloc((max-start+1)*(MAXSIDELOBE-min+1),sizeof(int)); 
	qsort((void *)matrices,counts,sizeof(struct fullentry),comparefullentry);
	n2=0;


	//now print out only the unique entries 
	fp=fopen(fname,"w"); 
	fprintf(fp,"Matrices for maximum sidelobe %d with dimensions %d by %d \n",MAXSIDELOBE,SIZE1,SIZE2); 

        //need to print out 1st matrix in list first, code works by printing out 1st unique matrix of sorted group and ignoring the rest
	calculateMatrix(matrices[0].intrep,mat); 
	displaymatrix(mat,fp); 	
	displayentry(matrices[0].intrep,fp);
	fprintf(fp,"\n");

	
	//printf("start %d \n",start);  
	counttype[(max-start+1)*(matrices[0].peaksidelobe-min)+matrices[0].ones-start]++; 
	for(n1=0; n1<=MAXSIDELOBE; n1++)
	{
		fprintf(fp,"%d ",matrices[0].spectrum[n1]); 
	}
	fprintf(fp," \n"); 
	fprintf(fp, "ones %d, peak sidelobe %d \n \n",matrices[0].ones,matrices[0].peaksidelobe);  
	n2++;  
	maxdiff=matrices[0].ones-matrices[0].peaksidelobe;

	printf("range for table is %d ones to %d, and sidelobe %d to %d \n",max,start,MAXSIDELOBE,min); 
	printf("entering loop %d counts \n",counts); 	
 
	for(n=1; n<counts; n++)
	{
		if(compareentry(&matrices[n],&matrices[n-1])!=0) //do not print out as long as previous entry same as current entry
		{

			calculateMatrix(matrices[n].intrep,mat);
			if(matrices[n].peaksidelobe>MAXSIDELOBE)
				continue;  
			displaymatrix(mat,fp); 			
			displayentry(matrices[n].intrep,fp);
			fprintf(fp,"\n"); 
			for(n1=0; n1<=MAXSIDELOBE; n1++)
			{
				fprintf(fp,"%d ",matrices[n].spectrum[n1]); 
			}
			fprintf(fp," \n"); 
			fprintf(fp, "ones %d, peak sidelobe %d \n \n",matrices[n].ones,matrices[n].peaksidelobe);  
			//printf("%d %d \n",(max-start+1)*(matrices[n].peaksidelobe-min)+matrices[n].ones-start,(max-start+1)*(MAXSIDELOBE-min+1)); 
			//printf("%d peaksidelobe, %d ones \n",matrices[n].peaksidelobe,matrices[n].ones); 
			counttype[(max-start+1)*(matrices[n].peaksidelobe-min)+matrices[n].ones-start]++; 
			n2++; 
			if((matrices[0].ones-matrices[0].peaksidelobe)>maxdiff)
				maxdiff=(matrices[0].ones-matrices[0].peaksidelobe);
		}		
	} 
	fprintf(fp,"Total Unique matrices are %d \n",n2); 
	printf("sorted through matrices and eliminated redundant elements, have %d unique matrices out of %d \n",n2,counts); 
	fprintf(fp,"Maximum ones reached in search is %d \n",max);
	fprintf(fp,"optimal sidelobe for each level \n"); 
	for(n=start; n<=max; n++)
		fprintf(fp,"%d : %d ",n,minsidelobes[n]); 
	fprintf(fp," \n"); 
	printf("maxdiff is %d, start is %d, max is %d \n",maxdiff,start,max); 
	printf("printing out table \n"); 
	//print out table of counts to give breakdown and sidelobe and int counts for given max
	for(n1=0; n1<=(max-start); n1++)
	{
		fprintf(fp," \n");
		if(n1==0) 
			fprintf(fp,"   ");
		else
			fprintf(fp,"%d  ",n1+start);  	
		for(n2=0; n2<=(MAXSIDELOBE-min); n2++)
		{
			if(n1==0)
				fprintf(fp,"%d  ",n2+min); 
			else
				fprintf(fp,"%d  ",counttype[(max-start+1)*n2+(n1)]); 			
		}
	}
	printf("finished loop \n"); 
	//needs to also give sum of lowest diagonal corresponding to highest max
	int sum=0; 
	for(n1=0; n1<=(max-start); n1++)
	{
		//printf("%d \n",start+n1-maxdiff-minsidelobes[start]); 
		if((start+n1-maxdiff-min)>=0) //if not lined up properly can give sidelobe we did not include before
			sum=sum+counttype[(max-start+1)*(start+n1-maxdiff-min)+n1]; //need to sweep constant diffmax contour	
	}
	printf("\n \n There are %d results with optimal difference of %d \n",sum,maxdiff); 
	fprintf(fp,"\n \n There are %d results with optimal difference of %d \n",sum,maxdiff);  
	fclose(fp);
	printf("reached end \n");  
	return 0; 
}
Пример #6
0
void SceneObject::setOrientation(glm::quat tquat)
{
	m_Orientation = tquat;
	calculateMatrix();
}
Пример #7
0
void SceneObject::setPosition(glm::vec4 tvec4)
{
	m_Position = tvec4;
	calculateMatrix();
}
Пример #8
0
void SceneObject::setPosition(glm::vec3 tvec3)
{
	m_Position = glm::vec4(tvec3,1.0f);
	calculateMatrix();
}
Пример #9
0
void CD3DCG::Render(LPDIRECT3DTEXTURE9 &origTex, D3DXVECTOR2 textureSize,
					D3DXVECTOR2 inputSize, D3DXVECTOR2 viewportSize, D3DXVECTOR2 windowSize)
{
	LPDIRECT3DSURFACE9 pRenderSurface = NULL,pBackBuffer = NULL;
	frameCnt++;

	if(!shaderLoaded)
		return;

	/* save back buffer render target
	*/
	pDevice->GetRenderTarget(0,&pBackBuffer);	

	/* pass 0 represents the original texture
	*/
	shaderPasses[0].tex = origTex;
	shaderPasses[0].outputSize = inputSize;
	shaderPasses[0].textureSize = textureSize;

	calculateMatrix();	

	for(int i=1;i<shaderPasses.size();i++) {
		switch(shaderPasses[i].scaleParams.scaleTypeX) {
			case CG_SCALE_ABSOLUTE:
				shaderPasses[i].outputSize.x = (double)shaderPasses[i].scaleParams.absX;
				break;
			case CG_SCALE_SOURCE:
				shaderPasses[i].outputSize.x = shaderPasses[i-1].outputSize.x * shaderPasses[i].scaleParams.scaleX;
				break;
			case CG_SCALE_VIEWPORT:
				shaderPasses[i].outputSize.x = viewportSize.x * shaderPasses[i].scaleParams.scaleX;
				break;
			default:
				shaderPasses[i].outputSize.x = viewportSize.x;
		}
		switch(shaderPasses[i].scaleParams.scaleTypeY) {
			case CG_SCALE_ABSOLUTE:
				shaderPasses[i].outputSize.y = (double)shaderPasses[i].scaleParams.absY;
				break;
			case CG_SCALE_SOURCE:
				shaderPasses[i].outputSize.y = shaderPasses[i-1].outputSize.y * shaderPasses[i].scaleParams.scaleY;
				break;
			case CG_SCALE_VIEWPORT:
				shaderPasses[i].outputSize.y = viewportSize.y * shaderPasses[i].scaleParams.scaleY;
				break;
			default:
				shaderPasses[i].outputSize.y = viewportSize.y;
		}
		float texSize = npot(max(shaderPasses[i].outputSize.x,shaderPasses[i].outputSize.y));
		
		/* make sure the render target exists and has an appropriate size,
		   then set as current render target with last pass as source
		*/
		ensureTextureSize(shaderPasses[i].tex,shaderPasses[i].textureSize,D3DXVECTOR2(texSize,texSize),true);
		shaderPasses[i].tex->GetSurfaceLevel(0,&pRenderSurface);
		pDevice->SetTexture(0, shaderPasses[i-1].tex);
		pDevice->SetRenderTarget(0,pRenderSurface);
		pRenderSurface->Release();

		/* set vertex declaration of current pass, update vertex
		   buffer and set base streams
		*/
		pDevice->SetVertexDeclaration(shaderPasses[i].vertexDeclaration);
		setVertexStream(shaderPasses[i].vertexBuffer,
			shaderPasses[i-1].outputSize,shaderPasses[i-1].textureSize,shaderPasses[i].outputSize);
		pDevice->SetSamplerState(0, D3DSAMP_ADDRESSU, D3DTADDRESS_BORDER);
		pDevice->SetSamplerState(0, D3DSAMP_ADDRESSV, D3DTADDRESS_BORDER);
		pDevice->SetSamplerState(0, D3DSAMP_MAGFILTER, shaderPasses[i].linearFilter?D3DTEXF_LINEAR:D3DTEXF_POINT);
		pDevice->SetSamplerState(0, D3DSAMP_MINFILTER, shaderPasses[i].linearFilter?D3DTEXF_LINEAR:D3DTEXF_POINT);

		/* shader vars need to be set after the base vertex streams
		   have been set so they can override them
		*/
		setShaderVars(i);

		cgD3D9BindProgram(shaderPasses[i].cgVertexProgram);
		checkForCgError("Binding vertex program");
		cgD3D9BindProgram(shaderPasses[i].cgFragmentProgram);
		checkForCgError("Binding fragment program");
		
		/* viewport defines output size
		*/
		setViewport(0,0,shaderPasses[i].outputSize.x,shaderPasses[i].outputSize.y);

		pDevice->BeginScene();
		pDevice->DrawPrimitive(D3DPT_TRIANGLESTRIP,0,2);
		pDevice->EndScene();
	}

	/* take oldes PREV out of deque, make sure it has
	   the same size as the current texture and
	   then set it up as new original texture
	*/
	prevPass &oldestPrev = prevPasses.back();
	ensureTextureSize(oldestPrev.tex,oldestPrev.textureSize,textureSize,false);
	if(oldestPrev.vertexBuffer)
		oldestPrev.vertexBuffer->Release();
	origTex = oldestPrev.tex;
	prevPasses.pop_back();
	
	/* push current original with corresponding vertex
	   buffer to front of PREV deque
	*/
	shaderPasses[0].vertexBuffer = shaderPasses[1].vertexBuffer;
	prevPasses.push_front(prevPass(shaderPasses[0]));
	
	/* create new vertex buffer so that next render call
	   will not overwrite the PREV
	*/
	pDevice->CreateVertexBuffer(sizeof(VERTEX)*4,D3DUSAGE_WRITEONLY,0,D3DPOOL_MANAGED,&shaderPasses[1].vertexBuffer,NULL);
	
	/* set up last pass texture, backbuffer and viewport
	   for final display pass without shaders
	*/
	pDevice->SetTexture(0, shaderPasses.back().tex);
	pDevice->SetRenderTarget(0,pBackBuffer);
	pBackBuffer->Release();
	RECT displayRect=CalculateDisplayRect(shaderPasses.back().outputSize.x,shaderPasses.back().outputSize.y,windowSize.x,windowSize.y);
	setViewport(displayRect.left,displayRect.top,displayRect.right - displayRect.left,displayRect.bottom - displayRect.top);
	setVertexStream(shaderPasses.back().vertexBuffer,
		shaderPasses.back().outputSize,shaderPasses.back().textureSize,
		D3DXVECTOR2(displayRect.right - displayRect.left,displayRect.bottom - displayRect.top));
	pDevice->SetVertexShader(NULL);
	pDevice->SetPixelShader(NULL);
}
Пример #10
0
 /// Moves the selected vertex by the argument vector.
 void moveLastVertex(const Nimble::Vector2 & move)
 { m_vertices[m_selected] += move; calculateMatrix(); }