| 1 |
#ifndef CNAMEDOBJECT_H_INCLUDED |
| 2 |
#define CNAMEDOBJECT_H_INCLUDED |
| 3 |
|
| 4 |
#include "CModelSwitch.h" |
| 5 |
#include "CPartsInst.h" |
| 6 |
|
| 7 |
class CModelInst; |
| 8 |
class CNamedObject; |
| 9 |
class CModelPlugin; |
| 10 |
|
| 11 |
const float SYMMETRIC_ROTATION_MAX = 0.45f; // 最高対称回転速度 |
| 12 |
|
| 13 |
// システムオブジェクト番号 |
| 14 |
extern enum{ |
| 15 |
SYS_OBJ_WORLD = 0, |
| 16 |
SYS_OBJ_LOCAL, |
| 17 |
SYS_OBJ_CAMERA, |
| 18 |
SYS_OBJ_LIGHT, |
| 19 |
SYS_OBJ_FORCE_DWORD = 0xffffffff |
| 20 |
} SYS_OBJ_ID; |
| 21 |
|
| 22 |
/* |
| 23 |
* 名前付きオブジェクトアフターレンダラ |
| 24 |
*/ |
| 25 |
class CNamedObjectAfterRenderer{ |
| 26 |
private: |
| 27 |
static CModelInst *ms_CurrentInst; // 現在のインスタンス |
| 28 |
static CModelPlugin *ms_CurrentPlugin; // 現在のモデルプラグイン |
| 29 |
int m_InstSwitch[INSTANCE_SWITCH_NUM]; // インスタンススイッチ |
| 30 |
CModelInst *m_ModelInst; // 現在のインスタンス |
| 31 |
CModelPlugin *m_ModelPlugin; // 現在のモデルプラグイン |
| 32 |
CNamedObject *m_NamedObject; // 名前付きオブジェクト |
| 33 |
CPartsInst *m_PartsInst; // パーツインスタンス |
| 34 |
bool m_PartsInstCreation; // パーツインスタンス作成フラグ |
| 35 |
public: |
| 36 |
static void SetCurrentInst(CModelInst *inst){ ms_CurrentInst = inst; } |
| 37 |
static void SetCurrentPlugin(CModelPlugin *mpi){ ms_CurrentPlugin = mpi; } |
| 38 |
CNamedObjectAfterRenderer(CNamedObject *, CPartsInst *); |
| 39 |
CNamedObjectAfterRenderer(const CNamedObjectAfterRenderer &); |
| 40 |
~CNamedObjectAfterRenderer(); |
| 41 |
void Render(int); |
| 42 |
}; |
| 43 |
|
| 44 |
// 反復子 |
| 45 |
typedef list<CNamedObjectAfterRenderer>::iterator INamedObjectAfterRenderer; |
| 46 |
|
| 47 |
/* |
| 48 |
* 名前付きオブジェクト |
| 49 |
*/ |
| 50 |
class CNamedObject{ |
| 51 |
friend class CNamedObjectAfterRenderer; |
| 52 |
protected: |
| 53 |
static int ms_AfterMode; // アフターレンダリングモード |
| 54 |
static int ms_AfterRender; // アフターレンダリングフラグ |
| 55 |
// (1: noshadow, 2: transparent) |
| 56 |
static bool ms_CastShadowDefault; // 影描画フラグデフォルト値 |
| 57 |
static bool ms_SetMaterial; // マテリアル変更フラグ |
| 58 |
static bool ms_PartsInstValid; // パーツインスタンス使用フラグ |
| 59 |
static IPartsInst ms_PartsInst; // パーツインスタンス反復子 |
| 60 |
static list<CNamedObjectAfterRenderer> ms_AfterRenderList; // アフターレンダラ |
| 61 |
static list<CNamedObjectAfterRenderer> ms_TransRenderList; // 透明ポリレンダラ |
| 62 |
float m_ModelScale; // モデルスケール |
| 63 |
bool m_Turn; // 反転フラグ |
| 64 |
bool m_CastShadow; // 影キャストフラグ |
| 65 |
string m_ModelFileName; // モデルファイル名 |
| 66 |
string m_ObjectName; // オブジェクト名 |
| 67 |
CMesh *m_Mesh; // メッシュ |
| 68 |
CObject *m_LastObject; // 最後に使用したオブジェクト |
| 69 |
CObject m_PreviewObject; // プレビュー用オブジェクト |
| 70 |
list<CCustomizerBase *> m_OffList; // 常時適用カスタマイザエントリ |
| 71 |
CCustomizerSwitchEntry m_Customizer; // ルートカスタマイザ |
| 72 |
public: |
| 73 |
static void SetCastShadowDefault(bool s){ ms_CastShadowDefault = s; } |
| 74 |
static void SetSetMaterial(bool s){ ms_SetMaterial = s; } |
| 75 |
static void SetPartsInst(list<CPartsInst> *); |
| 76 |
static CPartsInst *GetParts(){ return ms_PartsInstValid ? &*(ms_PartsInst++) : NULL; } |
| 77 |
static void SetRenderAfter(int m){ ms_AfterRender |= m; } |
| 78 |
static int GetAfterRender(){ return ms_AfterMode; } |
| 79 |
static void InitAfterRenderList(); |
| 80 |
static void AfterRenderAll(); |
| 81 |
CNamedObject(); |
| 82 |
virtual int GetType(){ return 0; } |
| 83 |
void Init(char *name){ m_ObjectName = name; } |
| 84 |
char *ReadModelInfo(char *, CModelPlugin *); |
| 85 |
char *GetName(){ return (char *)m_ObjectName.c_str(); } |
| 86 |
CNamedObject *Check(const string &name){ return m_ObjectName==name ? this : NULL; } |
| 87 |
CObject *GetObject(){ return m_LastObject; } |
| 88 |
CObject *GetPreviewObject(){ return &m_PreviewObject; } |
| 89 |
void LoadModel(CModelPlugin *); |
| 90 |
void AddOffList(CCustomizerBase *cb){ m_OffList.push_back(cb); } |
| 91 |
void SetMesh(CObject *); |
| 92 |
bool GetTurn(){ return m_Turn; } |
| 93 |
void SetPreviewPosture(VEC3, VEC3, VEC3); |
| 94 |
CObject *GetPartsObject(){ |
| 95 |
//Debug("&*ms_PartsInst = %p\n", &*ms_PartsInst); |
| 96 |
return m_LastObject = ms_PartsInstValid |
| 97 |
? (ms_PartsInst++)->GetObject() : &m_PreviewObject; |
| 98 |
} |
| 99 |
void CheckDetect(); |
| 100 |
void Render(); |
| 101 |
void RenderAfter(CPartsInst *, int); |
| 102 |
void SetMaterial(CMesh *mesh){ m_Customizer.Apply(mesh); } |
| 103 |
}; |
| 104 |
|
| 105 |
//////////////////////////////////////////////////////////////////////////////// |
| 106 |
//////////////////////////////////////////////////////////////////////////////// |
| 107 |
|
| 108 |
/* |
| 109 |
* オブジェクトジョイント基本クラス |
| 110 |
*/ |
| 111 |
class CObjectJoint{ |
| 112 |
public: |
| 113 |
CNamedObject *m_Link; // 接続先オブジェクト |
| 114 |
public: |
| 115 |
CObjectJoint(){ m_Link = NULL; } |
| 116 |
char *Read(char *, CModelPlugin *); |
| 117 |
bool IsLinked(){ return !!m_Link; } |
| 118 |
VEC3 GetRight(){ return m_Link->GetObject()->GetRight(); } |
| 119 |
VEC3 GetUp(){ return m_Link->GetObject()->GetUp(); } |
| 120 |
VEC3 GetDir(){ return m_Link->GetObject()->GetDir(); } |
| 121 |
}; |
| 122 |
|
| 123 |
/* |
| 124 |
* オブジェクトジョイント pos, dir, up 指定 |
| 125 |
*/ |
| 126 |
class CObjectJoint3D: public CObjectJoint{ |
| 127 |
public: |
| 128 |
bool m_FixCenter; // 中心修正フラグ |
| 129 |
VEC3 m_AttachCoord; // 接続先ローカル座標 |
| 130 |
VEC3 m_LocalCoord; // 接続元ローカル座標 |
| 131 |
VEC3 m_AttachDir; // 接続先ローカル dir |
| 132 |
VEC3 m_AttachUp; // 接続先ローカル up |
| 133 |
CNamedObject *m_DirLink; // dir 基準オブジェクト |
| 134 |
CNamedObject *m_UpLink; // up 基準オブジェクト |
| 135 |
public: |
| 136 |
CObjectJoint3D(){ m_DirLink = m_UpLink = NULL; } |
| 137 |
char *Read(char *, CModelPlugin *); |
| 138 |
void SetTurnLocal(); |
| 139 |
VEC3 GetPos(){ |
| 140 |
VEC3 ret; |
| 141 |
CObject *obj = m_Link->GetObject(); |
| 142 |
return *D3DXVec3TransformCoord( |
| 143 |
&ret, &(m_AttachCoord/obj->GetScale()), &obj->GetMatrix()); |
| 144 |
} |
| 145 |
VEC3 GetDir(){ |
| 146 |
VEC3 ret; |
| 147 |
return *D3DXVec3TransformNormal( |
| 148 |
&ret, &m_AttachDir, &m_DirLink->GetObject()->GetMatrix()); |
| 149 |
} |
| 150 |
VEC3 GetUp(){ |
| 151 |
VEC3 ret; |
| 152 |
return *D3DXVec3TransformNormal( |
| 153 |
&ret, &m_AttachUp, &m_UpLink->GetObject()->GetMatrix()); |
| 154 |
} |
| 155 |
}; |
| 156 |
|
| 157 |
//////////////////////////////////////////////////////////////////////////////// |
| 158 |
//////////////////////////////////////////////////////////////////////////////// |
| 159 |
|
| 160 |
/* |
| 161 |
* フリーオブジェクト基本クラス |
| 162 |
*/ |
| 163 |
class CFreeObjectBase{ |
| 164 |
protected: |
| 165 |
public: |
| 166 |
virtual ~CFreeObjectBase(){} |
| 167 |
virtual CFreeObjectBase *Duplicate() = 0; |
| 168 |
virtual void SetPostureFreeObject() = 0; |
| 169 |
virtual CNamedObject *CheckFreeObject(const string &) = 0; |
| 170 |
virtual int GetNamedObjectNum() = 0; |
| 171 |
virtual CNamedObject *GetNamedObject(int i) = 0; |
| 172 |
virtual void LoadModelFreeObject(CModelPlugin *) = 0; |
| 173 |
virtual void AttachPartsFreeObject() = 0; |
| 174 |
virtual void ScanInputFreeObject() = 0; |
| 175 |
virtual void RenderFreeObject() = 0; |
| 176 |
}; |
| 177 |
|
| 178 |
/* |
| 179 |
* ベクトル配置 |
| 180 |
*/ |
| 181 |
class CFreeObject3D: public CNamedObject, public CFreeObjectBase{ |
| 182 |
friend class CTrainPlugin; |
| 183 |
private: |
| 184 |
CObjectJoint3D m_Joint; // 接続情報 |
| 185 |
public: |
| 186 |
CFreeObject3D(){} |
| 187 |
CFreeObject3D(char *, char *, float); |
| 188 |
CFreeObjectBase *Duplicate(){ return new CFreeObject3D(*this); } |
| 189 |
char *Read(char *, CModelPlugin *); |
| 190 |
void SetPostureFreeObject(); |
| 191 |
CNamedObject *CheckFreeObject(const string &name){ return Check(name); } |
| 192 |
int GetNamedObjectNum(){ return 1; } |
| 193 |
CNamedObject *GetNamedObject(int i){ return this; } |
| 194 |
void LoadModelFreeObject(CModelPlugin *mpi){ LoadModel(mpi); } |
| 195 |
void AttachPartsFreeObject(){ GetPartsObject(); } |
| 196 |
void ScanInputFreeObject(){ CheckDetect(); } |
| 197 |
void RenderFreeObject(){ Render(); } |
| 198 |
}; |
| 199 |
|
| 200 |
// 反復子 |
| 201 |
typedef list<CFreeObject3D>::iterator IFreeObject3D; |
| 202 |
|
| 203 |
// 関数宣言 |
| 204 |
void InitSystemObject(); |
| 205 |
CNamedObject *FindSystemObject(const string &); |
| 206 |
CNamedObject *FindObjectHybrid(CModelPlugin *, const string &); |
| 207 |
void CheckObjectHybrid(char *, CModelPlugin *, const string &); |
| 208 |
|
| 209 |
// 外部グローバル |
| 210 |
extern bool g_PreSimulationFlag; |
| 211 |
extern CNamedObject g_SystemObject[]; |
| 212 |
|
| 213 |
#endif |