Forum |  HardWare.fr | News | Articles | PC | S'identifier | S'inscrire | Shop Recherche
817 connectés 

  FORUM HardWare.fr
  Programmation
  C++

  Effect de camera en 3D Simulation [plz help]

 

Sujet(s) à lire :
 

 Mot :   Pseudo :  
 
Bas de page
Auteur Sujet :

Effect de camera en 3D Simulation [plz help]

n°935762
nimo
New.Internet.Master.Operator
Posté le 03-01-2005 à 15:05:16  profilanswer
 

Salut
Je fais une simulation en 3d, j'ai mis en place 3 different camera, the boutton S fais avancer mon caracter ds la simulation, je voudrai aussi que les 3 camera change un par un quand le caracter avance ?
 
Es ce que vous pouvai m'aider please ?
 
Peu etre une loop avec les 3 cameras, quand la person appui sur S ca fais avancer le caracter mais aussi changes un par un les vue de camera (je voudrai faire cela pour montrer que le caracter marche)
 
Voici le code:
 

Code :
  1. #define SHOULDER 0
  2. #define SIDE 1
  3. #define TOP 2
  4. ....
  5. void SetShoulderCamera()
  6. {
  7. float distz=50,disty=20;
  8. DXUMatrixLookAtRH(&matCamera1, &DXUVECTOR3D
  9.   (
  10.   car.x-(car.matrix(2,0)*distz)+(car.matrix(1,0)*disty),
  11.   car.y-(car.matrix(2,1)*distz)+(car.matrix(1,1)*disty),
  12.   car.z-(car.matrix(2,2)*distz)+(car.matrix(1,2)*disty)
  13.   ),
  14.             &DXUVECTOR3D(car.x, car.y,car.z ),    &DXUVECTOR3D( car.matrix(1,0), car.matrix(1,1),car.matrix(1,2) ));
  15. DXUSetDeviceCameraMatrix(&matCamera1);
  16. vLookatPt.x=car.x; vLookatPt.y=car.y; vLookatPt.z=car.z;
  17. vEyePt.x= car.x-(car.matrix(2,0)*distz)+(car.matrix(1,0)*disty);
  18. vEyePt.y= car.y-(car.matrix(2,1)*distz)+(car.matrix(1,1)*disty);
  19. vEyePt.z= car.z-(car.matrix(2,2)*distz)+(car.matrix(1,2)*disty);
  20. }
  21. void SetTopCamera()
  22. {
  23. float disty=990,distx=100;
  24. DXUMatrixLookAtRH(&matCamera1, &DXUVECTOR3D
  25.   (
  26.   car.x+(car.matrix(1,0)*disty),
  27.   car.y+(car.matrix(1,1)*disty),
  28.   car.z+(car.matrix(1,2)*disty)
  29.   ),
  30.             &DXUVECTOR3D(car.x, car.y,car.z ),       &DXUVECTOR3D( car.matrix(2,0), car.matrix(2,1),car.matrix(2,2) ));
  31. DXUSetDeviceCameraMatrix(&matCamera1);
  32. vLookatPt.x=car.x; vLookatPt.y=car.y; vLookatPt.z=car.z;
  33. vEyePt.x= car.x-(car.matrix(2,0)*disty)+(car.matrix(1,0)*distx);
  34. vEyePt.y= car.y-(car.matrix(2,1)*disty)+(car.matrix(1,1)*distx);
  35. vEyePt.z= car.z-(car.matrix(2,2)*disty)+(car.matrix(1,2)*distx);
  36. }
  37. void SetSideCamera()
  38. {
  39. float disty=50,distx=100;
  40. DXUMatrixLookAtRH(&matCamera1,&DXUVECTOR3D
  41.   (
  42.   car.x+(car.matrix(0,0)*distx)+(car.matrix(1,0)*disty),
  43.   car.y+(car.matrix(0,1)*distx)+(car.matrix(1,1)*disty),
  44.   car.z+(car.matrix(0,2)*distx)+(car.matrix(1,2)*disty)
  45.   ),
  46.             &DXUVECTOR3D(car.x, car.y,car.z ),    &DXUVECTOR3D( car.matrix(1,0), car.matrix(1,1),car.matrix(1,2) ));
  47. DXUSetDeviceCameraMatrix(&matCamera1);
  48. vLookatPt.x=car.x; vLookatPt.y=car.y; vLookatPt.z=car.z;
  49. vEyePt.x= car.x-(car.matrix(2,0)*disty)+(car.matrix(1,0)*distx);
  50. vEyePt.y= car.y-(car.matrix(2,1)*disty)+(car.matrix(1,1)*distx);
  51. vEyePt.z= car.z-(car.matrix(2,2)*disty)+(car.matrix(1,2)*distx);
  52. }
  53. ...............
  54. VOID UpdateWorld()
  55. {
  56. ...
  57. static camera =SHOULDER;
  58. ...
  59. if( dxuKeyState[DIK_A])
  60. {
  61.  car.Advance();
  62. // camera =SHOULDER;
  63. // camera =TOP;
  64. // camera =SIDE;
  65.  for( i=0;i<ARRAYSIZE;i++)
  66.  {
  67.   for( j=0;j<ARRAYSIZE;j++)
  68.   {
  69.    if (OverlayMap[i][j]!=0)
  70.    {
  71.     if(collider.SimpleCollision(20,car.x,car.y,car.z,i*45,0,j*45))
  72.     {
  73.            car.Reverse();
  74.     }
  75.    }
  76.   }
  77.  }
  78. }
  79. if( dxuKeyState[DIK_S])
  80. {
  81.  car.Reverse();
  82.  for( i=0;i<ARRAYSIZE;i++)
  83.  {
  84.   for( j=0;j<ARRAYSIZE;j++)
  85.   {
  86.    if (OverlayMap[i][j]!=0)
  87.    {
  88.     if(collider.SimpleCollision(20,car.x,car.y,car.z,i*45,0,j*45))
  89.     {
  90.      car.Advance();
  91.     }
  92.    }
  93.   }
  94.  }
  95. }
  96. if(dxuKeyState[DIK_F1])
  97. {
  98.  camera=SIDE;
  99. }
  100. if(dxuKeyState[DIK_F2])
  101. {
  102.  camera=TOP;
  103. }
  104.  if(dxuKeyState[DIK_F3])
  105. {
  106.  camera=SHOULDER;
  107. }
  108. ...
  109. switch (camera)
  110. {
  111.  case 0:{
  112.   SetShoulderCamera();
  113.   break;
  114.  }
  115.  case 1:{
  116.   SetSideCamera();
  117.   break;
  118.  }
  119.  case 2:{
  120.   SetTopCamera();
  121.   break;
  122.  }
  123. }
  124. }


 
