summaryrefslogtreecommitdiff
path: root/hammer/ToolPickAngles.cpp
blob: ccc65df0b0a8fd0b09fcd89d3f5ec9f6c25ceb8e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: Tool used for point-and-click setting of angles.
//
//=============================================================================//

#include "stdafx.h"
#include "resource.h"
#include "ToolPickAngles.h"
#include "MapView3D.h"
#include "MapSolid.h"

// memdbgon must be the last include file in a .cpp file!!!
#include <tier0/memdbgon.h>


//-----------------------------------------------------------------------------
// Purpose: Constructor. Inits data members.
//-----------------------------------------------------------------------------
CToolPickAngles::CToolPickAngles(void)
{
	m_pNotifyTarget = NULL;
}


//-----------------------------------------------------------------------------
// Purpose: Destructor.
//-----------------------------------------------------------------------------
CToolPickAngles::~CToolPickAngles(void)
{
}


//-----------------------------------------------------------------------------
// Purpose: Handles the left mouse button up message in the 3D view.
// Input  : pView - The view that the event occurred in.
//			nFlags - Flags per the Windows mouse message.
//			point - Point in client coordinates where the event occurred.
// Output : Returns true if the message was handled by the tool, false if not.
//-----------------------------------------------------------------------------
bool CToolPickAngles::OnLMouseUp3D(CMapView3D *pView, UINT nFlags, const Vector2D &vPoint)
{
	return true;
}


//-----------------------------------------------------------------------------
// Purpose: Handles the left mouse button up message in the 3D view.
// Input  : pView - The view that the event occurred in.
//			nFlags - Flags per the Windows mouse message.
//			point - Point in client coordinates where the event occurred.
// Output : Returns true if the message was handled by the tool, false if not.
//-----------------------------------------------------------------------------
bool CToolPickAngles::OnLMouseDown3D(CMapView3D *pView, UINT nFlags, const Vector2D &vPoint)
{
	unsigned long ulFace;
	CMapClass *pObject = pView->NearestObjectAt( vPoint, ulFace);
	if (pObject != NULL)
	{
		CMapClass *pSelObject = pObject->PrepareSelection(selectObjects);
		CMapEntity *pEntity = dynamic_cast <CMapEntity *>(pSelObject);
		if (pEntity != NULL)
		{
			//
			// We clicked on an entity.
			//
			if (m_pNotifyTarget)
			{
				Vector vecCenter;
				pEntity->GetBoundsCenter(vecCenter);
				m_pNotifyTarget->OnNotifyPickAngles(vecCenter);
			}
		}
		else
		{
			CMapSolid *pSolid = dynamic_cast <CMapSolid *> (pObject);
			if (pSolid == NULL)
			{
				return true;
			}

			//
			// Build a ray to trace against the face that they clicked on to
			// find the point of intersection.
			//			
			Vector Start,End;
			pView->GetCamera()->BuildRay( vPoint, Start, End);

			Vector HitPos;
			Vector HitNormal;
			CMapFace *pFace = pSolid->GetFace(ulFace);
			if (pFace->TraceLine(HitPos, HitNormal, Start, End))
			{
				if (m_pNotifyTarget)
				{
					m_pNotifyTarget->OnNotifyPickAngles(HitPos);
				}
			}
		}
	}

	return true;
}


//-----------------------------------------------------------------------------
// Purpose: Handles the left mouse button double click message in the 3D view.
// Input  : pView - The view that the event occurred in.
//			nFlags - Flags per the Windows mouse message.
//			point - Point in client coordinates where the event occurred.
// Output : Returns true if the message was handled by the tool, false if not.
//-----------------------------------------------------------------------------
bool CToolPickAngles::OnLMouseDblClk3D(CMapView3D *pView, UINT nFlags, const Vector2D &vPoint)
{
	return true;
}


//-----------------------------------------------------------------------------
// Purpose: Handles the right mouse button up message in the 3D view.
// Input  : pView - The view that the event occurred in.
//			nFlags - Flags per the Windows mouse message.
//			point - Point in client coordinates where the event occurred.
// Output : Returns true if the message was handled by the tool, false if not.
//-----------------------------------------------------------------------------
bool CToolPickAngles::OnRMouseUp3D(CMapView3D *pView, UINT nFlags, const Vector2D &vPoint)
{
	return true;
}


//-----------------------------------------------------------------------------
// Purpose: Handles the mouse button up message in the 3D view.
// Input  : pView - The view that the event occurred in.
//			nFlags - Flags per the Windows mouse message.
//			point - Point in client coordinates where the event occurred.
// Output : Returns true if the message was handled by the tool, false if not.
//-----------------------------------------------------------------------------
bool CToolPickAngles::OnRMouseDown3D(CMapView3D *pView, UINT nFlags, const Vector2D &vPoint)
{
	return true;
}


//-----------------------------------------------------------------------------
// Purpose: Handles the mouse move message in the 3D view.
// Input  : pView - The view that the event occurred in.
//			nFlags - Flags per the Windows mouse message.
//			point - Point in client coordinates where the event occurred.
// Output : Returns true if the message was handled by the tool, false if not.
//-----------------------------------------------------------------------------
bool CToolPickAngles::OnMouseMove3D(CMapView3D *pView, UINT nFlags, const Vector2D &vPoint)
{
	SetToolCursor();
	return true;
}


//-----------------------------------------------------------------------------
// Purpose: Sets the cursor to the correct cursor for this tool.
//-----------------------------------------------------------------------------
void CToolPickAngles::SetToolCursor(void)
{
	static HCURSOR hcur = NULL;
	
	if (!hcur)
	{
		hcur = LoadCursor(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDC_CROSSHAIR));
	}
	
	SetCursor(hcur);
}