PageRenderTime 283ms CodeModel.GetById 161ms app.highlight 7ms RepoModel.GetById 114ms app.codeStats 0ms

/TheElements/jni/points.c

http://thelements.googlecode.com/
C | 101 lines | 73 code | 16 blank | 12 comment | 9 complexity | 9962ee515ebc79e6288f4a127565a42c MD5 | raw file
  1/*
  2 * points.c
  3 * ----------------------------
  4 * Defines functions for manipulating data
  5 * for individual points, such as adding and
  6 * deleting points.
  7 */
  8
  9#include "points.h"
 10
 11void CreatePoint(int k, int l, int e)
 12{
 13	int i;
 14	if (loq > 0)
 15	{
 16		loq--;
 17		i = avail[loq];
 18		avail[loq] = -1;
 19		x[i] = k;
 20		y[i] = l;
 21
 22		allcoords[k][l] = i;
 23
 24		// Set the element of the point
 25		element[i] = e;
 26
 27		//velocity setting part - all start at 0
 28
 29		xvel[i] = 0;
 30		yvel[i] = 0;
 31		frozen[i] = 0;
 32
 33		setBitmapColor(k, l, e);
 34
 35		set[i] = 1;
 36
 37		unFreezeParticles(k, l);
 38	}
 39}
 40void DeletePoint(int partnum)
 41{
 42	int tempx = x[partnum];
 43	int tempy = y[partnum];
 44	unFreezeParticles(tempx, tempy);
 45	setBitmapColor((int) x[partnum], (int) y[partnum], 3);
 46	allcoords[(int) x[partnum]][(int) y[partnum]] = -1;
 47	//cleaning up
 48	x[partnum] = 0;
 49	y[partnum] = 0;
 50	frozen[partnum] = 0;
 51	element[partnum] = 0;
 52	xvel[partnum] = 0;
 53	yvel[partnum] = 0;
 54	set[partnum] = 0;
 55	avail[loq] = partnum;
 56	loq++;
 57
 58}
 59
 60void setElement(int particle, int newelement)
 61{
 62	element[particle] = newelement;
 63	setBitmapColor(x[particle], y[particle], newelement);
 64}
 65
 66void setBitmapColor(int xpos, int ypos, int newelement)
 67{
 68	colors[3 * (xpos + ypos * 512)] = red[newelement];
 69	colors[3 * (xpos + ypos * 512) + 1] = green[newelement];
 70	colors[3 * (xpos + ypos * 512) + 2] = blue[newelement];
 71}
 72void createBitmapFromPoints(void)
 73{
 74	//Not implemented yet
 75}
 76//this function unfreezes particles around a point
 77void unFreezeParticles(int xcentre, int ycentre)
 78{
 79	int ix;
 80	int jy;
 81	for (ix = -1; ix <= 1; ix++)
 82	{
 83		for (jy = -1; jy <= 1; jy++)
 84		{
 85
 86			int tempx = xcentre + ix;
 87			int tempy = ycentre + jy;
 88			if (tempx < maxx && tempx > 0 && tempy < maxy && tempy > 0)
 89			{
 90
 91				int atemp = allcoords[tempx][tempy];
 92
 93				if (atemp != -1)
 94				{
 95					frozen[atemp] = 0; //reset the freeze counter
 96				}
 97			}
 98
 99		}
100	}
101}