doom3-gpl
Doom 3 GPL source release
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
VectorCtl.h
Go to the documentation of this file.
1 /*
2 ===========================================================================
3 
4 Doom 3 GPL Source Code
5 Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
6 
7 This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
8 
9 Doom 3 Source Code is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
13 
14 Doom 3 Source Code is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18 
19 You should have received a copy of the GNU General Public License
20 along with Doom 3 Source Code. If not, see <http://www.gnu.org/licenses/>.
21 
22 In addition, the Doom 3 Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 Source Code. If not, please request a copy in writing from id Software at the address below.
23 
24 If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
25 
26 ===========================================================================
27 */
28 /*****************************************************************************
29 * *
30 * Vector control *
31 * ---------------- *
32 * *
33 * A 3D vector MFC control derived from CButton. *
34 * Features: *
35 * - Real-time light rendering on a 3D ball. *
36 * - Variable ball radius and position. *
37 * - Supports bitmap background (tiled). *
38 * - Supports vertical gradient color background (from color to color). *
39 * - Variable ball color (diffuse), light color and ambient color. *
40 * - Variable specular intensity. *
41 * - Supports attached controls (for automatic update). *
42 * - Variable mouse sensitivity. *
43 * - Supports front clipping (vector will not have negative Z values). *
44 * - Supports callback functions for the following events: *
45 * 1. The trackball has moved (vector is changing). *
46 * 2. The user dropped the trackball (released left mouse button) *
47 * i.e., the vector was changed. *
48 * *
49 * *
50 *****************************************************************************/
51 
52 #ifndef _VECTOR_CTL_H
53 #define _VECTOR_CTL_H
54 
55 // Callback pointer prototype:
56 typedef void (*VectorCtlCallbackProc)( idQuat rotation );
57 
58 // The callback should look like:
59 // void CALLBACK MyCallBack (double dVecX, double dVecY, double dVecZ);
60 // or
61 // static void CALLBACK MyClass::MyCallBack (double dVecX, double dVecY, double dVecZ);
62 
63 
64 class CVectorCtl : public CButton
65 {
66 
67 #define EPS 1.0e-6 // Epsilon
68 
69 #define DEFAULT_VEC {0.00, 0.00, 1.00} // Default start vector
70 #define DEFAULT_DIFFUSE RGB( 30, 0, 200) // Default diffuse color
71 #define DEFAULT_AMBIENT RGB( 20, 20, 20) // Default ambient color
72 #define DEFAULT_LIGHT RGB(200, 200, 200) // Default light color
73 #define DEFAULT_START_BACKGROUND_COLOR RGB( 0, 0, 0) // Default gradient background start color
74 #define DEFAULT_END_BACKGROUND_COLOR RGB(140, 0, 120) // Default gradient background end color
75 #define DEFAULT_SPEC_EXP 25.0 // Default specular intensity
76 #define VAL_NOT_IN_USE -50000 // Internal use
77 
78 
79 public:
80  CVectorCtl ();
81 
82  virtual ~CVectorCtl ();
83 
84  // Owner-drawn control support function
85  virtual void DrawItem( LPDRAWITEMSTRUCT lpDrawItemStruct );
86 
87  // Sets / Gets diffuse (ball) color.
88  void SetDiffuseColor (COLORREF clr) { m_clrDiffuse = clr; Redraw (); }
89  COLORREF GetDiffuseColor () { return m_clrDiffuse; }
90 
91  // Sets / Gets ambient (background) color.
92  void SetAmbientColor (COLORREF clr) { m_clrAmbient = clr; Redraw (); }
93  COLORREF GetAmbientColor () { return m_clrAmbient; }
94 
95  // Sets / Gets light color.
96  void SetLightColor (COLORREF clr) { m_clrLight = clr; Redraw (); }
97  COLORREF GetLightColor () { return m_clrLight; }
98 
99  // Sets background gradient color (from start to finish vertically)
100  void SetBackgroundColor (COLORREF clrStart, COLORREF clrEnd);
101 
102  // Sets a background bitmap (resource ID)
103  BOOL SetBackgroundImage (UINT uBackgroundBitmapID);
104 
105  // Sets / Gets specular intensity
106  BOOL SetSpecularExponent (double dExp);
108 
109  // Enables auto-update of axis controls.
110  // Place the control's ID and the SetWindowText function will be called
111  // for each vector component to display the value in the control.
112  void SetAxisControl (int nXCtl, int nYCtl, int nZCtl);
113 
114  // Sets / Gets ball radius (in pixels)
115  void SetRadius (UINT uRadius);
116  UINT GetRadius () { return UINT(m_iRadius); }
117 
118  // Sets / Gets ball position (in pixels)
119  void SetCenter (UINT uHorizPos, UINT uVertPos);
122 
123  // Sets / Gets vector components
124  void SetX (double dx) { SetAxis (dx, 0); }
125  double GetX() { return m_dVec[0]; }
126  void SetY (double dy) { SetAxis (dy, 1); }
127  double GetY() { return m_dVec[1]; }
128  void SetZ (double dz) { SetAxis (dz, 2); }
129  double GetZ() { return m_dVec[2]; }
130  void SetVector (double dx, double dy, double dz);
131  void SetidAxis( const idMat3 &mat ) {
132  rotationMatrix = mat;
133  rotationQuat = mat.ToQuat();
134  m_dVec = mat[2];
135  }
136 
137  // Sets / Gets mouse sensitivity
138  BOOL SetSensitivity (UINT uSens);
140 
141  // Bounds / Unbounds vector to front (positive Z) only
142  void ClipToFront (BOOL bEnable) { m_bFrontVector = bEnable; }
143 
144  // Set user-defined callback function to call whenever the vector has changed.
145  // Set to NULL to disable callback.
147  { m_procVectorChanging = proc; }
148 
149  // Set user-defined callback function to call whenever the vector has finished
150  // changing (user dropped track-ball).
151  // Set to NULL to disable callback.
153  { m_procVectorChanged = proc; }
154 
155 private:
156  afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
157  afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
158  afx_msg void OnMouseMove(UINT nFlags, CPoint point);
159 
160  // Mouse is being dragged
161  void OnMouseDrag (int , int);
162  // Create and measure off-screen buffer
163  void InitBitmap (LPDRAWITEMSTRUCT lpDrawItemStruct, CDC *pDC);
164  // Build image to BitBlt
165  void BuildImage (LPDRAWITEMSTRUCT lpDrawItemStruct);
166  // Free resources of background (non-ball) bitmap
167  void ClearBackgroundBitmap ();
168  // Normalize vector
169  BOOL Normalize ();
170  // Calculate lightning effect for a pixel on the ball
171  COLORREF CalcLight (double dx, double dy, double dz);
172  // Rotate our vector by X and Y angles
173  void RotateByXandY (double XRot, double YRot);
174  // Create background image resource
175  void CreateBackground ();
176  // Force redraw of entire image
177  void Redraw (BOOL bErase = FALSE);
178  // Update user-defined vector components controls
179  void UpdateAxisControls ();
180  // Sets a specific vector component to a specific value
181  void SetAxis (double d, int nAxis);
182 
183  CBitmap m_bmpBuffer, // Buffer bitmap for BitBlt
184  m_bmpBack; // Background image bitmap
185  CDC m_dcMem; // Memory DC
186  BOOL m_bBmpCreated, // Was the bitmap created ?
187  m_bBackgroundBitmapUsed,// Are we using a background bitmap ?
188  m_bImageChange, // Has the image changed ?
189  m_bFrontVector, // Is the vector constrained to be facing front (positive Z) ?
190  m_bHasFocus, // Does the control have the focus ?
191  m_bSelected; // Is the control selected ?
192  int m_iWidth, // Region width
193  m_iHeight, // Region height
194  m_iRadius, // Ball radius
195  m_iSqrRadius, // Ball radius to the power of two
196  m_iXCenter, // X center point
197  m_iYCenter; // Y center point
198  CBitmap *m_pOldBitmap; // Previously selected bitmap
199  COLORREF m_clrDiffuse, // Ball diffusion color (self color)
200  m_clrAmbient, // Ambient (background) color
201  m_clrLight, // Color of light
202  m_clrBackgroundStart, // Background color gradient start
203  m_clrBackgroundEnd; // Background color gradient end
204  CWnd *pCtl[3]; // Pointers to axis display controls
205  double m_dSpecularExponent, // Specularity effect intensity
206  m_dSensitivity; // The bigger the number the less sensitive the mouse gets
207  // Valid ranges are 1..MAX_UINT
208  idVec3 m_dVec; // Vector components
213  float radius;
214 
215 
218 
219 protected:
220  DECLARE_MESSAGE_MAP()
221 
222 
223 };
224 
225 #endif
idMat3 rotationMatrix
Definition: VectorCtl.h:209
void SetVectorChangedCallback(VectorCtlCallbackProc proc)
Definition: VectorCtl.h:152
void SetRadius(UINT uRadius)
Definition: VectorCtl.cpp:256
afx_msg void OnLButtonUp(UINT nFlags, CPoint point)
Definition: VectorCtl.cpp:420
BOOL SetBackgroundImage(UINT uBackgroundBitmapID)
Definition: VectorCtl.cpp:305
CONST PIXELFORMATDESCRIPTOR UINT
Definition: win_qgl.cpp:47
VectorCtlCallbackProc m_procVectorChanging
Definition: VectorCtl.h:216
BOOL m_bFrontVector
Definition: VectorCtl.h:186
virtual void DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
Definition: VectorCtl.cpp:80
BOOL SetSensitivity(UINT uSens)
Definition: VectorCtl.cpp:364
COLORREF m_clrLight
Definition: VectorCtl.h:199
UINT GetRadius()
Definition: VectorCtl.h:116
CBitmap m_bmpBack
Definition: VectorCtl.h:183
void SetZ(double dz)
Definition: VectorCtl.h:128
COLORREF GetLightColor()
Definition: VectorCtl.h:97
int m_iSqrRadius
Definition: VectorCtl.h:192
void InitBitmap(LPDRAWITEMSTRUCT lpDrawItemStruct, CDC *pDC)
Definition: VectorCtl.cpp:186
Definition: Vector.h:316
BOOL SetSpecularExponent(double dExp)
Definition: VectorCtl.cpp:200
double GetY()
Definition: VectorCtl.h:127
double GetSpecularExponent()
Definition: VectorCtl.h:107
#define BOOL
Definition: mprintf.c:71
void(* VectorCtlCallbackProc)(idQuat rotation)
Definition: VectorCtl.h:56
void SetCenter(UINT uHorizPos, UINT uVertPos)
Definition: VectorCtl.cpp:265
void SetVector(double dx, double dy, double dz)
Definition: VectorCtl.cpp:287
CDC m_dcMem
Definition: VectorCtl.h:185
void SetBackgroundColor(COLORREF clrStart, COLORREF clrEnd)
Definition: VectorCtl.cpp:296
void SetAmbientColor(COLORREF clr)
Definition: VectorCtl.h:92
int m_iXCenter
Definition: VectorCtl.h:192
BOOL m_bImageChange
Definition: VectorCtl.h:186
COLORREF m_clrBackgroundStart
Definition: VectorCtl.h:199
float radius
Definition: VectorCtl.h:213
void SetY(double dy)
Definition: VectorCtl.h:126
void OnMouseDrag(int, int)
Definition: VectorCtl.cpp:108
idQuat rotationQuat
Definition: VectorCtl.h:210
void BuildImage(LPDRAWITEMSTRUCT lpDrawItemStruct)
Definition: VectorCtl.cpp:115
int m_iYCenter
Definition: VectorCtl.h:192
double GetZ()
Definition: VectorCtl.h:129
BOOL Normalize()
Definition: VectorCtl.cpp:133
double m_dSpecularExponent
Definition: VectorCtl.h:205
BOOL m_bBmpCreated
Definition: VectorCtl.h:186
void CreateBackground()
Definition: VectorCtl.cpp:318
void SetAxisControl(int nXCtl, int nYCtl, int nZCtl)
Definition: VectorCtl.cpp:249
int m_iHeight
Definition: VectorCtl.h:192
COLORREF m_clrAmbient
Definition: VectorCtl.h:199
CBitmap m_bmpBuffer
Definition: VectorCtl.h:183
VectorCtlCallbackProc m_procVectorChanged
Definition: VectorCtl.h:216
idQuat previousQuat
Definition: VectorCtl.h:211
virtual ~CVectorCtl()
Definition: VectorCtl.cpp:72
void SetAxis(double d, int nAxis)
Definition: VectorCtl.cpp:274
void SetVectorChangingCallback(VectorCtlCallbackProc proc)
Definition: VectorCtl.h:146
void RotateByXandY(double XRot, double YRot)
Definition: VectorCtl.cpp:210
UINT GetSensitivity()
Definition: VectorCtl.h:139
UINT GetHorizCenter()
Definition: VectorCtl.h:120
void SetLightColor(COLORREF clr)
Definition: VectorCtl.h:96
afx_msg void OnLButtonDown(UINT nFlags, CPoint point)
Definition: VectorCtl.cpp:413
Definition: Quat.h:48
COLORREF m_clrBackgroundEnd
Definition: VectorCtl.h:199
COLORREF GetDiffuseColor()
Definition: VectorCtl.h:89
UINT GetVertCenter()
Definition: VectorCtl.h:121
void ClipToFront(BOOL bEnable)
Definition: VectorCtl.h:142
Definition: Matrix.h:333
void Redraw(BOOL bErase=FALSE)
Definition: VectorCtl.cpp:372
void SetX(double dx)
Definition: VectorCtl.h:124
idQuat ToQuat(void) const
Definition: Matrix.cpp:182
BOOL m_bSelected
Definition: VectorCtl.h:186
idVec3 lastPress
Definition: VectorCtl.h:212
int m_iRadius
Definition: VectorCtl.h:192
typedef void(APIENTRYP PFNGLBLENDCOLORPROC)(GLclampf red
#define FALSE
Definition: mprintf.c:70
void SetDiffuseColor(COLORREF clr)
Definition: VectorCtl.h:88
idVec3 m_dVec
Definition: VectorCtl.h:208
int m_iWidth
Definition: VectorCtl.h:192
CWnd * pCtl[3]
Definition: VectorCtl.h:204
double m_dSensitivity
Definition: VectorCtl.h:205
void UpdateAxisControls()
Definition: VectorCtl.cpp:239
BOOL m_bHasFocus
Definition: VectorCtl.h:186
COLORREF CalcLight(double dx, double dy, double dz)
Definition: VectorCtl.cpp:152
void SetidAxis(const idMat3 &mat)
Definition: VectorCtl.h:131
void ClearBackgroundBitmap()
Definition: VectorCtl.cpp:356
double GetX()
Definition: VectorCtl.h:125
COLORREF m_clrDiffuse
Definition: VectorCtl.h:199
BOOL m_bBackgroundBitmapUsed
Definition: VectorCtl.h:186
afx_msg void OnMouseMove(UINT nFlags, CPoint point)
Definition: VectorCtl.cpp:378
CBitmap * m_pOldBitmap
Definition: VectorCtl.h:198
COLORREF GetAmbientColor()
Definition: VectorCtl.h:93