忍者ブログ

神戸電子専門学校ゲームソフト学科の生徒が運営するGESのブログです。

   

[PR]

×

[PR]上記の広告は3ヶ月以上新規記事投稿のないブログに表示されています。新しい記事を書く事で広告が消えます。

D3DXMATRIX

どーも2年プログラム担当加藤(パパ)です。
3連休明けに台風が直撃すればそのまま夏休みに突入してしまいそうですね(;一_一)

前回に引き続き
ラッピングクラスの例をご紹介。

コメントでご指摘がありましたが、今回はDoxygen対応できてません。
次回からはしっかりと対応したものを掲載したいと思います。

これもコピペは禁止です。
わからないところは、コメントなどに書いていただくと後で記事としてお答えしようと思います。

拍手[0回]


まずはヘッダから

// ====================================================
//
// 行列ラッピングクラス
//
// Createed by Yuki
//
// ====================================================
#ifndef _CMATRIX_H_
#define _CMATRIX_H_

#include "CBase.h"
#include "CVector3.h"

class CMatrix : public D3DXMATRIX
{
public :

 // コンストラクタ
 inline CMatrix( const float f_x = 0.0f , const float f_y = 0.0f , const float f_z = 0.0f ) ;
 inline CMatrix( const D3DXMATRIX &m ) ;

 // 単位行列にする
 inline CMatrix& Identity() ;

 // ローカル座標での移動をする
 // [in] f_x  移動量
 // [in] f_y
 // [in] f_z
 // return 答えを格納したものを返す
 inline CMatrix& MoveLocal( const float f_x = 0.0f , const float f_y = 0.0f , const float f_z = 0.0f ) ;

 // ワールド座標移動する
 // [in] f_x  移動量
 // [in] f_y
 // [in] f_z
 // return 答えを格納したものを返す
 inline CMatrix& MoveWorld( const float f_x = 0.0f , const float f_y = 0.0f , const float f_z = 0.0f ) ;
 inline CMatrix& MoveWorld( const D3DXVECTOR3 &xyz ) ;

 // 行列を合成する
 // [in] rightOp 掛け合わせる行列 右側
 // return 答えを格納したものを返す
 inline CMatrix& Multiply( const D3DXMATRIX &rightOp ) ;
 // 行列を合成する
 // [in] leftOp 掛け合わせる行列 左側
 // [in] rightOp 掛け合わせる行列 右側
 // return 答えを格納したものを返す
 inline CMatrix& Multiply( const D3DXMATRIX &leftOp , const D3DXMATRIX &rightOp ) ;

 // 回転行列化する
 // [in] f_x 回転角「度」
 // [in] f_y 回転角「度」
 // [in] f_z 回転角「度」
 inline CMatrix& Rotation( const float f_x = 0.0f , const float f_y = 0.0f , const float f_z = 0.0f ) ;
 // X軸回転
 inline CMatrix& RotationX( const float f_angle ) ;
 // Y軸回転
 inline CMatrix& RotationY( const float f_angle ) ;
 // Z軸回転
 inline CMatrix& RotationZ( const float f_angle ) ;

 // 任意軸回転させる
 // [in] axis 回転軸
 // [in] f_angle 回転角「度」
 inline CMatrix& RotationAxis( const D3DXVECTOR3& axis , const float f_angle ) ;

 // 拡大行列を作る
 // [in] f_x 個別の拡大率
 // [in] f_y 
 // [in] f_z 
 inline CMatrix& Scaling( const float f_x = 1.0f , const float f_y = 1.0f , const float f_z = 1.0f ) ;
 // [in] f_scal 
 inline CMatrix& Scaling( const float f_scal ) ;


 // 行列から座標を取得する
 inline float X() const ;
 inline float Y() const ;
 inline float Z() const ;

} ;

#include "CMatrix.inl"

#endif // _CMATRIX_H_




そして今回も実装部分は「.inl」に書いていきます


#ifndef _CMATRIX_INL_
#define _CMATRIX_INL_

// ====================================================
// コンストラクタ
// ====================================================
CMatrix::CMatrix( const float f_x , const float f_y , const float f_z ) :
D3DXMATRIX( 1.0f , 0.0f , 0.0f , 0.0f ,
      0.0f , 1.0f , 0.0f , 0.0f ,
   0.0f , 0.0f , 1.0f , 0.0f ,
   f_x , f_y , f_z , 0.0f )
{
}
CMatrix::CMatrix( const D3DXMATRIX &m ) :
D3DXMATRIX( m )
{
}

// ====================================================
// 単位行列にする
// ====================================================
CMatrix& CMatrix::Identity()
{
 D3DXMatrixIdentity( this ) ;
 return *this ;
}

