Example #1
0
File: main.c Project: PamC/VSPlugin
static void handleScreenEvent(bps_event_t *event) {
	int screen_val, buttons;
	int pair[2];

	static bool mouse_pressed = false;

	screen_event_t screen_event = screen_event_get_event(event);

	//Query type of screen event and its location on the screen
	screen_get_event_property_iv(screen_event, SCREEN_PROPERTY_TYPE,
			&screen_val);
	screen_get_event_property_iv(screen_event, SCREEN_PROPERTY_SOURCE_POSITION,
			pair);

	//There is a difference between touch screen events and mouse events
	if (screen_val == SCREEN_EVENT_MTOUCH_RELEASE) {
		//This is touch screen event.
		add_cube((float) pair[0], (float) pair[1]);
	} else if (screen_val == SCREEN_EVENT_POINTER) {
		//This is a mouse move event, it is applicable to a device with a usb mouse or simulator
		screen_get_event_property_iv(screen_event, SCREEN_PROPERTY_BUTTONS,
				&buttons);

		if (buttons == SCREEN_LEFT_MOUSE_BUTTON) {
			//Left mouse button is pressed
			mouse_pressed = true;
		} else {
			if (mouse_pressed) {
				//Left mouse button was released, add a cube
				add_cube((float) pair[0], (float) pair[1]);
				mouse_pressed = false;
			}
		}
	}
}
Example #2
0
File: 3d.c Project: hrldcpr/iso
void staircase() {
  int x, y, i;
  // make a grid
  for (y = -HEIGHT/2; y < HEIGHT/2; y++) {
    for (x = -WIDTH/2; x < WIDTH/2; x++)
      add_cube(x, y, 0);
  }

  // make an ambiguous staircase
  unsigned char r, g, b;
  for (i = 6; i >= 1; i--) {
    add_cube(i - WIDTH/2, i - HEIGHT/2, i + 1);
    rainbow(i / 6.0, &r, &g, &b);
    add_ball_on(r, g, b, cubes);
  }
}
Example #3
0
cube_list* negate_cube(cube* c, int var) {
  cube_list* result = new_cube_list(var);

  for (int i = 1; i <= var; i++) {
    val value = c->values[i];

    if (value == t) {
      cube* cn = new_cube(var);
      set_false(cn, i);
      add_cube(result, cn);
    } else if (value == f) {
      cube* cn = new_cube(var);
      set_true(cn, i);
      add_cube(result, cn);
    }
  }

  return result;
}
Example #4
0
/* Labyrinth aus Datei einlesen */
struct labyrinth *labyrinth_load(char *filename)
{
    FILE *file;
    char line[LINE_MAX];
    char *count, *type;
    char delim[] = " ,;#|";
    struct labyrinth *lab;
    int line_cnt, i, c;

    if ((file = fopen(filename, "r")) == NULL) {
        fprintf(stderr, "%s: ", filename);
        perror("fopen");
        exit(EXIT_FAILURE);
    }

    lab      = labyrinth_new();
    line_cnt = 0;

    while (fgets(line, LINE_MAX, file) != NULL) {
        line_cnt++;

        trim(line);

        if ((count = strtok(line, delim)) == NULL
            || (type = strtok(NULL, delim)) == NULL) {
            fprintf(stderr, "%s: Zeile %d konnte nicht eingelesen werden\n",
                    filename, line_cnt);
            exit(EXIT_FAILURE);
        }

        if ((c = atoi(count)) < 0) {
            fprintf(stderr, "%s: Zeile %d: Anzahl muss groesser 0 sein\n",
                    filename, line_cnt);
            exit(EXIT_FAILURE);
        }

        for (i = 0; i < c; i++)
            add_cube(lab, type);
    }

    if (fclose(file) == EOF) {
        perror("fclose");
        exit(EXIT_FAILURE);
    }

    if (lab->cube_cnt <= 1) {
        fprintf(stderr,
                "Das Labyrinth muss mindestens "
                "aus 2 Wuerfeln bestehen\n");
        exit(EXIT_FAILURE);
    }

