Exemplo n.º 1
0
Arquivo: ex5.c Projeto: z88dk/z88dk
void main() {
	
	//buf = (u_char*)malloc(MODE2_MAX);

	double	m_pi;
	double	a;
	int	c, i;
	surface_t surf;
	point_t	p[MAX_POINT];

	printf("calculating, wait...\n");

	m_pi = 8.0 * atan(1.0);

	// calculates points from circunference
	for (c = 0; c < MAX_POINT; c++) {
		a = (m_pi * (double)c) / (double)MAX_POINT;
		p[c].x = (int)(100.0 * cos(a) + 128.0);
		p[c].y = (int)(80.0 * sin(a) + 96.0);
	}

	// clear the off-screen surface
	printf("clearing buffer...\n");
	memset(buf, 0, MODE2_MAX);

	printf("drawing...\n");
	surf.data.ram = buf;

	// draw the eye's lines into the surface (obs: we are NOT in graphic mode yet)
	for (c = 0; c < MAX_POINT; c++) 
		for (i = c+1; i < MAX_POINT; i++)
			surface_line(&surf, p[c].x, p[c].y, p[i].x, p[i].y);

	surface_circle(&surf, 128, 96, 50, 1);

	// set screen to graphic mode
	set_color(15, 1, 1);
	set_mode(mode_2);
	fill(MODE2_ATTR, 0xF1, MODE2_MAX);

	// finally show the surface
	msx_vwrite_direct(surf.data.ram, 0, MODE2_MAX);

	while (!get_trigger(0)) {}

	set_mode(mode_0);
}
Exemplo n.º 2
0
main() {
	unsigned char c;
	star_t *st, stars[MAX_STARS];

	set_color(15, 1, 1);

	// set video mode to screen 2
	set_mode(mode_2);
	//msx_screen(2);

	// set whole screen to color white/black
	fill(MODE2_ATTR, 0xf1, MODE2_MAX);

	// initialize stars
	for (c=0; c < MAX_STARS; c++) {
		st = stars + c;
		star_randomize(st);
		st->z = (rand() & 63) ;
		st->addr = 0;
	}

	// animation loop
	while (!get_trigger(0)) {
		// calculate star movement
		for (st=stars, c=0; c < MAX_STARS; c++, st++)
			star_move(st);

		// erase previous stars
		for (st=stars, c=0; c < MAX_STARS; c++, st++)
			vpoke(st->last, 0);

		// show new stars
		for (st=stars, c=0; c < MAX_STARS; c++, st++)
			vmerge(st->addr, st->sub);
	}

	//set_mode(mode_0);
	msx_screen(0);
}
Exemplo n.º 3
0
main() {
	int c, l;
	unsigned char i;
	surface_t surf;

	//buf = (u_char*)malloc(MODE2_MAX);
	
	surf.data.ram = buf;

	set_color(15, 1, 1);
	set_mode(mode_2);
	fill(MODE2_ATTR, 0x31, MODE2_MAX);

	c = 0;
	//i = 0;

	// paint polygon
	for (;;) {	
		memset(buf, 0, MODE2_MAX);	// yeah... crap
		stencil_init(stencil);

		// calculate polygon
		//calculate_side
		stencil_add_side(128 + c, c + 20, 40, 180 - c, stencil);
		stencil_add_side(128 + c, c + 20, 255 - c, 96, stencil);
		stencil_add_side(255 - c, 96, 40, 180 - c, stencil);
		c = (c + 4) & 63;
		i = (c + 15) /6-2;

		surface_stencil_render(&surf, stencil, i);

		msx_vwrite_direct(surf.data.ram, 0, MODE2_MAX);
		if (get_trigger(0))
			break;
	}

	set_mode(mode_0);
}
Exemplo n.º 4
0
Arquivo: ex8.c Projeto: 128keaton/ltdc
// do the whole preview table and stuff :)
void do_preview(u_char* buf) {
	int asc, x, y, addr;
	u_char st;

	set_color(15, 4, 4);
	set_sprite_8(0, square);

	fill(MODE2_ATTR, 0xF0, MODE2_MAX);

	// start blitting buffer at pixel (16,16)
	addr = map_block(16, 16);

	// 16 chars of width (*8), 16 "lines", jump 256 in VRAM for each line
	blit_ram_vram(buf, addr, 16 * 8, 16, 16 * 8, 256);

	// fill yellow background
	blit_fill_vram(MODE2_ATTR + map_block(8, 8), 0x1A, 8 * 18, 18, 256);

	x = 0; y = 0;

	// preview loop
	while (!get_trigger(0)) {
		// move the cursor and set the zooming
		st = st_dir[get_stick(0)];

		x += (st & st_right) ? 1 : ((st & st_left) ? -1 : 0);
		y += (st & st_down) ? 1 : ((st & st_up) ? -1 : 0);

		x &= 15;
		y &= 15;
		asc = (y << 4) + x;
		put_sprite_8(0, (x + 2) << 3, (y + 2) << 3, 0, 9);

		preview_char(buf + (asc << 3));
	}	
}
void MapTile::update(const std::pair<gestoos::nui::Hand, gestoos::nui::Hand> & h)
{
 //   std::cout<<"1 hand_g present "<<hand_g->is_present()<<std::endl;
 
    
    
    
    hands = h;

    
    
    // manage Cursor and Pan
    
    if( hands.first.is_present() && !hands.second.is_present())
    {
        gestoos::nui::Hand & hand = hands.first;
        // Instant hand position scaled to screen
        Vec2f hand_pos_inst ;
        
        hand_pos_inst.x = ( hand.get_unit_pos().x - 0.5 ) * cinder::app::getWindowWidth()*2.0 + cinder::app::getWindowWidth()/2.0;
        hand_pos_inst.y = (hand.get_unit_pos().y -0.5)    *   cinder::app::getWindowHeight()*2.0 + cinder::app::getWindowHeight()/2.0;
        
        
        // Filter hand
        hand_pos_f += ( hand_pos_inst - hand_pos_f ) * 0.1 ;
        
        //Pan becomes a grab
        if(hand.get_gesture() == GEST_CLOSE)
        {
            if (track_mode!=MODE_PAN)
            {
                //Grab, record the current maporigin pos
                // and the and pos
                grab_reference = hand_pos_f;
                screen_reference = maporigin;
                std::cout << "Grabbed in " << grab_reference << std::endl;

            }
            track_mode = MODE_PAN;
            
            
            float mapW = cinder::app::getWindowWidth();
            float mapH = cinder::app::getWindowHeight();
            
            float panBorderx = 0.4;
            float panBordery = 0.45;

            maporigin = screen_reference + (hand_pos_f - grab_reference);
            
            //Hack: limit the pannning to X times the window size
            float min_x = -2.5*cinder::app::getWindowWidth();
            float max_x = 2.5*cinder::app::getWindowWidth();
            float min_y = -2.0*cinder::app::getWindowHeight();
            float max_y = 2.0*cinder::app::getWindowHeight();
            //Limit map origin to effectively limit the panning
            if (maporigin.x < min_x)
                maporigin.x = min_x;
            if (maporigin.x > max_x)
                maporigin.x = max_x;
      
            if (maporigin.y < min_y)
                maporigin.y = min_y;
            if (maporigin.y > max_y)
                maporigin.y = max_y;
            
            
//            if(hand_pos_f.x > mapW*(1.0-panBorderx)) 	maporigin.x -= 5.0;
//            if(hand_pos_f.y  > (mapH*(1.0-panBordery))) 	maporigin.y -= 5.0;//( mapH * panStep - pany ) * 0.05 ;
//            if(hand_pos_f.x  < mapW*panBorderx) 			maporigin.x += 5.0;//( (-mapW * panStep) - panx ) * 0.05 ;
//            if(hand_pos_f.y  < (mapH*panBordery)) 			maporigin.y += 5.0;// ( (-mapH * panStep) - pany ) * 0.05 ;
//            
            
            
            
            
        }
        else{
            track_mode = MODE_CURSOR;

        }
    }
    /// Manage ZOOM slider
    
    
    for( auto it=sliders.begin(); it!=sliders.end(); ++it )
        it->update();
    
    gestoos::nui::Hand hand1 = hands.first;
    gestoos::nui::Hand hand2 = hands.second;
    
    // start slider
    for( auto it=sliders.begin(); it!=sliders.end(); ++it )
    {
        
        if (!it->is_showing() &&
            hand1.is_present() && hand2.is_present() &&
            std::abs(hand1.get_pos().y - hand2.get_pos().y) < 4 )
        {
            if( hand1.get_gesture() == it->get_trigger()  )
            {
                
                
                
                track_mode = MODE_ZOOM;
                hand_g =        &hand1;
                hand_slider =   &hand2;
                ref_pos =       hand_g->get_pos();
                hide_all_sliders();
                it->show();
                zoomtimer.start();
                offset_zoom = zoom - 0.5;
                it->set_pctg( zoom );
    
                break;
            }
            if(  hand2.get_gesture() == it->get_trigger() )
            {
                track_mode = MODE_ZOOM;

                hand_g =        &hand2;
                hand_slider =   &hand1;
                ref_pos =       hand_g->get_pos();
                hide_all_sliders();
                it->show();
                
                zoomtimer.start();
                offset_zoom = zoom - 0.5;
                it->set_pctg( zoom );
   
                break;
            }
            
        }
    }
    

    // exit slider
    for( auto it=sliders.begin(); it!=sliders.end(); ++it )
    {
        
        if( it->is_showing() &&
           it->get_trigger() > 10 && ( !hand1.is_present() || !hand2.is_present()  || hand_g->get_gesture()!=it->get_trigger() ) )
        {
            track_mode = MODE_IDLE;

            hide_all_sliders();
            hand_g =empty_hand;
            hand_slider = empty_hand2;
            std::cout<<"quitting "<<it->get_trigger()<<std::endl;
            break;
        }
    }
    
    // filter ref pos
    if( hand_g->is_present() )
        ref_pos += (hand_g->get_pos() - ref_pos) * 0.1;
    
    // update pctg
    for( auto it=sliders.begin(); it!=sliders.end(); ++it )
    {
        if( it->is_showing() && hand_slider->is_present() )
        {
            float new_pctg = 0.0;
            
            if( it->get_type() == Slider::VERTICAL )
            {
                new_pctg = lmap<float>( ( hand_slider->get_pos().y - ref_pos.y ), -20, 20, 1.0, 0.0 );
            }
            
            
           
            it->set_pctg( (new_pctg + offset_zoom)  ) ;
            break;
        }
    }
    
    for( auto it=sliders.begin(); it!=sliders.end(); ++it )
    {
        if(track_mode == MODE_ZOOM  && it->is_showing())
        {
            float delta_zoom=zoom;
            zoom =  it->get_pctg();
            delta_zoom = zoom-delta_zoom;
            maporigin.x -=delta_zoom*5;
            maporigin.y -=delta_zoom*5;
            
        }
    }

    
}
Exemplo n.º 6
0
main() {
	bool flat = false;
	//int *low, *high;
	vector_t light;

	surface_t screen;

	// this is a vector buffer, for the transformations
	// our only object have 5 vertexes, but we'll make space for 32 anyway
	vector_t *pbuffer;

	// off-screen surface buffer
	//u_char* sbuffer = (u_char*)malloc(MODE2_MAX);

	// our solid :)
	object_t triangle;


	heapinit (HPSIZE);
	
	pbuffer = newa(vector_t, 32);

	triangle.mesh = build_mesh();
	triangle.rot_x = triangle.rot_y = triangle.rot_z = 0;
	triangle.trans_x = triangle.trans_y = 0;
	triangle.trans_z = i2f(30);	// remember: we are using fixed-point numbers

	screen.data.ram = sbuffer;

	// polygon rendering buffers
	//low = newa(int, MODE2_HEIGHT);
	//high = newa(int, MODE2_HEIGHT);

	// light source
	light.x = light.y = light.z = i2f(1);
	vector_normalize(&light, &light);

	printf("spinning solid demo\n\n");

	printf("instructions:\n   press [UP] to toggle flat shading\n\n");

	printf("creating look-up tables, please wait\n");
	create_lookup_tables();

	// set screen to graphic mode
	set_color(15, 1, 1);
	set_mode(mode_2);
	fill(MODE2_ATTR, 0xF1, MODE2_MAX);

	//surface_line(&screen, 0, 0, 0, 0); // FIXME: won't compile without this crap

	while (!get_trigger(0)) {
		if (get_stick(0) == 1)
			flat = !flat;

		// rotate a bit
		triangle.rot_y += 2;
		triangle.rot_x += 3;
		triangle.rot_z += 1;

		// clear the off-screen buffer
		memset(sbuffer, 0, MODE2_MAX);	// [*] 

	//surface_line(screen, 0, 0, 10, 10);

		// render the object
		if (flat)
			//object_render_flatshading(&screen, &triangle, pbuffer, low, high, &light);
			object_render_flatshading(&screen, &triangle, pbuffer, stencil, &light);
		else
			object_render_wireframe(&screen, &triangle, pbuffer);

		// show the off-screen buffer
		//vwrite(screen.data.ram, 0, MODE2_MAX); // [*]
		msx_vwrite_direct(screen.data.ram, 0, MODE2_MAX);

		// [*] FIXME: there will be better ways of doing this (soon)
	}

	// go back to text mode
	set_mode(mode_0);

	// deallocate stuff

	mesh_delete(triangle.mesh);
	//free(sbuffer);
	//free(low);
	//free(high);
	//destroy_lookup_tables();
}