// ====================================================
// ローカル座標での移動をする
// ====================================================
CMatrix& CMatrix::MoveLocal( const float f_x , const float f_y , const float f_z )
{
 CVector3 x( this->_11 , this->_12 , this->_13 ) ;
 CVector3 y( this->_21 , this->_22 , this->_23 ) ;
 CVector3 z( this->_31 , this->_32 , this->_33 ) ;

 x.Normalize() ;
 y.Normalize() ;
 z.Normalize() ;

 x *= f_x ;
 y *= f_y ;
 z *= f_z ;

 _41 += x.x + y.x + z.x ;
 _42 += x.y + y.y + z.y ;
 _43 += x.z + y.z + z.z ;
 return *this ;
}

// ====================================================
// ワールド座標移動する
// ====================================================
CMatrix& CMatrix::MoveWorld(const float f_x , const float f_y , const float f_z )
{
 _41 += f_x ;
 _42 += f_y ;
 _43 += f_z ;

 return *this ;
}

CMatrix& CMatrix::MoveWorld( const D3DXVECTOR3 &xyz )
{
 _41 += xyz.x ;
 _42 += xyz.y ;
 _43 += xyz.z ;
 return *this ;
}

// ====================================================
// 行列を合成する
// ====================================================
CMatrix& CMatrix::Multiply( const D3DXMATRIX &rightOp )
{
 D3DXMatrixMultiply( this , this , &rightOp ) ;
 return *this ;
}

CMatrix& CMatrix::Multiply( const D3DXMATRIX &leftOp , const D3DXMATRIX &rightOp )
{
 D3DXMatrixMultiply( this , &leftOp , &rightOp ) ;
 return *this ;
}

// ====================================================
// 回転行列化する
// ====================================================
CMatrix& CMatrix::Rotation(const float f_x , const float f_y , const float f_z )
{
 D3DXMatrixRotationYawPitchRoll( this , D3DXToRadian( f_y ) , D3DXToRadian( f_x ) , D3DXToRadian( f_z ) );
 return *this ;
}

// ====================================================
// 回転行列化する
// X軸回転
// ====================================================
CMatrix& CMatrix::RotationX( const float f_angle )
{
 D3DXMatrixRotationX( this , D3DXToRadian( f_angle ) ) ;
 return *this ;
}

// ====================================================
// 回転行列化する
// Y軸回転
// ====================================================
CMatrix& CMatrix::RotationY( const float f_angle )
{
 D3DXMatrixRotationY( this , D3DXToRadian( f_angle ) ) ;
 return *this ;
}

// ====================================================
// 回転行列化する
// Z軸回転
// ====================================================
CMatrix& CMatrix::RotationZ( const float f_angle )
{
 D3DXMatrixRotationZ( this , D3DXToRadian( f_angle ) ) ;
 return *this ;
}

// ====================================================
// 任意軸回転させる
// ====================================================
CMatrix& CMatrix::RotationAxis( const D3DXVECTOR3 &axis , const float f_angle )
{
 D3DXMatrixRotationAxis( this , &axis , D3DXToRadian( f_angle ) ) ;
 return *this ;
}

// ====================================================
// 拡大行列を作る
// ====================================================
CMatrix& CMatrix::Scaling(const float f_x , const float f_y , const float f_z )
{
 D3DXMatrixScaling( this , f_x , f_y , f_z ) ;
 return *this ;
}

// ====================================================
// 拡大行列を作る
// ====================================================
CMatrix& CMatrix::Scaling( const float f_scal )
{
 D3DXMatrixScaling( this , f_scal , f_scal , f_scal ) ;
 return *this ;
}

// ====================================================
// 行列から座標を取得する
// ====================================================
float CMatrix::X() const
{
 return _41 ;
}

float CMatrix::Y() const
{
 return _42 ;
}

float CMatrix::Z() const
{
 return _43 ;
}

#endif // _CMATRIX_INL_

必要最低限の機能だけを集めてみました。
このソースが皆様の参考になると嬉しいです。
2年生の皆様。
夢をかなえるために頑張ってください。
私も皆様に負けないよう頑張ります!!
PR

COMMENT

NAME
TITLE
MAIL(非公開)
URL
EMOJI
Vodafone絵文字 i-mode絵文字 Ezweb絵文字
COMMENT
PASS(コメント編集に必須です)
SECRET
管理人のみ閲覧できます

TRACKBACK

Trackback URL:

ブログ内検索

最新コメント

[01/29 人面犬]
[10/01 8ch]
[09/12 uncle]
[09/10 某卒業生]
[06/07 uncle]

カレンダー

03 2024/04 05
S M T W T F S
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30

テスト

Copyright ©  -- GESブログ --  All Rights Reserved
Design by CriCri / Photo by Geralt / powered by NINJA TOOLS / 忍者ブログ / [PR]