    return lab;
}
Example #5
0
bfun* try_simplify(bfun* b) {
  bfun* result = NULL;

  if (b->cube_count == 0) { // empty cubelist is never true -> change to true bfun
    result = new_cube_list(b->var_count);
    add_cube(result, new_cube(b->var_count));
  } else if (has_all_dc(b)) { // always true -> change to empty (false) bfun
    result = new_cube_list(b->var_count); 
  } else if (b->cube_count == 1) { // just one cube -> negate manually
    result = negate_cube(b->begin, b->var_count);
  }

  if (result == NULL) return b;
  return result;
}
/**
 * Find at most 26 cubes to start polygonization from.
 */
static void find_first_points(PROCESS *process, const unsigned int em)
{
	const MetaElem *ml;
	int center[3], lbn[3], rtf[3], it[3], dir[3], add[3];
	float tmp[3], a, b;

	ml = process->mainb[em];

	mid_v3_v3v3(tmp, ml->bb->vec[0], ml->bb->vec[6]);
	closest_latice(center, tmp, process->size);
	prev_lattice(lbn, ml->bb->vec[0], process->size);
	next_lattice(rtf, ml->bb->vec[6], process->size);

	for (dir[0] = -1; dir[0] <= 1; dir[0]++) {
		for (dir[1] = -1; dir[1] <= 1; dir[1]++) {
			for (dir[2] = -1; dir[2] <= 1; dir[2]++) {
				if (dir[0] == 0 && dir[1] == 0 && dir[2] == 0) {
					continue;
				}

				copy_v3_v3_int(it, center);

				b = setcorner(process, it[0], it[1], it[2])->value;
				do {
					it[0] += dir[0];
					it[1] += dir[1];
					it[2] += dir[2];
					a = b;
					b = setcorner(process, it[0], it[1], it[2])->value;

					if (a * b < 0.0f) {
						add[0] = it[0] - dir[0];
						add[1] = it[1] - dir[1];
						add[2] = it[2] - dir[2];
						DO_MIN(it, add);
						add_cube(process, add[0], add[1], add[2]);
						break;
					}
				} while ((it[0] > lbn[0]) && (it[1] > lbn[1]) && (it[2] > lbn[2]) &&
				         (it[0] < rtf[0]) && (it[1] < rtf[1]) && (it[2] < rtf[2]));
			}
		}
	}
}
Example #7
0
		void insert(const RawDataT& data, F& filter) {
			LOG4_TRACE("about to insert " << data.size() << " elements");
			keys.reserve(data.size() + keys.size());
			pk.reserve(data.size() + pk.size());

			for(auto i = data.begin();
					 i != data.end();
					 ++i)
			{
				keys.push_back(i->first);

				uint32_t bs = i->second.size() * sizeof(typename CubeData::Val);

				if (filter.can_compress(bs)) {
					add_cube(filter.compress(i->second), i->second);
				} else {
					add_cube_pk(make_buf(i->second));
				}

				counter++;
			}
		}