Merci d'avance


---------------
NEC 3500 | YAMADA 6600 | NIMO_CORP
mood
Publicité
Posté le 03-01-2005 à 15:05:16  profilanswer
 

n°935764
FlorentG
Unité de Masse
Posté le 03-01-2005 à 15:05:47  profilanswer
 

:pt1cable:

n°935772
nimo
New.Internet.Master.Operator
Posté le 03-01-2005 à 15:10:45  profilanswer
 

je ne voulai pas mettre tout le code car c'est long et encore plus complex, mais ce qui concerne ma question, tous devrai etre ici.
 
Je voudrai que quand mon caracter avance, les camera change de vue un par un, comme ca on dirai vraiment que le caracter advance sinon si la camera reste la meme, ca ne fais pas trop comme un simulation d'une persone qui marche, faudrai que le caracter marche mais la vue change aussi en meme temps...
 
please help me guys


---------------
NEC 3500 | YAMADA 6600 | NIMO_CORP
n°935856
bjone
Insert booze to continue
Posté le 03-01-2005 à 16:28:35  profilanswer
 

je comprends pas.
 
tu veux faire un changement de caméra extérieure à la Alone In  The Dark, style tu as un jeu de points de vue et tu sélectionne le plus approprié ?


Message édité par bjone le 03-01-2005 à 16:28:43
n°935878
nimo
New.Internet.Master.Operator
Posté le 03-01-2005 à 16:43:17  profilanswer
 

merci de ta reponse:
 
je voudrai juste changer la vue de camera a chaque fois que la person apuis sur S (pour avancer)
 
