/** * @file XTPOpenGLUtils.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(__XTPOPENGLUTILS_H__) # define __XTPOPENGLUTILS_H__ /** @endcond */ # if _MSC_VER > 1000 # pragma once # endif // _MSC_VER > 1000 # include "Common/Base/Diagnostic/XTPDisableNoisyWarnings.h" template class CXTPMatrix; /** * @brief * Provides a set of common OpenGL utilities. */ class _XTP_EXT_CLASS CXTPOpenGLUtils { public: /** @cond */ # ifdef _DEBUG // Debugging static void DebugAxes(double dSize); static void DebugBox(const CXTPPoint3d& ptMin, const CXTPPoint3d& ptMax, BOOL bSolid = FALSE); static void DebugNormal(const CXTPPoint3d& a, const CXTPPoint3d& b, const CXTPPoint3d& c, const CXTPPoint3d& n, double dLen = 5.); static void DebugNormal(const CXTPPoint3d& v, const CXTPPoint3d& n, double dLen = 5.); # endif /*_DEBUG*/ /** @endcond */ /** * @brief * Sets a vertex from point coordinates. * @param ptVertex Vertex coordinates. */ static void Vertex(const CXTPPoint3d& ptVertex); /** * @brief * Sets a vertex and its normal from point coordinates. * @param ptVertex Vertex coordinates. * @param vNormal Normal coordinates. */ static void Vertex(const CXTPPoint3d& ptVertex, const CXTPPoint3d& vNormal); /** * @brief * Rotates the active matrix using Euler angles. * @param dYaw Yaw angle value in degrees. * @param dPitch Pitch angle value in degrees. * @param dRoll Roll angle value in degrees. */ static void Rotate(double dYaw, double dPitch, double dRoll); /** * @brief * Projects 3D space coordinates between the near and far planes to * 2D space coordinates of the current viewport. * @param pt3d Reference to a CPoint object containing the * 3D space coordinates between the near and far planes. * @param pt2d Reference to a CPoint object to receive the resulting * 2D space point coordinates of the current viewport. * @param pdWinZ Z-plane coordinate of the specified 3D point (i.e. the position * between the near plane (0) and the far plane (1)); can be NULL. * @return * TRUE if the coordinates are mapped successfully. * @see * Unproject */ static BOOL Project(const CXTPPoint3d& pt3d, CPoint& pt2d, double* pdWinZ = NULL); /** * @brief * Unprojects 2D space coordinates of the current viewport to * 3D space coordinates between the near and far planes. * @param pt2d Reference to a CPoint object containing the * 2D space coordinates of the current viewport. * @param pt3d Reference to a CPoint object to receive the resulting * 3D space coordinates between the near and far planes. * @param dWinZ Z-plane coordinate of the specified 3D point (i.e. the position * between the near plane (0) and the far plane (1)). * @return * TRUE if the coordinates are mapped successfully. * @see * Project */ static BOOL Unproject(const CPoint& pt2d, CXTPPoint3d& pt3d, double dWinZ = 0.); /** * @brief * Multiplies a vector by a specified matrix. * @param v Vector to multiply by the matrix. * @param matrix Matrix by which the vector is multiplied. */ static void MultiplyByMatrix(CXTPPoint3d& v, const CXTPMatrix& matrix); /** * @brief * Multiplies a vector by a specified OpenGL matrix. * @param v Vector to multiply by the OpenGL matrix. * @param name Name of an OpenGL matrix by which the vector is multiplied. */ static void MultiplyByMatrix(CXTPPoint3d& v, GLenum name); /** * @brief * Computes a normal for a specified triangle. * @param vA 1st triangle point. * @param vB 2nd triangle point. * @param vC 3rd triangle point. * @param ccw Determines which side of the triangle that the normal vector * will be directed from. By default, triangle points are assumed * to be in clockwise order which determines the front face of * the triangle for which the normal is computed. In order to * reverse a normal vector, this value has to be false which means * counter-clockwise vertex unwinding. * @return * Computed normal vector. */ static CXTPPoint3d ComputeTriangleNormal(const CXTPPoint3d& vA, const CXTPPoint3d& vB, const CXTPPoint3d& vC, bool ccw = false); }; # include "Common/Base/Diagnostic/XTPEnableNoisyWarnings.h" /** @cond */ #endif // #if !defined(__XTPOPENGLUTILS_H__) /** @endcond */