コード例 #1
0
ファイル: mesh.cpp プロジェクト: andreaswatch/dizuo
//
// Test a line against a mesh
// Selects the closest front-facing triangle
//
int CMesh::LineSelect( const CVec3 &LP1, const CVec3 &LP2 )
{
	CVec3 HitP;
	int nbHits = 0;
	int nSelTri = -1;
	float fDistance = 1000000000.0f;
	
	for (int nTri = 0; nTri < m_nbTris; nTri++ )
		{
		if ( m_pTriFlags[ nTri ] & TF_BACKFACING ) continue; // Check only front facing triangles
		
		int nV = nTri*3;	

		bool bHit = CheckLineTri( LP2, LP1, m_pVerts[ m_pTris[nV] ], m_pVerts[ m_pTris[nV+1] ], m_pVerts[ m_pTris[nV+2] ], HitP );
		if ( bHit ) {
			if ( HitP.Distance( LP1 ) < fDistance ) {
				fDistance = HitP.Distance( LP1 );
				nSelTri = nTri;
				}
			nbHits++;
			}
		}
		
	SelectTriangle( nSelTri );
	
	return nbHits;
}
コード例 #2
0
ファイル: img21.c プロジェクト: justinapps/2d-drawing
void CallTriangle(GLint button, GLint state, GLint x, GLint y){

	static int first=1;
	if (state == GLUT_DOWN && button == GLUT_LEFT_BUTTON){

		if (first == 1){

			x1 = x; 
			y10 = hh - y;
			first++;
		}

		else if(first == 2){

			x2 = x;
			y2 = hh - y;
			first++;
		}

		else{

			x3 = x;
			y3 = hh - y;
			first = 1;
			SelectTriangle();
		}	
	}

	return;
}
コード例 #3
0
void Unitselect::UiDraw(){
	Vec2f warrior_draw_pos = Vec2f((WIDTH / 2 - 250) - 300 * static_cast<int>(Job::WARRIOR),
								   HEIGHT / 4);
	Vec2f lancer_draw_pos = Vec2f((WIDTH / 2 - 250) - 300 * static_cast<int>(Job::LANCER),
								  HEIGHT / 4);
	Vec2f select_job_pos = Vec2f(-100, 300);

	selectjob_color[static_cast<int>(Job::WARRIOR)] = warrior.GetColor();
	selectjob_color[static_cast<int>(Job::LANCER)] = lancer.GetColor();

	if (select_job == static_cast<int>(Job::WARRIOR))
	{
		SelectTriangle(Vec2f(warrior_draw_pos.x() + 50, warrior_draw_pos.y() + 220));
	}
	if (select_job == static_cast<int>(Job::LANCER))
	{
		SelectTriangle(Vec2f(lancer_draw_pos.x() + 50, lancer_draw_pos.y() + 220));
	}
	if (select_job == static_cast<int>(Job::JOB_MAX)){
		SelectTriangle(Vec2f(select_job_pos.x() + 200, select_job_pos.y() + 50));
	}

	font.draw("ウォーリアー", Vec2f(warrior_draw_pos.x() - 50, warrior_draw_pos.y() - 100),
			  Color::white);

	font.draw("ランサー", Vec2f(lancer_draw_pos.x() - 50, lancer_draw_pos.y() - 100),
			  Color::white);

	if (player_or_enemy)
	{
		font.draw("プレイヤーセレクト", Vec2f(select_job_pos.x(), select_job_pos.y()),
				  Color::white);
	}
	else
	{
		font.draw("エネミーセレクト", Vec2f(select_job_pos.x(), select_job_pos.y()),
				  Color::white);
	}
}
コード例 #4
0
ファイル: mesh.cpp プロジェクト: andreaswatch/dizuo
//
// Select mesh triangles that are in a frustum defined by 8 Points( and 4 face normals )
// I'm currently ignoring near and far planes, but they could be easily added
//
int CMesh::FrustumSelect( CVec3 Normals[4], CVec3 Points[8] )
{
	int nbHits = 0;
	CVec3 Tri[3];
	
	for (int nTri = 0; nTri < m_nbTris; nTri++ )
		{	
		int nV = nTri*3;
		Tri[0] = m_pVerts[ m_pTris[ nV ] ];
		Tri[1] = m_pVerts[ m_pTris[ nV+1 ] ];
		Tri[2] = m_pVerts[ m_pTris[ nV+2 ] ];

		if ( TriInFrustum( Tri, Normals, Points ) )
			{
			SelectTriangle( nTri );			
			nbHits++;			
			}
		}
	
	return nbHits;
}