Leaked source code of windows server 2003
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.

1000 lines
32 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. LPSTR pszName = NULL;
  271. __try { pszName = W2T(filename); /* Now convert to ANSI */ } __except(EXCEPTION_EXECUTE_HANDLER) { return E_FAIL; }
  272. void *args=NULL;
  273. DWORD pos=0;
  274. GUID loadGuid;
  275. VARIANT var;
  276. VariantInit(&var);
  277. if ((flags & D3DRMLOAD_BYNAME)||(D3DRMLOAD_FROMURL & flags)) {
  278. hr=VariantChangeType(&var,&id,0,VT_BSTR);
  279. if FAILED(hr) return E_INVALIDARG;
  280. __try { args=(void*)W2T(V_BSTR(&id)); } __except(EXCEPTION_EXECUTE_HANDLER) { return E_FAIL; }
  281. }
  282. else if(flags & D3DRMLOAD_BYPOSITION){
  283. hr=VariantChangeType(&var,&id,0,VT_I4);
  284. if FAILED(hr) return E_INVALIDARG;
  285. pos=V_I4(&id);
  286. args=&pos;
  287. }
  288. else if(flags & D3DRMLOAD_BYGUID){
  289. hr=VariantChangeType(&var,&id,0,VT_BSTR);
  290. if FAILED(hr) return E_INVALIDARG;
  291. hr=BSTRtoGUID(&loadGuid,V_BSTR(&id));
  292. if FAILED(hr) return E_INVALIDARG;
  293. args=&loadGuid;
  294. }
  295. VariantClear(&var);
  296. if (flags &D3DRMLOAD_FROMRESOURCE){
  297. D3DRMLOADRESOURCE res;
  298. ZeroMemory(&res,sizeof(D3DRMLOADRESOURCE));
  299. res.lpName=pszName;
  300. res.lpType="XFILE";
  301. hr = m__dxj_Direct3dRMFrame3->Load((void *)&res,(DWORD*) args,(DWORD) flags, d3dtcb, pArgs);
  302. }
  303. else {
  304. hr = m__dxj_Direct3dRMFrame3->Load((void *)pszName,(DWORD*) args,(DWORD) flags, d3dtcb, pArgs);
  305. }
  306. if (tcb)
  307. {
  308. delete tcb;
  309. }
  310. return hr;
  311. }
  312. /////////////////////////////////////////////////////////////////////////////
  313. STDMETHODIMP C_dxj_Direct3dRMFrame3Object::setOrientation( I_dxj_Direct3dRMFrame3 *reference, d3dvalue dx,d3dvalue dy,d3dvalue dz, d3dvalue ux,d3dvalue uy,d3dvalue uz)
  314. {
  315. DO_GETOBJECT_NOTNULL( LPDIRECT3DRMFRAME3, f, reference);
  316. return m__dxj_Direct3dRMFrame3->SetOrientation((LPDIRECT3DRMFRAME3)f, dx, dy, dz, ux, uy, uz);
  317. }
  318. /////////////////////////////////////////////////////////////////////////////
  319. STDMETHODIMP C_dxj_Direct3dRMFrame3Object::setPosition(I_dxj_Direct3dRMFrame3 *reference,d3dvalue x,d3dvalue y,d3dvalue z)
  320. {
  321. DO_GETOBJECT_NOTNULL( LPDIRECT3DRMFRAME3, f, reference);
  322. return m__dxj_Direct3dRMFrame3->SetPosition((LPDIRECT3DRMFRAME3)f, x, y, z);
  323. }
  324. /////////////////////////////////////////////////////////////////////////////
  325. STDMETHODIMP C_dxj_Direct3dRMFrame3Object::setRotation(I_dxj_Direct3dRMFrame3 *reference,d3dvalue x,d3dvalue y,
  326. d3dvalue z,d3dvalue theta)
  327. {
  328. DO_GETOBJECT_NOTNULL( LPDIRECT3DRMFRAME3, f, reference);
  329. return m__dxj_Direct3dRMFrame3->SetRotation((LPDIRECT3DRMFRAME3)f, x, y, z, theta);
  330. }
  331. /////////////////////////////////////////////////////////////////////////////
  332. // remove this frame from the callback list. (After debugging, put this into
  333. // the destructor macro at the tof).
  334. //
  335. /////////////////////////////////////////////////////////////////////////////
  336. STDMETHODIMP C_dxj_Direct3dRMFrame3Object::transform(D3dVector* dst, D3dVector* src)
  337. {
  338. if(! (dst && src) )
  339. return E_POINTER;
  340. return m__dxj_Direct3dRMFrame3->Transform( (D3DVECTOR *)dst, (D3DVECTOR *)src );
  341. }
  342. /////////////////////////////////////////////////////////////////////////////
  343. STDMETHODIMP C_dxj_Direct3dRMFrame3Object::inverseTransform(D3dVector* dst, D3dVector* src)
  344. {
  345. if(! (dst && src) )
  346. return E_POINTER;
  347. return m__dxj_Direct3dRMFrame3->InverseTransform( (D3DVECTOR *)dst, (D3DVECTOR *)src );
  348. }
  349. /////////////////////////////////////////////////////////////////////////////
  350. STDMETHODIMP C_dxj_Direct3dRMFrame3Object::getParent(I_dxj_Direct3dRMFrame3 **ret)
  351. {
  352. HRESULT hr;
  353. IDirect3DRMFrame3 *lpFrame3=NULL;
  354. hr= m__dxj_Direct3dRMFrame3->GetParent(&lpFrame3);
  355. *ret=NULL;
  356. if FAILED(hr) return hr;
  357. if (lpFrame3==NULL) return S_OK;
  358. INTERNAL_CREATE(_dxj_Direct3dRMFrame3, lpFrame3, ret);
  359. return hr;
  360. }
  361. /////////////////////////////////////////////////////////////////////////////
  362. STDMETHODIMP C_dxj_Direct3dRMFrame3Object::getScene(I_dxj_Direct3dRMFrame3 **ret)
  363. {
  364. HRESULT hr;
  365. IDirect3DRMFrame3 *lpFrame3=NULL;
  366. hr= m__dxj_Direct3dRMFrame3->GetScene(&lpFrame3);
  367. *ret=NULL;
  368. if FAILED(hr) return hr;
  369. if (lpFrame3==NULL) return S_OK;
  370. INTERNAL_CREATE(_dxj_Direct3dRMFrame3, lpFrame3, ret);
  371. return hr;
  372. }
  373. /////////////////////////////////////////////////////////////////////////////
  374. STDMETHODIMP C_dxj_Direct3dRMFrame3Object::getTexture(I_dxj_Direct3dRMTexture3 **ret)
  375. {
  376. HRESULT hr;
  377. IDirect3DRMTexture *tex=NULL;
  378. IDirect3DRMTexture3 *lpTex3=NULL;
  379. hr= m__dxj_Direct3dRMFrame3->GetTexture(&lpTex3);
  380. *ret=NULL;
  381. if FAILED(hr) return hr;
  382. if (lpTex3==NULL) return S_OK;
  383. INTERNAL_CREATE(_dxj_Direct3dRMTexture3, lpTex3, ret);
  384. return hr;
  385. }
  386. /////////////////////////////////////////////////////////////////////////////
  387. STDMETHODIMP C_dxj_Direct3dRMFrame3Object::getSceneBackgroundDepth(I_dxj_DirectDrawSurface7 **ret)
  388. {
  389. HRESULT hr;
  390. IDirectDrawSurface7 *lpSurf7=NULL;
  391. IDirectDrawSurface *lpSurf=NULL;
  392. hr= m__dxj_Direct3dRMFrame3->GetSceneBackgroundDepth(&lpSurf);
  393. *ret=NULL;
  394. if FAILED(hr) return hr;
  395. if (lpSurf==NULL) return S_OK;
  396. if FAILED(lpSurf->QueryInterface(IID_IDirectDrawSurface7,(void**)&lpSurf7)){
  397. lpSurf->Release();
  398. return E_NOINTERFACE;
  399. }
  400. INTERNAL_CREATE(_dxj_DirectDrawSurface7, lpSurf7, ret);
  401. lpSurf->Release();
  402. return hr;
  403. }
  404. /////////////////////////////////////////////////////////////////////////////
  405. STDMETHODIMP C_dxj_Direct3dRMFrame3Object::setSceneBackgroundDepth(I_dxj_DirectDrawSurface7 *surf)
  406. {
  407. HRESULT hr;
  408. if (!surf) return E_INVALIDARG;
  409. LPDIRECTDRAWSURFACE s=NULL;
  410. //Get our real surface s7 becomes NULL if surf is NULL
  411. DO_GETOBJECT_NOTNULL( LPDIRECTDRAWSURFACE7, s7, surf);
  412. if (s7){
  413. hr=s7->QueryInterface(IID_IDirectDrawSurface,(void**)&s);
  414. if FAILED(hr) return hr;
  415. }
  416. hr= m__dxj_Direct3dRMFrame3->SetSceneBackgroundDepth(s);
  417. return hr;
  418. }
  419. /////////////////////////////////////////////////////////////////////////////
  420. STDMETHODIMP C_dxj_Direct3dRMFrame3Object::setSceneBackgroundImage(I_dxj_Direct3dRMTexture3 *tex)
  421. {
  422. HRESULT hr;
  423. DO_GETOBJECT_NOTNULL( LPDIRECT3DRMTEXTURE3, t, tex);
  424. hr= m__dxj_Direct3dRMFrame3->SetSceneBackgroundImage(t);
  425. return hr;
  426. }
  427. /////////////////////////////////////////////////////////////////////////////
  428. STDMETHODIMP C_dxj_Direct3dRMFrame3Object::setTexture(I_dxj_Direct3dRMTexture3 *tex)
  429. {
  430. HRESULT hr;
  431. DO_GETOBJECT_NOTNULL(IDirect3DRMTexture3*, t, tex);
  432. hr= m__dxj_Direct3dRMFrame3->SetTexture(t);
  433. return hr;
  434. }
  435. /////////////////////////////////////////////////////////////////////////////
  436. STDMETHODIMP C_dxj_Direct3dRMFrame3Object::addChild(I_dxj_Direct3dRMFrame3 *frame)
  437. {
  438. HRESULT hr;
  439. DO_GETOBJECT_NOTNULL(IDirect3DRMFrame3*, f, frame);
  440. hr= m__dxj_Direct3dRMFrame3->AddChild(f);
  441. return hr;
  442. }
  443. /////////////////////////////////////////////////////////////////////////////
  444. STDMETHODIMP C_dxj_Direct3dRMFrame3Object::deleteChild(I_dxj_Direct3dRMFrame3 *frame)
  445. {
  446. HRESULT hr;
  447. DO_GETOBJECT_NOTNULL(IDirect3DRMFrame3*, f, frame);
  448. hr= m__dxj_Direct3dRMFrame3->DeleteChild(f);
  449. return hr;
  450. }
  451. /////////////////////////////////////////////////////////////////////////////
  452. STDMETHODIMP C_dxj_Direct3dRMFrame3Object::getAxes(D3dVector *dir,D3dVector *up)
  453. {
  454. HRESULT hr;
  455. hr= m__dxj_Direct3dRMFrame3->GetAxes((D3DVECTOR*)dir,(D3DVECTOR*)up);
  456. return hr;
  457. }
  458. /////////////////////////////////////////////////////////////////////////////
  459. STDMETHODIMP C_dxj_Direct3dRMFrame3Object::getBox(D3dRMBox *box)
  460. {
  461. HRESULT hr;
  462. hr= m__dxj_Direct3dRMFrame3->GetBox((D3DRMBOX*)box);
  463. return S_OK;
  464. }
  465. /////////////////////////////////////////////////////////////////////////////
  466. STDMETHODIMP C_dxj_Direct3dRMFrame3Object::getBoxEnable(long *box)
  467. {
  468. HRESULT hr=S_OK;
  469. *box= m__dxj_Direct3dRMFrame3->GetBoxEnable();
  470. return hr;
  471. }
  472. /////////////////////////////////////////////////////////////////////////////
  473. STDMETHODIMP C_dxj_Direct3dRMFrame3Object::getHierarchyBox(D3dRMBox *box)
  474. {
  475. HRESULT hr;
  476. hr= m__dxj_Direct3dRMFrame3->GetHierarchyBox((D3DRMBOX*)box);
  477. return hr;
  478. }
  479. /////////////////////////////////////////////////////////////////////////////
  480. STDMETHODIMP C_dxj_Direct3dRMFrame3Object::getInheritAxes(long *box)
  481. {
  482. HRESULT hr=S_OK;
  483. *box= m__dxj_Direct3dRMFrame3->GetInheritAxes();
  484. return hr;
  485. }
  486. /////////////////////////////////////////////////////////////////////////////
  487. STDMETHODIMP C_dxj_Direct3dRMFrame3Object::setAxes(float dx,float dy,float dz, float ux,float uy,float uz)
  488. {
  489. HRESULT hr;
  490. hr= m__dxj_Direct3dRMFrame3->SetAxes(dx,dy,dz,ux,uy,uz);
  491. return hr;
  492. }
  493. /////////////////////////////////////////////////////////////////////////////
  494. STDMETHODIMP C_dxj_Direct3dRMFrame3Object::setBox(D3dRMBox *box)
  495. {
  496. HRESULT hr;
  497. hr= m__dxj_Direct3dRMFrame3->SetBox((D3DRMBOX*)box);
  498. return hr;
  499. }
  500. /////////////////////////////////////////////////////////////////////////////
  501. STDMETHODIMP C_dxj_Direct3dRMFrame3Object::setInheritAxes(long bl)
  502. {
  503. HRESULT hr;
  504. hr= m__dxj_Direct3dRMFrame3->SetInheritAxes(bl);
  505. return hr;
  506. }
  507. /////////////////////////////////////////////////////////////////////////////
  508. STDMETHODIMP C_dxj_Direct3dRMFrame3Object::setBoxEnable(long bl)
  509. {
  510. HRESULT hr;
  511. hr= m__dxj_Direct3dRMFrame3->SetBoxEnable(bl);
  512. return hr;
  513. }
  514. /////////////////////////////////////////////////////////////////////////////
  515. STDMETHODIMP C_dxj_Direct3dRMFrame3Object::setQuaternion(I_dxj_Direct3dRMFrame3 *refer,D3dRMQuaternion *quat)
  516. {
  517. DO_GETOBJECT_NOTNULL(IDirect3DRMFrame3*, f, refer);
  518. HRESULT hr;
  519. hr= m__dxj_Direct3dRMFrame3->SetQuaternion(f,(D3DRMQUATERNION*)quat);
  520. return hr;
  521. }
  522. /////////////////////////////////////////////////////////////////////////////
  523. STDMETHODIMP C_dxj_Direct3dRMFrame3Object::rayPick(I_dxj_Direct3dRMFrame3 *refer,D3dRMRay *ray,long flags,I_dxj_Direct3dRMPick2Array **retv)
  524. {
  525. DO_GETOBJECT_NOTNULL(IDirect3DRMFrame3*, f, refer);
  526. LPDIRECT3DRMPICKED2ARRAY lpArray=NULL;
  527. HRESULT hr;
  528. hr= m__dxj_Direct3dRMFrame3->RayPick(f,(D3DRMRAY*)ray,(DWORD)flags,&lpArray);
  529. INTERNAL_CREATE(_dxj_Direct3dRMPick2Array, lpArray, retv);
  530. return hr;
  531. }
  532. /////////////////////////////////////////////////////////////////////////////
  533. STDMETHODIMP C_dxj_Direct3dRMFrame3Object::save(BSTR name,long format,long flags)
  534. {
  535. //RM FAILED TO IMPLEMENT FRAME SAVE SO
  536. //IT ALWAYS RETURNS E_NOTIMPL
  537. //CONGPA PROVIDED A LIBRARY FOR SAVING
  538. //return E_NOTIMPL;
  539. USES_CONVERSION;
  540. LPSTR pszNam = NULL;
  541. __try { pszNam = W2T(name); /* Now convert to ANSI */ } __except(EXCEPTION_EXECUTE_HANDLER) { return E_FAIL; }
  542. HRESULT hr;
  543. //hr= m__dxj_Direct3dRMFrame3->Save(pszNam,(D3DRMXOFFORMAT)format,(DWORD)flags);
  544. hr=FrameToXFile(m__dxj_Direct3dRMFrame3,
  545. pszNam,
  546. (D3DRMXOFFORMAT)format,
  547. (D3DRMSAVEOPTIONS) flags);
  548. return hr;
  549. }
  550. /////////////////////////////////////////////////////////////////////////////
  551. STDMETHODIMP C_dxj_Direct3dRMFrame3Object::setTraversalOptions(long flags)
  552. {
  553. HRESULT hr;
  554. hr= m__dxj_Direct3dRMFrame3->SetTraversalOptions((DWORD)flags);
  555. return hr;
  556. }
  557. /////////////////////////////////////////////////////////////////////////////
  558. STDMETHODIMP C_dxj_Direct3dRMFrame3Object::getTraversalOptions(long *flags)
  559. {
  560. HRESULT hr;
  561. hr= m__dxj_Direct3dRMFrame3->GetTraversalOptions((DWORD*)flags);
  562. return hr;
  563. }
  564. /////////////////////////////////////////////////////////////////////////////
  565. STDMETHODIMP C_dxj_Direct3dRMFrame3Object::transformVectors(
  566. /* [in] */ I_dxj_Direct3dRMFrame3 __RPC_FAR *reference,
  567. /* [in] */ long num,
  568. /* [out][in] */ SAFEARRAY __RPC_FAR * __RPC_FAR *DstVectors,
  569. /* [out][in] */ SAFEARRAY __RPC_FAR * __RPC_FAR *SrcVectors)
  570. {
  571. HRESULT hr;
  572. DO_GETOBJECT_NOTNULL(LPDIRECT3DRMFRAME3,ref,reference);
  573. if (!reference) ref=NULL;
  574. __try{
  575. hr= m__dxj_Direct3dRMFrame3->TransformVectors(ref,(DWORD)num,
  576. (D3DVECTOR*)((SAFEARRAY*)*DstVectors)->pvData,
  577. (D3DVECTOR*)((SAFEARRAY*)*SrcVectors)->pvData);
  578. }
  579. __except(1,1){
  580. return E_INVALIDARG;
  581. }
  582. return hr;
  583. }
  584. /////////////////////////////////////////////////////////////////////////////
  585. STDMETHODIMP C_dxj_Direct3dRMFrame3Object::inverseTransformVectors(
  586. /* [in] */ I_dxj_Direct3dRMFrame3 __RPC_FAR *reference,
  587. /* [in] */ long num,
  588. /* [out][in] */ SAFEARRAY __RPC_FAR * __RPC_FAR *DstVectors,
  589. /* [out][in] */ SAFEARRAY __RPC_FAR * __RPC_FAR *SrcVectors)
  590. {
  591. HRESULT hr;
  592. DO_GETOBJECT_NOTNULL(LPDIRECT3DRMFRAME3,ref,reference);
  593. __try{
  594. hr= m__dxj_Direct3dRMFrame3->InverseTransformVectors(ref,(DWORD)num,
  595. (D3DVECTOR*)((SAFEARRAY*)*DstVectors)->pvData,
  596. (D3DVECTOR*)((SAFEARRAY*)*SrcVectors)->pvData);
  597. }
  598. __except(1,1){
  599. return E_INVALIDARG;
  600. }
  601. return hr;
  602. }
  603. /////////////////////////////////////////////////////////////////////////////
  604. STDMETHODIMP C_dxj_Direct3dRMFrame3Object::getMaterial(I_dxj_Direct3dRMMaterial2 **ret)
  605. {
  606. HRESULT hr;
  607. IDirect3DRMMaterial2 *lpMat2=NULL;
  608. hr= m__dxj_Direct3dRMFrame3->GetMaterial(&lpMat2);
  609. *ret=NULL;
  610. if FAILED(hr) return hr;
  611. INTERNAL_CREATE(_dxj_Direct3dRMMaterial2, lpMat2, ret);
  612. return hr;
  613. }
  614. /////////////////////////////////////////////////////////////////////////////
  615. STDMETHODIMP C_dxj_Direct3dRMFrame3Object::setMaterial(I_dxj_Direct3dRMMaterial2 *mat)
  616. {
  617. HRESULT hr;
  618. if (mat==NULL)
  619. return m__dxj_Direct3dRMFrame3->SetMaterial(NULL);
  620. DO_GETOBJECT_NOTNULL(LPDIRECT3DRMMATERIAL2,lpMat2,mat);
  621. hr= m__dxj_Direct3dRMFrame3->SetMaterial(lpMat2);
  622. return hr;
  623. }
  624. /////////////////////////////////////////////////////////////////////////////
  625. STDMETHODIMP C_dxj_Direct3dRMFrame3Object::getMaterialOverride(D3dMaterialOverride *override)
  626. {
  627. HRESULT hr;
  628. if (!override) return E_INVALIDARG;
  629. override->lSize=sizeof(D3DRMMATERIALOVERRIDE);
  630. hr= m__dxj_Direct3dRMFrame3->GetMaterialOverride((D3DRMMATERIALOVERRIDE*)override);
  631. if FAILED(hr) return hr;
  632. if (((D3DRMMATERIALOVERRIDE*)override)->lpD3DRMTex)
  633. (((D3DRMMATERIALOVERRIDE*)override)->lpD3DRMTex)->Release();
  634. return hr;
  635. }
  636. /////////////////////////////////////////////////////////////////////////////
  637. STDMETHODIMP C_dxj_Direct3dRMFrame3Object::setMaterialOverride(D3dMaterialOverride *override)
  638. {
  639. HRESULT hr;
  640. if (!override) return E_INVALIDARG;
  641. D3DRMMATERIALOVERRIDE override2;
  642. ZeroMemory(&override2,sizeof(D3DRMMATERIALOVERRIDE));
  643. override->lSize=sizeof(D3DRMMATERIALOVERRIDE);
  644. override2.dwSize=sizeof(D3DRMMATERIALOVERRIDE);
  645. hr= m__dxj_Direct3dRMFrame3->GetMaterialOverride(&override2);
  646. if FAILED(hr) return hr;
  647. ((D3DRMMATERIALOVERRIDE*)override)->lpD3DRMTex=override2.lpD3DRMTex;
  648. hr= m__dxj_Direct3dRMFrame3->SetMaterialOverride((D3DRMMATERIALOVERRIDE*)override);
  649. if (override2.lpD3DRMTex) override2.lpD3DRMTex->Release();
  650. return hr;
  651. }
  652. /////////////////////////////////////////////////////////////////////////////
  653. STDMETHODIMP C_dxj_Direct3dRMFrame3Object::setMaterialOverrideTexture(I_dxj_Direct3dRMTexture3 *tex)
  654. {
  655. HRESULT hr;
  656. D3DRMMATERIALOVERRIDE override2;
  657. ZeroMemory(&override2,sizeof(D3DRMMATERIALOVERRIDE));
  658. override2.dwSize=sizeof(D3DRMMATERIALOVERRIDE);
  659. hr= m__dxj_Direct3dRMFrame3->GetMaterialOverride(&override2);
  660. if FAILED(hr) return hr;
  661. if (override2.lpD3DRMTex) override2.lpD3DRMTex->Release();
  662. override2.lpD3DRMTex=NULL;
  663. DO_GETOBJECT_NOTNULL(LPDIRECT3DRMTEXTURE3,t,tex);
  664. if (!tex) {
  665. hr= m__dxj_Direct3dRMFrame3->SetMaterialOverride(&override2);
  666. }
  667. else {
  668. override2.lpD3DRMTex=t;
  669. override2.lpD3DRMTex->AddRef();
  670. hr= m__dxj_Direct3dRMFrame3->SetMaterialOverride(&override2);
  671. override2.lpD3DRMTex->Release();
  672. }
  673. return hr;
  674. }
  675. /////////////////////////////////////////////////////////////////////////////
  676. STDMETHODIMP C_dxj_Direct3dRMFrame3Object::getMaterialOverrideTexture(I_dxj_Direct3dRMTexture3 **tex)
  677. {
  678. HRESULT hr;
  679. D3DRMMATERIALOVERRIDE override2;
  680. ZeroMemory(&override2,sizeof(D3DRMMATERIALOVERRIDE));
  681. override2.dwSize=sizeof(D3DRMMATERIALOVERRIDE);
  682. hr= m__dxj_Direct3dRMFrame3->GetMaterialOverride(&override2);
  683. if FAILED(hr) return hr;
  684. if (override2.lpD3DRMTex){
  685. INTERNAL_CREATE(_dxj_Direct3dRMTexture3,override2.lpD3DRMTex,tex);
  686. return hr;
  687. }
  688. *tex=NULL;
  689. return S_OK;;
  690. }
  691. STDMETHODIMP C_dxj_Direct3dRMFrame3Object::getVisual(long index,I_dxj_Direct3dRMVisual **ret)
  692. {
  693. HRESULT hr;
  694. DWORD count=0;
  695. IUnknown **ppUnk=NULL;
  696. IDirect3DRMVisual *vis=NULL;
  697. *ret=NULL;
  698. hr=m__dxj_Direct3dRMFrame3->GetVisuals(&count,NULL);
  699. if FAILED(hr) return hr;
  700. if (count==0) return E_INVALIDARG;
  701. ppUnk=(IUnknown**)malloc(sizeof(IUnknown*)*count);
  702. if (!ppUnk) return E_OUTOFMEMORY;
  703. hr=m__dxj_Direct3dRMFrame3->GetVisuals(&count,ppUnk);
  704. if FAILED(hr) goto exitOut;
  705. hr= ppUnk[index]->QueryInterface(IID_IDirect3DRMVisual,(void**)&vis);
  706. if FAILED(hr) goto exitOut;
  707. hr=CreateCoverVisual(vis,ret);
  708. if FAILED(hr) goto exitOut;
  709. exitOut:
  710. for (DWORD i=0;i<count;i++){
  711. if (ppUnk[index]) ppUnk[index]->Release();
  712. }
  713. free(ppUnk);
  714. return hr;
  715. }
  716. STDMETHODIMP C_dxj_Direct3dRMFrame3Object::getVisualCount (long *count)
  717. {
  718. HRESULT hr=m__dxj_Direct3dRMFrame3->GetVisuals((DWORD*)count,NULL);
  719. return hr;
  720. }
  721. STDMETHODIMP C_dxj_Direct3dRMFrame3Object::setSceneFogMethod (long meth)
  722. {
  723. HRESULT hr=m__dxj_Direct3dRMFrame3->SetSceneFogMethod(meth);
  724. return hr;
  725. }
  726. STDMETHODIMP C_dxj_Direct3dRMFrame3Object::getSceneFogMethod (long *meth)
  727. {
  728. HRESULT hr=m__dxj_Direct3dRMFrame3->GetSceneFogMethod((DWORD*)meth);
  729. return hr;
  730. }
  731. /////////////////////////////////////////////////////////////////////////////
  732. extern "C" void __cdecl myFrameMoveCallback3( LPDIRECT3DRMFRAME3 lpf, void *lpArg, D3DVALUE delta)
  733. {
  734. DPF(1,"Entered myFrameMoveCallback3\r\n");
  735. FrameMoveCallback3 *fmcb = (FrameMoveCallback3 *)lpArg;
  736. // note: need to get OUR frame object from the direct frame object, if
  737. // one exists. If not, we have a crisis!
  738. for( C_dxj_Direct3dRMFrame3Object *that = (C_dxj_Direct3dRMFrame3Object *)g_dxj_Direct3dRMFrame3; that ; that = (C_dxj_Direct3dRMFrame3Object *)that->nextobj )
  739. {
  740. DO_GETOBJECT_NOTNULL(LPDIRECT3DRMFRAME3, f, that)
  741. if( f == lpf )
  742. {
  743. if (fmcb->pUser) fmcb->pUser->AddRef();
  744. IUNK(that)->AddRef();
  745. fmcb->c->callbackRMFrameMove(that,fmcb->pUser, delta);
  746. IUNK(that)->Release();
  747. if (fmcb->pUser) fmcb->pUser->Release();
  748. return;
  749. }
  750. }
  751. //
  752. // I didn't create this frame, create a new one
  753. //
  754. C_dxj_Direct3dRMFrame3Object *c=new CComObject<C_dxj_Direct3dRMFrame3Object>;
  755. I_dxj_Direct3dRMFrame3 *Iframe=NULL;
  756. if( c == NULL )
  757. {
  758. lpf->Release();
  759. return;
  760. }
  761. c->InternalSetObject((LPDIRECT3DRMFRAME3)lpf);
  762. if ( fmcb->pParent )
  763. {
  764. c->parent = fmcb->pParent;
  765. fmcb->pParent->AddRef();
  766. }
  767. if (FAILED(((I_dxj_Direct3dRMFrame3*)c)->QueryInterface(IID_I_dxj_Direct3dRMFrame3, (void **)&Iframe)))
  768. {
  769. delete c;
  770. return;
  771. }
  772. c->pinterface = Iframe;
  773. if (fmcb->pUser) fmcb->pUser->AddRef();
  774. IUNK(Iframe)->AddRef();
  775. fmcb->c->callbackRMFrameMove(Iframe, fmcb->pUser, delta);
  776. IUNK(Iframe)->Release();
  777. if (fmcb->pUser) fmcb->pUser->Release();
  778. }