Example #8
0
main()
{
	DB		db[2];		/* packet double buffer */
	DB		*cdb;		/* current db */
	MATRIX		rottrans;	/* rot-trans matrix */
	int		i;		/* work */
	int		dmy, flg;	/* dummy */
	CVECTOR		col[12];	/* cube color */
	u_long		cnt;

	etc.near_clip=500;
	etc.far_clip=5000;
	etc.clip_off=0;
	
	PadInit(0);             /* initialize PAD */
	ResetGraph(0);		/* reset graphic subsystem (0:cold,1:warm) */
	SetGraphDebug(0);	/* set debug mode (0:off, 1:monitor, 2:dump) */
	
	InitGeom();			/* initialize geometry subsystem */
	SetGeomOffset(320, 240);	/* set geometry origin as (160, 120) */
	SetGeomScreen(SCR_Z);		/* distance to viewing-screen */

	SetLightMatrix(&LLM);
	SetColorMatrix(&LCM);
	SetBackColor(BK.vx,BK.vy,BK.vz);
	SetFarColor(FC.vx,FC.vy,FC.vz);
	SetFogNear(1*SCR_Z,SCR_Z);
	
	/* initialize environment for double buffer (interlace)
	 *	buffer ID	VRAM address 
	 *-------------------------------------------------------
	 *	buffer #0	(0,  0)-(640,480)
	 *	buffer #1	(0,  0)-(640,480)
	 */
	SetDefDrawEnv(&db[0].draw, 0, 0, 640, 480);	
	SetDefDrawEnv(&db[1].draw, 0, 0, 640, 480);	
	SetDefDispEnv(&db[0].disp, 0, 0, 640, 480);	
	SetDefDispEnv(&db[1].disp, 0, 0, 640, 480);
	
	FntLoad(960,256);
	SetDumpFnt(FntOpen(64,64,256,200,0,512));
	SetRCnt(RCntCNT2,0xffff,RCntMdNOINTR|RCntMdFR);
	StartRCnt(RCntCNT2);

	/* set surface colors */
	for (i = 0; i < 12; i+=2) {
		col[i].r = col[i+1].r = 0xff/*rand()*/;	/* R */
		col[i].g = col[i+1].g = 0xff/*rand()*/;	/* G */
		col[i].b = col[i+1].b = 0xff/*rand()*/;	/* B */
		col[i].cd = col[i+1].cd = CODE_G3;	/* cd */
	}
	
	init_prim(&db[0]);	/* set primitive parameters on buffer #0 */
	init_prim(&db[1]);	/* set primitive parameters on buffer #1 */
	
	SetDispMask(1);		/* enable to display (0:inhibit, 1:enable) */
	
	while (pad_read(&rottrans) == 0) {
		cdb = (cdb==db)? db+1: db;	/* swap double buffer ID */
		ClearOTagR(cdb->ot, OTSIZE);	/* clear ordering table */

		/* add cube */
		ResetRCnt(RCntCNT2);

		add_cube(cdb->ot, cdb->s, v, n, col);

		cnt= GetRCnt(RCntCNT2);
		FntPrint("cnt=%d\n",cnt);
		
		/* swap buffer */
		DrawSync(0);	/* wait for end of drawing */
		VSync(0);	/* wait for the next V-BLNK */
	
		PutDrawEnv(&cdb->draw); /* update drawing environment */
		PutDispEnv(&cdb->disp); /* update display environment */

		DrawOTag(cdb->ot+OTSIZE-1);	/* draw */
		FntFlush(-1);
	}
        PadStop();
        exit();
}
Example #9
0
// Process a production string and generate form
void L_draw(const context& Context, const k3d::signed_axis Orientation)
{
	// Save values
	k3d::double_t thick_l = 0;
	k3d::double_t ang_l = 0;
	k3d::double_t dis_l = 0;
	k3d::double_t dis2_l = 0;
	k3d::double_t trope_l = 0;

	bool poly_on = false;

	// Setup vectors
	k3d::point3 pos(0.0, 0.0, 0.0);
	k3d::vector3 fow(0.0, 0.0, 1.0);
	k3d::vector3 lef(0.0, 1.0, 0.0);
	k3d::vector3 upp(1.0, 0.0, 0.0);

	trope = k3d::normalize(trope);

	for(unsigned long i = 0; i < object_string.size(); i++)
	{
		// Overflow
		if(polcount > poly_limit)
			break;

		// The next char in the string
		char next = object_string[i + 1];

		// The current char in the string
		switch(object_string[i])
		{
			default:
				break;

			// Marks last recursion level during growing phase
			case '@':
				last_recur = !last_recur;
				if(last_recur)
				{
					// Store all variables and do fraction
					thick_l = thick;
					ang_l = ang;
					dis_l = dis;
					dis2_l = dis2;
					trope_l = trope_amount;

					dis *= fraction;
					dis2 *= fraction;
					thick *= fraction;
					ang *= fraction;
					trope_amount *= fraction;
				}
				else
				{
					// Restore
					thick = thick_l;
					ang = ang_l;
					dis = dis_l;
					dis2 = dis2_l;
					trope_amount = trope_l;
				}
			break;

			case '+':
				save.ang = ang;
				if(next == '(')
				{
					ang = 0.017453 * parse_value(i);
					if(last_recur)
						ang *= fraction;
				}

				set_rotation_matrix(-ang, upp);
				fow = rotate(fow);
				lef = rotate(lef);
				ang = save.ang;
			break;

			case '-':
				save.ang = ang;
				if(next == '(')
				{
					ang = 0.017453 * parse_value(i);
					if(last_recur)
						ang *= fraction;
				}

				set_rotation_matrix(ang, upp);
				fow = rotate(fow);
				lef = rotate(lef);
				ang = save.ang;
			break;

			case '~':
			{
				k3d::double_t r = 6.0;
				if(next == '(')
					r = 0.017453 * parse_value(i);
				else if(rand_set)
					r = 0.017453 * rand_amount;

				k3d::double_t a = Rnd() * r * 2.0 - r;
				set_rotation_matrix(a, upp);
				fow = rotate(fow);
				lef = rotate(lef);
				a = (Rnd() * r * 2.0) - r;
				set_rotation_matrix(a, lef);
				fow = rotate(fow);
				upp = rotate(upp);
				a = (Rnd() * r * 2.0) - r;
				set_rotation_matrix(a, fow);
				lef = rotate(lef);
				upp = rotate(upp);
			}
			break;

			case 't':
			{
				if((fow[0] == 0.0) && (fow[1] == 0.0))
					break;

				save.tr = tr;
				if(trope_set)
					tr = trope_amount;

				if(next == '(')
				{
					tr = parse_value(i);
					if(last_recur)
						tr *= fraction;
				}

				trope = fow;
				trope[0] = -trope[0];
				trope[1] = -trope[1];
				trope[2] = 0.0;
				trope = k3d::normalize(trope);
				k3d::double_t r = tr * (fow * trope);
				set_rotation_matrix(-r, lef);
				fow = rotate(fow);
				upp = rotate(upp);
				tr = save.tr;
			}
			break;

			case '$':
			{
				k3d::vector3 v = fow - sky;
				if(v.length() == 0.0)
					break;

				lef = fow ^ sky;
				upp = fow ^ lef;
				if(upp[2] < 0.0)
				{
					upp = -upp;
					lef = -lef;
				}
			}
			break;

			case '&':
				save.ang = ang;
				if(next == '(')
				{
					ang = 0.017453 * parse_value(i);
					 if(last_recur)
					ang *= fraction;
				}

				set_rotation_matrix(ang, lef);
				fow = rotate(fow);
				upp = rotate(upp);
				ang = save.ang;
			break;

			case '^':
				save.ang = ang;
				if(next == '(')
				{
					ang = 0.017453 * parse_value(i);
					if(last_recur)
						ang *= fraction;
				}

				set_rotation_matrix(-ang, lef);
				fow = rotate(fow);
				upp = rotate(upp);
				ang = save.ang;
			break;

			case '<':
				save.ang = ang;
				if(next == '(')
				{
					ang = 0.017453 * parse_value(i);
					if(last_recur)
						ang *= fraction;
				}

				set_rotation_matrix(-ang, fow);
				lef = rotate(lef);
				upp = rotate(upp);
				ang = save.ang;
			break;

			case '>':
				save.ang = ang;
				if(next == '(')
				{
					ang = 0.017453 * parse_value(i);
					if(last_recur)
						ang *= fraction;
				}

				set_rotation_matrix(ang, fow);
				lef = rotate(lef);
				upp = rotate(upp);
				ang = save.ang;
			break;

			case '%':
				set_rotation_matrix(3.141592654, fow);
				lef = rotate(lef);
				upp = rotate(upp);
			break;

			case '|':
				set_rotation_matrix(3.141592654, upp);
				fow = rotate(fow);
				lef = rotate(lef);
			break;

			case '!':
				if(next == '(')
				{
					if(last_recur)
						thick *= 1.0 + fraction * (parse_value(i) - 1.0);
					else
						thick *= parse_value(i);
				}
				else
				{
					if(last_recur)
						thick *= 1.0 + fraction * (0.7 - 1.0);
					else
						thick *= 0.7;
				}
			break;

			case '?':
				if(next == '(')
				{
					if(last_recur)
						thick *= 1.0 + fraction * (parse_value(i) - 1.0);
					else
						thick *= parse_value(i);
				}
				else
				{
					if(last_recur)
						thick /= 1.0 + fraction * (0.7 - 1.0);
					else
						thick /= 0.7;
				}
			break;

			case ':':
				if(next == '(')
				{
					if(last_recur)
						ang *= 1.0 + fraction * (parse_value(i) - 1.0);
					else
						ang *= parse_value(i);
				}
				else
				{
					if(last_recur)
						ang *= 1.0 + fraction * (0.9 - 1.0);
					else
						ang *= 0.9;
				}
			break;

			case ';':
				if(next == '(')
				{
					if(last_recur)
						ang *= 1.0 + fraction * (parse_value(i) - 1.0);
					else
						ang *= parse_value(i);
				}
				else
				{
					if(last_recur)
						ang /= 1.0 + fraction * (0.9 - 1.0);
					else
						ang /= 0.9;
				}
			break;

			case '\'':
				if(next == '(')
				{
					k3d::double_t r = parse_value(i);
					if(last_recur)
					{
						dis *= 1.0 + fraction * (r - 1.0);
						dis2 *= 1.0 + fraction * (r - 1.0);
					}
					else
					{
						dis *= r;
						dis2 *= r;
					}
				}
				else
				{
					if(last_recur)
					{
						dis *= 1.0 + fraction * (0.9 - 1.0);
						dis2 *= 1.0 + fraction * (0.9 - 1.0);
					}
					else
					{
						dis *= 0.9;
						dis2 *= 0.9;
					}
				}
			break;

			case '"':
				if(next == '(')
				{
					k3d::double_t r = parse_value(i);
					if(last_recur)
					{
						dis *= 1.0 + fraction * (r - 1.0);
						dis2 *= 1.0 + fraction * (r - 1.0);
					}
					else
					{
						dis *= r;
						dis2 *= r;
					}
				}
				else
				{
					if(last_recur)
					{
						dis /= 1.0 + fraction * (0.9 - 1.0);
						dis2 /= 1.0 + fraction * (0.9 - 1.0);
					}
					else
					{
						dis /= 0.9;
						dis2 /= 0.9;
					}
				}
			break;

			case 'Z':
			{
				save.dis2 = dis2;
				if(next == '(')
				{
					dis2 = parse_value(i);
					if(last_recur)
						dis2 *= fraction;
				}

				k3d::point3 end = pos + dis2 * fow;
				if(closed_form)
					add_cylinder(pos, end, upp, col, Context, Orientation);
				else
					add_cube(pos, end, upp, col, Context, Orientation);

				pos = end;
				dis2 = save.dis2;
			}
			break;

			case 'F':
			{
				save.dis = dis;
				if(next == '(')
				{
					dis = parse_value(i);
					if(last_recur)
						dis *= fraction;
				}

				k3d::point3 end = pos + dis * fow;
				if(closed_form)
					add_cylinder(pos, end, upp, col, Context, Orientation);
				else
					add_cube(pos, end, upp, col, Context, Orientation);

				pos = end;
				dis = save.dis;
			}
			break;

			case '[':
			{
				s_rec new_rec;
				new_rec.pos = pos;
				new_rec.fow = fow;
				new_rec.lef = lef;
				new_rec.upp = upp;
				new_rec.col = col;
				new_rec.dis = dis;
				new_rec.dis2 = dis2;
				new_rec.ang = ang;
				new_rec.thick = thick;
				new_rec.tr = tr;

				if(closed_form)
				{
					new_rec.last = last;
					new_rec.last_col = last_col;
					for(unsigned long j = 0; j < 8; j++)
						new_rec.last_v[j] = last_v[j];
				}

				if(stack.size() < max_stack_size)
					stack.push(new_rec);
			}
			break;

			case ']':
			{
				if(!stack.size())
					break;

				s_rec old_rec = stack.top();
				pos = old_rec.pos;
				fow = old_rec.fow;
				lef = old_rec.lef;
				upp = old_rec.upp;
				col = old_rec.col;
				dis = old_rec.dis;
				dis2 = old_rec.dis2;
				ang = old_rec.ang;
				thick = old_rec.thick;
				tr = old_rec.tr;
				if(closed_form)
				{
					last = old_rec.last;
					last_col = old_rec.last_col;
					for(unsigned long j = 0; j < 8; j++)
						last_v[j] = old_rec.last_v[j];
				}

				stack.pop();
			}
			break;

			case '{':
				if(poly_on)
				{
					vectors_t new_rec = vertices;
					if(pstack.size() < max_stack_size)
						pstack.push(new_rec);
				}

				poly_on = true;

				vertices.clear();
				vertices.push_back(pos);
			break;

			case 'f':
				save.dis = dis;
				if(next == '(')
				{
					dis = parse_value(i);
					if(last_recur)
						dis *= fraction;
				}

				pos = pos + dis * fow;
				if(poly_on)
					vertices.push_back(pos);

				dis = save.dis;
			break;

			case '.':
				if(poly_on)
					vertices.push_back(pos);
			break;

			case 'g':
				save.dis = dis;
				if(next == '(')
				{
					dis = parse_value(i);
					if(last_recur)
						dis *= fraction;
				}

				pos = pos + dis * fow;
				dis = save.dis;
			break;

			case 'z':
				save.dis2 = dis2;
				if(next == '(')
				{
					dis2 = parse_value(i);
					if(last_recur)
						dis2 *= fraction;
				}

				pos = pos + dis2 * fow;
				if(poly_on)
					vertices.push_back(pos);

				dis2 = save.dis2;
			break;

			case '}':
				polygons.clear();
				if(vertices.size() > 3)
				{
					for(unsigned long j = 1; j < vertices.size() - 1; j++)
						polygons.push_back(polygon(0, j, j + 1, j + 1));

					add_geometry(col, Context);
				}

				poly_on = false;
				if(pstack.size() > 0)
				{
					vertices.clear();

					if(!pstack.size())
						break;

					vertices = pstack.top();
					pstack.pop();

					poly_on = true;
				}
			break;

			case 'c':
				if(next == '(')
					col = (unsigned long)parse_value(i);
				else
					col++;
			break;
		}
	}
}
Example #10
0
main_window::main_window(QGLWidget *parent)
    : QGLWidget (parent)
{
    QApplication::setOverrideCursor(Qt::BlankCursor);
    setMouseTracking(true);

    setFixedSize(600, 200);

    auto randomc = std::bind(std::uniform_int_distribution<int>(0, world_size - 1), std::default_random_engine());
    auto randomh = std::bind(std::uniform_int_distribution<int>(-3, 3), std::default_random_engine());


    randomf = std::bind(std::uniform_real_distribution<double>(0.0, 1.0), std::default_random_engine());

    int start = (-1) << 0;

    std::vector<std::vector<int> > height(world_size, std::vector<int>(world_size, start + 5));

    for (int iter = 0; iter < world_size * world_size / 10; ++iter)
    {
        int x = randomc();
        int z = randomc();
        int h = randomh();
        if (h == 0) continue;

        int ah = (h > 0) ? h : -h;
        int th = (h > 0) ? 1 : -1;

        for (int dx = -ah; dx <= ah; ++dx)
            for (int dz = -ah; dz <= ah; ++dz)
                if (x + dx >= 0 && x + dx < world_size && z + dz >= 0 && z + dz < world_size)
                {
                    height[x + dx][z + dz] += th * (ah - std::max(abs(dx), abs(dz)));
                }
    }

    hue = 0.0;
    brightness = 0.4;

    for (int x = 0; x < world_size; ++x)
        for (int z = 0; z < world_size; ++z)
        {
            for (int y = start; y < height[x][z]; ++y)
                add_cube(x, y, z);

            add_cube(x, height[x][z], z);
            for (int ci = 0; ci < 4; ++ci)
            {
                cubes.back().planes[2].hue = 1.5;
                cubes.back().planes[2].brightness = 0.7;
            }
        }

    std::cout << cubes.size() << '\n';

    brightness = 1.0 + 0.5 / sphere_y;
    hue = -3.0 / sphere_x;

    sphere_hue = hue;
    sphere_brightness = brightness;

    pl.x = world_size * 0.5;
    pl.z = world_size * 0.5;
    pl.y = start + 10;
    pl.vy = 0.0;
    pl.init();

    has_chosen_plane = false;

    enable_gravity = true;
    on_surface = false;

    rainbow = false;

    health = 1.0;

    last_frame = 0.0;
    startTimer(10);
}
Example #11
0
File: main.c Project: PamC/VSPlugin
int main(int argc, char **argv) {
	shutdown = false;

	//Create a screen context that will be used to create an EGL surface to to receive libscreen events
	screen_create_context(&screen_cxt, 0);

	//Initialize BPS library
	bps_initialize();

	//Determine initial orientation angle
	orientation_direction_t direction;
	orientation_get(&direction, &orientation_angle);

	//Use utility code to initialize EGL for rendering with GL ES 1.1
	if (EXIT_SUCCESS != bbutil_init_egl(screen_cxt, GL_ES_1)) {
		fprintf(stderr, "bbutil_init_egl failed\n");
		bbutil_terminate();
		screen_destroy_context(screen_cxt);
		return 0;
	}

	//Initialize application logic
	if (EXIT_SUCCESS != init_blocks()) {
		fprintf(stderr, "initialize failed\n");
		bbutil_terminate();
		screen_destroy_context(screen_cxt);
		return 0;
	}

	//Signal BPS library that navigator and screen events will be requested
	if (BPS_SUCCESS != screen_request_events(screen_cxt)) {
		fprintf(stderr, "screen_request_events failed\n");
		bbutil_terminate();
		screen_destroy_context(screen_cxt);
		return 0;
	}

	if (BPS_SUCCESS != navigator_request_events(0)) {
		fprintf(stderr, "navigator_request_events failed\n");
		bbutil_terminate();
		screen_destroy_context(screen_cxt);
		return 0;
	}

	//Signal BPS library that navigator orientation is not to be locked
	if (BPS_SUCCESS != navigator_rotation_lock(false)) {
		fprintf(stderr, "navigator_rotation_lock failed\n");
		bbutil_terminate();
		screen_destroy_context(screen_cxt);
		return 0;
	}

	//Setup Sensors
	if (sensor_is_supported(SENSOR_TYPE_AZIMUTH_PITCH_ROLL)) {
		//Microseconds between sensor reads. This is the rate at which the
		//sensor data will be updated from hardware. The hardware update
		//rate is set below using sensor_set_rate.
		static const int SENSOR_RATE = 25000;

		//Initialize the sensor by setting the rates at which the
		//sensor values will be updated from hardware
		sensor_set_rate(SENSOR_TYPE_AZIMUTH_PITCH_ROLL, SENSOR_RATE);

		sensor_set_skip_duplicates(SENSOR_TYPE_AZIMUTH_PITCH_ROLL, true);
		sensor_request_events(SENSOR_TYPE_AZIMUTH_PITCH_ROLL);
	} else {
		set_gravity(0.0f, -1.0f);
	}

	//Start with one cube on the screen
	add_cube(200, 100);

	int i = 0;

	while (!shutdown) {


		i = check(1);

		// Handle user input and sensors
		handle_events();

		//Update cube positions
		update();

		// Draw Scene
		render();
	}

	//Stop requesting events from libscreen
	screen_stop_events(screen_cxt);

	//Shut down BPS library for this process
	bps_shutdown();

	//Free app data
	free(boxes);

	//Use utility code to terminate EGL setup
	bbutil_terminate();

	//Destroy libscreen context
	screen_destroy_context(screen_cxt);
	return 0;
}
Example #12
0
void append_cubes(bfun* b, bfun* g) {
  for (cube* c = g->begin; c != NULL; c = c->next) {
    add_cube(b, copy(c, b->var_count));
  }
}
/**
 * triangulate the cube directly, without decomposition
 */
