サンプル

アイテム着脱

アイテム着脱 - MascotCapsule eruption

ここではアイテム着脱について解説します。




※ 開発環境によってダウンロードするサンプルデータが異なります。

目次





ボーンが設定されているモデルに対し、ボーンに別のモデルの着脱が行える機能です。これにより手に剣や盾、頭部に髪飾りなどといったものを着けたり外したりすることが可能です。


1. アイテム着脱の設定

着脱対象のボーンが設定されているモデルに対して、mceFigure_getTransformTree( This ) を用いて、mceTransformTree を取得します。
取得後は、mceTransformTree_getToWorldTransform( This, index, dst ) を用いてアイテム着脱したいボーンの mceTransform を取得し、着脱したいモデルを描画します。

#define ANGLE        (360)             /* 角度 */

    (中略)

typedef struct tagWork
{
    (中略)

    mceGraphics3D *G3d;                /* Graphics3D */

    (中略)

    mceFigure        *Figure0;         /* 着脱対象モデル   */
    mceFigure        *Figure1;         /* アイテム着脱モデル */

    (中略)

    hi_uint8 ItemFlag;                 /* アイテムフラグ */

    mceTransformTree *Transtree;       /* TransformTree */

    hi_coord ObjRy;                    /* オブジェクトY軸回転 */

    (中略)

    hi_coord AnimeCounter;             /* オブジェクトアニメーション カウンター */

} WORK;
work->ItemFlag = 0;

/* 着脱対象ボーンを持つモデルより、mceTransformTreeを取得 */
work->Transtree = mceFigure_getTransformTree (work->Figure0);
if (work->Transtree == NULL)
{
    return 1;
};

    (中略)

hi_exception exception;

mceTransform matrix;                  /* 着脱対象モデル用   */
mceTransform matrix2;
mceVector3D  rotate;

mceTransform item_matrix;             /* アイテム着脱モデル用 */

    (中略)

/*------ アニメーション設定 ------*/

exception = mceFigure_setFrame (work->Figure0, work->AnimeCounter);
if (exception != hi_NoException)
{
    return 1;
}

/*------ アイテム描画MATRIX取得 ------*/

if (work->ItemFlag == 0)
{
/* 左手のボーン座標への変換行列を取得 */
    exception = mceTransformTree_getToWorldTransform (
                work->Transtree, 1, &item_matrix);
}
else
{
/* 右手のボーン座標への変換行列を取得 */
    exception = mceTransformTree_getToWorldTransform (
                work->Transtree, 2, &item_matrix);
}

if (exception != hi_NoException)
{
    return 1;
}

/*------ 描画 ------*/

mceTransform_setTranslate (&matrix,
                           MCE_F2C (0.0f), MCE_F2C (0.0f), MCE_F2C (0.0f));

mceVector3D_set           (&rotate,
                           MCE_F2C (0.0f), MCE_F2C (1.0f), MCE_F2C (0.0f));
mceTransform_setRotate    (&matrix2, &rotate, work->ObjRy / ANGLE);
mceTransform_multiply     (&matrix, &matrix2);

/* 着脱対象モデルを描画 */
exception = mceGraphics3D_drawFigure (work->G3d, work->Figure0,
                                      &matrix, 0);
if (exception != hi_NoException)
{
    return 1;
}

/* 着脱したいアイテムを描画 */
exception = mceGraphics3D_drawFigure (work->G3d, work->Figure1,
                                      &item_matrix, 0);
if (exception != hi_NoException)
{
    return 1;
}
描画結果 アイテムを左手に装着 描画結果 アイテムを右手に装着
アイテムを左手に装着 アイテムを右手に装着
描画結果



このページの先頭へ戻る