示例#1
0
	void Framework::update(){
		if ( gFirstFrame ){
			gFirstFrame = false;
			gImage = new Image( "background.dds" ); 
			createTexture( 
				&gTexture,
				gImage->width(), 
				gImage->height(), 
				gImage->data(), 
				gImage->width(), 
				gImage->height() );
			SAFE_DELETE( gImage );
		}
		setTexture( gTexture );
		double p0[ 2 ] = { 100.0, 100.0 };
		double p1[ 2 ] = { 200.0, 120.0 };
		double p2[ 2 ] = { 120.0, 200.0 };
		double t0[ 2 ] = { 0.0, 0.0 };
		double t1[ 2 ] = { 1.0, 0.0 };
		double t2[ 2 ] = { 0.0, 1.0 };
		drawTriangle2D( p0, p1, p2, t0, t1, t2 );

		//終了処理してみようか
		if ( isEndRequested() ){
			destroyTexture( &gTexture );
		}		
	}
示例#2
0
void drawTriangle(const geo::Vec3& p1_3d, const geo::Vec3& p2_3d, const geo::Vec3& p3_3d, const ProjectionMatrix& P, Result& res)
{
    geo::Vec2i p1_2d = P.project3Dto2D(p1_3d);
    geo::Vec2i p2_2d = P.project3Dto2D(p2_3d);
    geo::Vec2i p3_2d = P.project3Dto2D(p3_3d);

    drawTriangle2D(geo::Vec3f(p1_2d.x, p1_2d.y, 1.0f / -p1_3d.z),
                   geo::Vec3f(p2_2d.x, p2_2d.y, 1.0f / -p2_3d.z),
                   geo::Vec3f(p3_2d.x, p3_2d.y, 1.0f / -p3_3d.z),
                   res);
}
示例#3
0
	void Framework::update(){
		if ( !gCircles ){
			gCircles = new Circle[ N*N ];
			//初期配置
			for ( int i = 0; i < N*N; ++i ){
				gCircles[ i ].mPosition.set( 
					static_cast< double >( ( ( i % N ) - N/2 ) * 4 ) + 0.001 * i, //ちょっとずらす
					static_cast< double >( ( ( i / N ) - N/2 ) * 4 ) );
			}
		}
		//速度初期化
		for ( int i = 0;i < N*N; ++i ){
			//速度を原点方向で初期化
			gCircles[ i ].mVelocity.setMul( gCircles[ i ].mPosition, -0.001 );
		}
		int test;
		int hit;
		processCollision( &test, &hit ); //衝突検出関数

		//更新
		for ( int i = 0;i < N*N; ++i ){
			gCircles[ i ].mPosition += gCircles[ i ].mVelocity;

			//描画
			double p[ 4 ][ 2 ];
			p[ 0 ][ 0 ] = p[ 1 ][ 0 ] = gCircles[ i ].mPosition.x - 0.5 + 160.0;
			p[ 2 ][ 0 ] = p[ 3 ][ 0 ] = gCircles[ i ].mPosition.x + 0.5 + 160.0;
			p[ 0 ][ 1 ] = p[ 2 ][ 1 ] = gCircles[ i ].mPosition.y - 0.5 + 120.0;
			p[ 1 ][ 1 ] = p[ 3 ][ 1 ] = gCircles[ i ].mPosition.y + 0.5 + 120.0;
			drawTriangle2D( p[ 0 ], p[ 1 ], p[ 2 ] );
			drawTriangle2D( p[ 3 ], p[ 1 ], p[ 2 ] );
		}
		ostringstream oss;
		oss << frameRate() << " " << test << " " << hit;
		drawDebugString( 0, 0, oss.str().c_str() );
	}
示例#4
0
	void Framework::update(){
		sleep( 16 );
		if ( gFirstFrame ){
			gFirstFrame = false;
			gImage = new Image( "background.dds" ); 
			gImageWidth = gImage->width();
			gImageHeight = gImage->height();
			createTexture( 
				&gTexture,
				gImageWidth, 
				gImageHeight, 
				gImage->data(), 
				gImageWidth, 
				gImageHeight );
			SAFE_DELETE( gImage );
		}
		setTexture( gTexture );
		
		double rotation = static_cast< double >( gCount );
		Vector2 scale( sin( rotation ) + 0.5, cos( rotation ) + 0.5 );

		//行列作る
		Matrix23 m;
		m.setTranslation( Vector2( gImageWidth/2, gImageHeight/2 ) );
		if ( gScaleFirst ){
			m.rotate( rotation );
			m.scale( scale );
		}else{
			m.scale( scale );
			m.rotate( rotation );
		}
		m.translate( Vector2( -gImageWidth/2, -gImageHeight/2 ) );

		Vector2 p0( 0.0, 0.0 );
		Vector2 p1( 100.0, 0.0 );
		Vector2 p2( 0.0, 100.0 );
		Vector2 p3( 100.0, 100.0 );
		double t0[ 2 ] = { 0.0, 0.0 };
		double t1[ 2 ] = { 1.0, 0.0 };
		double t2[ 2 ] = { 0.0, 1.0 };
		double t3[ 2 ] = { 1.0, 1.0 };
		//行列乗算
		m.multiply( &p0, p0 );
		m.multiply( &p1, p1 );
		m.multiply( &p2, p2 );
		m.multiply( &p3, p3 );
		//描画
		//Vector2はそのままは渡せません。
		drawTriangle2D( &p0.x, &p1.x, &p2.x, t0, t1, t2 ); //012
		drawTriangle2D( &p3.x, &p1.x, &p2.x, t3, t1, t2 ); //312

		//スペースで切り替え
		if ( Input::Manager::instance().keyboard().isTriggered( ' ' ) ){
			gScaleFirst = !gScaleFirst;
		}
		++gCount;

		drawDebugString( 0, 0, "press SPACE to swap ROTATION and SCALING" );
		//終了処理してみようか
		if ( isEndRequested() ){
			destroyTexture( &gTexture );
		}
	}