j'ai mis en place 3 camera et je voudrai que chaque camera se montre un par un au lieu d'avoir juste une camera, c'est pour faire un effect plus reel, comme une persone qui marche, les trois camera sont devant la persone, on ne voit pas la persone mais la camera est comme la vue de la persone, comme ds doom ou quake, on ne voix pas la persone mais la camera fais comme si la persone regarde ds le monde
 
es ce que c'est un peu plus clair ?
 
aidez moi


---------------
NEC 3500 | YAMADA 6600 | NIMO_CORP
n°935981
Rits75
to?be:!be
Posté le 03-01-2005 à 18:34:27  profilanswer
 

a mon avis tu es pas sur la bonne piste!!
une seul camera suffit!
c'est la camera qu'il faut deplacer et pas simuler un deplacement par un "chainage de cam"!
 
j'ai fais un truk du genre, tu peux te deplacer (avant, arriere, droite, gauche) et regarder (bouge la cam sur elle meme)!
maintenant pour le code
j'ai fé une classe cam (inspiré par divers exemple)
je t'en fé part si elle pe t'aider!
 

Code :
  1. /*---------------------------------------------------------------------*/
  2. /* Camera()                               */
  3. /*---------------------------------------------------------------------*/
  4. ClsCamera::ClsCamera()
  5. {
  6. atVector = D3DXVECTOR3( 0, 0, 1 );
  7. upVector = D3DXVECTOR3( 0, 1, 0 );
  8. position = D3DXVECTOR3( 0, 0, 0 );
  9. D3DXMatrixIdentity( &matrixProjection );
  10. }
  11. /*---------------------------------------------------------------------*/
  12. /* Camera(int X, int Y, int Z)                     */
  13. /*---------------------------------------------------------------------*/
  14. ClsCamera::ClsCamera(D3DXVECTOR3 _atVector, D3DXVECTOR3 _upVector, D3DXVECTOR3 _position)
  15. {
  16. atVector = _atVector;
  17. upVector = _atVector;
  18. position = _position;
  19. D3DXMatrixIdentity( &matrixProjection );
  20. }
  21. /*---------------------------------------------------------------------*/
  22. /* Camera()                               */
  23. /*---------------------------------------------------------------------*/
  24. ClsCamera::~ClsCamera()
  25. {
  26. }
  27. /*---------------------------------------------------------------------*/
  28. /* SetProjectionMatrix                         */
  29. /*---------------------------------------------------------------------*/
  30. void ClsCamera::SetProjectionMatrix(D3DXMATRIX *matrix)
  31. {
  32. matrixProjection = *matrix;
  33. }
  34. /*---------------------------------------------------------------------*/
  35. /* MovePosition                             */
  36. /*---------------------------------------------------------------------*/
  37. void ClsCamera::MovePosition( D3DXVECTOR3 *positionDelta )
  38. {
  39. D3DXMATRIX matTrans;
  40. D3DXMatrixTranslation( &matTrans, positionDelta->x, positionDelta->y, positionDelta->z );
  41. D3DXVec3TransformCoord( &position, &position, &matTrans );
  42. }
  43. /*---------------------------------------------------------------------*/
  44. /* SetPosition()                             */
  45. /*---------------------------------------------------------------------*/
  46. void ClsCamera::SetPosition( D3DXVECTOR3 *positionNew )
  47. {
  48. position = *positionNew;
  49. }
  50. /*---------------------------------------------------------------------*/
  51. /* SetUp                                */
  52. /*---------------------------------------------------------------------*/
  53. void ClsCamera::SetUp( D3DXVECTOR3 *upNew )
  54. {
  55. D3DXVec3Normalize(&upVector, upNew);
  56. }
  57. /*---------------------------------------------------------------------*/
  58. /* SetLookAt()                              */
  59. /*---------------------------------------------------------------------*/
  60. void ClsCamera::SetLookAt( D3DXVECTOR3 *lookAtNew )
  61. {
  62. D3DXVec3Subtract( &atVector, lookAtNew, &position );
  63. D3DXVec3Normalize(&atVector, &atVector);
  64. }
  65. /*---------------------------------------------------------------------*/
  66. /* SetAt()                                 */
  67. /*---------------------------------------------------------------------*/
  68. void ClsCamera::SetAt( D3DXVECTOR3 *atNew )
  69. {
  70. D3DXVec3Normalize(&atVector, atNew);
  71. }
  72. /*---------------------------------------------------------------------*/
  73. /* SetRotation()                              */
  74. /*---------------------------------------------------------------------*/
  75. void ClsCamera::SetRotation( float rX, float rY, float rZ )
  76. {
  77. D3DXMATRIX matrixRotateX, matrixRotateY, matrixRotateZ;
  78. D3DXMatrixRotationX( &matrixRotateX, rX );
  79. D3DXMatrixRotationY( &matrixRotateY, rY );
  80. D3DXMatrixRotationZ( &matrixRotateZ, rZ );
  81. D3DXMATRIX matrixRotation;
  82. D3DXMatrixIdentity( &matrixRotation );
  83. D3DXMatrixMultiply( &matrixRotation, &matrixRotation, &matrixRotateX );
  84. D3DXMatrixMultiply( &matrixRotation, &matrixRotation, &matrixRotateY );
  85. D3DXMatrixMultiply( &matrixRotation, &matrixRotation, &matrixRotateZ );
  86. atVector = D3DXVECTOR3( 0, 0, 1 );
  87. upVector = D3DXVECTOR3( 0, 1, 0 );
  88. D3DXVec3TransformNormal( &atVector, &atVector, &matrixRotation );
  89. D3DXVec3TransformNormal( &upVector, &upVector, &matrixRotation );
  90. D3DXVec3Normalize(&atVector, &atVector);
  91. D3DXVec3Normalize(&upVector, &upVector);
  92. }
  93. /*---------------------------------------------------------------------*/
  94. /* GetPosition                             */
  95. /*---------------------------------------------------------------------*/
  96. void ClsCamera::GetPosition( D3DXVECTOR3 *pos )
  97. {
  98. *pos = position;
  99. }
  100. /*---------------------------------------------------------------------*/
  101. /* GetAt()                                 */
  102. /*---------------------------------------------------------------------*/
  103. void ClsCamera::GetAt( D3DXVECTOR3 *at )
  104. {
  105. *at = atVector;
  106. }
  107. /*---------------------------------------------------------------------*/
  108. /* Camera()                               */
  109. /*---------------------------------------------------------------------*/
  110. void ClsCamera::GetUp( D3DXVECTOR3 *up )
  111. {
  112. *up = upVector;
  113. }
  114. /*---------------------------------------------------------------------*/
  115. /* GetRight()                              */
  116. /*---------------------------------------------------------------------*/
  117. void ClsCamera::GetRight( D3DXVECTOR3 *right )
  118. {
  119. D3DXVec3Cross( right, &atVector, &upVector );
  120. }
  121. /*---------------------------------------------------------------------*/
  122. /* GetViewMatrix()                            */
  123. /*---------------------------------------------------------------------*/
  124. void ClsCamera::GetViewMatrix(D3DXMATRIX *matrix)
  125. {
  126. D3DXVECTOR3 lookAtTarget;
  127. D3DXVec3Add( &lookAtTarget, &position, &atVector );
  128. D3DXMatrixLookAtLH( matrix, &position, &lookAtTarget, &upVector );
  129. }
  130. /*---------------------------------------------------------------------*/
  131. /* Activate()                              */
  132. /*---------------------------------------------------------------------*/
  133. void ClsCamera::Activate( LPDIRECT3DDEVICE9 d3dDevice )
  134. {
  135. D3DXMATRIX matrixView;
  136. GetViewMatrix( &matrixView );
  137.   d3dDevice->SetTransform( D3DTS_VIEW, &matrixView );
  138.   d3dDevice->SetTransform( D3DTS_PROJECTION, &matrixProjection );
  139. }


 
