 
/*=========================================================================*/
/* DEVVp3D.hpp :	Viewport 3D.*/
/* This is a part of the PCA project.*/
/**/
/* Version			1.0*/
/* Creation date	17/07/96*/
/* Revision date*/
/**/
/* (c) Ubi Studios 1996*/
/**/
/* DO NOT MODIFY THAT FILE. IF SOMETHING NEEDS TO BE CHANGE, PLEASE CONTACT*/
/* OLIVIER DIDELOT.*/
/*=========================================================================*/
 
#ifndef __DEVVP3D_HPP__
#define __DEVVP3D_HPP__
#include "DEVViewp.hpp"
/*#include "CPACam.hpp"*/
#include "itf/DEVDevic.hpp"
#include "lst.hpp"
#include "spo.h"
 
#ifdef ACTIVE_EDITOR
class CPA_SuperObject;
class CPA_BaseObject;
class CPA_CameraDLLBase;
class CPA_MainWorld;
#endif
 
/****************************************/
#ifndef CPA_EXPORT
#if defined(CPA_WANTS_IMPORT)
#define CPA_EXPORT __declspec(dllimport)
#elif defined(CPA_WANTS_EXPORT)
#define CPA_EXPORT __declspec(dllexport)
#else
#define CPA_EXPORT
#endif
#endif
/****************************************/
 
/*##########################################################################*/
/* Definition of mouse position in main view*/
typedef struct tdstMousePos_
{
    CPoint                  stPos;          /* 2D pos of editor*/
    GLI_tdst2DVertex        stPos2D;        /* GLI 2D pos of editor*/
    MTH3D_tdstVector          stPos3D;        /* GLI 3D pos of editor*/
} tdstMousePos;
/*##########################################################################*/
 
/*#################################################################################*/
/* Definition of mouse swap in main view*/
typedef enum eForceSwap 
{
	eNone, 
	eSwapRight, 
	eSwapLeft,
	eSwapBoth
}
tdeForceSwap;
/*#################################################################################*/
 
/*##########################################################################*/
/* Definition of light for selection*/
typedef struct tdstSaveLight_
{
    GLI_tdxHandleToLight	hLight;
	long					lInitialState;
} tdstSaveLight;
/*##########################################################################*/
 
template <class DEV_ViewPort3D> class DEV_Timer;
 
class CPA_EXPORT DEV_ViewPort3D : public DEV_ViewPort
{
	/* public functions, with and without editor*/
public:
	DEV_ViewPort3D();
	virtual ~DEV_ViewPort3D();
    DECLARE_DYNCREATE(DEV_ViewPort3D)
	void	CreateViewPort(void *, GLD_tdhDevice);
	GLI_tdxHandleToCamera	GetEngineCamera	();
	void m_vFakeMouseMove(CPoint oScreenMousePoint);
	void m_vFakeMouseLButtonDown(CPoint oScreenMousePoint);
	BOOL m_bWasInSecondScreen;
	BOOL m_bIsVerticalSwap;
 
/* private member, with and without editor*/
private:
	GLI_tdstSpecificAttributesFor3D m_Attributes3D;
	UINT							m_uiLastMouseState;
 
 
#ifdef ACTIVE_EDITOR
private:
	CPA_SuperObject					*m_p_oCameraSO;
	CPA_BaseObject					*m_p_oCamera;
	CPA_CameraDLLBase				*m_p_oCameraInterface;
	CPoint							m_oLastCursorScreenPos;
 
    MTH3D_tdstVector				m_stMousePos;                      /* The 3D-coordinates of the mouse*/
    MTH3D_tdstVector				m_stInitMousePos;                  /* The 3D-coordinates of the initial position of the mouse ( when we start to move the object )*/
 
public:
	tdstSaveLight		m_a_tdxhArrayOfLights[C_lMaxLightInViewport];
	long				m_lCurrentLights;
 
	CPA_SuperObject		*GetCameraSO		(void)	{ return m_p_oCameraSO; }
	CPA_BaseObject		*GetCamera			(void)	{ return m_p_oCamera; }
	CPA_CameraDLLBase	*GetCameraInterface	(void)	{ return m_p_oCameraInterface; }
 
	CPA_SuperObject		*ChangeCamera (CPA_SuperObject *p_oCamera, BOOL bWithPrevCam = TRUE);
 
	void				fn_vInitLightsInViewport (GLD_tdxHandleToViewportAttributes _hVpt, GLI_tdxHandleToLight _hLight, CPA_MainWorld *pMainWorld);
 
	void				DrawObject		(GLI_tdxHandleToLight hLight, HIE_tdxHandleToSuperObject hObject);
    void				DrawEditorObject(GLI_tdxHandleToLight hLight, CPA_SuperObject *pRoot);
 
    void				DetectMouseSwap (BOOL bDrawCursor = FALSE, GLD_tdstViewportAttributes *p_stViewportAttr = NULL);
 
	void fn_vUpdateStatusBarMessage (void);
 
