?? dxutmisc.h
字號(hào):
const D3DXMATRIX* GetViewMatrix() const { return &m_mView; }
const D3DXMATRIX* GetProjMatrix() const { return &m_mProj; }
const D3DXVECTOR3* GetEyePt() const { return &m_vEye; }
const D3DXVECTOR3* GetLookAtPt() const { return &m_vLookAt; }
float GetNearClip() const { return m_fNearPlane; }
float GetFarClip() const { return m_fFarPlane; }
bool IsBeingDragged() const { return (m_bMouseLButtonDown || m_bMouseMButtonDown || m_bMouseRButtonDown); }
bool IsMouseLButtonDown() const { return m_bMouseLButtonDown; }
bool IsMouseMButtonDown() const { return m_bMouseMButtonDown; }
bool IsMouseRButtonDown() const { return m_bMouseRButtonDown; }
protected:
// Functions to map a WM_KEYDOWN key to a D3DUtil_CameraKeys enum
virtual D3DUtil_CameraKeys MapKey( UINT nKey );
bool IsKeyDown( BYTE key ) const { return( (key & KEY_IS_DOWN_MASK) == KEY_IS_DOWN_MASK ); }
bool WasKeyDown( BYTE key ) const { return( (key & KEY_WAS_DOWN_MASK) == KEY_WAS_DOWN_MASK ); }
void ConstrainToBoundary( D3DXVECTOR3* pV );
void UpdateVelocity( float fElapsedTime );
void GetInput( bool bGetKeyboardInput, bool bGetMouseInput, bool bGetGamepadInput, bool bResetCursorAfterMove );
D3DXMATRIX m_mView; // View matrix
D3DXMATRIX m_mProj; // Projection matrix
DXUT_GAMEPAD m_GamePad[DXUT_MAX_CONTROLLERS]; // XInput controller state
D3DXVECTOR3 m_vGamePadLeftThumb;
D3DXVECTOR3 m_vGamePadRightThumb;
double m_GamePadLastActive[DXUT_MAX_CONTROLLERS];
int m_cKeysDown; // Number of camera keys that are down.
BYTE m_aKeys[CAM_MAX_KEYS]; // State of input - KEY_WAS_DOWN_MASK|KEY_IS_DOWN_MASK
D3DXVECTOR3 m_vKeyboardDirection; // Direction vector of keyboard input
POINT m_ptLastMousePosition; // Last absolute position of mouse cursor
bool m_bMouseLButtonDown; // True if left button is down
bool m_bMouseMButtonDown; // True if middle button is down
bool m_bMouseRButtonDown; // True if right button is down
int m_nCurrentButtonMask; // mask of which buttons are down
int m_nMouseWheelDelta; // Amount of middle wheel scroll (+/-)
D3DXVECTOR2 m_vMouseDelta; // Mouse relative delta smoothed over a few frames
float m_fFramesToSmoothMouseData; // Number of frames to smooth mouse data over
D3DXVECTOR3 m_vDefaultEye; // Default camera eye position
D3DXVECTOR3 m_vDefaultLookAt; // Default LookAt position
D3DXVECTOR3 m_vEye; // Camera eye position
D3DXVECTOR3 m_vLookAt; // LookAt position
float m_fCameraYawAngle; // Yaw angle of camera
float m_fCameraPitchAngle; // Pitch angle of camera
RECT m_rcDrag; // Rectangle within which a drag can be initiated.
D3DXVECTOR3 m_vVelocity; // Velocity of camera
bool m_bMovementDrag; // If true, then camera movement will slow to a stop otherwise movement is instant
D3DXVECTOR3 m_vVelocityDrag; // Velocity drag force
FLOAT m_fDragTimer; // Countdown timer to apply drag
FLOAT m_fTotalDragTimeToZero; // Time it takes for velocity to go from full to 0
D3DXVECTOR2 m_vRotVelocity; // Velocity of camera
float m_fFOV; // Field of view
float m_fAspect; // Aspect ratio
float m_fNearPlane; // Near plane
float m_fFarPlane; // Far plane
float m_fRotationScaler; // Scaler for rotation
float m_fMoveScaler; // Scaler for movement
bool m_bInvertPitch; // Invert the pitch axis
bool m_bEnablePositionMovement; // If true, then the user can translate the camera/model
bool m_bEnableYAxisMovement; // If true, then camera can move in the y-axis
bool m_bClipToBoundary; // If true, then the camera will be clipped to the boundary
D3DXVECTOR3 m_vMinBoundary; // Min point in clip boundary
D3DXVECTOR3 m_vMaxBoundary; // Max point in clip boundary
};
//--------------------------------------------------------------------------------------
// Simple first person camera class that moves and rotates.
// It allows yaw and pitch but not roll. It uses WM_KEYDOWN and
// GetCursorPos() to respond to keyboard and mouse input and updates the
// view matrix based on input.
//--------------------------------------------------------------------------------------
class CFirstPersonCamera : public CBaseCamera
{
public:
CFirstPersonCamera();
// Call these from client and use Get*Matrix() to read new matrices
virtual void FrameMove( FLOAT fElapsedTime );
// Functions to change behavior
void SetRotateButtons( bool bLeft, bool bMiddle, bool bRight, bool bRotateWithoutButtonDown = false );
void SetResetCursorAfterMove( bool bResetCursorAfterMove ) { m_bResetCursorAfterMove = bResetCursorAfterMove; }
// Functions to get state
D3DXMATRIX* GetWorldMatrix() { return &m_mCameraWorld; }
const D3DXVECTOR3* GetWorldRight() const { return (D3DXVECTOR3*)&m_mCameraWorld._11; }
const D3DXVECTOR3* GetWorldUp() const { return (D3DXVECTOR3*)&m_mCameraWorld._21; }
const D3DXVECTOR3* GetWorldAhead() const { return (D3DXVECTOR3*)&m_mCameraWorld._31; }
const D3DXVECTOR3* GetEyePt() const { return (D3DXVECTOR3*)&m_mCameraWorld._41; }
protected:
D3DXMATRIX m_mCameraWorld; // World matrix of the camera (inverse of the view matrix)
int m_nActiveButtonMask; // Mask to determine which button to enable for rotation
bool m_bRotateWithoutButtonDown;
bool m_bResetCursorAfterMove;// If true, the class will reset the cursor position so that the cursor always has space to move
};
//--------------------------------------------------------------------------------------
// Simple model viewing camera class that rotates around the object.
//--------------------------------------------------------------------------------------
class CModelViewerCamera : public CBaseCamera
{
public:
CModelViewerCamera();
// Call these from client and use Get*Matrix() to read new matrices
virtual LRESULT HandleMessages( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam );
virtual void FrameMove( FLOAT fElapsedTime );
// Functions to change behavior
virtual void SetDragRect( RECT &rc );
void Reset();
void SetViewParams( D3DXVECTOR3* pvEyePt, D3DXVECTOR3* pvLookatPt );
void SetButtonMasks( int nRotateModelButtonMask = MOUSE_LEFT_BUTTON, int nZoomButtonMask = MOUSE_WHEEL, int nRotateCameraButtonMask = MOUSE_RIGHT_BUTTON ) { m_nRotateModelButtonMask = nRotateModelButtonMask, m_nZoomButtonMask = nZoomButtonMask; m_nRotateCameraButtonMask = nRotateCameraButtonMask; }
void SetAttachCameraToModel( bool bEnable = false ) { m_bAttachCameraToModel = bEnable; }
void SetWindow( int nWidth, int nHeight, float fArcballRadius=0.9f ) { m_WorldArcBall.SetWindow( nWidth, nHeight, fArcballRadius ); m_ViewArcBall.SetWindow( nWidth, nHeight, fArcballRadius ); }
void SetRadius( float fDefaultRadius=5.0f, float fMinRadius=1.0f, float fMaxRadius=FLT_MAX ) { m_fDefaultRadius = m_fRadius = fDefaultRadius; m_fMinRadius = fMinRadius; m_fMaxRadius = fMaxRadius; m_bDragSinceLastUpdate = true; }
void SetModelCenter( D3DXVECTOR3 vModelCenter ) { m_vModelCenter = vModelCenter; }
void SetLimitPitch( bool bLimitPitch ) { m_bLimitPitch = bLimitPitch; }
void SetViewQuat( D3DXQUATERNION q ) { m_ViewArcBall.SetQuatNow( q ); m_bDragSinceLastUpdate = true; }
void SetWorldQuat( D3DXQUATERNION q ) { m_WorldArcBall.SetQuatNow( q ); m_bDragSinceLastUpdate = true; }
// Functions to get state
const D3DXMATRIX* GetWorldMatrix() const { return &m_mWorld; }
void SetWorldMatrix( D3DXMATRIX &mWorld ) { m_mWorld = mWorld; m_bDragSinceLastUpdate = true; }
protected:
CD3DArcBall m_WorldArcBall;
CD3DArcBall m_ViewArcBall;
D3DXVECTOR3 m_vModelCenter;
D3DXMATRIX m_mModelLastRot; // Last arcball rotation matrix for model
D3DXMATRIX m_mModelRot; // Rotation matrix of model
D3DXMATRIX m_mWorld; // World matrix of model
int m_nRotateModelButtonMask;
int m_nZoomButtonMask;
int m_nRotateCameraButtonMask;
bool m_bAttachCameraToModel;
bool m_bLimitPitch;
float m_fRadius; // Distance from the camera to model
float m_fDefaultRadius; // Distance from the camera to model
float m_fMinRadius; // Min radius
float m_fMaxRadius; // Max radius
bool m_bDragSinceLastUpdate; // True if mouse drag has happened since last time FrameMove is called.
D3DXMATRIX m_mCameraRotLast;
};
//--------------------------------------------------------------------------------------
// Manages the intertion point when drawing text
//--------------------------------------------------------------------------------------
class CDXUTTextHelper
{
public:
CDXUTTextHelper( ID3DXFont* pFont, ID3DXSprite* pSprite, int nLineHeight );
void SetInsertionPos( int x, int y ) { m_pt.x = x; m_pt.y = y; }
void SetForegroundColor( D3DXCOLOR clr ) { m_clr = clr; }
void Begin();
HRESULT DrawFormattedTextLine( const WCHAR* strMsg, ... );
HRESULT DrawTextLine( const WCHAR* strMsg );
HRESULT DrawFormattedTextLine( RECT &rc, DWORD dwFlags, const WCHAR* strMsg, ... );
HRESULT DrawTextLine( RECT &rc, DWORD dwFlags, const WCHAR* strMsg );
void End();
protected:
ID3DXFont* m_pFont;
ID3DXSprite* m_pSprite;
D3DXCOLOR m_clr;
POINT m_pt;
int m_nLineHeight;
};
//--------------------------------------------------------------------------------------
// Manages a persistent list of lines and draws them using ID3DXLine
//--------------------------------------------------------------------------------------
class CDXUTLineManager
{
public:
CDXUTLineManager();
~CDXUTLineManager();
HRESULT OnCreatedDevice( IDirect3DDevice9* pd3dDevice );
HRESULT OnResetDevice();
HRESULT OnRender();
HRESULT OnLostDevice();
HRESULT OnDeletedDevice();
HRESULT AddLine( int* pnLineID, D3DXVECTOR2* pVertexList, DWORD dwVertexListCount, D3DCOLOR Color, float fWidth, float fScaleRatio, bool bAntiAlias );
HRESULT AddRect( int* pnLineID, RECT rc, D3DCOLOR Color, float fWidth, float fScaleRatio, bool bAntiAlias );
HRESULT RemoveLine( int nLineID );
HRESULT RemoveAllLines();
protected:
struct LINE_NODE
{
int nLineID;
D3DCOLOR Color;
float fWidth;
bool bAntiAlias;
float fScaleRatio;
D3DXVECTOR2* pVertexList;
DWORD dwVertexListCount;
};
CGrowableArray<LINE_NODE*> m_LinesList;
IDirect3DDevice9* m_pd3dDevice;
ID3DXLine* m_pD3DXLine;
};
//--------------------------------------------------------------------------------------
// Manages the mesh, direction, mouse events of a directional arrow that
// rotates around a radius controlled by an arcball
//--------------------------------------------------------------------------------------
class CDXUTDirectionWidget
{
public:
CDXUTDirectionWidget();
static HRESULT StaticOnCreateDevice( IDirect3DDevice9* pd3dDevice );
HRESULT OnResetDevice( const D3DSURFACE_DESC* pBackBufferSurfaceDesc );
HRESULT OnRender( D3DXCOLOR color, const D3DXMATRIX* pmView, const D3DXMATRIX* pmProj, const D3DXVECTOR3* pEyePt );
LRESULT HandleMessages( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam );
static void StaticOnLostDevice();
static void StaticOnDestroyDevice();
D3DXVECTOR3 GetLightDirection() { return m_vCurrentDir; };
void SetLightDirection( D3DXVECTOR3 vDir ) { m_vDefaultDir = m_vCurrentDir = vDir; };
void SetButtonMask( int nRotate = MOUSE_RIGHT_BUTTON ) { m_nRotateMask = nRotate; }
float GetRadius() { return m_fRadius; };
void SetRadius( float fRadius ) { m_fRadius = fRadius; };
bool IsBeingDragged() { return m_ArcBall.IsBeingDragged(); };
protected:
HRESULT UpdateLightDir();
D3DXMATRIXA16 m_mRot;
D3DXMATRIXA16 m_mRotSnapshot;
static IDirect3DDevice9* s_pd3dDevice;
static ID3DXEffect* s_pEffect;
static ID3DXMesh* s_pMesh;
float m_fRadius;
int m_nRotateMask;
CD3DArcBall m_ArcBall;
D3DXVECTOR3 m_vDefaultDir;
D3DXVECTOR3 m_vCurrentDir;
D3DXMATRIX m_mView;
};
//--------------------------------------------------------------------------------------
// Shared code for samples to ask user if they want to use a REF device or quit
//--------------------------------------------------------------------------------------
void DXUTDisplaySwitchingToREFWarning();
//--------------------------------------------------------------------------------------
// Tries to finds a media file by searching in common locations
//--------------------------------------------------------------------------------------
HRESULT DXUTFindDXSDKMediaFileCch( WCHAR* strDestPath, int cchDest, LPCWSTR strFilename );
HRESULT DXUTSetMediaSearchPath( LPCWSTR strPath );
LPCWSTR DXUTGetMediaSearchPath();
//--------------------------------------------------------------------------------------
// Returns the string for the given D3DFORMAT.
// bWithPrefix determines whether the string should include the "D3DFMT_"
//--------------------------------------------------------------------------------------
LPCWSTR DXUTD3DFormatToString( D3DFORMAT format, bool bWithPrefix );
//--------------------------------------------------------------------------------------
// Returns a view matrix for rendering to a face of a cubemap.
//--------------------------------------------------------------------------------------
D3DXMATRIX DXUTGetCubeMapViewMatrix( DWORD dwFace );
//--------------------------------------------------------------------------------------
// Helper function to launch the Media Center UI after the program terminates
//--------------------------------------------------------------------------------------
bool DXUTReLaunchMediaCenter();
//--------------------------------------------------------------------------------------
// Debug printing support
// See dxerr.h for more debug printing support
//--------------------------------------------------------------------------------------
void DXUTOutputDebugStringW( LPCWSTR strMsg, ... );
void DXUTOutputDebugStringA( LPCSTR strMsg, ... );
HRESULT WINAPI DXUTTrace( const CHAR* strFile, DWORD dwLine, HRESULT hr, const WCHAR* strMsg, bool bPopMsgBox );
void DXUTTraceDecl( D3DVERTEXELEMENT9 decl[MAX_FVF_DECL_SIZE] );
WCHAR* DXUTTraceD3DDECLUSAGEtoString( BYTE u );
WCHAR* DXUTTraceD3DDECLMETHODtoString( BYTE m );
WCHAR* DXUTTraceD3DDECLTYPEtoString( BYTE t );
#ifdef UNICODE
#define DXUTOutputDebugString DXUTOutputDebugStringW
#else
#define DXUTOutputDebugString DXUTOutputDebugStringA
#endif
// These macros are very similar to dxerr's but it special cases the HRESULT defined
// by DXUT to pop better message boxes.
#if defined(DEBUG) || defined(_DEBUG)
#define DXUT_ERR(str,hr) DXUTTrace( __FILE__, (DWORD)__LINE__, hr, str, false )
#define DXUT_ERR_MSGBOX(str,hr) DXUTTrace( __FILE__, (DWORD)__LINE__, hr, str, true )
#define DXUTTRACE DXUTOutputDebugString
#else
#define DXUT_ERR(str,hr) (hr)
#define DXUT_ERR_MSGBOX(str,hr) (hr)
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -