Ejemplo n.º 1
0
//コンストラクタ(読み込み)
XFrame::XFrame(XModel *model)
{
	index = model->Frame.size();	//フレーム番号を格納
	model->Frame.push_back(this);	//フレームをベクターに追加
	
	//行列の初期化
	MatrixIdentity(TransformMatrix);
	MatrixIdentity(OffsetMatrix);
	
	//フレーム名の取得
	GetToken();
	name = new char[strlen(Token)+1];
	strcpy(name, Token);
	
	//フレームからうまく抜けるため、現在のノード記憶
	int node = Node;
	
	//次のトークンが"{"であると確認する
	GetToken("{");
	
	//変換行列と子フレーム読み込み
	while (*Pointer!='\0') {
		GetToken();
		
		//ノードが終わったらループを抜ける
		if ( node == Node ) break;
		
		//フレームの場合、子フレームを作成 
		if ( CheckToken("Frame") ) {
			child.push_back(new XFrame(model));
		}
		
		// 変換行列を読み込む
		else if ( CheckToken("FrameTransformMatrix") ) {
			GetToken("{");
			for(int g=0; g<4; g++)
				for(int r=0; r<4; r++)
					TransformMatrix[g][r]=GetFloatToken();
			GetToken("}");
		}
		
		// 子フレームと変換行列以外の時
		else {
			//要素を識別して読み込み
			if( !model->Load_element() )
				model->loaded |= 1;	//エラー検出
		}
		
	}
}
Ejemplo n.º 2
0
//----------------------------------------------------------------------------------------------
// Protected : OnLine
//----------------------------------------------------------------------------------------------
void CObjMesh::OnLine()
{
	char *sToken = GetToken();

	// It's possible to have an integer "modifier" appended to a command
	EOb2Command eCmd = ParseCommandString( sToken );

	switch (eCmd)
	{
	case eVertexCoord:
		{
			float fX = GetFloatToken();
			float fY = GetFloatToken();
			float fZ = GetFloatToken();
			OnVertexCoordinate( fX, fY, fZ );
		}
		break;
	case eTextureCoord:
		{
			float fX = GetFloatToken();
			float fY = GetFloatToken();

			OnVertexTextureCoordinate( fX, fY );
		}
		break;
	case eNormalCoord:
		{
			float fX = GetFloatToken();
			float fY = GetFloatToken();
			float fZ = GetFloatToken();
			OnVertexNormal( fX, fY, fZ );
		}
		break;
	case eFace:
		{
			int pVertexCoords[128];
			int pTexCoords[128];
			int pNormal[128];

			// Initialize to -1
			for (int i = 0; i < 128; i++)
				pNormal[i] = pTexCoords[i] = -1;

			// Tokens can be of the form <vertex>/<texture>/<normal>, or <vertex>/<texture> or <vertex>
			int nNumCoords = 0;
			while ( sToken = GetToken() )
			{
				string sVertexString( sToken );

				int nStart = 0;
				for ( int nNum = 0; nNum < 3; nNum++ )
				{
					unsigned int nEnd = (int)sVertexString.find_first_of("/", nStart);

					bool bExit = false;
					if ( nEnd == string::npos)
					{
						nEnd = sVertexString.size();
						bExit = true;
					}

					string sNumber = sVertexString.substr( nStart, nEnd-nStart );

					if ( nNum == 0 )
						pVertexCoords[nNumCoords] = atoi(sNumber.c_str());
					else if ( nNum == 1 )
						pTexCoords[nNumCoords] = atoi(sNumber.c_str());
					else if ( nNum == 2 )
						pNormal[nNumCoords] = atoi(sNumber.c_str());

					if ( bExit )
						break;

					nStart = nEnd + 1;
				}
				nNumCoords++;
			}
			OnFace( pVertexCoords, pTexCoords, pNormal, nNumCoords );

		}
		break;
	}
}