Camera.cpp
上传用户:hkb425
上传日期:2007-06-16
资源大小:34191k
文件大小:2k
源码类别:

游戏引擎

开发平台:

Visual C++

  1. // Camera.cpp: implementation of the CCamera class.
  2. //
  3. //////////////////////////////////////////////////////////////////////
  4. #include "stdafx.h"
  5. #include "Camera.h"
  6. //////////////////////////////////////////////////////////////////////
  7. // Construction/Destruction
  8. //////////////////////////////////////////////////////////////////////
  9. CCamera::CCamera()
  10. {
  11.     m_CamPos=VERTEX(10,0,10);
  12.     m_CamDirection=NORMAL(1,0,0);
  13. m_CamRotX=0;
  14. m_CamRotY=-90;
  15. m_CamRotZ=0;
  16. m_VisualAngle=60;
  17. }
  18. CCamera::~CCamera()
  19. {
  20. }
  21. void CCamera::UpdateCamera(VERTEX position,float rotX,float rotY,float rotZ)
  22. {
  23.     m_CamPos=position;
  24. m_CamRotX=rotX;
  25. m_CamRotY=rotY;
  26. m_CamRotZ=rotZ;
  27. m_CamDirection=NORMAL(-cosf(rotX*0.0174533f)*sinf(rotY*0.0174533f),
  28.                   sinf(rotX*0.0174533f),
  29.   -cosf(rotX*0.0174533f)*cosf(rotY*0.0174533f));
  30. m_CamDirection=math.Normalization(m_CamDirection);
  31. }
  32. void CCamera::UpdateCamera(VERTEX newFoucs)
  33. {
  34. m_CamDirection=NORMAL(newFoucs.xpos-m_CamPos.xpos,newFoucs.ypos-m_CamPos.ypos,newFoucs.zpos-m_CamPos.zpos);
  35. m_CamDirection=math.Normalization(m_CamDirection);
  36. m_CamRotX=asinf(m_CamDirection.ny)*57.29578f;
  37. m_CamRotY=acosf(-m_CamDirection.nz/(sqrt(m_CamDirection.nz*m_CamDirection.nz+m_CamDirection.nx*m_CamDirection.nx)))*57.29578f;
  38. // m_CamRotY=float(57.29583f*acos(-m_CamDirection.nz/(sqrt(m_CamDirection.nz*m_CamDirection.nz+m_CamDirection.nx*m_CamDirection.nx))));
  39. if(m_CamDirection.nx>0)m_CamRotY=360-m_CamRotY;
  40. }
  41. void CCamera::SetVisualAngle(float visualAngle)
  42. {
  43. m_VisualAngle=visualAngle;
  44. }
  45. float CCamera::GetAngleCosine(VERTEX point)
  46. {
  47.     float cosValue=math.GetTwoVectorAngleCosine(NORMAL(point.xpos-m_CamPos.xpos,
  48.                                  point.ypos -m_CamPos.ypos,
  49.  point.zpos-m_CamPos.zpos ) , 
  50.  m_CamDirection);
  51. if(cosValue>cosf(m_VisualAngle*0.0174533f))
  52. {
  53. return cosValue;
  54. }
  55.     return 0;
  56. }
  57. bool CCamera::IsOnFoucs(VERTEX point)
  58. {
  59.     return false;
  60. }