/** * @file XTPChart3dDeviceContext.h * * @copyright * (c) 1998-2025 Codejock Software, All Rights Reserved. * * This source file is the property of Codejock Software and must not be * redistributed by any means without the explicit written permission of * Codejock Software. * * The use of this source code is governed by the terms and conditions specified * in the Toolkit Pro license agreement. Codejock Software grants you, as a * single software developer, the limited right to use this software on one * computer only. * * Contact Information: * support@codejock.com * http://www.codejock.com * */ /** @cond */ #if !defined(__XTPCHART3DDEVICECONTEXT_H__) # define __XTPCHART3DDEVICECONTEXT_H__ /** @endcond */ # if _MSC_VER >= 1000 # pragma once # endif // _MSC_VER >= 1000 # include "Common/Base/Diagnostic/XTPDisableNoisyWarnings.h" class CXTPChartContainer; class CXTPChartDeviceCommand; class CXTPMarkupUIElement; class CXTPChartFont; class CXTPChartDrawingObjectFactory; class CXTPOpenGLTriangleRenderList; /** * @brief * A base implementation of 3D device context. * * @see * CXTPChartDeviceContext */ class _XTP_EXT_CLASS CXTPChart3dDeviceContext : public CXTPChartDeviceContext { DECLARE_DYNAMIC(CXTPChart3dDeviceContext); protected: /** * @brief * Constructs a CXTPChart3dDeviceContext object. * * @param pContainer Parent container pointer. * @param hDC Handle to the windows device context. * @param rcBounds Rectangle that defined device context boundaries. * @param pDrawingObjectFactory Drawing object factory pointer. */ CXTPChart3dDeviceContext(CXTPChartContainer* pContainer, HDC hDC, CRect rcBounds, CXTPChartDrawingObjectFactory* pDrawingObjectFactory); public: /** * @brief * Destroys a CXTPChartDeviceContext object, handles cleanup. */ ~CXTPChart3dDeviceContext(); /** * @brief * Rotates current matrix. * * @param rotation Matrix rotation arguments. */ virtual void Rotate(const CXTPChart3dRotation& rotation) = 0; /** * @brief * Projects 3D coordinates to 2D space point coordinates. * * @param pt3d 3D space point coordinates. * @param pt2d Result 2D space point coordinates. * @param pdWinZ If specified the result value is within range 0..1 * where 0 defines the near plane and 1 defines the far * plane defined by the view frustum. * * @return TRUE if coordinates are mapped successfully, FALSE otherwise. * * @see * Unproject */ virtual BOOL Project(const CXTPPoint3d& pt3d, CPoint& pt2d, double* pdWinZ = NULL) = 0; /** * @brief * Projects 3D coordinates to 2D space point coordinates. * * @param box 3D box to map to the outer 2D rectangle. * @param rc Resuylt 2D outer rectangle for the 3D box specified. * * @return TRUE if coordinates are mapped successfully, FALSE otherwise. * * @see * Unproject */ virtual BOOL Project(const CXTPChart3dBox& box, CRect& rc) = 0; /** * @brief * Projects 2D space point coordinates to 3D space point coordinate * on the specified plane. * * @param pt2d 2D space point coordinates. * @param pt3d Result 3D space point coordinates. * @param dWinZ Determines how far the point is from the near plane. * The value must be within 0..1 range where 0 determines * the near frustum plane and 1 determines the far plane. * * @return TRUE is the coordinates are mapped successfully, FALSE otherwise. * * @see * Project */ virtual BOOL Unproject(const CPoint& pt2d, CXTPPoint3d& pt3d, double dWinZ = 0) = 0; /** * @brief * Transforms vector or box coordinates. * * @param v A vector to transform. * @param pTranslation Optional translation offsets to add to the vector or box vertices. * @param pRotation Optional vector opr box vertices rotation parameters. */ virtual void Transform(CXTPPoint3d& v, const CXTPPoint3d* pTranslation = NULL, const CXTPChart3dRotation* pRotation = NULL) = 0; /** * @brief * Transforms vector or box coordinates. * * @param box A box to transform. * @param pTranslation Optional translation offsets to add to the vector or box vertices. * @param pRotation Optional vector opr box vertices rotation parameters. */ virtual void Transform(CXTPChart3dBox& box, const CXTPPoint3d* pTranslation = NULL, const CXTPChart3dRotation* pRotation = NULL) = 0; /** * @brief * Performs depth dest for 2D point provided. * * @param point Viewport offset for which depth test is to be performed. * @param dWinZ If succeeds the value contains the distance from the near (0) * plane of the view frustum to the fist visible point. * * @return TRUE if depth test is successful, FALSE otherwise. */ virtual BOOL DepthTest(CPoint point, double& dWinZ) = 0; /** * @brief * Obtains the device contains boundary rectangle. * * @return The device contains boundary rectangle. */ const CRect& GetBounds() const; /** * @brief * Checks if the device context is currently rendering anti-aliasing. * * @return TRUE if the device context is currently rendering anti-aliasing, FALSE otherwise. * * @see * IsSkippingAntialiasing */ BOOL IsRenderingAntialiasing() const; /** * @brief * Checks if the device context is skipping anti-aliasing rendering. * * @return TRUE if the device context is skipping anti-aliasing rendering, FALSE otherwise. * * @see * IsRenderingAntialiasing */ BOOL IsSkippingAntialiasing() const; /** * @brief * Is called when the camera state is updated. * * @param ptPosition New camera position. * @param ptFocal New camera focal point. * @param ptUpVector New camera up vector. */ void OnUpdateCameraState(const CXTPPoint3f& ptPosition, const CXTPPoint3f& ptFocal, const CXTPPoint3f& ptUpVector); /** * @brief * Sets limits for distance between view point and scene center point. * * @param fMinDistance Minimal distance allowed. * @param fMaxDistance Maximum distance allowed. */ void SetModelDistanceLimits(float fMinDistance, float fMaxDistance); /** * @brief * Sets/obtains light position normalized vector where * each component is within range [0..1]. * * @param position New light vector. */ void SetLightPosition(const CXTPPoint3f& position); /** * @brief * Sets/obtains light position normalized vector where * each component is within range [0..1]. * * @return Current light vector. */ const CXTPPoint3f& GetLightPosition() const; /** * @brief * Sets/obtains light ambient color. * * @param color New light ambient color. */ void SetLightAmbientColor(const CXTPChartColor& color); /** * @brief * Sets/obtains light ambient color. * * @return Current light ambient color. */ const CXTPChartColor& GetLightAmbientColor() const; /** * @brief * Sets/obtains light diffuse color. * * @param color New light diffuse color. */ void SetLightDiffuseColor(const CXTPChartColor& color); /** * @brief * Sets/obtains light diffuse color. * * @return Current light diffuse color. */ const CXTPChartColor& GetLightDiffuseColor() const; /** * @brief * Sets/obtains light specular color. * * @param color New light specular color. */ void SetLightSpecularColor(const CXTPChartColor& color); /** * @brief * Sets/obtains light specular color. * * @return Current light specular color. */ const CXTPChartColor& GetLightSpecularColor() const; /** * @brief * Sets/obtains light model ambient color. * * @param color New light model ambient color. */ void SetLightModelAmbientColor(const CXTPChartColor& color); /** * @brief * Sets/obtains light model ambient color. * * @return Current light model ambient color. */ const CXTPChartColor& GetLightModelAmbientColor() const; /** * @brief * Sets/obtains material emission color. * * @param color New material emission color. */ void SetMaterialEmissionColor(const CXTPChartColor& color); /** * @brief * Sets/obtains material emission color. * * @return Current material emission color. */ const CXTPChartColor& GetMaterialEmissionColor() const; /** * @brief * Sets/obtains material diffuse color. * * @param color New material diffuse color. */ void SetMaterialDiffuseColor(const CXTPChartColor& color); /** * @brief * Sets/obtains material diffuse color. * * @return Current material diffuse color. */ const CXTPChartColor& GetMaterialDiffuseColor() const; /** * @brief * Sets/obtains material specular color. * * @param color New material specular color. */ void SetMaterialSpecularColor(const CXTPChartColor& color); /** * @brief * Sets/obtains material specular color. * * @return Current material specular color. */ const CXTPChartColor& GetMaterialSpecularColor() const; /** * @brief * Sets/obtains material shininess factor, a value within range [0..1]. * * @param fShininess New opacity factor. */ void SetMaterialShininess(float fShininess); /** * @brief * Sets/obtains material shininess factor, a value within range [0..1]. * * @return Current material shininess factor. */ float GetMaterialShininess() const; /** * @brief * Enables/disables antialiasing if supported. * * @return TRUE if antialiasing is enabled. */ BOOL GetAntialiasing() const; /** * @brief * Enables/disables antialiasing if supported. * * @param bEnable TRUE to enable antialiasing, FALSE to disable. */ void SetAntialiasing(BOOL bEnable = TRUE); /** @cond */ BOOL IsInitialPass() const; CXTPOpenGLTriangleRenderList& GetTriangleRenderList(); /** @endcond */ protected: /** * @brief * Resets saved camera state to default zero values. */ void ResetSavedCameraState(); protected: const CRect m_rcBounds; /**< Device context bounary rectangle. */ BOOL m_bRenderingAntialiasing; /**< TRUE if currently rendering anti-aliasing */ BOOL m_bSkippingAntialiasing; /**< TRUE if skipping anti-aliasing rendering */ struct CameraState { CXTPPoint3f ptPosition; CXTPPoint3f ptFocal; CXTPPoint3f ptUpVector; } m_cameraState; /**< Saved camera state*/ float m_fMinModelDistance; /**< Minimal distance allowed to the center of the scene. */ float m_fMaxModelDistance; /**< Maximum distance allowed to the center of the scene. */ CXTPPoint3f m_ptLightPosition; /**< Light position vector, each component is a normalized value in range [0..1].*/ CXTPChartColor m_clrLightAmbientColor; /**< Light ambient color. */ CXTPChartColor m_clrLightDiffuseColor; /**< Light diffuse color. */ CXTPChartColor m_clrLightSpecularColor; /**< Light specular color. */ CXTPChartColor m_clrLightModelAmbientColor; /**< Light model ambient color. */ CXTPChartColor m_clrMaterialEmissionColor; /**< Material emission color. */ CXTPChartColor m_clrMaterialDiffuseColor; /**< Material diffuse color. */ CXTPChartColor m_clrMaterialSpecularColor; /**< Material specular color. */ float m_fMaterialShininess; /**< Material shininess factor in range [0..1].*/ BOOL m_bAntialiasing; /**< Antialiasing flag */ BOOL m_bInitialPass; /**< TRUE if the command tree is executed the very first time.*/ CXTPOpenGLTriangleRenderList* m_pTriangles; }; AFX_INLINE const CRect& CXTPChart3dDeviceContext::GetBounds() const { return m_rcBounds; } AFX_INLINE BOOL CXTPChart3dDeviceContext::IsRenderingAntialiasing() const { return m_bRenderingAntialiasing; } AFX_INLINE BOOL CXTPChart3dDeviceContext::IsSkippingAntialiasing() const { return m_bSkippingAntialiasing; } AFX_INLINE void CXTPChart3dDeviceContext::SetModelDistanceLimits(float fMinDistance, float fMaxDistance) { m_fMinModelDistance = fMinDistance; m_fMaxModelDistance = fMaxDistance; } AFX_INLINE void CXTPChart3dDeviceContext::SetLightPosition(const CXTPPoint3f& position) { m_ptLightPosition = position; } AFX_INLINE const CXTPPoint3f& CXTPChart3dDeviceContext::GetLightPosition() const { return m_ptLightPosition; } AFX_INLINE void CXTPChart3dDeviceContext::SetLightAmbientColor(const CXTPChartColor& color) { m_clrLightAmbientColor = color; } AFX_INLINE const CXTPChartColor& CXTPChart3dDeviceContext::GetLightAmbientColor() const { return m_clrLightAmbientColor; } AFX_INLINE void CXTPChart3dDeviceContext::SetLightDiffuseColor(const CXTPChartColor& color) { m_clrLightDiffuseColor = color; } AFX_INLINE const CXTPChartColor& CXTPChart3dDeviceContext::GetLightDiffuseColor() const { return m_clrLightDiffuseColor; } AFX_INLINE void CXTPChart3dDeviceContext::SetLightSpecularColor(const CXTPChartColor& color) { m_clrLightSpecularColor = color; } AFX_INLINE const CXTPChartColor& CXTPChart3dDeviceContext::GetLightSpecularColor() const { return m_clrLightSpecularColor; } AFX_INLINE void CXTPChart3dDeviceContext::SetLightModelAmbientColor(const CXTPChartColor& color) { m_clrLightModelAmbientColor = color; } AFX_INLINE const CXTPChartColor& CXTPChart3dDeviceContext::GetLightModelAmbientColor() const { return m_clrLightModelAmbientColor; } AFX_INLINE void CXTPChart3dDeviceContext::SetMaterialEmissionColor(const CXTPChartColor& color) { m_clrMaterialEmissionColor = color; } AFX_INLINE const CXTPChartColor& CXTPChart3dDeviceContext::GetMaterialEmissionColor() const { return m_clrMaterialEmissionColor; } AFX_INLINE void CXTPChart3dDeviceContext::SetMaterialDiffuseColor(const CXTPChartColor& color) { m_clrMaterialDiffuseColor = color; } AFX_INLINE const CXTPChartColor& CXTPChart3dDeviceContext::GetMaterialDiffuseColor() const { return m_clrMaterialDiffuseColor; } AFX_INLINE void CXTPChart3dDeviceContext::SetMaterialSpecularColor(const CXTPChartColor& color) { m_clrMaterialSpecularColor = color; } AFX_INLINE const CXTPChartColor& CXTPChart3dDeviceContext::GetMaterialSpecularColor() const { return m_clrMaterialSpecularColor; } AFX_INLINE void CXTPChart3dDeviceContext::SetMaterialShininess(float fShininess) { m_fMaterialShininess = fShininess; } AFX_INLINE float CXTPChart3dDeviceContext::GetMaterialShininess() const { return m_fMaterialShininess; } /** @cond */ AFX_INLINE BOOL CXTPChart3dDeviceContext::IsInitialPass() const { return m_bInitialPass; } AFX_INLINE CXTPOpenGLTriangleRenderList& CXTPChart3dDeviceContext::GetTriangleRenderList() { return *m_pTriangles; } /** @endcond */ AFX_INLINE BOOL CXTPChart3dDeviceContext::GetAntialiasing() const { return m_bAntialiasing; } AFX_INLINE void CXTPChart3dDeviceContext::SetAntialiasing(BOOL bAntialiasing) { m_bAntialiasing = bAntialiasing; } /** @cond */ # include "Common/Base/Diagnostic/XTPEnableNoisyWarnings.h" #endif //#if !defined(__XTPCHART3DDEVICECONTEXT_H__) /** @endcond */