maintenant comment je m'en sers!

Code :
  1. BOOL CMNTDlg::PreTranslateMessage(MSG* pMsg)
  2. {
  3. static float cameraRotationX = .059f;
  4. static float cameraRotationY = 1.3462f;
  5. float distance = 0; float strafe = 0;
  6.  if(pMsg->message == WM_KEYDOWN)
  7.   {
  8.   FLOAT fAppTime        = DXUtil_Timer( TIMER_GETAPPTIME );
  9.       FLOAT fElapsedAppTime = DXUtil_Timer( TIMER_GETELAPSEDTIME );
  10.   switch(pMsg->wParam)
  11.    {
  12.    case VK_UP :
  13.     {
  14.     if(cameraRotationX > -D3DX_PI/2 )
  15.        cameraRotationX -= fElapsedAppTime;
  16.              //this->Render();
  17.     break;
  18.     }
  19.    case VK_DOWN :
  20.     {
  21.     if(cameraRotationX < D3DX_PI/2 )
  22.        cameraRotationX += fElapsedAppTime;
  23.        //this->Render();
  24.     break;
  25.     }
  26.    case VK_LEFT :
  27.     {
  28.     cameraRotationY -= fElapsedAppTime;
  29.     //this->Render();
  30.     break;
  31.     }
  32.    case VK_RIGHT:
  33.     {
  34.     cameraRotationY += fElapsedAppTime;
  35.     //this->Render();
  36.     break;
  37.     }
  38.    }
  39.   D3DXVECTOR3 at;
  40.   Camera->GetAt(&at);
  41.   D3DXVec3Scale( &at, &at, distance);
  42.   D3DXVECTOR3 right;
  43.   Camera->GetRight(&right);
  44.   D3DXVec3Scale( &right, &right, strafe);
  45.   Camera->MovePosition(&at);
  46.   Camera->MovePosition(&right);
  47.   Camera->SetRotation(cameraRotationX, cameraRotationY, 0);
  48.   this->Render();
  49.   }
  50.  if(pMsg->message == WM_CHAR)
  51.   {
  52.   FLOAT fAppTime        = DXUtil_Timer(TIMER_GETAPPTIME);
  53.       FLOAT fElapsedAppTime = DXUtil_Timer(TIMER_GETELAPSEDTIME);
  54.   switch(pMsg->wParam)
  55.    {
  56.    case 'z' :  //AVANT
  57.     {
  58.      distance = 500*fElapsedAppTime;
  59.           //this->Render();
  60.     break;
  61.     }
  62.    case 's' :  //ARRIERE
  63.     {
  64.       distance = -500*fElapsedAppTime;
  65.     //this->Render();
  66.     break;
  67.     }
  68.    case 'q' :  //GAUCHE
  69.     {
  70.     strafe = 500*fElapsedAppTime;
  71.     //this->Render();
  72.     break;
  73.     }
  74.    case 'd':   //DROIT
  75.     {
  76.     strafe = -500*fElapsedAppTime;
  77.     //this->Render();
  78.     break;
  79.     }
  80.    }
  81.   D3DXVECTOR3 at;
  82.   Camera->GetAt(&at);
  83.   D3DXVec3Scale( &at, &at, distance);
  84.   D3DXVECTOR3 right;
  85.   Camera->GetRight(&right);
  86.   D3DXVec3Scale( &right, &right, strafe);
  87.   Camera->MovePosition(&at);
  88.   Camera->MovePosition(&right);
  89.   Camera->SetRotation(cameraRotationX, cameraRotationY, 0);
  90.   this->Render();
  91.   }
  92. return CDialog::PreTranslateMessage(pMsg);
  93. }


 
bon la gestion des touches c'est pas super bien codé ;) je fé ca a l'arrache aussi ;)
mais je v corrigé, en attendant ca fonctionne ;)
voila si ca peut t'aider!
 


Aller à :
Ajouter une réponse
  FORUM HardWare.fr
  Programmation
  C++

  Effect de camera en 3D Simulation [plz help]

 

Sujets relatifs
help: probleme de fonction .h en C[php]preg_replace et limite | help me and get a free cookie
Pro*c/c++ Help !!!Help
HELP[HELP] utilisation ID et IDREF
[HELP] License Visual Basic 6Presentation de site en fenetre, help !
calibration de caméra avec openCV 
Plus de sujets relatifs à : Effect de camera en 3D Simulation [plz help]


Copyright © 1997-2022 Hardware.fr SARL (Signaler un contenu illicite / Données personnelles) / Groupe LDLC / Shop HFR