示例#5
0
	void Framework::update(){
		double p0[ 2 ] = { 100.0, 100.0 };
		double p1[ 2 ] = { 200.0, 120.0 };
		double p2[ 2 ] = { 120.0, 200.0 };
		drawTriangle2D( p0, p1, p2 );
	}
示例#6
0
void renderDepth(const WorldModel& wm, const ProjectionMatrix& P, const geo::Pose3D& sensor_pose, Result& res)
{
    // Parameters
    double near_clip_z = -0.1;

    // - - - - - - - - - - - - - - - - - - - - - - - - - - - -

    const std::vector<Triangle>& triangles = wm.triangles();
    const std::vector<geo::Vec3>& vertices = wm.vertices();

    // transform points
    std::vector<geo::Vec3> vertices_t(vertices.size());
    std::vector<geo::Vec2i> vertices_proj(vertices.size());

    geo::Pose3D sensor_pose_inv = sensor_pose.inverse();

    for(unsigned int i = 0; i < vertices.size(); ++i)
    {
        vertices_t[i] = sensor_pose_inv * vertices[i];
        vertices_proj[i] = P.project3Dto2D(vertices_t[i]);
    }

    for(const auto& t : triangles)
    {
        const geo::Vec3& p1_3d = vertices_t[t.i1];
        const geo::Vec3& p2_3d = vertices_t[t.i2];
        const geo::Vec3& p3_3d = vertices_t[t.i3];

        res.triangleHook(t, p1_3d, p2_3d, p3_3d);

        int n_verts_in = 0;
        bool v1_in = false;
        bool v2_in = false;
        bool v3_in = false;
        const geo::Vec3* vIn[3];

        if (p1_3d.z < near_clip_z) {
            ++n_verts_in;
            v1_in = true;
        }

        if (p2_3d.z < near_clip_z) {
            ++n_verts_in;
            v2_in = true;
        }

        if (p3_3d.z < near_clip_z) {
            ++n_verts_in;
            v3_in = true;
        }

        if (n_verts_in == 1)
        {
            if (v1_in) { vIn[0] = &(p1_3d); vIn[1] = &(p2_3d); vIn[2] = &(p3_3d); }
            if (v2_in) { vIn[0] = &(p2_3d); vIn[1] = &(p3_3d); vIn[2] = &(p1_3d); }
            if (v3_in) { vIn[0] = &(p3_3d); vIn[1] = &(p1_3d); vIn[2] = &(p2_3d); }

            //Parametric line stuff
            // p = v0 + v01*t
            geo::Vec3 v01 = *vIn[1] - *vIn[0];

            float t1 = ((near_clip_z - (*vIn[0]).z) / v01.z );

            geo::Vec3 new2(vIn[0]->x + v01.x * t1, vIn[0]->y + v01.y * t1, near_clip_z);

            // Second vert point
            geo::Vec3 v02 = *vIn[2] - *vIn[0];

            float t2 = ((near_clip_z - (*vIn[0]).z) / v02.z);

            geo::Vec3 new3(vIn[0]->x + v02.x * t2, vIn[0]->y + v02.y * t2, near_clip_z);

            drawTriangle(*vIn[0], new2, new3, P, res);
        }
        else if (n_verts_in == 2)
        {
            if (!v1_in) { vIn[0]=&(p2_3d); vIn[1]=&(p3_3d); vIn[2]=&(p1_3d); }
            if (!v2_in) { vIn[0]=&(p3_3d); vIn[1]=&(p1_3d); vIn[2]=&(p2_3d); }
            if (!v3_in) { vIn[0]=&(p1_3d); vIn[1]=&(p2_3d); vIn[2]=&(p3_3d); }

            //Parametric line stuff
            // p = v0 + v01*t
            geo::Vec3 v01 = *vIn[2] - *vIn[0];

            float t1 = ((near_clip_z - (*vIn[0]).z)/v01.z );

            geo::Vec3 new2((*vIn[0]).x + v01.x * t1,(*vIn[0]).y + v01.y * t1, near_clip_z);

            // Second point
            geo::Vec3 v02 = *vIn[2] - *vIn[1];

            float t2 = ((near_clip_z - (*vIn[1]).z)/v02.z);

            geo::Vec3 new3((*vIn[1]).x + v02.x * t2, (*vIn[1]).y + v02.y * t2, near_clip_z);

            drawTriangle(*vIn[0], *vIn[1], new2, P, res);

            drawTriangle(new2, *vIn[1], new3, P, res);

        }
        else if (n_verts_in == 3)
        {
            const geo::Vec2i& p1_2d = vertices_proj[t.i1];
            const geo::Vec2i& p2_2d = vertices_proj[t.i2];
            const geo::Vec2i& p3_2d = vertices_proj[t.i3];

            drawTriangle2D(geo::Vec3f(p1_2d.x, p1_2d.y, 1.0f / -p1_3d.z),
                           geo::Vec3f(p2_2d.x, p2_2d.y, 1.0f / -p2_3d.z),
                           geo::Vec3f(p3_2d.x, p3_2d.y, 1.0f / -p3_3d.z),
                           res);
        }
    }
}