サンプル
リージョン
ここではリージョンについて解説します。
※ 開発環境によってダウンロードするサンプルデータが異なります。
目次
テクスチャデータを指定の矩形転送描画するもので、さらに回転や拡大・縮小の処理も行え、スプライト機能としても使用できるものです。
1. リージョンの設定と描画
リージョン用の mceAppearance を生成し、mceAppearance_setTexture( This, ix, texture ) を用いて描画したいテクスチャを設定します。
設定後は、mceGraphics3D_drawRect( This, x, y, width, height, roll, abgr, appearance, regions, regionNum ) を用いて指定した矩形領域、回転角などと共に、先ほど設定した mceAppearance を指定、描画を行います。
#define COORD_SHIFT (16) /* int→hi_coordのシフト */
(中略)
#define ANGLE (360) /* 角度 */
(中略)
#define REGION_W (128) /* 矩形転送X軸サイズ */
#define REGION_H (256) /* 矩形転送Y軸サイズ */
(中略)
typedef struct tagWork
{
(中略)
mceGraphics3D *G3d; /* Graphics3D */
(中略)
hi_uint16 WindowWidth; /* 画面幅 */
hi_uint16 WindowHeight; /* 画面高さ */
(中略)
mceTextureTable *Textbl; /* TextureTable */
/*------ テクスチャー矩形転送 ------*/
mceTexture *RegionTexture; /* RegionTexture */
mceAppearance *RegionAppe; /* RegionAppearance */
hi_coord ReZoom; /* 矩形転送拡縮率 */
hi_coord ReRotate; /* 矩形転送回転値 */
} WORK;
hi_exception exception;
(中略)
/* リージョン用mceAppearanceを生成 */
work->RegionAppe = mceAppearance_create (&exception);
if ((work->RegionAppe == NULL) || (exception != hi_NoException))
{
return 1;
}
/* mceTextureTableから表示したいテクスチャを取得 */
work->RegionTexture = mceTextureTable_findTexture (work->Textbl, 0);
if (work->RegionTexture == NULL)
{
return 1;
}
/* リージョン用mceAppearanceに取得したテクスチャを設定 */
exception = mceAppearance_setTexture (work->RegionAppe, 0,
work->RegionTexture);
if (exception != hi_NoException)
{
return 1;
}
work.ReZoom = 1.0f;
work.ReRotate = 0.0f;
(中略)
hi_sint16 x, y, w, h;
(中略)
/* テクスチャシートの矩形領域を設定 */
w = ((REGION_W * work->ReZoom) >> COORD_SHIFT);
h = ((REGION_H * work->ReZoom) >> COORD_SHIFT);
x = (work->WindowWidth / 2) - (w / 2);
y = (work->WindowHeight / 2) - (h / 2);
/* mceAppearance指定の描画を行なう */
exception = mceGraphics3D_drawRect (work->G3d, x, y, w, h,
work->ReRotate / ANGLE, 0xffffffff, work->RegionAppe, NULL, 0);
if (exception != hi_NoException)
{
return 1;
}
また、mceGraphics3D_drawRect( This, x, y, width, height, roll, abgr, appearance, regions, regionNum ) の引数 regions を適用すると描画テクスチャシート内の矩形領域を指定することができます。
mceRegionF Region; /* WORK構造体内に追加 */
/* テクスチャシート内の矩形領域を指定 */
mceRegionF_set (&work->Region, MCE_F2C (0.0f), MCE_F2C (0.0f),
MCE_F2C (0.5f), MCE_F2C (0.5f));
(中略)
hi_exception exception;
(中略)
hi_sint16 x, y, w, h;
(中略)
/* mceAppearance指定の描画を行なう */
exception = mceGraphics3D_drawRect (work->G3d, x, y, w, h,
work->ReRotate / ANGLE, 0xffffffff,
work->RegionAppe, &work->Region, 2);
if (exception != hi_NoException)
{
return 1;
}
![]() |
|
| リージョン描画 | |
![]() |
![]() |
| mceRegionFを用いた場合 矩形領域(0.0f, 0.0f, 0.5f, 0.5f) |
mceRegionFを用いた場合 矩形領域(0.0f, 0.0f, 2.0f, 2.0f) |
| 描画結果 | |




