Japanese | English | Korean

Samples

ライト

MascotCapsule V3では、環境光と平行光源の2種類が用意されています。

目次

1. 環境光( Ambient Light )

環境光はワールド内を一様に照らすライトです。MascotCapsule V3では、白色光のみが用意されています。環境光を使用するには、OEMC_Micro3D_Render_setAmbientLight( Render *render, hi_sint32 intensity ) を呼び出します。第2引数のintensityはライトの強さです。0~4096の範囲内で指定してください。4096が元のテクスチャの色になります。



2. 平行光源( Direction Light )

平行光源はワールド内を一定の方向から照らすライトです。MascotCapsule V3では白色光源のみが用意されています。

平行光源を使用するには、OEMC_Micro3D_Render_setDirectionLight( Render *render, Vec3i dir, hi_sint32 intensity ) を呼び出し、さらにOEMC_Micro3D_Render_setAttribute( Render *render, hi_sint32 attribute ) でM3D_LIGHTING または、M3D_TOON_SHADINGを有効にします。M3D_LIGHTINGとM3D_TOON_SHADINGの違いについては、シェーディングについて書かれたチュートリアルを参照してください。OEMC_Micro3D_Render_setDirectionLight() の第2引数のdirはライトの向きです。x, y, zの各成分をVec3i オブジェクトを用いて指定してください。第3引数のintensityはライトの強さです。0~4096の範囲内で指定してください。

また、環境光と平行光源は組み合わせて使うことが可能ですが、その明るさは元のテクスチャの色(4096)までです。環境光と平行光源を合わせた明るさが4096を超えた場合は、最も明るい部分が4096になるように調整されます。

 
環境光+平行光源 環境光のみ
 
平行光源のみ 光源無し



3.サンプルコード

このマニュアルのサンプルコードのライトの設定をしている部分を以下に示します。サンプルでは決定キーで平行光源、5キーで環境光のオン・オフの切り替えができます。また、方向キーで平行光源の向きを変えることが可能です。

/**
 * ライト設定
 */

static void setLight( void )
{
Atrans3i xtrans, ytrans;

/* 平行光源 */
if( isDirection ){
light_dir.x = 0;
light_dir.y = 0;
light_dir.z = 4096;
/* 回転行列初期化 */
OEMC_Micro3D_Atrans3i_setIdentity( &xtrans );
OEMC_Micro3D_Atrans3i_setIdentity( &ytrans );
/* 回転行列設定 */
OEMC_Micro3D_Atrans3i_setRotateX( &xtrans, rotX );
OEMC_Micro3D_Atrans3i_setRotateY( &ytrans, rotY );
/* ライト方向ベクトル変換 */
OEMC_Micro3D_Atrans3i_transPoint(
&xtrans, &light_dir, &light_dir );
OEMC_Micro3D_Atrans3i_transPoint(
&ytrans, &light_dir, &light_dir );
/* 平行光源設定 */
OEMC_Micro3D_Render_setDirectionLight(
&render, &light_dir, dir_light_intensity );
}else{
OEMC_Micro3D_Render_setDirectionLight(
&render, &light_dir, 0 );
}

/* 環境光 */
if( isAmbient ){
OEMC_Micro3D_Render_setAmbientLight(
&render, amb_light_intensity );
}else{
OEMC_Micro3D_Render_setAmbientLight( &render, 0 );
}
}