// K3DCamera.h: interface for the K3DCamera class. // ////////////////////////////////////////////////////////////////////// #if !defined(AFX_K3DCAMERA_H__87E8A41E_F986_4EB7_91BC_81EC2F3D414F__INCLUDED_) #define AFX_K3DCAMERA_H__87E8A41E_F986_4EB7_91BC_81EC2F3D414F__INCLUDED_ #if _MSC_VER > 1000 #pragma once #endif // _MSC_VER > 1000 #include "K3DTypes.h" //#include "K3DFrustum.h" class KViewportObject; //class K3DRenderDeviceDX; /** K3DCamera class Description - This class sets view matrix and projection matrix to viewport when render is called. - Support pan (like side step), turn, elavation (vertical turn), zoom. - Need to call the Initialize Function before using this class. */ class K3DCamera { public: K3DCamera(); ~K3DCamera(); /// Reset Camera Status. /** fov : 24 degree, near : 100, far : 50000 \n distance from target : 1500 , elvation : 1.57 / 2.0 (radian) - 45 degree \n Cam Pos x,y,z = {0, 1500 * sin45 degree, 1500 * cos45 degree} \n Target Pos = {0,0,0} Up Vector = { 0, 0 , 1} \n */ void Reset(); /// Initialize Camera void Initialize( float fov) { m_fFOV = fov; } void SetFOV( float fov ) { m_fFOV = fov; } float GetFOV() const { return m_fFOV; } void SetCoordinateToRightHand() { m_bIsRightHandCoordinate = true; } void SetCoordinateToLeftHand() { m_bIsRightHandCoordinate = false; } bool IsCoordinateRightHand() const { return m_bIsRightHandCoordinate; } bool IsCoordinateLeftHand() const { return !m_bIsRightHandCoordinate; } void SetCameraPerspectiveMode() { m_bIsPerspective = true; } void SetCameraOrthogonalMode() { m_bIsPerspective = false; } bool IsCameraPerspectiveMode() const { return m_bIsPerspective; } bool IsCameraOrthogonalMode() const { return !m_bIsPerspective; } K3DVector GetCamPos() const { return K3DVector( m_fXPos, m_fYPos, m_fZPos ); } void GetCamPos(float &x,float &y,float &z ) const { x = m_fXPos; y = m_fYPos; z = m_fZPos; } K3DVector GetCamOrgPos() const { return K3DVector( m_fOrgXPos, m_fOrgYPos, m_fOrgZPos ); } void GetCamOrgPos(float &x,float &y,float &z ) const { x = m_fOrgXPos; y = m_fOrgYPos; z = m_fOrgZPos; } K3DVector GetTargetPos() const { return K3DVector( m_fTXPos, m_fTYPos, m_fTZPos ); } void GetTargetPos(float &x,float &y,float &z ) const { x= m_fTXPos; y = m_fTYPos; z = m_fTZPos; } void SetCamPos( float x, float y, float z ) { m_fXPos = x; m_fYPos = y; m_fZPos = z; m_fOrgXPos = m_fXPos; m_fOrgYPos = m_fYPos; m_fOrgZPos = m_fZPos; } void SetCurCamPos( float x, float y, float z ) { m_fXPos = x; m_fYPos = y; m_fZPos = z; // m_fOrgXPos = m_fXPos; m_fOrgYPos = m_fYPos; m_fOrgZPos = m_fZPos; } void SetOrgCamPos( float x, float y, float z ) { m_fOrgXPos = x; m_fOrgYPos = y; m_fOrgZPos = z; } void SetCurCamPos(float fRatio) { if(fRatio <= 0.0f || fRatio > 1.0f) return; K3DVector vres; K3DVector v1(m_fTXPos, m_fTYPos, m_fTZPos); K3DVector v2(m_fOrgXPos, m_fOrgYPos, m_fOrgZPos); vres = v1 + (v2 - v1) * fRatio; m_fXPos = vres.x; m_fYPos = vres.y; m_fZPos = vres.z; } void SetTargetPos( float x, float y, float z ) { m_fTXPos = x; m_fTYPos = y; m_fTZPos = z; } /// Set Panning(like side move) /** Camera Pos = Vc, Target Pos = Vt, Argument Pos = Va \n Diff Vector Vd = Va - Vt, and new Vc = Vc + Vd \n Setting Vt = Va \n */ void SetPan( float x, float y, float z ) { float dx = x - m_fTXPos; float dy = y - m_fTYPos; float dz = z - m_fTZPos; m_fXPos += dx; m_fYPos += dy; m_fZPos += dz; m_fOrgXPos += dx; m_fOrgYPos += dy; m_fOrgZPos += dz; m_fTXPos = x; m_fTYPos = y; m_fTZPos = z; } /// Get View matrix from Cam Pos, Target Pos /** @return K3DMatrix Pointer which denote View Matrix. */ K3DMatrix *GetViewMatrix(); //K3DMatrix *GetProjMatrix(); void Point(float fXPos, float fYPos, float fZPos, float fTXPos, float fTYPos, float fTZPos); /// Set Elavation (Vetical Turn) /** @param fAngle Radian Unit. This function will cause a problem if the value of fAngle becomes larger than \n (1.57) 90 degrees.\n (Because UPVector and SideVector going to be same direction.) \n */ void Elevation(float fAngle); /// Set Turn (Horizontal Turn) /** @param fAngle Radian Unit. */ void Turn(float fAngle); /// Pannig Camera /** @param dx,dy,dz : How you can get these panning arguments? Some preprocessing is needed. See the below! \n \n K3DVector vtView = m_pCamera->GetViewVector(); \n K3DVector vtUp = m_pCamera->GetUpVector(); \n K3DVector vtRes = CrossProduct(vtView, vtUp); // Get Side Vector. \n Normalize(vtRes); \n vtUp = CrossProduct(vtRes, vtView); // Get appropriate UpVector. \n Normalize(vtUp); \n If you need horizontal pannig, use vtRes. \n else if you need vertical panning, use vtUp. \n */ void Pan(float dx, float dy, float dz); /// 2010.11.11 카메라 방향에 맞게 - prodongi void PanWithCamDir(float dx, float dy, float dz); /// Zoom Camera /** @param dist : The camera's distance will be descreased by dist value. And cam pos changed too. */ void Zoom(float dist); /// Get Camera's view vector ( Target Pos - Cam Pos) /** @return Normalized Vt - Vc. */ K3DVector GetViewVector() const { K3DVector vtView = K3DVector(m_fTXPos - m_fXPos, m_fTYPos - m_fYPos, m_fTZPos - m_fZPos); Normalize(vtView); return vtView; } K3DVector GetOrgViewVector() const { K3DVector vtView = K3DVector(m_fTXPos - m_fOrgXPos, m_fTYPos - m_fOrgYPos, m_fTZPos - m_fOrgZPos); Normalize(vtView); return vtView; } K3DVector GetUpVector() const { return m_dxvtUp; } void SetUpVector(float x, float y, float z) { m_dxvtUp = K3DVector(x,y,z); } /// Get Distance between Cam Pos and Target Pos. /** @return ||Vt - Vc|| + 0.5f */ float GetDistance() { m_fDistance = sqrtf( powf(m_fXPos - m_fTXPos, 2) + powf(m_fYPos - m_fTYPos, 2) + powf(m_fZPos - m_fTZPos,2) ) + .5f; return m_fDistance; } /// Render this camera. /** * It will set view Matrix and projection Matrix to viewport. */ //void Render( KViewportObject *viewport, bool bOffSet = false ); /// Get two vertex from near clip point and far clip point. /*! Compute line which is linked from near clip to far clip. @param srcx, srcy (in) : Screen coordinate. @param vNear (out) : 3D point in near clipping plane. @param vFar (out) : 3D point in far clipping plane. */ //void GetLineFromScreen( KViewportObject* pViewport, int scrx, int scry, K3DVector *vNear, K3DVector *vFar ) const; //void GetScreenPosition( KViewportObject* pViewport, const K3DVector & vWorldPos, int *pPosX, int *pPosY); //void GetFrustumCube( KViewportObject* pViewport, const KViewportStruct& rViewPort, int nMarginX, int nMarginY, K3DVertex* pFrustumCube ) const; // void SetMinDistance( float fMinDistance ) { m_fMinDistance = fMinDistance; m_bUseMinDistance=true; } //K3DVector* GetFrustum(KViewportObject* pViewport); void FileTextOut( FILE* pF ); void FileTextIn( char *pBuf ); private: //void _MakeFrustum(KViewportObject* pViewport); //K3DFrustum m_Frustum; bool m_bIsRightHandCoordinate; bool m_bIsPerspective; float m_fFOV; float m_fXPos, m_fYPos, m_fZPos; float m_fOrgXPos, m_fOrgYPos, m_fOrgZPos; float m_fTXPos, m_fTYPos, m_fTZPos; float m_fZoomDelta; K3DVector m_dxvtUp; float m_fElavation; float m_fTurn; float m_fDistance; bool m_bUseMinDistance; float m_fMinDistance; K3DMatrix m_MatView; // K3DMatrix m_matProjection; K3DMatrix m_OffSetMatView; K3DVALUE m_fValue; ///< 제한 각 }; #endif // !defined(AFX_K3DCAMERA_H__87E8A41E_F986_4EB7_91BC_81EC2F3D414F__INCLUDED_)