Ejemplo n.º 1
0
//三角形登録
void sankakOBJ::Set(Vector3 *vec)
{
	//コピー
	for(int i=0; i<3; i++){
		oVertex[i] = vec[i];
		vertex[i] = vec[i];
	}
	//当たり判定登録
	colliOBJ.Set_3(vertex);
	
	//UV
	float uv[3][2] = { {0.0,0.0}, {1.0,0.0}, {0.0,1.0} };
	
	setDefaultMaterial();
	//ディスプレイリストを作成
	DisplayList = glGenLists(1);
	glNewList(DisplayList,GL_COMPILE); //コンパイルのみ
	
	glBindTexture(GL_TEXTURE_2D, texturePNG);
	glNormal3fv( (GLfloat*)&(colliOBJ.GetNormal().x) );
	glBegin(GL_TRIANGLES);
	for(int i=0; i<3; i++){
		glTexCoord2fv( uv[i] );
		glVertex3fv( vertex[i] );
	}
	glEnd();
	glBindTexture(GL_TEXTURE_2D, 0);//バインドしたのをもとに戻す
	
	glEndList();	//ディスプレイリストおわり
}
Ejemplo n.º 2
0
//セット。ディスプレイリストを作成する
//12分割の白黒の板をつくる
void Ita::SetRender(float u, float v){
	const static GLfloat ground[][4] = {   /* 台の色    */
		{ 0.6, 0.6, 0.6, 1.0 },
		{ 1.0, 1.0, 1.0, 1.0 }
	};
	
	DisplayList = glGenLists(1);//ディスプレイリストを作成
	glNewList(DisplayList,GL_COMPILE); //コンパイルのみ
	
	//マテリアルをデフォルトにもどす。
	setDefaultMaterial();
	
	glBegin(GL_QUADS);
	glNormal3d(0.0, 1.0, 0.0);
	for (int j = -6; j < 6; ++j) {
		for (int i = -6; i < 6; ++i) {
			glMaterialfv(GL_FRONT, GL_DIFFUSE, ground[(i + j) & 1]);
			glVertex3f( (GLfloat) i     *(u/12.0), 0.0, (GLfloat) j     *(v/12.0) );
			glVertex3f( (GLfloat) i     *(u/12.0), 0.0, (GLfloat)(j + 1)*(v/12.0) );
			glVertex3f( (GLfloat)(i + 1)*(u/12.0), 0.0, (GLfloat)(j + 1)*(v/12.0) );
			glVertex3f( (GLfloat)(i + 1)*(u/12.0), 0.0, (GLfloat) j     *(v/12.0) );
		}
	}
	glEnd();
	glEndList();	//ディスプレイリストおわり
	
	size.x = u;
	size.y = v;
	//頂点位置保存
	vertex[0].Set( -u/2, 0.0, -v/2);
	vertex[1].Set( -u/2, 0.0,  v/2);
	vertex[2].Set(  u/2, 0.0,  v/2);
	vertex[3].Set(  u/2, 0.0, -v/2);
}
Ejemplo n.º 3
0
//描画
void sankakOBJ::Render()
{
	//UV
	float uv[3][2] = { {0.0,0.0}, {1.0,0.0}, {0.0,1.0} };
	
	glPushMatrix();
	glTranslatef(pos.x, pos.y, pos.z);	//移動
	setDefaultMaterial();
	
	glBindTexture(GL_TEXTURE_2D, texturePNG);
	glNormal3fv( (GLfloat*)&(colliOBJ.GetNormal().x) );
	glBegin(GL_TRIANGLES);
	for(int i=0; i<3; i++){
		glTexCoord2fv( uv[i] );
		glVertex3fv( vertex[i] );
	}
	glEnd();
	glBindTexture(GL_TEXTURE_2D, 0);//バインドしたのをもとに戻す
	//glCallList(DisplayList);	//描画
	glPopMatrix();
}
Ejemplo n.º 4
0
//登録
void boxOBJ::Set(Vector3 *vec, const char *texName)
{
	//すでに呼ばれたかどうか
	if(isSet) return;
	isSet = true;
	
	//コピー&頂点位置決定
	oVertex[0].x = fabs(vec->x);
	oVertex[0].y = fabs(vec->y);
	oVertex[0].z = fabs(vec->z);
	oVertex[1].Set( -oVertex[0].x,  oVertex[0].y,  oVertex[0].z); 
	oVertex[2].Set( -oVertex[0].x, -oVertex[0].y,  oVertex[0].z); 
	oVertex[3].Set(  oVertex[0].x, -oVertex[0].y,  oVertex[0].z); 
	oVertex[4].Set(  oVertex[0].x,  oVertex[0].y, -oVertex[0].z); 
	oVertex[5].Set( -oVertex[0].x,  oVertex[0].y, -oVertex[0].z); 
	oVertex[6].Set( -oVertex[0].x, -oVertex[0].y, -oVertex[0].z); 
	oVertex[7].Set(  oVertex[0].x, -oVertex[0].y, -oVertex[0].z); 
	for(int i=0; i<8; i++){
		vertex[i] = oVertex[i];
	}
	
	//当たり判定登録
	Vector3 v[4];
	for(int i=0; i<6; i++){
		v[0]=vertex[ index[i][0] ];
		v[1]=vertex[ index[i][1] ];
		v[2]=vertex[ index[i][2] ];
		v[3]=vertex[ index[i][3] ];
		colli[i].Set_4(v);
	}
	
	//判定球の半径測定
	r = sqrt( vec->x*vec->x + vec->y*vec->y + vec->z*vec->z );
	
	//テクスチャ読み込み
	if( texName != NULL ){
#if USE_GLPNG
		pngInfo info;
		texturePNG = pngBind(texName, PNG_NOMIPMAP, PNG_ALPHA, &info, GL_CLAMP, GL_NEAREST, GL_NEAREST);
#else
		texturePNG = pngt.load(texName);
#endif
	}
	
	//UV
	float uv[4][2] = { {0.0,0.0}, {0.0,1.0}, {1.0,1.0}, {1.0,0.0} };
	
	//ディスプレイリスト
	DisplayList = glGenLists(1);//ディスプレイリストを作成
	glNewList(DisplayList,GL_COMPILE); //コンパイルのみ
	
	if(texturePNG) glBindTexture(GL_TEXTURE_2D, texturePNG);
	
	setDefaultMaterial();
	
	glBegin(GL_QUADS);
	for(int f=0; f<6; f++){
		glNormal3fv( (GLfloat*)&(colli[f].GetNormal()) );
		for(int i=0; i<4; i++){
			if(texturePNG) glTexCoord2fv( uv[i] );
			glVertex3fv( oVertex[ index[f][i] ] );
		}
	}
	glEnd();
	
	if(texturePNG) glBindTexture(GL_TEXTURE_2D, 0);//バインドしたのをもとに戻す
	
	glEndList();	//ディスプレイリストおわり
}
Ejemplo n.º 5
0
void MD5Surface::parseFromTokens(parser::DefTokeniser& tok)
{
	// Start of datablock
	tok.assertNextToken("mesh");
	tok.assertNextToken("{");

	// Get the reference to the mesh definition
	MD5Mesh& mesh = *_mesh;

	// Get the shader name
	tok.assertNextToken("shader");
	setDefaultMaterial(tok.nextToken());

	// ----- VERTICES ------

	// Read the vertex count
	tok.assertNextToken("numverts");
	std::size_t numVerts = string::convert<std::size_t>(tok.nextToken());

	// Initialise the vertex vector
	MD5Verts& verts = mesh.vertices;
	verts.resize(numVerts);

	// Populate each vertex struct with parsed values
	for (MD5Verts::iterator vt = verts.begin(); vt != verts.end(); ++vt) {

		tok.assertNextToken("vert");

		// Index of vert
		vt->index = string::convert<std::size_t>(tok.nextToken());

		// U and V texcoords
		tok.assertNextToken("(");
		vt->u = string::convert<float>(tok.nextToken());
		vt->v = string::convert<float>(tok.nextToken());
		tok.assertNextToken(")");

		// Weight index and count
		vt->weight_index = string::convert<std::size_t>(tok.nextToken());
		vt->weight_count = string::convert<std::size_t>(tok.nextToken());

	} // for each vertex

	// ------  TRIANGLES ------

	// Read the number of triangles
	tok.assertNextToken("numtris");
	std::size_t numTris = string::convert<std::size_t>(tok.nextToken());

	// Initialise the triangle vector
	MD5Tris& tris = mesh.triangles;
	tris.resize(numTris);

	// Read each triangle
	for(MD5Tris::iterator tr = tris.begin(); tr != tris.end(); ++tr) {

		tok.assertNextToken("tri");

		// Triangle index, followed by the indexes of its 3 vertices
		tr->index = string::convert<std::size_t>(tok.nextToken());
		tr->a = 	string::convert<std::size_t>(tok.nextToken());
		tr->b = 	string::convert<std::size_t>(tok.nextToken());
		tr->c = 	string::convert<std::size_t>(tok.nextToken());

	} // for each triangle

	// -----  WEIGHTS ------

	// Read the number of weights
	tok.assertNextToken("numweights");
	std::size_t numWeights = string::convert<std::size_t>(tok.nextToken());

	// Initialise weights vector
	MD5Weights& weights = mesh.weights;
	weights.resize(numWeights);

	// Populate with weight data
	for(MD5Weights::iterator w = weights.begin(); w != weights.end(); ++w) {

		tok.assertNextToken("weight");

		// Index and joint
		w->index = string::convert<std::size_t>(tok.nextToken());
		w->joint = string::convert<std::size_t>(tok.nextToken());

		// Strength and relative position
		w->t = string::convert<float>(tok.nextToken());
		w->v = MD5Model::parseVector3(tok);

	} // for each weight

	// ----- END OF MESH DECL -----

	tok.assertNextToken("}");
}