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.
 
 
 
 
 
 

390 lines
14 KiB

  1. /*
  2. ---------------------------------------------------------------------------
  3. Open Asset Import Library (ASSIMP)
  4. ---------------------------------------------------------------------------
  5. Copyright (c) 2006-2010, ASSIMP Development Team
  6. All rights reserved.
  7. Redistribution and use of this software in source and binary forms,
  8. with or without modification, are permitted provided that the following
  9. conditions are met:
  10. * Redistributions of source code must retain the above
  11. copyright notice, this list of conditions and the
  12. following disclaimer.
  13. * Redistributions in binary form must reproduce the above
  14. copyright notice, this list of conditions and the
  15. following disclaimer in the documentation and/or other
  16. materials provided with the distribution.
  17. * Neither the name of the ASSIMP team, nor the names of its
  18. contributors may be used to endorse or promote products
  19. derived from this software without specific prior
  20. written permission of the ASSIMP Development Team.
  21. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  22. "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  23. LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  24. A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  25. OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  26. SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  27. LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  28. DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  29. THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  30. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  31. OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  32. ---------------------------------------------------------------------------
  33. */
  34. using System.Drawing;
  35. using System.Windows.Forms;
  36. using Microsoft.DirectX;
  37. using Microsoft.DirectX.Direct3D;
  38. using System;
  39. namespace Assimp.Viewer
  40. {
  41. partial class AssimpView {
  42. private EClickPos g_eClick = EClickPos.Circle;
  43. private bool g_bMousePressed;
  44. private bool g_bMousePressedR;
  45. private bool g_bMousePressedM;
  46. private bool g_bMousePressedBoth;
  47. private Point g_mousePos;
  48. private Point g_LastmousePos;
  49. private bool g_bInvert;
  50. #if false
  51. //-------------------------------------------------------------------------------
  52. // Handle mouse input for the FPS input behaviour
  53. //
  54. // Movement in x and y axis is possible
  55. //-------------------------------------------------------------------------------
  56. private void HandleMouseInputFPS()
  57. {
  58. Point mousePos;
  59. mousePos = Control.MousePosition;
  60. mousePos = PointToClient(mousePos);
  61. g_mousePos.X = mousePos.X;
  62. g_mousePos.Y = mousePos.Y;
  63. Matrix matRotation;
  64. if (g_bMousePressed)
  65. {
  66. int nXDiff = (g_mousePos.X - g_LastmousePos.X);
  67. int nYDiff = (g_mousePos.Y - g_LastmousePos.Y);
  68. if( 0 != nYDiff)
  69. {
  70. D3DXMatrixRotationAxis( &matRotation, (D3DXVECTOR3*)& g_sCamera.vRight, D3DXToRadian((float)nYDiff / 6.0f));
  71. D3DXVec3TransformCoord( (D3DXVECTOR3*)&g_sCamera.vLookAt, (D3DXVECTOR3*)& g_sCamera.vLookAt, &matRotation );
  72. D3DXVec3TransformCoord( (D3DXVECTOR3*)&g_sCamera.vUp, (D3DXVECTOR3*)&g_sCamera.vUp, &matRotation );
  73. }
  74. if( 0 != nXDiff )
  75. {
  76. D3DXVECTOR3 v(0,1,0);
  77. D3DXMatrixRotationAxis( &matRotation, (D3DXVECTOR3*)&g_sCamera.vUp, D3DXToRadian((float)nXDiff / 6.0f) );
  78. D3DXVec3TransformCoord( (D3DXVECTOR3*)&g_sCamera.vLookAt, (D3DXVECTOR3*)&g_sCamera.vLookAt, &matRotation );
  79. D3DXVec3TransformCoord( (D3DXVECTOR3*)&g_sCamera.vRight,(D3DXVECTOR3*) &g_sCamera.vRight, &matRotation );
  80. }
  81. }
  82. g_LastmousePos.X = g_mousePos.X;
  83. g_LastmousePos.Y = g_mousePos.Y;
  84. }
  85. //-------------------------------------------------------------------------------
  86. // Handle mouse input for the FPS input behaviour
  87. //
  88. // Movement in x and y axis is possible
  89. //-------------------------------------------------------------------------------
  90. void HandleMouseInputTextureView( void )
  91. {
  92. POINT mousePos;
  93. GetCursorPos( &mousePos );
  94. ScreenToClient( GetDlgItem(g_hDlg,IDC_RT), &mousePos );
  95. g_mousePos.X = mousePos.X;
  96. g_mousePos.Y = mousePos.Y;
  97. D3DXMATRIX matRotation;
  98. if (g_bMousePressed)
  99. {
  100. CDisplay::Instance().SetTextureViewOffsetX((float)(g_mousePos.X - g_LastmousePos.X));
  101. CDisplay::Instance().SetTextureViewOffsetY((float)(g_mousePos.Y - g_LastmousePos.Y));
  102. }
  103. g_LastmousePos.X = g_mousePos.X;
  104. g_LastmousePos.Y = g_mousePos.Y;
  105. }
  106. //-------------------------------------------------------------------------------
  107. // handle mouse input for the light rotation
  108. //
  109. // Axes: global x/y axis
  110. //-------------------------------------------------------------------------------
  111. private void HandleMouseInputLightRotate()
  112. {
  113. Point mousePos;
  114. mousePos = Control.MousePosition;
  115. mousePos = PointToClient(mousePos);
  116. g_mousePos.X = mousePos.X;
  117. g_mousePos.Y = mousePos.Y;
  118. if (g_bMousePressedR)
  119. {
  120. int nXDiff = -(g_mousePos.X - g_LastmousePos.X);
  121. int nYDiff = -(g_mousePos.Y - g_LastmousePos.Y);
  122. Vector3 v = new Vector3(1.0f,0.0f,0.0f);
  123. Matrix mTemp;
  124. mTemp = Matrix.RotationAxis(v, Geometry.DegreeToRadian((float)nYDiff / 2.0f));
  125. D3DXMatrixRotationAxis( (D3DXMATRIX*) &mTemp, (D3DXVECTOR3*)&v, D3DXToRadian((float)nYDiff / 2.0f));
  126. Vector3.TransformCoordinate(
  127. D3DXVec3TransformCoord((D3DXVECTOR3*)&g_avLightDirs[0],
  128. (const D3DXVECTOR3*)&g_avLightDirs[0],(const D3DXMATRIX*)&mTemp);
  129. v = aiVector3D(0.0f,1.0f,0.0f);
  130. D3DXMatrixRotationAxis( (D3DXMATRIX*) &mTemp, (D3DXVECTOR3*)&v, D3DXToRadian((float)nXDiff / 2.0f));
  131. D3DXVec3TransformCoord((D3DXVECTOR3*)&g_avLightDirs[0],
  132. (const D3DXVECTOR3*)&g_avLightDirs[0],(const D3DXMATRIX*)&mTemp);
  133. }
  134. }
  135. //-------------------------------------------------------------------------------
  136. // Handle mouse input for movements of the skybox
  137. //
  138. // The skybox can be moved by holding both the left and the right mouse button
  139. // pressed. Rotation is possible in x and y direction.
  140. //-------------------------------------------------------------------------------
  141. void HandleMouseInputSkyBox( void )
  142. {
  143. POINT mousePos;
  144. GetCursorPos( &mousePos );
  145. ScreenToClient( GetDlgItem(g_hDlg,IDC_RT), &mousePos );
  146. g_mousePos.X = mousePos.X;
  147. g_mousePos.Y = mousePos.Y;
  148. aiMatrix4x4 matRotation;
  149. if (g_bMousePressedBoth )
  150. {
  151. int nXDiff = -(g_mousePos.X - g_LastmousePos.X);
  152. int nYDiff = -(g_mousePos.Y - g_LastmousePos.Y);
  153. aiMatrix4x4 matWorld;
  154. if( 0 != nYDiff)
  155. {
  156. aiVector3D v = aiVector3D(1.0f,0.0f,0.0f);
  157. D3DXMatrixRotationAxis( (D3DXMATRIX*) &matWorld, (D3DXVECTOR3*)&v, D3DXToRadian((float)nYDiff / 2.0f));
  158. CBackgroundPainter::Instance().RotateSB(&matWorld);
  159. }
  160. if( 0 != nXDiff)
  161. {
  162. aiMatrix4x4 matWorldOld;
  163. if( 0 != nYDiff)
  164. {
  165. matWorldOld = matWorld;
  166. }
  167. aiVector3D v = aiVector3D(0.0f,1.0f,0.0f);
  168. D3DXMatrixRotationAxis( (D3DXMATRIX*)&matWorld, (D3DXVECTOR3*)&v, D3DXToRadian((float)nXDiff / 2.0f) );
  169. matWorld = matWorldOld * matWorld;
  170. CBackgroundPainter::Instance().RotateSB(&matWorld);
  171. }
  172. }
  173. }
  174. //-------------------------------------------------------------------------------
  175. //-------------------------------------------------------------------------------
  176. void HandleMouseInputLightIntensityAndColor( void )
  177. {
  178. POINT mousePos;
  179. GetCursorPos( &mousePos );
  180. ScreenToClient( GetDlgItem(g_hDlg,IDC_RT), &mousePos );
  181. g_mousePos.X = mousePos.X;
  182. g_mousePos.Y = mousePos.Y;
  183. if (g_bMousePressedM)
  184. {
  185. int nXDiff = -(g_mousePos.X - g_LastmousePos.X);
  186. int nYDiff = -(g_mousePos.Y - g_LastmousePos.Y);
  187. g_fLightIntensity -= (float)nXDiff / 400.0f;
  188. if ((nYDiff > 2 || nYDiff < -2) && (nXDiff < 20 && nXDiff > -20))
  189. {
  190. if (!g_bFPSView)
  191. {
  192. g_sCamera.vPos.Z += nYDiff / 120.0f;
  193. }
  194. else
  195. {
  196. g_sCamera.vPos += (nYDiff / 120.0f) * g_sCamera.vLookAt.Normalize();
  197. }
  198. }
  199. }
  200. return;
  201. }
  202. #endif
  203. //-------------------------------------------------------------------------------
  204. //-------------------------------------------------------------------------------
  205. private void HandleMouseInputLocal()
  206. {
  207. Point mousePos;
  208. mousePos = Control.MousePosition;
  209. mousePos = PointToClient(mousePos);
  210. g_mousePos.X = mousePos.X;
  211. g_mousePos.Y = mousePos.Y;
  212. if (g_bMousePressed)
  213. {
  214. int nXDiff = -(g_mousePos.X - g_LastmousePos.X);
  215. int nYDiff = -(g_mousePos.Y - g_LastmousePos.Y);
  216. Matrix matWorld;
  217. if (g_eClick != EClickPos.Outside)
  218. {
  219. if( 0 != nYDiff && g_eClick != EClickPos.CircleHor)
  220. {
  221. Vector3 v = new Vector3(1.0f,0.0f,0.0f);
  222. matWorld = Matrix.RotationAxis(v, Geometry.DegreeToRadian((float)nYDiff / 2.0f));
  223. g_mWorldRotate = g_mWorldRotate * matWorld;
  224. }
  225. if( 0 != nXDiff && g_eClick != EClickPos.CircleVert)
  226. {
  227. Vector3 v = new Vector3(0.0f,1.0f,0.0f);
  228. matWorld = Matrix.RotationAxis(v, Geometry.DegreeToRadian((float)nXDiff / 2.0f));
  229. g_mWorldRotate = g_mWorldRotate * matWorld;
  230. }
  231. }
  232. else
  233. {
  234. if(0 != nYDiff || 0 != nXDiff)
  235. {
  236. var sRect = new Rectangle(Point.Empty, this.Size);
  237. // rotate around the z-axis
  238. int xPos = g_mousePos.X - sRect.Right/2;
  239. int yPos = g_mousePos.Y - sRect.Bottom/2;
  240. float fXDist = (float)xPos;
  241. float fYDist = (float)yPos / (float)Math.Sqrt(yPos * yPos + xPos * xPos);
  242. bool bSign1;
  243. if (fXDist < 0.0f)bSign1 = false;
  244. else bSign1 = true;
  245. float fAngle = (float)Math.Asin(fYDist);
  246. xPos = g_LastmousePos.X - sRect.Right/2;
  247. yPos = g_LastmousePos.Y - sRect.Bottom/2;
  248. fXDist = (float)xPos;
  249. fYDist = (float)yPos / (float)Math.Sqrt(yPos * yPos + xPos * xPos);
  250. bool bSign2;
  251. if (fXDist < 0.0f)bSign2 = false;
  252. else bSign2 = true;
  253. float fAngle2 = (float)Math.Asin(fYDist);
  254. fAngle -= fAngle2;
  255. if (bSign1 != bSign2)
  256. {
  257. g_bInvert = !g_bInvert;
  258. }
  259. if (g_bInvert)fAngle *= -1.0f;
  260. Vector3 v = new Vector3(0.0f, 0.0f, 1.0f);
  261. matWorld = Matrix.RotationAxis(v, (float)(fAngle * 1.2));
  262. g_mWorldRotate = g_mWorldRotate * matWorld;
  263. }
  264. }
  265. }
  266. g_LastmousePos.X = g_mousePos.X;
  267. g_LastmousePos.Y = g_mousePos.Y;
  268. }
  269. #if false
  270. //-------------------------------------------------------------------------------
  271. //-------------------------------------------------------------------------------
  272. void HandleKeyboardInputFPS( void )
  273. {
  274. unsigned char keys[256];
  275. GetKeyboardState( keys );
  276. aiVector3D tmpLook = g_sCamera.vLookAt;
  277. aiVector3D tmpRight = g_sCamera.vRight;
  278. aiVector3D vOldPos = g_sCamera.vPos;
  279. // Up Arrow Key - View moves forward
  280. if( keys[VK_UP] & 0x80 )
  281. g_sCamera.vPos -= (tmpLook*-MOVE_SPEED)*g_fElpasedTime;
  282. // Down Arrow Key - View moves backward
  283. if( keys[VK_DOWN] & 0x80 )
  284. g_sCamera.vPos += (tmpLook*-MOVE_SPEED)*g_fElpasedTime;
  285. // Left Arrow Key - View side-steps or strafes to the left
  286. if( keys[VK_LEFT] & 0x80 )
  287. g_sCamera.vPos -= (tmpRight*MOVE_SPEED)*g_fElpasedTime;
  288. // Right Arrow Key - View side-steps or strafes to the right
  289. if( keys[VK_RIGHT] & 0x80 )
  290. g_sCamera.vPos += (tmpRight*MOVE_SPEED)*g_fElpasedTime;
  291. // Home Key - View elevates up
  292. if( keys[VK_HOME] & 0x80 )
  293. g_sCamera.vPos .Y += MOVE_SPEED*g_fElpasedTime;
  294. // End Key - View elevates down
  295. if( keys[VK_END] & 0x80 )
  296. g_sCamera.vPos.Y -= MOVE_SPEED*g_fElpasedTime;
  297. }
  298. //-------------------------------------------------------------------------------
  299. //-------------------------------------------------------------------------------
  300. void HandleKeyboardInputTextureView( void )
  301. {
  302. unsigned char keys[256];
  303. GetKeyboardState( keys );
  304. // Up Arrow Key
  305. if( keys[VK_UP] & 0x80 )
  306. CDisplay::Instance().SetTextureViewOffsetY ( g_fElpasedTime * 150.0f );
  307. // Down Arrow Key
  308. if( keys[VK_DOWN] & 0x80 )
  309. CDisplay::Instance().SetTextureViewOffsetY ( -g_fElpasedTime * 150.0f );
  310. // Left Arrow Key
  311. if( keys[VK_LEFT] & 0x80 )
  312. CDisplay::Instance().SetTextureViewOffsetX ( g_fElpasedTime * 150.0f );
  313. // Right Arrow Key
  314. if( keys[VK_RIGHT] & 0x80 )
  315. CDisplay::Instance().SetTextureViewOffsetX ( -g_fElpasedTime * 150.0f );
  316. }
  317. };
  318. #endif
  319. }
  320. }