aboutsummaryrefslogtreecommitdiff
path: root/cvs/cvsweb.cgi/~checkout~/code/client/Attic/move_listener.h?rev=1.2&content-type=text/plain&hideattic=0&sortby=date/index.html
blob: 8fc3444cc5781a9ed8ba24b77633334f3ba74a15 (plain)
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
/** \file move_listener.h
 * <File description>
 *
 * $Id: move_listener.h,v 1.2 2000/12/04 17:58:09 coutelas Exp $
 */

/* Copyright, 2000 Nevrax Ltd.
 *
 * This file is part of NEVRAX NEL.
 * NEVRAX NEL is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2, or (at your option)
 * any later version.

 * NEVRAX NEL is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * General Public License for more details.

 * You should have received a copy of the GNU General Public License
 * along with NEVRAX NEL; see the file COPYING. If not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
 * MA 02111-1307, USA.
 */

#ifndef NL_MOVE_LISTENER_H
#define NL_MOVE_LISTENER_H

#include "nel/misc/types_nl.h"
#include "nel/misc/event_listener.h"
#include "nel/misc/matrix.h"
#include "nel/3d/viewport.h"
#include "nel/3d/scene.h"
#include "nel/3d/camera.h"



namespace NL3D 
{


/**
 * CMoveListener is a listener that handle a 3d matrix with mouse events.
 * \author Stephane Coutelas
 * \author Nevrax France
 * \date 2000
 */
class CMoveListener : public NLMISC::IEventListener
{
public:
	
	/** 
	 * TMoveMode. 
	 * moving modes
	 */
	enum TMoveMode
	{
		WALK,
		FREE
	};
	
	/** 
	 * Constructor. 
	 * You should call init then.
	 */
	CMoveListener();


	/** 
	 * Constructor. 
	 * You should call init then.
	 * \param scene the scene
	 * \param w screen width in pixels
	 * \param h screen height in pixels
	 * \param camera the camera
	 */
	void init(CScene * scene, uint w, uint h, const class CCamera& camera)
	{
		_Scene = scene;
		_Width = w;
		_Height = h;
		
		_Viewport = scene->getViewport();

		float dummy;
		_ViewMatrix = camera.getMatrix ();
		camera.getFrustum (_Left, _Right, _Bottom, _Top, _Depth, dummy);
	}

	/**
	 * Set the moving mode
	 * \param m the moving mode
	 */
	void setMode(TMoveMode m)
	{
		_Mode = m;
	}

	/** 
     * Register the listener to the server.
	 */
	void addToServer (NLMISC::CEventServer& server);

	/** 
	  * Unregister the listener to the server.
	  */
	void removeFromServer (NLMISC::CEventServer& server);
	

private:

	/// Internal use
	virtual void operator()(const NLMISC::CEvent& event);

	/// moving mode
	TMoveMode _Mode;
	
	/// view matrix
	NLMISC::CMatrix _ViewMatrix;

	/// viewport
	NL3D::CViewport	_Viewport;
	
	/// true if previous mouse move event was re-centering cursor
	bool _CursorReset;

	CScene * _Scene;
	
	/// screen width
	uint _Width;

	/// screen height
	uint _Height;

	///frustum parameters
	float _Top;
	float _Bottom;
	float _Left;
	float _Right;
	float _Depth;
	
	/// current position
	CVector _Pos;

	///current rotation z angle
	float _RotZ;

	///current rotation x angle
	float _RotX;
	
	/// step for translation
	static const float _StepTrans;

	/// step for rotation
	static const float _StepRot;

}; // NL3D

}

#endif // NL_MOVE_LISTENER_H

/* End of move_listener.h */