Пример #1
0
void level::addTile(int2D position)
{
	if(position.getX() >= _size.getX() || position.getY() >= _size.getY()) return;
	int startPoisition = (position.getY()*_size.getX() + position.getX())*6;
	float3D tempColor;
	int2D tempVertices[4];
	map[position.getY()][position.getX()] ? tempColor = float3D(0.8, 0.8, 0.8) : tempColor = float3D(0.2, 0.2, 1);
	for(int i = 0; i < 6; i++)
		colorArray[i + startPoisition] = tempColor;
	//bottom left
	tempVertices[0] = int2D(position.getX()*_tileSize + 1, position.getY()*_tileSize + 1), 
		//bottom right
		tempVertices[1] = int2D((position.getX() + 1)*_tileSize - 1, position.getY()*_tileSize + 1),
		//upper right
		tempVertices[2] = int2D((position.getX() + 1)*_tileSize - 1, (position.getY() + 1)*_tileSize - 1),
		//upper left
		tempVertices[3] = int2D(position.getX()*_tileSize + 1, (position.getY() + 1)*_tileSize - 1);
	vertexArray[startPoisition] = tempVertices[0];
	vertexArray[startPoisition + 1] = tempVertices[1];
	vertexArray[startPoisition + 2] = tempVertices[2];

	vertexArray[startPoisition + 3] = tempVertices[2];
	vertexArray[startPoisition + 4] = tempVertices[3];
	vertexArray[startPoisition + 5] = tempVertices[0];
}
Пример #2
0
void level::_addRayToTexture(ray * parentRay)
{
	ray * tempRay = parentRay;
	int2D pos = int2D(tempRay->getEndPos().getX(), tempRay->getEndPos().getY());
	double currentAlpha = tempRay -> getAlpha();
	while(tempRay)
	{
		pos = int2D(tempRay->getEndPos().getX(), tempRay->getEndPos().getY());
		currentAlpha = tempRay->getAlpha();
		_processArray[pos.getY()][pos.getX()][3] += currentAlpha;
		_processPointArray[pos.getY()][pos.getX()][3] -= currentAlpha;
		tempRay = tempRay->getNext();
	}
}
Пример #3
0
void makeDistrPlot(atom *atoms,int natoms,double ax) {
	int j,i,count,ind;
	int **list;
	FILE *fp;

	printf("Atom kinds: %d: ",muls->atomKinds);
	for (i=0;i<muls->atomKinds;i++) printf(" %3d ",muls->Znums[i]);
	printf("\n");

	count = (int)(ax/DR+1);
	list = int2D(muls->atomKinds,count,"list");
	memset(list[0],0,count*muls->atomKinds*sizeof(int));
	for (j=0;j<natoms;j++) {
		ind = (int)(atoms[j].x/DR);
		if (ind < 0) ind = 0;
		if (ind >= count) ind = count;
		for (i=0;i<muls->atomKinds;i++) if (muls->Znums[i] == atoms[j].Znum) break;
		if (i==muls->atomKinds) {
			// printf("Error: wrong Z (%d)\n",atoms[j].Znum);
		}
		else list[i][ind]++;
	}
	fp = fopen("disList.dat","w");
	for (j=0;j<count;j++) {
		fprintf(fp,"%.3f ",j*DR);
		for (i=0;i<muls->atomKinds;i++) fprintf(fp,"%d ",list[i][j]);
		fprintf(fp,"\n");
	}
}
Пример #4
0
int2D level::getIndexFromLocation(int2D location)
{
	location = location / _tileSize;
	if(location.getX() >= _size.getX() ||
	   location.getY() >= _size.getY() ||
	   location.getX() < 0 || location.getY() < 0)
	{
		int tempX = 0, tempY = 0;
		if(location.getX() >= _size.getX())
			tempX = _size.getX() - 1;
		else if(location.getX() < 0)
			tempX = 0;
		else tempX = location.getX();

		if(location.getY() >= _size.getY())
			tempY = _size.getY() - 1;
		else if(location.getY() < 0)
			tempY = 0;
		else tempY = location.getX();
		return int2D(tempX, tempY);
	}
	return location;
}
Пример #5
0
void level::_readFile(string fileName)
{
	FILE * currentFile = NULL;
	int fileSize = 0;
	int count = 0;
	int xSize, ySize, tileSize;
	char * readBuffer;
	string currentValue = "";
	float2D playerStart;
	float2D goalPosition;
	fopen_s(&currentFile, &fileName[0], "rb");
	if(currentFile == NULL)
	{
		cout << "that level file is not available, exiting program";
		for(int i = 0; i < 3; i++)
		{
			Sleep(500);
			cout << ".";
		}
		exit(100);
	}
	if(!currentFile) return;
	//The file lay out is as follow
	/*
		first line
		is the tile size
		second line
		x and y size of map
		
		next is the grid 
		0s for a blocked path
		1s for a clear path

		next line is the x and y start position
		next line is the x and y goal position

		after that is the information needed for 
		the generation of the lights in the map

		the next line is the start position
		the next line is the goal position

		the next series of lines is the lighting data

	*/
	fseek(currentFile, 0, SEEK_END);
	fileSize = ftell(currentFile);
	rewind(currentFile);
	readBuffer = new char[fileSize];
	fread_s(readBuffer, fileSize, sizeof(char), fileSize, currentFile);
	while(readBuffer[count] != '\n')
	{
		currentValue += readBuffer[count];
		count++;
	}
	tileSize = atoi(&currentValue[0]);
	currentValue = "";
	count++;
	while(readBuffer[count] != ' ')
	{
		currentValue += readBuffer[count];
		count++;
	}
	xSize = atoi(&currentValue[0]);
	currentValue = "";
	count++;
	while(readBuffer[count] != '\n')
	{
		currentValue += readBuffer[count];
		count++;
	}
	ySize = atoi(&currentValue[0]);
	map = new bool*[ySize];

	for(int i = ySize; i--;)
		map[i] = new bool[xSize];
	count++;
	for(int i = ySize; i--;)
	{
		for(int j = 0; j < xSize; j++)
		{
			while(readBuffer[count] != '1' && readBuffer[count] != '0')
			{
				count++;
				if(count > fileSize) return;
			}
			if(readBuffer[count] == '1')
				map[i][j] = true;
			else
				map[i][j] = false;
			count++;
		}
	}
	_tileSize = tileSize;
	_size = int2D(xSize, ySize);
	colorArray = new float3D[_size.getX()*_size.getY() * 6];
	vertexArray = new int2D[_size.getX()*_size.getY() * 6];
	//Now we need to set up the start position and the goal goal position
	currentValue = "";
	count++;
	while(readBuffer[count] != ' ')
	{
		currentValue += readBuffer[count];
		count++;
	}
	playerStart = float2D(float(atoi(&currentValue[0])), 0);
	count++;
	currentValue = "";
	while(readBuffer[count] != '\n')
	{
		currentValue += readBuffer[count];
		count++;
	}
	playerStart = float2D(playerStart.getX(), float(atoi(&currentValue[0])));
	//Now we need to set up the start position and the goal goal position
	currentValue = "";
	count++;
	while(readBuffer[count] != ' ')
	{
		currentValue += readBuffer[count];
		count++;
	}
	goalPosition = float2D(float(atoi(&currentValue[0])), 0);
	count++;
	currentValue = "";
	while(readBuffer[count] != '\n')
	{
		currentValue += readBuffer[count];
		count++;
	}
	goalPosition = float2D(goalPosition.getX(), float(atoi(&currentValue[0])));
	count++;
	_generateTexture();
	//Next get the values for the light volume that will be built
	//which are minimum radiance followed by the levels, and then by passes
	while(readBuffer[count] != ' ')
	{
		currentValue += readBuffer[count];
		count++;
	}
	count++;
	_minimumIntensity = atof(&currentValue[0]);
	currentValue = "";
	while(readBuffer[count] != ' ')
	{
		currentValue += readBuffer[count];
		count++;
	}
	count++;
	_levels = atoi(&currentValue[0]);
	currentValue = "";
	while(readBuffer[count] != '\n')
	{
		currentValue += readBuffer[count];
		count++;
	}
	count++;
	_passes = atoi(&currentValue[0]);
	currentValue = "";
	//Now get the lights that the users want to build
	//These are the light variables
	float lightXPos, lightYPos, lightDirection;
	int radianceAngle, rayNumber, rayIntensity;
	//now run through the file and get all of the lighting information
	while(count < fileSize)
	{
		while(readBuffer[count] != ' ')
		{
			currentValue += readBuffer[count];
			count++;
		}
		count++;
		lightXPos = atoi(&currentValue[0]);
		currentValue = "";
		while(readBuffer[count] != ' ')
		{
			currentValue += readBuffer[count];
			count++;
		}
		count++;
		lightYPos = atoi(&currentValue[0]);
		currentValue = "";
		while(readBuffer[count] != ' ')
		{
			currentValue += readBuffer[count];
			count++;
		}
		count++;
		lightDirection = stof(&currentValue[0]);
		currentValue = "";
		while(readBuffer[count] != ' ')
		{
			currentValue += readBuffer[count];
			count++;
		}
		count++;
		radianceAngle = atoi(&currentValue[0]);
		currentValue = "";
		while(readBuffer[count] != ' ')
		{
			currentValue += readBuffer[count];
			count++;
		}
		count++;
		rayNumber = atoi(&currentValue[0]);
		currentValue = "";
		while(readBuffer[count] != '\n')
		{
			currentValue += readBuffer[count];
			count++;
		}
		count++;
		rayIntensity = atoi(&currentValue[0]);
		currentValue = "";
		addLight(float2D(lightXPos, lightYPos), lightDirection, radianceAngle, rayNumber, rayIntensity);
	}
	fclose(currentFile);
}
Пример #6
0
void level::buildLevel(void)
{
	for(int i = 0; i < _size.getY(); i++)
		for(int j = 0; j < _size.getX(); j++)
			addTile(int2D(j, i));
}
Пример #7
0
void level::_renderRayTexture(void)
{
	int maxX = _size.getX()*_tileSize, maxY = _size.getY()*_tileSize;

	glEnable(GL_TEXTURE_2D);

	switch(_colorModel)
	{
		case 3:
			glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, maxX, maxY, 0, GL_RGBA, GL_FLOAT, &_rayTexture[0]);
			glBindTexture(GL_TEXTURE_2D, _interpolatedTexture);
			break;
		case 4:
		default:
			glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, maxX, maxY, 0, GL_RGBA, GL_FLOAT, &_pointTexture[0]);
			glBindTexture(GL_TEXTURE_2D, _outlineTexture);
			break;
	}
	

	glPixelStorei(GL_UNPACK_ALIGNMENT, 1);

	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
	glClear(GL_DEPTH_BUFFER_BIT);
	float2D textureArray[6];
	int2D corners[6];
	float3D colors[6];
	corners[0] = int2D(0, 0);
	textureArray[0] = float2D(0, 0);
	corners[1] = int2D(0, maxY);
	textureArray[1] = float2D(0, 1.f);
	corners[2] = int2D(maxX, maxY);
	textureArray[2] = float2D(1.f, 1.f);
	corners[3] = int2D(maxX, maxY);
	textureArray[3] = float2D(1.f, 1.f);
	corners[4] = int2D(maxX, 0);
	textureArray[4] = float2D(1.f, 0);
	corners[5] = int2D(0, 0);
	textureArray[5] = float2D(0, 0);
	for(int i = 0; i < 6; i++) colors[i] = float3D(1.f, 1.f, 1.f);

	glEnableClientState(GL_COLOR_ARRAY);
	glEnableClientState(GL_VERTEX_ARRAY);
	glEnableClientState(GL_TEXTURE_COORD_ARRAY);

	glColorPointer(3, GL_FLOAT, 0, &colors[0]);
	glVertexPointer(2, GL_INT, 0, &corners[0]);
	glTexCoordPointer(2, GL_FLOAT, 0, &textureArray[0]);
	glDrawArrays(GL_TRIANGLES, 0, 6);

	glDisableClientState(GL_COLOR_ARRAY);
	glDisableClientState(GL_VERTEX_ARRAY);
	glDisableClientState(GL_TEXTURE_COORD_ARRAY);
	
	glClear(GL_DEPTH_BUFFER_BIT);
	glDisable(GL_TEXTURE_2D);
	

}