FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
SimpleEarth/src/PathTool.cpp at master · MAPSWorks/SimpleEarth · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
MAPSWorks
/
SimpleEarth
Public
forked from
hmendoza2001/SimpleEarth
Notifications
You must be signed in to change notification settings
Fork
2
Star
4
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
SimpleEarth
/
src
/
PathTool.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
177 lines (162 loc) · 5.35 KB
Breadcrumbs
SimpleEarth
/
src
/
PathTool.cpp
Copy path
File metadata and controls
177 lines (162 loc) · 5.35 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
175
176
177
/*
* The Simple Earth Project
* Copyright (C) 2016 HueSoft LLC
* Author: Hector Mendoza, hector.mendoza@huesoftllc.com
*
* This file is part of the Simple Earth Project.
*
* The Simple Earth Project is free software: you can redistribute it
* and/or modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation, either version
* 3 of the License, or (at your option) any later version.
*
* This program 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/>.
*/
#
include
<
QtOpenGL
>
#
include
"
PathTool.h
"
#
include
"
PathRenderer.h
"
#
include
"
WorldObjectManager.h
"
#
include
"
Utilities.h
"
//
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
/*
*
* Constructor. Calls parent constructor with given parameter values and
* initializes attributes.
*
* @param toolButton Handle to corresponding toolbar button
* @param dialog Handle to corresponding dialog
*/
PathTool::PathTool
(QToolButton* toolButton, QDialog* dialog) : Tool(
"
Path
"
, toolButton, dialog)
//
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
{
mCurrentNumberOfPoints
=
0
;
mClickCordinates
.
x
=
0
;
mClickCordinates
.
y
=
0
;
mAddPoint
=
false
;
mColor
.
red
=
1
.
0f
;
mColor
.
green
=
1
.
0f
;
mColor
.
blue
=
1
.
0f
;
mColor
.
alpha
=
1
.
0f
;
}
//
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
/*
*
* Destructor.
*/
PathTool::~PathTool
()
//
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
{
}
//
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
/*
*
* This method is called to initialize attributes for path tool rendering.
*/
void
PathTool::initialize
()
//
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
{
mCurrentNumberOfPoints
=
0
;
mAddPoint
=
false
;
}
//
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
/*
*
* OVERRIDE FOR Tool. Builds the geometry to render a temporary path for
* the tool.
*/
void
PathTool::render
()
//
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
{
//
check if we need a projection computation because we are adding a point
if
(
mAddPoint
&&
mCurrentNumberOfPoints
<
MAX_NUMBER_OF_POINTS
)
{
//
convert click coordinates and add point to our list
mPoints
[
mCurrentNumberOfPoints
] =
Utilities::screenToWorld
(
mClickCordinates
);
mAddPoint
=
false
;
mCurrentNumberOfPoints
++;
}
//
render path
glColor4f
(
mColor
.
red
,
mColor
.
green
,
mColor
.
blue
,
1
.
0f
);
glDisable
(
GL_DEPTH_TEST
);
glLineWidth
(
2
.
0f
);
glBegin
(
GL_LINE_STRIP
);
for
(
int
i =
0
; i <
mCurrentNumberOfPoints
; i++)
{
glVertex3f
(
mPoints
[i].
x
,
mPoints
[i].
y
,
mPoints
[i].
z
);
}
glEnd
();
glLineWidth
(
1
.
0f
);
glEnable
(
GL_DEPTH_TEST
);
}
//
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
/*
*
* Sets the name for this path.
*
* @param name New name for this path
*/
void
PathTool::setName
(
const
QString& name)
//
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
{
mName
= name;
}
//
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
/*
*
* Sets the color for this path.
*
* @param color New color for this path
*/
void
PathTool::setColor
(
const
SimpleColor& color)
//
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
{
mColor
= color;
}
//
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
/*
*
* Adds current path to WorldObjectManager's list. Note how we copy all the local
* to a new instance of a path world object.
*/
bool
PathTool::addCurrent
()
//
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
{
bool
returnValue =
true
;
//
only add path if it has more than 1 point
if
(
mCurrentNumberOfPoints
>
1
)
{
WorldObject* worldObject =
new
WorldObject
();
worldObject->
setName
(
mName
);
worldObject->
setColor
(
mColor
);
worldObject->
setGroup
(WorldObject::
PATH
);
//
instantiate path renderer and associate it with world object
PathRenderer* pathRenderer =
new
PathRenderer
();
for
(
int
i =
0
; i <
mCurrentNumberOfPoints
; i++)
{
pathRenderer->
addPoint
(
mPoints
[i]);
}
worldObject->
setMeshRenderer
(pathRenderer);
//
if object already exists (cannot add) perform cleanup
if
(!
WorldObjectManager::getInstance
()->
addWorldObject
(worldObject))
{
//
note: the path renderer that we associated with this world
//
object will get deleted on the world object's destructor
delete
worldObject;
returnValue =
false
;
}
}
return
returnValue;
}
//
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
/*
*
* Called on a right mouse button release event when the path tools is selected.
*
* @param event Qt's mouse event
*/
void
PathTool::onMouseReleaseEvent
(QMouseEvent* event)
//
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
{
mClickCordinates
.
x
= event->
x
();
mClickCordinates
.
y
= event->
y
();
mAddPoint
=
true
;
}
Back
|
FazBrowse Home
|
New Git URL