Exemple #1
0
int main()
{
	set_perspective(1, 100.0);
	
	init();
	//clear the screen
	draw_rect(0,0,320,240,0x0);
	flush_to_lcd();
	
	uint32_t count = 1;
	char str[10];
	
	uint16_t colors[] = {0xF800, 0xF600, 0x7E0, 0x1F, 0xFFFF,0xF800, 0xF600, 0x7E0, 0x1F, 0xFFFF,0xF800, 0xF600, 0x7E0, 0x1F, 0xFFFF};

	//int16_t centerx = 320/2;
	//int16_t centery = 240/2;
	
	//int16_t polysize = 30;
	
	
	int16_t rot = 0;
	
	polygon poly;
	
	#ifdef FORAERY
	for (;;)
	#endif
	{
		count = 0;
		START_MEASURING_CYCLES();
		rot++;
		if (rot >= 360) rot = 0;
		
		/*
		for (int i = 0; i < 15; i++)
		{
			poly.x0 = (i-7)*20+centerx+lcd_cos(rot+120)*polysize;
			poly.y0 = centery+lcd_sin(rot+120)*polysize;
			poly.x1 = (i-7)*20+centerx+lcd_cos(rot+120*2)*polysize;
			poly.y1 = centery+lcd_sin(rot+120*2)*polysize;
			poly.x2 = (i-7)*20+centerx+lcd_cos(rot+120*3)*polysize;
			poly.y2 = centery+lcd_sin(rot+120*3)*polysize;
			draw_b_poly(poly, colors[i]);
		}
		for (int i = 0; i < 15; i++)
		{
			poly.x0 = (i-7)*20+centerx+lcd_cos(rot+120)*polysize;
			poly.y0 = 20+centery+lcd_sin(rot+120)*polysize;
			poly.x1 = (i-7)*20+centerx+lcd_cos(rot+120*2)*polysize;
			poly.y1 = 20+centery+lcd_sin(rot+120*2)*polysize;
			poly.x2 = (i-7)*20+centerx+lcd_cos(rot+120*3)*polysize;
			poly.y2 = 20+centery+lcd_sin(rot+120*3)*polysize;
			draw_b_poly(poly, colors[i]);
		}
		*/
 
				translate_camera(Vector3D(0,1,4));		
		rotate_camera(20,lcd_sin(rot)*180.0, 0);
		
		Polygon3D p;
		
		//front
		p.p0 = Vector3D(-1, 1, 1);
		p.p1 = Vector3D(-1,-1, 1);
		p.p2 = Vector3D( 1,-1, 1);
		draw_poly3D(p, colors[0]);
		
		p.p0 = Vector3D(-1, 1, 1);
		p.p1 = Vector3D( 1,-1, 1);
		p.p2 = Vector3D( 1, 1, 1);
		draw_poly3D(p, colors[0]);
		
		//left side
		p.p0 = Vector3D(-1, 1, -1);
		p.p1 = Vector3D(-1,-1, -1);
		p.p2 = Vector3D(-1,-1, 1);
		draw_poly3D(p, colors[1]);
		
		p.p0 = Vector3D(-1, 1,-1);
		p.p1 = Vector3D(-1,-1, 1);
		p.p2 = Vector3D(-1, 1, 1);
		draw_poly3D(p, colors[1]);
		
		//right side
		
		p.p0 = Vector3D( 1, 1, 1);
		p.p1 = Vector3D( 1,-1, 1);
		p.p2 = Vector3D( 1,-1,-1);
		draw_poly3D(p, colors[2]);
		
		p.p0 = Vector3D( 1, 1, 1);
		p.p1 = Vector3D( 1,-1,-1);
		p.p2 = Vector3D( 1, 1,-1);
		draw_poly3D(p, colors[2]);
		
		//backside
		
		p.p0 = Vector3D( 1, 1,-1);
		p.p1 = Vector3D( 1,-1,-1);
		p.p2 = Vector3D(-1,-1,-1);
		draw_poly3D(p, colors[3]);
		
		p.p0 = Vector3D( 1, 1,-1);
		p.p1 = Vector3D(-1,-1,-1);
		p.p2 = Vector3D(-1, 1,-1);
		draw_poly3D(p,colors[3]);
		
		//top
		
		p.p0 = Vector3D(-1, 1,-1);
		p.p1 = Vector3D(-1, 1, 1);
		p.p2 = Vector3D( 1, 1, 1);
		draw_poly3D(p, colors[4]);
		
		p.p0 = Vector3D(-1, 1,-1);
		p.p1 = Vector3D( 1, 1, 1);
		p.p2 = Vector3D( 1, 1,-1);
		draw_poly3D(p, colors[4]);
		
		
		draw_poly_buffer();
		draw_text(str,0,220,0xF800);
		flush_to_lcd();
		
		END_MEASURING_CYCLES(count);
		#ifdef FORAERY
		itoa(66000000/count,str);
		#endif
	}

	#ifdef FORPC
	while (sfmlwindow.isOpen())
	{
		//input
		sf::Vector2i localPosition = sf::Mouse::getPosition(sfmlwindow);
		
		if (sf::Mouse::isButtonPressed(sf::Mouse::Left))
		{
			//std::cout<<"x: " <<localPosition.x << " y: " << localPosition.y <<"\n";
		}
		sf::Event eventti;
		while (sfmlwindow.pollEvent(eventti))
		{
			switch(eventti.type)
			{
				case sf::Event::Closed:
					sfmlwindow.close();
					break;
				default:
					break;
			}
			
		}
		//logic
		
		rot++;
		if (rot >= 360) rot = 0;
		
		translate_camera(Vector3D(0,1,4));		
		rotate_camera(20,lcd_sin(rot)*180.0, 0);
		
		Polygon3D p;
		
		//front
		p.p0 = Vector3D(-1, 1, 1);
		p.p1 = Vector3D(-1,-1, 1);
		p.p2 = Vector3D( 1,-1, 1);
		draw_poly3D(p, colors[0]);
		
		p.p0 = Vector3D(-1, 1, 1);
		p.p1 = Vector3D( 1,-1, 1);
		p.p2 = Vector3D( 1, 1, 1);
		draw_poly3D(p, colors[0]);
		
		//left side
		p.p0 = Vector3D(-1, 1, -1);
		p.p1 = Vector3D(-1,-1, -1);
		p.p2 = Vector3D(-1,-1, 1);
		draw_poly3D(p, colors[1]);
		
		p.p0 = Vector3D(-1, 1,-1);
		p.p1 = Vector3D(-1,-1, 1);
		p.p2 = Vector3D(-1, 1, 1);
		draw_poly3D(p, colors[1]);
		
		//right side
		
		p.p0 = Vector3D( 1, 1, 1);
		p.p1 = Vector3D( 1,-1, 1);
		p.p2 = Vector3D( 1,-1,-1);
		draw_poly3D(p, colors[2]);
		
		p.p0 = Vector3D( 1, 1, 1);
		p.p1 = Vector3D( 1,-1,-1);
		p.p2 = Vector3D( 1, 1,-1);
		draw_poly3D(p, colors[2]);
		
		//backside
		
		p.p0 = Vector3D( 1, 1,-1);
		p.p1 = Vector3D( 1,-1,-1);
		p.p2 = Vector3D(-1,-1,-1);
		draw_poly3D(p, colors[3]);
		
		p.p0 = Vector3D( 1, 1,-1);
		p.p1 = Vector3D(-1,-1,-1);
		p.p2 = Vector3D(-1, 1,-1);
		draw_poly3D(p,colors[3]);
		
		//top
		
		p.p0 = Vector3D(-1, 1,-1);
		p.p1 = Vector3D(-1, 1, 1);
		p.p2 = Vector3D( 1, 1, 1);
		draw_poly3D(p, colors[4]);
		
		p.p0 = Vector3D(-1, 1,-1);
		p.p1 = Vector3D( 1, 1, 1);
		p.p2 = Vector3D( 1, 1,-1);
		draw_poly3D(p, colors[4]);
		
		
		draw_poly_buffer();
		draw_text(str,0,220,0xF800);
		
		flush_to_lcd();

		
		//render
		simscreen_render();
		sfmlwindow.display();
		//sleep
		sf::sleep(sf::milliseconds(33));
	}
	#endif
	return 0;
}
Exemple #2
0
//================================================================
void render_track(TrackSceneNode* t, Canvas* c)
{
#ifdef DEBUG
    printf("\n\t--- Render Track ---\n");
#endif

    if( !t || !c ) 
    {
#ifdef DEBUG
        printf("Track or Canvas is NULL!\n");
#endif
        return;
    }

    if(!t->show) return;

    // move our canvas
    float x, y, z;

#ifdef DEBUG
    get_camera_position(c->camera, &x, &y, &z);
    printf("Track b4: Camera position %.2f %.2f\n", x, y);
    printf("Track translation: %.2f %.2f\n", -t->px, -t->py);
#endif

    // orig: translate_camera( c->camera, -t->px, -t->py, 0);
    if(get_horizontal_depth()) {
        translate_camera( c->camera, -t->px, -t->py, 0);
    } else {
        translate_camera( c->camera, t->py, -t->px, 0);
    }

    glTranslatef( t->px, t->py, 0);

#ifdef DEBUG
    get_camera_position( c->camera, &x, &y, &z);
    printf("Track after: Camera position %.2f, %.2f\n", x, y);
    printf("Track has zorder of size %d\n", t->zorder.size());
#endif

    int i;
    // draw back to front
    glPushMatrix();
    for( i = t->zorder.size() - 1; i > - 1; --i)
    {
#ifdef DEBUG
        printf("Rendering Core Section %d\n", t->zorder[i]);
#endif

        if( t->zorder[i] >= 0 && t->modelvec[ t->zorder[i] ] != NULL)
            render_section_model( t->modelvec[ t->zorder[i] ], c);
    }
    glPopMatrix();

    // draw plugin free draw rectangles, scale so x,y,w,h are in meters
    glPushMatrix();
    float scale = 1.0 / c->dpi_x * CM_PER_INCH / 100.0f;
    float indep_scale = c->w / c->w0;
    glScalef(1.0 /scale,1.0 /scale,1.0 /scale);
    for( i = 0; i < t->freedrawvec.size(); i++)
    {
        if( is_free_draw_scale_independent(t->freedrawvec[i]))
        {
            glScalef( indep_scale, indep_scale, 1.0f);
            render_free_draw(t->freedrawvec[i]);
            glScalef( 1.0 / indep_scale, 1.0 / indep_scale, 1.0f);
        }
        else
        {
            render_free_draw(t->freedrawvec[i]);

        }
    }

    glPopMatrix();

    glTranslatef( -t->px, -t->py, 0);

    // orig: translate_camera( c->camera, t->px, t->py, 0);
    if(get_horizontal_depth()) {
        translate_camera( c->camera, t->px, t->py, 0);
    } else {
        translate_camera( c->camera, -t->py, t->px, 0);
    }
}