	void SetSelectedInstance	(CString csName)		{ m_csSelectedInstance = csName; }
	void SetPickedInstance		(CString csName)		{ m_csPickedInstance = csName; }
	void SetPosition			(MTH3D_tdstVector *pNewPos);
	void SetMoveVector			(MTH3D_tdstVector *pNewMove);
	void AddtoMoveVector		(MTH3D_tdstVector *pNewMove);
	void SetDistanceVector		(MTH3D_tdstVector *pDist);
	void SetDistanceToCamera	(MTH3D_tdstVector *pDist);
 
/*fonctions à revoire FBFFBF*/
 
/*    void SetPlaneForMouseMove (MTH3D_tdstVector * p_stX_Axe , MTH3D_tdstVector * p_stY_Axe);*/
    /*void GetPlaneForMouseMove (MTH3D_tdstVector * p_stX_Axe , MTH3D_tdstVector * p_stY_Axe);*/
	void Convert3dTo2d(GLI_tdst2DVertex *p_stDest, MTH3D_tdstVector *p_stSource);
	void InitMouseMove (MTH3D_tdstVector *stMousePos3D, GLI_tdst2DVertex* stMousePos2D);
	void DoneMouseMove (void);
 
	/*CPA2 Gabi Dumitrascu 98/06/26*/
	BOOL IsCursorInFirstScreen ();
	void SetCursorInFirstScreen ();
	void SetCursorInSecondScreen ();
	BOOL IsCursorInDeadScreen ();
	void mfn_vChangeCursorFrom1To2 (CPoint &rptMouse, tdeForceSwap eSwapMode, BOOL bVerticalSwap = FALSE);
	void mfn_vChangeCursorFrom2To1 (CPoint &rptMouse, tdeForceSwap eSwapMode, BOOL bVerticalSwap = FALSE);
	/*End CPA2 Gabi Dumitrascu 98/06/26*/
 
 
private:
	CString				m_csMessage;
	CString				m_csSelectedInstance;
	CString				m_csPickedInstance;
	MTH3D_tdstVector	m_stPosition;
	MTH3D_tdstVector	m_stMoveVector;
	MTH3D_tdstVector	m_stCameraDistance;
	MTH3D_tdstVector	m_stDistance;
	
	CString fn_csGetSelectedInstanceName( ACP_tdxIndex, HIE_tdstPickInfo*, tdstMousePos* );
 
  /* Function used by OnMouseMove to compute mouse move into the selected plane*/
  /* Input : p_stOriginalMouseMove, output : p_stConstrainedMouseMove*/
  BOOL ComputeMouseMoveIntoPlane(MTH3D_tdstVector *p_stConstrainedMouseMove, MTH3D_tdstVector *p_stOriginalMouseMove);
 
/*FBFFBF to remove when we have rush voodoo cards*/
public:
	BOOL				m_bObjectIsMoving;
	BOOL				m_bBeginMove;
	MTH3D_tdstVector	m_stCamToEndingPos;
 
	void ClientToVoodooFullScreen(CPoint &point);
	void ClientToVoodoo(CPoint &point);
	void VoodooToClient(CPoint &point);
	void ClientToVoodoo(GLI_tdst2DVertex & point);
 
	void PointToMousePos(CPoint point, tdstMousePos* pPos);
 
#endif /* ACTIVE_EDITOR*/
 
 
protected:
	/*{{AFX_MSG(DEV_ViewPort3D)*/
	afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
	afx_msg void    OnDestroy();
#ifdef ACTIVE_EDITOR
	afx_msg void OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags);
    afx_msg void OnKeyUp(UINT nChar, UINT nRepCnt, UINT nFlags);
	afx_msg void OnSysKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags); /* CPA2 Corneliu Babiuc (Alt Key) 14-05-98 */
    afx_msg void OnSysKeyUp(UINT nChar, UINT nRepCnt, UINT nFlags);   /* CPA2 Corneliu Babiuc (Alt Key) 14-05-98 */
	afx_msg void OnSetFocus(CWnd* pOldWnd);
	afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
	afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
	afx_msg void OnRButtonDown(UINT nFlags, CPoint point);
	afx_msg void OnRButtonUp(UINT nFlags, CPoint point); /* CPA_Ed_1 FS*/
    afx_msg void OnLButtonDblClk(UINT nFlags, CPoint point);
	afx_msg void OnMouseMove(UINT nFlags, CPoint point);
	afx_msg LONG OnDragDropEnd(WPARAM wparam, LPARAM lparam);
	afx_msg LONG OnDragDropLooseFocus(WPARAM wparam, LPARAM lparam);
	afx_msg LONG OnDragDropGainFocus(WPARAM wparam, LPARAM lparam);
	afx_msg LONG OnDragDropMove(WPARAM wparam, LPARAM lparam);
	afx_msg void OnTimer( UINT  nIDEvent );
	/*CPA2 Gabi Dumitrascu 98/07/13*/
	afx_msg void OnNcMouseMove (UINT nHitTest, CPoint point);
	afx_msg UINT OnNcHitTest (CPoint point);
	afx_msg void OnKillFocus(CWnd* pNewWnd);
	/*End CPA2 Gabi Dumitrascu 98/07/13*/
#endif /* ACTIVE_EDITOR*/
	/*}}AFX_MSG*/
 
	DECLARE_MESSAGE_MAP()
};
 
/*///////////////////////////////////////////////////////////////////////////*/
 
#endif /* __DEVVP3D_HPP__*/
 
 
