Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

998 lines
30 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1998 - 1999
  6. //
  7. // File: d3drmframe3obj.cpp
  8. //
  9. //--------------------------------------------------------------------------
  10. // d3drmFrameObj.cpp : Implementation of CDirectApp and DLL registration.
  11. #include "stdafx.h"
  12. #include "Direct.h"
  13. #include "dms.h"
  14. #include "d3drmArrayObj.h"
  15. #include "d3drmFrame3Obj.h"
  16. #include "d3drmFrameArrayObj.h"
  17. #include "d3drmLightObj.h"
  18. #include "d3drmLightArrayObj.h"
  19. #include "d3drmTexture3Obj.h"
  20. #include "d3drmVisualObj.h"
  21. #include "d3drmVisualArrayObj.h"
  22. #include "d3drmMeshObj.h"
  23. #include "d3drmMeshBuilder3Obj.h"
  24. #include "d3drmMaterial2Obj.h"
  25. #include "ddSurface7Obj.h"
  26. #include "d3drmShadow2Obj.h"
  27. #include "d3drmUserVisualObj.h"
  28. #include "d3drmObjectObj.h"
  29. extern HRESULT FrameToXFile(LPDIRECT3DRMFRAME3 pFrame,
  30. LPCSTR filename,
  31. D3DRMXOFFORMAT d3dFormat,
  32. D3DRMSAVEOPTIONS d3dSaveFlags);
  33. extern HRESULT BSTRtoGUID(LPGUID pGuid,BSTR bstr);
  34. C_dxj_Direct3dRMFrame3Object::C_dxj_Direct3dRMFrame3Object(){
  35. m__dxj_Direct3dRMFrame3=NULL;
  36. parent=NULL;
  37. pinterface=NULL;
  38. creationid = ++g_creationcount;
  39. DPF1(1,"Constructor Creation Direct3dRMFrame3[%d] \n ",g_creationcount);
  40. nextobj = g_dxj_Direct3dRMFrame3;
  41. g_dxj_Direct3dRMFrame3 = (void *)this;
  42. }
  43. C_dxj_Direct3dRMFrame3Object::~C_dxj_Direct3dRMFrame3Object()
  44. {
  45. C_dxj_Direct3dRMFrame3Object *prev=NULL;
  46. for(C_dxj_Direct3dRMFrame3Object *ptr=(C_dxj_Direct3dRMFrame3Object *)g_dxj_Direct3dRMFrame3; ptr; ptr=(C_dxj_Direct3dRMFrame3Object *)ptr->nextobj)
  47. {
  48. if(ptr == this)
  49. {
  50. if(prev)
  51. prev->nextobj = ptr->nextobj;
  52. else
  53. g_dxj_Direct3dRMFrame3 = (void*)ptr->nextobj;
  54. break;
  55. }
  56. prev = ptr;
  57. }
  58. if(m__dxj_Direct3dRMFrame3){
  59. int count = IUNK(m__dxj_Direct3dRMFrame3)->Release();
  60. #ifdef DEBUG
  61. char buffer[256];
  62. wsprintf(buffer,"DirectX IDirect3DRMFrame3 Ref count %d \n",count);
  63. #endif
  64. if(count==0) m__dxj_Direct3dRMFrame3 = NULL;
  65. }
  66. if(parent) IUNK(parent)->Release();
  67. }
  68. GETSET_OBJECT(_dxj_Direct3dRMFrame3);
  69. CLONE_R(_dxj_Direct3dRMFrame3, Direct3DRMFrame3);
  70. GETNAME_R(_dxj_Direct3dRMFrame3);
  71. SETNAME_R(_dxj_Direct3dRMFrame3);
  72. GETCLASSNAME_R(_dxj_Direct3dRMFrame3);
  73. ADDDESTROYCALLBACK_R(_dxj_Direct3dRMFrame3);
  74. DELETEDESTROYCALLBACK_R(_dxj_Direct3dRMFrame3);
  75. RETURN_NEW_ITEM_R(_dxj_Direct3dRMFrame3, getChildren, GetChildren, _dxj_Direct3dRMFrameArray);
  76. RETURN_NEW_ITEM_R(_dxj_Direct3dRMFrame3, getLights,GetLights,_dxj_Direct3dRMLightArray);
  77. GET_DIRECT_R(_dxj_Direct3dRMFrame3, getColor, GetColor, d3dcolor);
  78. GET_DIRECT_R(_dxj_Direct3dRMFrame3, getAppData, GetAppData, long);
  79. GET_DIRECT_R(_dxj_Direct3dRMFrame3, getMaterialMode, GetMaterialMode, d3drmMaterialMode);
  80. GET_DIRECT_R(_dxj_Direct3dRMFrame3, getSortMode, GetSortMode, d3drmSortMode);
  81. GET_DIRECT_R(_dxj_Direct3dRMFrame3, getSceneBackground, GetSceneBackground, d3dcolor);
  82. GET_DIRECT_R(_dxj_Direct3dRMFrame3, getSceneFogColor, GetSceneFogColor, d3dcolor);
  83. GET_DIRECT_R(_dxj_Direct3dRMFrame3, getSceneFogEnable, GetSceneFogEnable, long); //BOOL
  84. GET_DIRECT_R(_dxj_Direct3dRMFrame3, getSceneFogMode, GetSceneFogMode, d3drmFogMode);
  85. GET_DIRECT_R(_dxj_Direct3dRMFrame3, getZBufferMode, GetZbufferMode, d3drmZbufferMode);
  86. DO_GETOBJECT_ANDUSEIT_R(_dxj_Direct3dRMFrame3, addLight, AddLight, _dxj_Direct3dRMLight);
  87. DO_GETOBJECT_ANDUSEIT_R(_dxj_Direct3dRMFrame3, deleteLight, DeleteLight, _dxj_Direct3dRMLight);
  88. PASS_THROUGH1_R(_dxj_Direct3dRMFrame3, setSceneBackground, SetSceneBackground, d3dcolor);
  89. PASS_THROUGH1_R(_dxj_Direct3dRMFrame3, setSceneFogEnable, SetSceneFogEnable, long); //BOOL
  90. PASS_THROUGH1_R(_dxj_Direct3dRMFrame3, setSceneFogColor, SetSceneFogColor, d3dcolor);
  91. PASS_THROUGH1_R(_dxj_Direct3dRMFrame3, setColor, SetColor, d3dcolor);
  92. PASS_THROUGH_CAST_1_R(_dxj_Direct3dRMFrame3, setAppData, SetAppData, long,(DWORD));
  93. PASS_THROUGH1_R(_dxj_Direct3dRMFrame3, move, Move, d3dvalue);
  94. //PASS_THROUGH2_R(_dxj_Direct3dRMFrame3, getTextureTopology, GetTextureTopology, int*, int*);
  95. //PASS_THROUGH2_R(_dxj_Direct3dRMFrame3, setTextureTopology, SetTextureTopology, int, int);
  96. PASS_THROUGH3_R(_dxj_Direct3dRMFrame3, getSceneFogParams, GetSceneFogParams, d3dvalue*, d3dvalue*, d3dvalue*);
  97. PASS_THROUGH3_R(_dxj_Direct3dRMFrame3, setSceneBackgroundRGB, SetSceneBackgroundRGB, d3dvalue, d3dvalue, d3dvalue);
  98. PASS_THROUGH3_R(_dxj_Direct3dRMFrame3, setSceneFogParams, SetSceneFogParams, d3dvalue,d3dvalue,d3dvalue);
  99. PASS_THROUGH3_R(_dxj_Direct3dRMFrame3, setColorRGB, SetColorRGB, d3dvalue,d3dvalue,d3dvalue);
  100. PASS_THROUGH_CAST_1_R(_dxj_Direct3dRMFrame3, setSceneFogMode, SetSceneFogMode, d3drmFogMode, (D3DRMFOGMODE));
  101. PASS_THROUGH_CAST_1_R(_dxj_Direct3dRMFrame3, setMaterialMode, SetMaterialMode, d3drmMaterialMode, (enum _D3DRMMATERIALMODE));
  102. PASS_THROUGH_CAST_1_R(_dxj_Direct3dRMFrame3, setSortMode, SetSortMode, d3drmSortMode,(enum _D3DRMSORTMODE));
  103. PASS_THROUGH_CAST_1_R(_dxj_Direct3dRMFrame3, setZbufferMode, SetZbufferMode, d3drmZbufferMode, (enum _D3DRMZBUFFERMODE) );
  104. PASS_THROUGH_CAST_4_R(_dxj_Direct3dRMFrame3, addScale, AddScale, d3drmCombineType, (enum _D3DRMCOMBINETYPE), d3dvalue, (d3dvalue), d3dvalue, (d3dvalue), d3dvalue, (d3dvalue));
  105. PASS_THROUGH_CAST_4_R(_dxj_Direct3dRMFrame3, addTranslation, AddTranslation, d3drmCombineType, (enum _D3DRMCOMBINETYPE), d3dvalue, (d3dvalue), d3dvalue, (d3dvalue), d3dvalue, (d3dvalue));
  106. PASS_THROUGH_CAST_5_R(_dxj_Direct3dRMFrame3, addRotation, AddRotation, d3drmCombineType, (enum _D3DRMCOMBINETYPE), d3dvalue, (d3dvalue), d3dvalue, (d3dvalue), d3dvalue, (d3dvalue), d3dvalue, (d3dvalue));
  107. STDMETHODIMP C_dxj_Direct3dRMFrame3Object::addVisual(I_dxj_Direct3dRMVisual *f){
  108. IDirect3DRMVisual *vis=NULL;
  109. IUnknown *unk=NULL;
  110. HRESULT hr;
  111. if (f==NULL) return E_INVALIDARG;
  112. ((I_dxj_Direct3dRMVisual*)f)->InternalGetObject(&unk);
  113. if FAILED(unk->QueryInterface(IID_IDirect3DRMVisual,(void**)&vis))
  114. return E_INVALIDARG;
  115. hr= m__dxj_Direct3dRMFrame3->AddVisual(vis);
  116. if (vis) vis->Release();
  117. return hr;
  118. }
  119. STDMETHODIMP C_dxj_Direct3dRMFrame3Object::deleteVisual(I_dxj_Direct3dRMVisual *f){
  120. IDirect3DRMVisual *vis=NULL;
  121. IUnknown *unk=NULL;
  122. HRESULT hr;
  123. if (f==NULL) return E_INVALIDARG;
  124. f->InternalGetObject(&unk);
  125. if FAILED(unk->QueryInterface(IID_IDirect3DRMVisual,(void**)&vis))
  126. return E_INVALIDARG;
  127. hr= m__dxj_Direct3dRMFrame3->DeleteVisual(vis);
  128. if (vis) vis->Release ();
  129. return hr;
  130. }
  131. /////////////////////////////////////////////////////////////////////////////
  132. STDMETHODIMP C_dxj_Direct3dRMFrame3Object::getVisuals(I_dxj_Direct3dRMVisualArray **retv)
  133. {
  134. LPDIRECT3DRMVISUALARRAY lpv;
  135. HRESULT hr;
  136. LPDIRECT3DRMFRAME2 frame2;
  137. hr=m__dxj_Direct3dRMFrame3->QueryInterface(IID_IDirect3DRMFrame2,(void**)&frame2);
  138. if FAILED(hr) return hr;
  139. frame2->GetVisuals(&lpv);
  140. frame2->Release();
  141. INTERNAL_CREATE(_dxj_Direct3dRMVisualArray, lpv, retv);
  142. return S_OK;
  143. }
  144. /////////////////////////////////////////////////////////////////////////////
  145. STDMETHODIMP C_dxj_Direct3dRMFrame3Object::getVelocity(I_dxj_Direct3dRMFrame3 *ref, D3dVector *vel, long flags)
  146. {
  147. DO_GETOBJECT_NOTNULL( LPDIRECT3DRMFRAME3, lpf, ref);
  148. return m__dxj_Direct3dRMFrame3->GetVelocity((LPDIRECT3DRMFRAME3)lpf, (_D3DVECTOR*)vel, (DWORD)flags);
  149. }
  150. /////////////////////////////////////////////////////////////////////////////
  151. STDMETHODIMP C_dxj_Direct3dRMFrame3Object::getRotation(I_dxj_Direct3dRMFrame3 *ref,
  152. D3dVector *axis, d3dvalue *theta)
  153. {
  154. DO_GETOBJECT_NOTNULL( LPDIRECT3DRMFRAME3, lpf, ref);
  155. return m__dxj_Direct3dRMFrame3->GetRotation((LPDIRECT3DRMFRAME3)lpf, (_D3DVECTOR*)axis, (D3DVALUE*)theta);
  156. }
  157. /////////////////////////////////////////////////////////////////////////////
  158. STDMETHODIMP C_dxj_Direct3dRMFrame3Object::getPosition(I_dxj_Direct3dRMFrame3 *ref, D3dVector *position)
  159. {
  160. DO_GETOBJECT_NOTNULL( LPDIRECT3DRMFRAME3, lpf, ref);
  161. return m__dxj_Direct3dRMFrame3->GetPosition((LPDIRECT3DRMFRAME3)lpf, (_D3DVECTOR*)position);
  162. }
  163. /////////////////////////////////////////////////////////////////////////////
  164. // PASS_THROUGH_CAST_3(_dxj_Direct3dRMFrame, LookAt, I_dxj_Direct3dRMFrame*, (LPDIRECT3DRMFRAME3),
  165. // I_dxj_Direct3dRMFrame*, (LPDIRECT3DRMFRAME3), d3drmFrameConstraint, (_D3DRMFRAMECONSTRAINT));
  166. STDMETHODIMP C_dxj_Direct3dRMFrame3Object::lookAt(I_dxj_Direct3dRMFrame3 *tgt,
  167. I_dxj_Direct3dRMFrame3 *ref,d3drmFrameConstraint axis)
  168. {
  169. // if(! (tgt && ref) )
  170. // return E_POINTER;
  171. DO_GETOBJECT_NOTNULL( LPDIRECT3DRMFRAME3, lpr, ref);
  172. DO_GETOBJECT_NOTNULL( LPDIRECT3DRMFRAME3, lpt, tgt);
  173. return m__dxj_Direct3dRMFrame3->LookAt((LPDIRECT3DRMFRAME3)lpt,(LPDIRECT3DRMFRAME3) lpr, (enum _D3DRMFRAMECONSTRAINT)axis);
  174. }
  175. /////////////////////////////////////////////////////////////////////////////
  176. STDMETHODIMP C_dxj_Direct3dRMFrame3Object::addTransform(d3drmCombineType typ, SAFEARRAY **ppmat)
  177. {
  178. D3DVALUE rmMatrix[4][4];
  179. CopyFloats((d3dvalue*)&rmMatrix, (float*)((SAFEARRAY*)*ppmat)->pvData, 16 );
  180. m__dxj_Direct3dRMFrame3->AddTransform((enum _D3DRMCOMBINETYPE)typ, rmMatrix );
  181. return S_OK;
  182. }
  183. /////////////////////////////////////////////////////////////////////////////
  184. STDMETHODIMP C_dxj_Direct3dRMFrame3Object::getTransform(I_dxj_Direct3dRMFrame3 *ref,SAFEARRAY **ppmat)
  185. {
  186. D3DVALUE rmMatrix[4][4]; // Get info to here
  187. HRESULT hr;
  188. DO_GETOBJECT_NOTNULL(LPDIRECT3DRMFRAME3,f3,ref);
  189. hr=m__dxj_Direct3dRMFrame3->GetTransform(f3,rmMatrix);
  190. if FAILED(hr) return hr;
  191. CopyFloats((float*)((SAFEARRAY*)*ppmat)->pvData, (d3dvalue*)&rmMatrix, 16 );
  192. return(S_OK);
  193. }
  194. /////////////////////////////////////////////////////////////////////////////
  195. STDMETHODIMP C_dxj_Direct3dRMFrame3Object::addMoveCallback( I_dxj_Direct3dRMFrameMoveCallback3 *fmC, IUnknown *args, long flags)
  196. {
  197. // killed by companion DeleteMove
  198. FrameMoveCallback3 *fmcb;
  199. if (!fmC) return E_INVALIDARG;
  200. fmcb = (FrameMoveCallback3*)AddCallbackLink(
  201. (void**)&FrameMoveCallbacks3, (I_dxj_Direct3dRMCallback*)fmC, (void*) args);
  202. if( !fmcb )
  203. {
  204. DPF(1,"Callback AddMove creation failed!\r\n");
  205. return E_FAIL;
  206. }
  207. fmC->AddRef();
  208. return m__dxj_Direct3dRMFrame3->AddMoveCallback(myFrameMoveCallback3, fmcb, (DWORD) flags);
  209. }
  210. ///////////////////////////////////////////////////////////////////////
  211. STDMETHODIMP C_dxj_Direct3dRMFrame3Object::deleteMoveCallback(I_dxj_Direct3dRMFrameMoveCallback3 *fmC, IUnknown *args)
  212. {
  213. DPF(1,"DeleteMoveCallback entered!\r\n");
  214. FrameMoveCallback3 *fmcb = FrameMoveCallbacks3;
  215. // look for our own specific entry
  216. for ( ; fmcb; fmcb = fmcb->next ) {
  217. if( (fmcb->c == fmC) && (fmcb->pUser == args) ) {
  218. //note: assume the callback is not called: only removed from a list.
  219. m__dxj_Direct3dRMFrame3->DeleteMoveCallback(myFrameMoveCallback3, fmcb);
  220. // Remove ourselves in a thread-safe manner.
  221. UndoCallbackLink((GeneralCallback*)fmcb,
  222. (GeneralCallback**)&FrameMoveCallbacks3);
  223. return S_OK;
  224. }
  225. }
  226. return E_FAIL;
  227. }
  228. /////////////////////////////////////////////////////////////////////////////
  229. STDMETHODIMP C_dxj_Direct3dRMFrame3Object::setVelocity( I_dxj_Direct3dRMFrame3 *reference, d3dvalue x, d3dvalue y,
  230. d3dvalue z, long with_rotation)
  231. {
  232. DO_GETOBJECT_NOTNULL( LPDIRECT3DRMFRAME3, lpf, reference);
  233. m__dxj_Direct3dRMFrame3->SetVelocity((LPDIRECT3DRMFRAME3)lpf, x, y, z, with_rotation);
  234. return S_OK;
  235. }
  236. /////////////////////////////////////////////////////////////////////////////
  237. STDMETHODIMP C_dxj_Direct3dRMFrame3Object::getOrientation( I_dxj_Direct3dRMFrame3 *reference, D3dVector *dir, D3dVector *up)
  238. {
  239. DO_GETOBJECT_NOTNULL( LPDIRECT3DRMFRAME3, lpf, reference);
  240. m__dxj_Direct3dRMFrame3->GetOrientation(lpf, (struct _D3DVECTOR *)dir, (struct _D3DVECTOR *)up);
  241. return S_OK;
  242. }
  243. /////////////////////////////////////////////////////////////////////////////
  244. STDMETHODIMP C_dxj_Direct3dRMFrame3Object::loadFromFile(BSTR filename, VARIANT id,long flags, I_dxj_Direct3dRMLoadTextureCallback3 *callme, IUnknown *useMe)
  245. {
  246. D3DRMLOADTEXTURE3CALLBACK d3dtcb = NULL;
  247. LPVOID pArgs = NULL;
  248. TextureCallback3 *tcb = NULL;
  249. HRESULT hr;
  250. if( callme )
  251. {
  252. tcb = new TextureCallback3;
  253. if( tcb )
  254. {
  255. tcb->c = callme;
  256. tcb->pUser = useMe;
  257. tcb->next = NULL; // TextureCallbacks3;
  258. tcb->prev = NULL; //(TextureCallback3*)NULL;
  259. TextureCallbacks3 = tcb;
  260. d3dtcb = myLoadTextureCallback3;
  261. pArgs = (void *)tcb;
  262. }
  263. else
  264. {
  265. DPF(1,"Callback object creation failed!\r\n");
  266. return E_FAIL;
  267. }
  268. }
  269. USES_CONVERSION;
  270. LPCTSTR pszName = W2T(filename);
  271. void *args=NULL;
  272. DWORD pos=0;
  273. GUID loadGuid;
  274. VARIANT var;
  275. VariantInit(&var);
  276. if ((flags & D3DRMLOAD_BYNAME)||(D3DRMLOAD_FROMURL & flags)) {
  277. hr=VariantChangeType(&var,&id,0,VT_BSTR);
  278. if FAILED(hr) return E_INVALIDARG;
  279. args=(void*)W2T(V_BSTR(&id));
  280. }
  281. else if(flags & D3DRMLOAD_BYPOSITION){
  282. hr=VariantChangeType(&var,&id,0,VT_I4);
  283. if FAILED(hr) return E_INVALIDARG;
  284. pos=V_I4(&id);
  285. args=&pos;
  286. }
  287. else if(flags & D3DRMLOAD_BYGUID){
  288. hr=VariantChangeType(&var,&id,0,VT_BSTR);
  289. if FAILED(hr) return E_INVALIDARG;
  290. hr=BSTRtoGUID(&loadGuid,V_BSTR(&id));
  291. if FAILED(hr) return E_INVALIDARG;
  292. args=&loadGuid;
  293. }
  294. VariantClear(&var);
  295. if (flags &D3DRMLOAD_FROMRESOURCE){
  296. D3DRMLOADRESOURCE res;
  297. ZeroMemory(&res,sizeof(D3DRMLOADRESOURCE));
  298. res.lpName=pszName;
  299. res.lpType="XFILE";
  300. hr = m__dxj_Direct3dRMFrame3->Load((void *)&res,(DWORD*) args,(DWORD) flags, d3dtcb, pArgs);
  301. }
  302. else {
  303. hr = m__dxj_Direct3dRMFrame3->Load((void *)pszName,(DWORD*) args,(DWORD) flags, d3dtcb, pArgs);
  304. }
  305. if (tcb)
  306. {
  307. delete tcb;
  308. }
  309. return hr;
  310. }
  311. /////////////////////////////////////////////////////////////////////////////
  312. STDMETHODIMP C_dxj_Direct3dRMFrame3Object::setOrientation( I_dxj_Direct3dRMFrame3 *reference, d3dvalue dx,d3dvalue dy,d3dvalue dz, d3dvalue ux,d3dvalue uy,d3dvalue uz)
  313. {
  314. DO_GETOBJECT_NOTNULL( LPDIRECT3DRMFRAME3, f, reference);
  315. return m__dxj_Direct3dRMFrame3->SetOrientation((LPDIRECT3DRMFRAME3)f, dx, dy, dz, ux, uy, uz);
  316. }
  317. /////////////////////////////////////////////////////////////////////////////
  318. STDMETHODIMP C_dxj_Direct3dRMFrame3Object::setPosition(I_dxj_Direct3dRMFrame3 *reference,d3dvalue x,d3dvalue y,d3dvalue z)
  319. {
  320. DO_GETOBJECT_NOTNULL( LPDIRECT3DRMFRAME3, f, reference);
  321. return m__dxj_Direct3dRMFrame3->SetPosition((LPDIRECT3DRMFRAME3)f, x, y, z);
  322. }
  323. /////////////////////////////////////////////////////////////////////////////
  324. STDMETHODIMP C_dxj_Direct3dRMFrame3Object::setRotation(I_dxj_Direct3dRMFrame3 *reference,d3dvalue x,d3dvalue y,
  325. d3dvalue z,d3dvalue theta)
  326. {
  327. DO_GETOBJECT_NOTNULL( LPDIRECT3DRMFRAME3, f, reference);
  328. return m__dxj_Direct3dRMFrame3->SetRotation((LPDIRECT3DRMFRAME3)f, x, y, z, theta);
  329. }
  330. /////////////////////////////////////////////////////////////////////////////
  331. // remove this frame from the callback list. (After debugging, put this into
  332. // the destructor macro at the tof).
  333. //
  334. /////////////////////////////////////////////////////////////////////////////
  335. STDMETHODIMP C_dxj_Direct3dRMFrame3Object::transform(D3dVector* dst, D3dVector* src)
  336. {
  337. if(! (dst && src) )
  338. return E_POINTER;
  339. return m__dxj_Direct3dRMFrame3->Transform( (D3DVECTOR *)dst, (D3DVECTOR *)src );
  340. }
  341. /////////////////////////////////////////////////////////////////////////////
  342. STDMETHODIMP C_dxj_Direct3dRMFrame3Object::inverseTransform(D3dVector* dst, D3dVector* src)
  343. {
  344. if(! (dst && src) )
  345. return E_POINTER;
  346. return m__dxj_Direct3dRMFrame3->InverseTransform( (D3DVECTOR *)dst, (D3DVECTOR *)src );
  347. }
  348. /////////////////////////////////////////////////////////////////////////////
  349. STDMETHODIMP C_dxj_Direct3dRMFrame3Object::getParent(I_dxj_Direct3dRMFrame3 **ret)
  350. {
  351. HRESULT hr;
  352. IDirect3DRMFrame3 *lpFrame3=NULL;
  353. hr= m__dxj_Direct3dRMFrame3->GetParent(&lpFrame3);
  354. *ret=NULL;
  355. if FAILED(hr) return hr;
  356. if (lpFrame3==NULL) return S_OK;
  357. INTERNAL_CREATE(_dxj_Direct3dRMFrame3, lpFrame3, ret);
  358. return hr;
  359. }
  360. /////////////////////////////////////////////////////////////////////////////
  361. STDMETHODIMP C_dxj_Direct3dRMFrame3Object::getScene(I_dxj_Direct3dRMFrame3 **ret)
  362. {
  363. HRESULT hr;
  364. IDirect3DRMFrame3 *lpFrame3=NULL;
  365. hr= m__dxj_Direct3dRMFrame3->GetScene(&lpFrame3);
  366. *ret=NULL;
  367. if FAILED(hr) return hr;
  368. if (lpFrame3==NULL) return S_OK;
  369. INTERNAL_CREATE(_dxj_Direct3dRMFrame3, lpFrame3, ret);
  370. return hr;
  371. }
  372. /////////////////////////////////////////////////////////////////////////////
  373. STDMETHODIMP C_dxj_Direct3dRMFrame3Object::getTexture(I_dxj_Direct3dRMTexture3 **ret)
  374. {
  375. HRESULT hr;
  376. IDirect3DRMTexture *tex=NULL;
  377. IDirect3DRMTexture3 *lpTex3=NULL;
  378. hr= m__dxj_Direct3dRMFrame3->GetTexture(&lpTex3);
  379. *ret=NULL;
  380. if FAILED(hr) return hr;
  381. if (lpTex3==NULL) return S_OK;
  382. INTERNAL_CREATE(_dxj_Direct3dRMTexture3, lpTex3, ret);
  383. return hr;
  384. }
  385. /////////////////////////////////////////////////////////////////////////////
  386. STDMETHODIMP C_dxj_Direct3dRMFrame3Object::getSceneBackgroundDepth(I_dxj_DirectDrawSurface7 **ret)
  387. {
  388. HRESULT hr;
  389. IDirectDrawSurface7 *lpSurf7=NULL;
  390. IDirectDrawSurface *lpSurf=NULL;
  391. hr= m__dxj_Direct3dRMFrame3->GetSceneBackgroundDepth(&lpSurf);
  392. *ret=NULL;
  393. if FAILED(hr) return hr;
  394. if (lpSurf==NULL) return S_OK;
  395. if FAILED(lpSurf->QueryInterface(IID_IDirectDrawSurface7,(void**)&lpSurf7)){
  396. lpSurf->Release();
  397. return E_NOINTERFACE;
  398. }
  399. INTERNAL_CREATE(_dxj_DirectDrawSurface7, lpSurf7, ret);
  400. lpSurf->Release();
  401. return hr;
  402. }
  403. /////////////////////////////////////////////////////////////////////////////
  404. STDMETHODIMP C_dxj_Direct3dRMFrame3Object::setSceneBackgroundDepth(I_dxj_DirectDrawSurface7 *surf)
  405. {
  406. HRESULT hr;
  407. if (!surf) return E_INVALIDARG;
  408. LPDIRECTDRAWSURFACE s=NULL;
  409. //Get our real surface s7 becomes NULL if surf is NULL
  410. DO_GETOBJECT_NOTNULL( LPDIRECTDRAWSURFACE7, s7, surf);
  411. if (s7){
  412. hr=s7->QueryInterface(IID_IDirectDrawSurface,(void**)&s);
  413. if FAILED(hr) return hr;
  414. }
  415. hr= m__dxj_Direct3dRMFrame3->SetSceneBackgroundDepth(s);
  416. return hr;
  417. }
  418. /////////////////////////////////////////////////////////////////////////////
  419. STDMETHODIMP C_dxj_Direct3dRMFrame3Object::setSceneBackgroundImage(I_dxj_Direct3dRMTexture3 *tex)
  420. {
  421. HRESULT hr;
  422. DO_GETOBJECT_NOTNULL( LPDIRECT3DRMTEXTURE3, t, tex);
  423. hr= m__dxj_Direct3dRMFrame3->SetSceneBackgroundImage(t);
  424. return hr;
  425. }
  426. /////////////////////////////////////////////////////////////////////////////
  427. STDMETHODIMP C_dxj_Direct3dRMFrame3Object::setTexture(I_dxj_Direct3dRMTexture3 *tex)
  428. {
  429. HRESULT hr;
  430. DO_GETOBJECT_NOTNULL(IDirect3DRMTexture3*, t, tex);
  431. hr= m__dxj_Direct3dRMFrame3->SetTexture(t);
  432. return hr;
  433. }
  434. /////////////////////////////////////////////////////////////////////////////
  435. STDMETHODIMP C_dxj_Direct3dRMFrame3Object::addChild(I_dxj_Direct3dRMFrame3 *frame)
  436. {
  437. HRESULT hr;
  438. DO_GETOBJECT_NOTNULL(IDirect3DRMFrame3*, f, frame);
  439. hr= m__dxj_Direct3dRMFrame3->AddChild(f);
  440. return hr;
  441. }
  442. /////////////////////////////////////////////////////////////////////////////
  443. STDMETHODIMP C_dxj_Direct3dRMFrame3Object::deleteChild(I_dxj_Direct3dRMFrame3 *frame)
  444. {
  445. HRESULT hr;
  446. DO_GETOBJECT_NOTNULL(IDirect3DRMFrame3*, f, frame);
  447. hr= m__dxj_Direct3dRMFrame3->DeleteChild(f);
  448. return hr;
  449. }
  450. /////////////////////////////////////////////////////////////////////////////
  451. STDMETHODIMP C_dxj_Direct3dRMFrame3Object::getAxes(D3dVector *dir,D3dVector *up)
  452. {
  453. HRESULT hr;
  454. hr= m__dxj_Direct3dRMFrame3->GetAxes((D3DVECTOR*)dir,(D3DVECTOR*)up);
  455. return hr;
  456. }
  457. /////////////////////////////////////////////////////////////////////////////
  458. STDMETHODIMP C_dxj_Direct3dRMFrame3Object::getBox(D3dRMBox *box)
  459. {
  460. HRESULT hr;
  461. hr= m__dxj_Direct3dRMFrame3->GetBox((D3DRMBOX*)box);
  462. return S_OK;
  463. }
  464. /////////////////////////////////////////////////////////////////////////////
  465. STDMETHODIMP C_dxj_Direct3dRMFrame3Object::getBoxEnable(long *box)
  466. {
  467. HRESULT hr=S_OK;
  468. *box= m__dxj_Direct3dRMFrame3->GetBoxEnable();
  469. return hr;
  470. }
  471. /////////////////////////////////////////////////////////////////////////////
  472. STDMETHODIMP C_dxj_Direct3dRMFrame3Object::getHierarchyBox(D3dRMBox *box)
  473. {
  474. HRESULT hr;
  475. hr= m__dxj_Direct3dRMFrame3->GetHierarchyBox((D3DRMBOX*)box);
  476. return hr;
  477. }
  478. /////////////////////////////////////////////////////////////////////////////
  479. STDMETHODIMP C_dxj_Direct3dRMFrame3Object::getInheritAxes(long *box)
  480. {
  481. HRESULT hr=S_OK;
  482. *box= m__dxj_Direct3dRMFrame3->GetInheritAxes();
  483. return hr;
  484. }
  485. /////////////////////////////////////////////////////////////////////////////
  486. STDMETHODIMP C_dxj_Direct3dRMFrame3Object::setAxes(float dx,float dy,float dz, float ux,float uy,float uz)
  487. {
  488. HRESULT hr;
  489. hr= m__dxj_Direct3dRMFrame3->SetAxes(dx,dy,dz,ux,uy,uz);
  490. return hr;
  491. }
  492. /////////////////////////////////////////////////////////////////////////////
  493. STDMETHODIMP C_dxj_Direct3dRMFrame3Object::setBox(D3dRMBox *box)
  494. {
  495. HRESULT hr;
  496. hr= m__dxj_Direct3dRMFrame3->SetBox((D3DRMBOX*)box);
  497. return hr;
  498. }
  499. /////////////////////////////////////////////////////////////////////////////
  500. STDMETHODIMP C_dxj_Direct3dRMFrame3Object::setInheritAxes(long bl)
  501. {
  502. HRESULT hr;
  503. hr= m__dxj_Direct3dRMFrame3->SetInheritAxes(bl);
  504. return hr;
  505. }
  506. /////////////////////////////////////////////////////////////////////////////
  507. STDMETHODIMP C_dxj_Direct3dRMFrame3Object::setBoxEnable(long bl)
  508. {
  509. HRESULT hr;
  510. hr= m__dxj_Direct3dRMFrame3->SetBoxEnable(bl);
  511. return hr;
  512. }
  513. /////////////////////////////////////////////////////////////////////////////
  514. STDMETHODIMP C_dxj_Direct3dRMFrame3Object::setQuaternion(I_dxj_Direct3dRMFrame3 *refer,D3dRMQuaternion *quat)
  515. {
  516. DO_GETOBJECT_NOTNULL(IDirect3DRMFrame3*, f, refer);
  517. HRESULT hr;
  518. hr= m__dxj_Direct3dRMFrame3->SetQuaternion(f,(D3DRMQUATERNION*)quat);
  519. return hr;
  520. }
  521. /////////////////////////////////////////////////////////////////////////////
  522. STDMETHODIMP C_dxj_Direct3dRMFrame3Object::rayPick(I_dxj_Direct3dRMFrame3 *refer,D3dRMRay *ray,long flags,I_dxj_Direct3dRMPick2Array **retv)
  523. {
  524. DO_GETOBJECT_NOTNULL(IDirect3DRMFrame3*, f, refer);
  525. LPDIRECT3DRMPICKED2ARRAY lpArray=NULL;
  526. HRESULT hr;
  527. hr= m__dxj_Direct3dRMFrame3->RayPick(f,(D3DRMRAY*)ray,(DWORD)flags,&lpArray);
  528. INTERNAL_CREATE(_dxj_Direct3dRMPick2Array, lpArray, retv);
  529. return hr;
  530. }
  531. /////////////////////////////////////////////////////////////////////////////
  532. STDMETHODIMP C_dxj_Direct3dRMFrame3Object::save(BSTR name,long format,long flags)
  533. {
  534. //RM FAILED TO IMPLEMENT FRAME SAVE SO
  535. //IT ALWAYS RETURNS E_NOTIMPL
  536. //CONGPA PROVIDED A LIBRARY FOR SAVING
  537. //return E_NOTIMPL;
  538. USES_CONVERSION;
  539. LPSTR pszNam = W2T(name); // Now convert to ANSI
  540. HRESULT hr;
  541. //hr= m__dxj_Direct3dRMFrame3->Save(pszNam,(D3DRMXOFFORMAT)format,(DWORD)flags);
  542. hr=FrameToXFile(m__dxj_Direct3dRMFrame3,
  543. pszNam,
  544. (D3DRMXOFFORMAT)format,
  545. (D3DRMSAVEOPTIONS) flags);
  546. return hr;
  547. }
  548. /////////////////////////////////////////////////////////////////////////////
  549. STDMETHODIMP C_dxj_Direct3dRMFrame3Object::setTraversalOptions(long flags)
  550. {
  551. HRESULT hr;
  552. hr= m__dxj_Direct3dRMFrame3->SetTraversalOptions((DWORD)flags);
  553. return hr;
  554. }
  555. /////////////////////////////////////////////////////////////////////////////
  556. STDMETHODIMP C_dxj_Direct3dRMFrame3Object::getTraversalOptions(long *flags)
  557. {
  558. HRESULT hr;
  559. hr= m__dxj_Direct3dRMFrame3->GetTraversalOptions((DWORD*)flags);
  560. return hr;
  561. }
  562. /////////////////////////////////////////////////////////////////////////////
  563. STDMETHODIMP C_dxj_Direct3dRMFrame3Object::transformVectors(
  564. /* [in] */ I_dxj_Direct3dRMFrame3 __RPC_FAR *reference,
  565. /* [in] */ long num,
  566. /* [out][in] */ SAFEARRAY __RPC_FAR * __RPC_FAR *DstVectors,
  567. /* [out][in] */ SAFEARRAY __RPC_FAR * __RPC_FAR *SrcVectors)
  568. {
  569. HRESULT hr;
  570. DO_GETOBJECT_NOTNULL(LPDIRECT3DRMFRAME3,ref,reference);
  571. if (!reference) ref=NULL;
  572. __try{
  573. hr= m__dxj_Direct3dRMFrame3->TransformVectors(ref,(DWORD)num,
  574. (D3DVECTOR*)((SAFEARRAY*)*DstVectors)->pvData,
  575. (D3DVECTOR*)((SAFEARRAY*)*SrcVectors)->pvData);
  576. }
  577. __except(1,1){
  578. return E_INVALIDARG;
  579. }
  580. return hr;
  581. }
  582. /////////////////////////////////////////////////////////////////////////////
  583. STDMETHODIMP C_dxj_Direct3dRMFrame3Object::inverseTransformVectors(
  584. /* [in] */ I_dxj_Direct3dRMFrame3 __RPC_FAR *reference,
  585. /* [in] */ long num,
  586. /* [out][in] */ SAFEARRAY __RPC_FAR * __RPC_FAR *DstVectors,
  587. /* [out][in] */ SAFEARRAY __RPC_FAR * __RPC_FAR *SrcVectors)
  588. {
  589. HRESULT hr;
  590. DO_GETOBJECT_NOTNULL(LPDIRECT3DRMFRAME3,ref,reference);
  591. __try{
  592. hr= m__dxj_Direct3dRMFrame3->InverseTransformVectors(ref,(DWORD)num,
  593. (D3DVECTOR*)((SAFEARRAY*)*DstVectors)->pvData,
  594. (D3DVECTOR*)((SAFEARRAY*)*SrcVectors)->pvData);
  595. }
  596. __except(1,1){
  597. return E_INVALIDARG;
  598. }
  599. return hr;
  600. }
  601. /////////////////////////////////////////////////////////////////////////////
  602. STDMETHODIMP C_dxj_Direct3dRMFrame3Object::getMaterial(I_dxj_Direct3dRMMaterial2 **ret)
  603. {
  604. HRESULT hr;
  605. IDirect3DRMMaterial2 *lpMat2=NULL;
  606. hr= m__dxj_Direct3dRMFrame3->GetMaterial(&lpMat2);
  607. *ret=NULL;
  608. if FAILED(hr) return hr;
  609. INTERNAL_CREATE(_dxj_Direct3dRMMaterial2, lpMat2, ret);
  610. return hr;
  611. }
  612. /////////////////////////////////////////////////////////////////////////////
  613. STDMETHODIMP C_dxj_Direct3dRMFrame3Object::setMaterial(I_dxj_Direct3dRMMaterial2 *mat)
  614. {
  615. HRESULT hr;
  616. if (mat==NULL)
  617. return m__dxj_Direct3dRMFrame3->SetMaterial(NULL);
  618. DO_GETOBJECT_NOTNULL(LPDIRECT3DRMMATERIAL2,lpMat2,mat);
  619. hr= m__dxj_Direct3dRMFrame3->SetMaterial(lpMat2);
  620. return hr;
  621. }
  622. /////////////////////////////////////////////////////////////////////////////
  623. STDMETHODIMP C_dxj_Direct3dRMFrame3Object::getMaterialOverride(D3dMaterialOverride *override)
  624. {
  625. HRESULT hr;
  626. if (!override) return E_INVALIDARG;
  627. override->lSize=sizeof(D3DRMMATERIALOVERRIDE);
  628. hr= m__dxj_Direct3dRMFrame3->GetMaterialOverride((D3DRMMATERIALOVERRIDE*)override);
  629. if FAILED(hr) return hr;
  630. if (((D3DRMMATERIALOVERRIDE*)override)->lpD3DRMTex)
  631. (((D3DRMMATERIALOVERRIDE*)override)->lpD3DRMTex)->Release();
  632. return hr;
  633. }
  634. /////////////////////////////////////////////////////////////////////////////
  635. STDMETHODIMP C_dxj_Direct3dRMFrame3Object::setMaterialOverride(D3dMaterialOverride *override)
  636. {
  637. HRESULT hr;
  638. if (!override) return E_INVALIDARG;
  639. D3DRMMATERIALOVERRIDE override2;
  640. ZeroMemory(&override2,sizeof(D3DRMMATERIALOVERRIDE));
  641. override->lSize=sizeof(D3DRMMATERIALOVERRIDE);
  642. override2.dwSize=sizeof(D3DRMMATERIALOVERRIDE);
  643. hr= m__dxj_Direct3dRMFrame3->GetMaterialOverride(&override2);
  644. if FAILED(hr) return hr;
  645. ((D3DRMMATERIALOVERRIDE*)override)->lpD3DRMTex=override2.lpD3DRMTex;
  646. hr= m__dxj_Direct3dRMFrame3->SetMaterialOverride((D3DRMMATERIALOVERRIDE*)override);
  647. if (override2.lpD3DRMTex) override2.lpD3DRMTex->Release();
  648. return hr;
  649. }
  650. /////////////////////////////////////////////////////////////////////////////
  651. STDMETHODIMP C_dxj_Direct3dRMFrame3Object::setMaterialOverrideTexture(I_dxj_Direct3dRMTexture3 *tex)
  652. {
  653. HRESULT hr;
  654. D3DRMMATERIALOVERRIDE override2;
  655. ZeroMemory(&override2,sizeof(D3DRMMATERIALOVERRIDE));
  656. override2.dwSize=sizeof(D3DRMMATERIALOVERRIDE);
  657. hr= m__dxj_Direct3dRMFrame3->GetMaterialOverride(&override2);
  658. if FAILED(hr) return hr;
  659. if (override2.lpD3DRMTex) override2.lpD3DRMTex->Release();
  660. override2.lpD3DRMTex=NULL;
  661. DO_GETOBJECT_NOTNULL(LPDIRECT3DRMTEXTURE3,t,tex);
  662. if (!tex) {
  663. hr= m__dxj_Direct3dRMFrame3->SetMaterialOverride(&override2);
  664. }
  665. else {
  666. override2.lpD3DRMTex=t;
  667. override2.lpD3DRMTex->AddRef();
  668. hr= m__dxj_Direct3dRMFrame3->SetMaterialOverride(&override2);
  669. override2.lpD3DRMTex->Release();
  670. }
  671. return hr;
  672. }
  673. /////////////////////////////////////////////////////////////////////////////
  674. STDMETHODIMP C_dxj_Direct3dRMFrame3Object::getMaterialOverrideTexture(I_dxj_Direct3dRMTexture3 **tex)
  675. {
  676. HRESULT hr;
  677. D3DRMMATERIALOVERRIDE override2;
  678. ZeroMemory(&override2,sizeof(D3DRMMATERIALOVERRIDE));
  679. override2.dwSize=sizeof(D3DRMMATERIALOVERRIDE);
  680. hr= m__dxj_Direct3dRMFrame3->GetMaterialOverride(&override2);
  681. if FAILED(hr) return hr;
  682. if (override2.lpD3DRMTex){
  683. INTERNAL_CREATE(_dxj_Direct3dRMTexture3,override2.lpD3DRMTex,tex);
  684. return hr;
  685. }
  686. *tex=NULL;
  687. return S_OK;;
  688. }
  689. STDMETHODIMP C_dxj_Direct3dRMFrame3Object::getVisual(long index,I_dxj_Direct3dRMVisual **ret)
  690. {
  691. HRESULT hr;
  692. DWORD count=0;
  693. IUnknown **ppUnk=NULL;
  694. IDirect3DRMVisual *vis=NULL;
  695. *ret=NULL;
  696. hr=m__dxj_Direct3dRMFrame3->GetVisuals(&count,NULL);
  697. if FAILED(hr) return hr;
  698. if (count==0) return E_INVALIDARG;
  699. ppUnk=(IUnknown**)malloc(sizeof(IUnknown*)*count);
  700. if (!ppUnk) return E_OUTOFMEMORY;
  701. hr=m__dxj_Direct3dRMFrame3->GetVisuals(&count,ppUnk);
  702. if FAILED(hr) goto exitOut;
  703. hr= ppUnk[index]->QueryInterface(IID_IDirect3DRMVisual,(void**)&vis);
  704. if FAILED(hr) goto exitOut;
  705. hr=CreateCoverVisual(vis,ret);
  706. if FAILED(hr) goto exitOut;
  707. exitOut:
  708. for (DWORD i=0;i<count;i++){
  709. if (ppUnk[index]) ppUnk[index]->Release();
  710. }
  711. free(ppUnk);
  712. return hr;
  713. }
  714. STDMETHODIMP C_dxj_Direct3dRMFrame3Object::getVisualCount (long *count)
  715. {
  716. HRESULT hr=m__dxj_Direct3dRMFrame3->GetVisuals((DWORD*)count,NULL);
  717. return hr;
  718. }
  719. STDMETHODIMP C_dxj_Direct3dRMFrame3Object::setSceneFogMethod (long meth)
  720. {
  721. HRESULT hr=m__dxj_Direct3dRMFrame3->SetSceneFogMethod(meth);
  722. return hr;
  723. }
  724. STDMETHODIMP C_dxj_Direct3dRMFrame3Object::getSceneFogMethod (long *meth)
  725. {
  726. HRESULT hr=m__dxj_Direct3dRMFrame3->GetSceneFogMethod((DWORD*)meth);
  727. return hr;
  728. }
  729. /////////////////////////////////////////////////////////////////////////////
  730. extern "C" void __cdecl myFrameMoveCallback3( LPDIRECT3DRMFRAME3 lpf, void *lpArg, D3DVALUE delta)
  731. {
  732. DPF(1,"Entered myFrameMoveCallback3\r\n");
  733. FrameMoveCallback3 *fmcb = (FrameMoveCallback3 *)lpArg;
  734. // note: need to get OUR frame object from the direct frame object, if
  735. // one exists. If not, we have a crisis!
  736. for( C_dxj_Direct3dRMFrame3Object *that = (C_dxj_Direct3dRMFrame3Object *)g_dxj_Direct3dRMFrame3; that ; that = (C_dxj_Direct3dRMFrame3Object *)that->nextobj )
  737. {
  738. DO_GETOBJECT_NOTNULL(LPDIRECT3DRMFRAME3, f, that)
  739. if( f == lpf )
  740. {
  741. if (fmcb->pUser) fmcb->pUser->AddRef();
  742. IUNK(that)->AddRef();
  743. fmcb->c->callbackRMFrameMove(that,fmcb->pUser, delta);
  744. IUNK(that)->Release();
  745. if (fmcb->pUser) fmcb->pUser->Release();
  746. return;
  747. }
  748. }
  749. //
  750. // I didn't create this frame, create a new one
  751. //
  752. C_dxj_Direct3dRMFrame3Object *c=new CComObject<C_dxj_Direct3dRMFrame3Object>;
  753. I_dxj_Direct3dRMFrame3 *Iframe=NULL;
  754. if( c == NULL )
  755. {
  756. lpf->Release();
  757. return;
  758. }
  759. c->InternalSetObject((LPDIRECT3DRMFRAME3)lpf);
  760. if ( fmcb->pParent )
  761. {
  762. c->parent = fmcb->pParent;
  763. fmcb->pParent->AddRef();
  764. }
  765. if (FAILED(((I_dxj_Direct3dRMFrame3*)c)->QueryInterface(IID_I_dxj_Direct3dRMFrame3, (void **)&Iframe)))
  766. {
  767. delete c;
  768. return;
  769. }
  770. c->pinterface = Iframe;
  771. if (fmcb->pUser) fmcb->pUser->AddRef();
  772. IUNK(Iframe)->AddRef();
  773. fmcb->c->callbackRMFrameMove(Iframe, fmcb->pUser, delta);
  774. IUNK(Iframe)->Release();
  775. if (fmcb->pUser) fmcb->pUser->Release();
  776. }