static void docube(PROCESS *process, CUBE *cube)
{
	INTLISTS *polys;
	CORNER *c1, *c2;
	int i, index = 0, count, indexar[8];

	/* Determine which case cube falls into. */
	for (i = 0; i < 8; i++) {
		if (cube->corners[i]->value > 0.0f) {
			index += (1 << i);
		}
	}

	/* Using faces[] table, adds neighbouring cube if surface intersects face in this direction. */
	if (MB_BIT(faces[index], 0)) add_cube(process, cube->i - 1, cube->j, cube->k);
	if (MB_BIT(faces[index], 1)) add_cube(process, cube->i + 1, cube->j, cube->k);
	if (MB_BIT(faces[index], 2)) add_cube(process, cube->i, cube->j - 1, cube->k);
	if (MB_BIT(faces[index], 3)) add_cube(process, cube->i, cube->j + 1, cube->k);
	if (MB_BIT(faces[index], 4)) add_cube(process, cube->i, cube->j, cube->k - 1);
	if (MB_BIT(faces[index], 5)) add_cube(process, cube->i, cube->j, cube->k + 1);

	/* Using cubetable[], determines polygons for output. */
	for (polys = cubetable[index]; polys; polys = polys->next) {
		INTLIST *edges;

		count = 0;
		/* Sets needed vertex id's lying on the edges. */
		for (edges = polys->list; edges; edges = edges->next) {
			c1 = cube->corners[corner1[edges->i]];
			c2 = cube->corners[corner2[edges->i]];

			indexar[count] = vertid(process, c1, c2);
			count++;
		}

		/* Adds faces to output. */
		if (count > 2) {
			switch (count) {
				case 3:
					make_face(process, indexar[2], indexar[1], indexar[0], 0);
					break;
				case 4:
					if (indexar[0] == 0) make_face(process, indexar[0], indexar[3], indexar[2], indexar[1]);
					else make_face(process, indexar[3], indexar[2], indexar[1], indexar[0]);
					break;
				case 5:
					if (indexar[0] == 0) make_face(process, indexar[0], indexar[3], indexar[2], indexar[1]);
					else make_face(process, indexar[3], indexar[2], indexar[1], indexar[0]);

					make_face(process, indexar[4], indexar[3], indexar[0], 0);
					break;
				case 6:
					if (indexar[0] == 0) {
						make_face(process, indexar[0], indexar[3], indexar[2], indexar[1]);
						make_face(process, indexar[0], indexar[5], indexar[4], indexar[3]);
					}
					else {
						make_face(process, indexar[3], indexar[2], indexar[1], indexar[0]);
						make_face(process, indexar[5], indexar[4], indexar[3], indexar[0]);
					}
					break;
				case 7:
					if (indexar[0] == 0) {
						make_face(process, indexar[0], indexar[3], indexar[2], indexar[1]);
						make_face(process, indexar[0], indexar[5], indexar[4], indexar[3]);
					}
					else {
						make_face(process, indexar[3], indexar[2], indexar[1], indexar[0]);
						make_face(process, indexar[5], indexar[4], indexar[3], indexar[0]);
					}

					make_face(process, indexar[6], indexar[5], indexar[0], 0);

					break;
			}
		}
	}
}
Example #14
0
File: 3d.c Project: hrldcpr/iso
void mouse(int button, int state, int u, int v) {
  if (button == GLUT_LEFT_BUTTON) {
    if (state == GLUT_DOWN) {
      mouse_x = u;
      mouse_y = v;
    }
    else if (state == GLUT_UP) {
      if (!dragging) {
        double model[16], projection[16], x, y, z, near[3], far[3];
        int viewport[4];
        float depth;

        glViewport(0, VIEW_HEIGHT, VIEW_WIDTH, VIEW_HEIGHT);
        lookFrom(1, 1, 1, 0, 0, 1); // isometric

        glGetDoublev(GL_MODELVIEW_MATRIX, model);
        glGetDoublev(GL_PROJECTION_MATRIX, projection);
        glGetIntegerv(GL_VIEWPORT, viewport);

        v = 2 * VIEW_HEIGHT - v;

        glReadPixels(u, v, 1, 1, // the 1x1 rect at (u,v)
                     GL_DEPTH_COMPONENT, GL_FLOAT, &depth);

        if (depth > 0 && depth < 1) { // not clipped
          gluUnProject(u, v, depth,
                       model, projection, viewport,
                       &x, &y, &z);
        }
        else { // clipped or empty
          gluUnProject(u, v, 0,
                       model, projection, viewport,
                       near + 0, near + 1, near + 2);
          gluUnProject(u, v, 1,
                       model, projection, viewport,
                       far + 0, far + 1, far + 2);
          intercept(near, far, &x, &y);
          z = 0;
        }

        x = round(x);
        y = round(y);
        z = round(z);
        Cube **prev = &cubes, *next = *prev;
        while (next) {
          if (next->x == x && next->y == y && next->z == z)
            break;
          prev = &next->next;
          next = *prev;
        }
        if (next) {// hit
          *prev = next->next; // remove from list
          Ball *ball = balls;
          while(ball) {
            if (ball->cube == next)
              ball->cube = NULL;
            ball = ball->next;
          }
        }
        else
          add_cube(x, y, z);
      }

      dragging = 0;
    }

    glutPostRedisplay();
  }
}