忍者ブログ

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

   

[PR]

×

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

D3DXVECTOR3のラッピング

どーもセミナー担当加藤(パパ)です。
顔がわからない人は、ラボ1に貼ってある写真を見てね。
そのうち写真も一緒にアップできたらと思います。

一応要望があったので、前回やった「D3DXVECTOR3」のラッピングのソースを公開したいと思います。

制作に使用していただいてもいいですが、
ただし注意事項!!!

コピペ禁止!!


以上の事柄が守れるお友達は続きを見てネ♪

拍手[0回]


まずは「CVector3.h」

// ====================================================
//
// ベクトルラッピングクラス
//
// ラッピングとは?
// あるモノを使いやすいように加工すること
//
// Created by Yuki
//
// ====================================================
#ifndef _CVECTOR3_H_
#define _CVECTOR3_H_

#include "CBase.h"

class CVector3 : public D3DXVECTOR3
{
public :

 // コンストラクタ
 inline CVector3(
  const float f_x = 0.0f ,
  const float f_y = 0.0f ,
  const float f_z = 0.0f
  ) ;
 // ( 継承元との互換用 )
 inline CVector3( const D3DXVECTOR3& v );

 // 内積
 // ラジアンで返す
 inline float Dot( const D3DXVECTOR3& v_target ) const ;
 // 角度で返す
 inline float DotAng( const D3DXVECTOR3& v_target ) const ;

 // 外積
 inline CVector3& Cross( const D3DXVECTOR3& v1 , const D3DXVECTOR3&v2 ) ;

 // 長さ
 inline float Length() const ;

 // 距離
 inline float Distance( const D3DXVECTOR3& v_target ) const ;

 // 正規化
 inline CVector3& Normalize() ;
 inline CVector3& Normalize( const D3DXVECTOR3& v_src ) ;

 // 方向ベクトルにする
 inline CVector3& TransNormal( const D3DXMATRIX &m_mat ) ;
 inline CVector3& TransNormal( const D3DXVECTOR3 &v_src , const D3DXMATRIX &m_mat ) ;

 // ワールドベクトル(位置ベクトル)にする
 inline CVector3& TransCoord( const D3DXMATRIX& m_mat ) ;
 inline CVector3& TransCoord( const D3DXVECTOR3 &v_src , const D3DXMATRIX &m_mat ) ;

} ;

#include "CVector3.inl"

#endif // _CVECTOR3_H_
 

で関数の実装部分の「CVector3.inl
今回のクラスのすべてがinline宣言なので
「cpp」ではなく「inl」に実装をしていきます。

#ifndef _CVECTOR3_INL_
#define _CVECTOR3_INL_

// ====================================================
// コンストラクタ
// ====================================================
CVector3::CVector3( const float f_x , const float f_y , const float f_z ) :
D3DXVECTOR3( f_x , f_y , f_z )
{
}

CVector3::CVector3( const D3DXVECTOR3 &v ) :
D3DXVECTOR3( v )
{
}

// ====================================================
// 内積
// ラジアンで返す
// ====================================================
float CVector3::Dot( const D3DXVECTOR3 &v_target ) const
{
 return D3DXVec3Dot( this , &v_target ) ;
}

// ====================================================
// 内積
// 角度で返す
// ====================================================
float CVector3::DotAng( const D3DXVECTOR3& v_target ) const
{
 float dot = Dot( v_target ) / ( Length() * D3DXVec3Length( &v_target ) );

 if( dot >=  1.0f ) return 0.0f ;
 if( dot <= -1.0f ) return 180.0f ;

 return D3DXToDegree( acosf( dot ) );
}

// ====================================================
// 外積
// ====================================================
CVector3& CVector3::Cross( const D3DXVECTOR3& v1 , const D3DXVECTOR3&v2 )
{
 D3DXVec3Cross( this , &v1 , &v2 ) ;
 return *this ;
}

// ====================================================
// 長さ
// ====================================================
float CVector3::Length() const
{
 return D3DXVec3Length( this ) ;
}

// ====================================================
// 距離
// ====================================================
float CVector3::Distance( const D3DXVECTOR3 &v_target ) const
{
 CVector3 tmp = *this - v_target ;
 return tmp.Length() ;
}

// ====================================================
// 正規化
// ====================================================
CVector3& CVector3::Normalize()
{
 D3DXVec3Normalize( this , this ) ;
 return *this ;
}

CVector3& CVector3::Normalize( const D3DXVECTOR3 &v_src )
{
 D3DXVec3Normalize( this , &v_src ) ;
 return *this ;
}

// ====================================================
// ベクトル変換
// 方向ベクトルにする
// ====================================================
CVector3& CVector3::TransNormal( const D3DXMATRIX &m_mat )
{
 D3DXVec3TransformNormal( this , this , &m_mat ) ;
 return *this ;
}
CVector3& CVector3::TransNormal( const D3DXVECTOR3 &v_src , const D3DXMATRIX &m_mat )
{
 D3DXVec3TransformNormal( this , &v_src , &m_mat ) ;
 return *this ;
}

// ====================================================
// ベクトル変換
// ワールドベクトル(位置ベクトル)にする
// ====================================================
CVector3& CVector3::TransCoord( const D3DXMATRIX &m_mat )
{
 D3DXVec3TransformCoord( this , this , &m_mat ) ;
 return *this ;
}

CVector3& CVector3::TransCoord( const D3DXVECTOR3 &v_src , const D3DXMATRIX &m_mat )
{
 D3DXVec3TransformCoord( this , &v_src , &m_mat ) ;
 return *this ;
}

#endif // _CVECTOR3_INL_

PR

COMMENT

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

無題

  • by パシリ1号
  • 2011/07/15(Fri)21:46
  • Edit
こういうライブラリ系のもんはDxygen対応せいておいた方がいいと思います
後々必ず役に立ちます

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]