NicogameLog
OpenGLメモ_Xファイル読み込み
最終更新:
nico_nonono
-
view
OpenGLメモ
Xファイルの読み込み
全体の流れ
- Xファイルをテキスト形式で開く
- 情報の読み込み
- Xファイルを閉じる
- 情報をもとに描画
Xファイルをテキスト形式で開く
Xファイルをテキスト形式で開き、情報の読み込みを行います。
FILE *file; file = fopen( "ファイル名", "rt" ))
情報の読み込み
データをコピーし、各情報を変数に保存します。
そのため、Xファイル内のどの数値が何の情報かを知っている必要があります。
そのため、Xファイル内のどの数値が何の情報かを知っている必要があります。
◆Xファイルの構造
情報を読み込むためには、構造を知っている必要があります。
情報を読み込むためには、構造を知っている必要があります。
◆読み込む
情報を保存するために↓のようなクラスを作成。
情報を保存するために↓のようなクラスを作成。
// 3角
class vector3f
{
public:
vector3f();
vector3f( const float &x, const float &y, const float &z );
~vector3f();
void set( const float &x, const float &y, const float &z );
void operator+=( const vector3f );
void operator-=( const vector3f );
void operator =( const vector3f );
// メンバ変数
float x;
float y;
float z;
};
class vector3d
{
public:
vector3d();
vector3d( const int &x, const int &y, const int &z );
~vector3d();
void set( const int &x, const int &y, const int &z );
void operator+=( const vector3d &vector );
void operator-=( const vector3d &vector );
void operator =( const vector3d &vector );
// メンバ変数
int x;
int y;
int z;
};
// 4角
class vector4f
{
public:
vector4f();
vector4f( const float &x, const float &y, const float &z, const float &w );
~vector4f();
void set( const float &x, const float &y, const float &z, const float &w );
void operator+=( const vector4f &vector );
void operator-=( const vector4f &vector );
void operator =( const vector4f &vector );
// メンバ変数
float x;
float y;
float z;
float w;
};
class vector4d
{
public:
vector4d();
vector4d( const int &x, const int &y, const int &z, const int &w );
~vector4d();
void set( const int &x, const int &y, const int &z, const int &w );
void operator+=( const vector4d &vector );
void operator-=( const vector4d &vector );
void operator =( const vector4d &vector );
// メンバ変数
int x;
int y;
int z;
int w;
};
Xファイルを閉じる
必要な情報をコピーした後は、Xファイルを開いておく必要はないので閉じます。
fclose( file ); free( file );
情報をもとに描画
コピーした情報をもとに描画を行っていきます。