|
@@ -20,7 +20,10 @@
|
20
|
20
|
|
21
|
21
|
bool Selector::visible = false;
|
22
|
22
|
WorldObjects Selector::lastClickedObject = WorldObjectCount;
|
23
|
|
-std::array<bool, WorldObjectCount> Selector::clickOnObject = {{ false, true, true, true, false, false }};
|
|
23
|
+
|
|
24
|
+// geometryObject, roomSpriteObject, roomModelObject, spriteObject, meshObject, modelObject, entityObject
|
|
25
|
+std::array<bool, WorldObjectCount> Selector::clickOnObject = {{ false, true, true, false, false, false, false }};
|
|
26
|
+
|
24
|
27
|
glm::i32vec2 Selector::rayScreen(-1, -1);
|
25
|
28
|
glm::vec3 Selector::rayWorld, Selector::lastIntersectPos, Selector::lastIntersectNorm;
|
26
|
29
|
unsigned long Selector::lastIndexA, Selector::lastIndexB;
|
|
@@ -41,48 +44,48 @@ void Selector::handleMouseClick(unsigned int x, unsigned int y, KeyboardButton b
|
41
|
44
|
bool foundSomething = false;
|
42
|
45
|
float depth = -1.0f;
|
43
|
46
|
|
44
|
|
- if (clickOnObject[modelObject]) {
|
45
|
|
-
|
46
|
|
- }
|
47
|
|
-
|
48
|
|
- if (clickOnObject[meshObject]) {
|
49
|
|
-
|
50
|
|
- }
|
51
|
|
-
|
52
|
|
- if (clickOnObject[spriteObject]) {
|
53
|
|
-
|
54
|
|
- }
|
55
|
|
-
|
56
|
|
- if (clickOnObject[roomModelObject]) {
|
|
47
|
+ if (clickOnObject[roomModelObject] || clickOnObject[roomSpriteObject]) {
|
57
|
48
|
for (unsigned long i = 0; i < World::sizeRoom(); i++) {
|
58
|
|
- Room &r = World::getRoom(i);
|
59
|
|
- for (unsigned long j = 0; j < r.sizeModels(); j++) {
|
60
|
|
- StaticModel &sm = r.getModel(j);
|
61
|
|
- glm::vec3 pos, norm;
|
62
|
|
- if (glm::intersectRaySphere(Camera::getPosition(), rayWorld, sm.getCenter(), sm.getRadius(),
|
63
|
|
- pos, norm)) {
|
64
|
|
- float newDepth = glm::abs(glm::distance(sm.getCenter(), Camera::getPosition()));
|
65
|
|
- if ((newDepth < depth) || (depth < 0.0f)) {
|
66
|
|
- depth = newDepth;
|
67
|
|
- lastIndexA = i;
|
68
|
|
- lastIndexB = j;
|
69
|
|
- lastIntersectPos = pos;
|
70
|
|
- lastIntersectNorm = norm;
|
71
|
|
- lastClickedObject = roomModelObject;
|
72
|
|
- foundSomething = true;
|
|
49
|
+ Room& r = World::getRoom(i);
|
|
50
|
+ glm::vec3 pos, norm;
|
|
51
|
+
|
|
52
|
+ if (clickOnObject[roomModelObject]) {
|
|
53
|
+ for (unsigned long j = 0; j < r.sizeModels(); j++) {
|
|
54
|
+ StaticModel& sm = r.getModel(j);
|
|
55
|
+ if (glm::intersectRaySphere(Camera::getPosition(), rayWorld, sm.getCenter(), sm.getRadius(),
|
|
56
|
+ pos, norm)) {
|
|
57
|
+ float newDepth = glm::abs(glm::distance(sm.getCenter(), Camera::getPosition()));
|
|
58
|
+ if ((newDepth < depth) || (depth < 0.0f)) {
|
|
59
|
+ depth = newDepth;
|
|
60
|
+ lastIndexA = i;
|
|
61
|
+ lastIndexB = j;
|
|
62
|
+ lastIntersectPos = pos;
|
|
63
|
+ lastIntersectNorm = norm;
|
|
64
|
+ lastClickedObject = roomModelObject;
|
|
65
|
+ foundSomething = true;
|
|
66
|
+ }
|
73
|
67
|
}
|
74
|
68
|
}
|
75
|
69
|
}
|
76
|
|
- }
|
77
|
|
- }
|
78
|
|
-
|
79
|
|
- if (clickOnObject[roomSpriteObject]) {
|
80
|
|
-
|
81
|
|
- }
|
82
|
|
-
|
83
|
|
- if (clickOnObject[geometryObject]) {
|
84
|
|
-
|
85
|
70
|
|
|
71
|
+ if (clickOnObject[roomSpriteObject]) {
|
|
72
|
+ for (unsigned long j = 0; j < r.sizeSprites(); j++) {
|
|
73
|
+ RoomSprite& rs = r.getSprite(j);
|
|
74
|
+ if (glm::intersectRaySphere(Camera::getPosition(), rayWorld, rs.getCenter(), rs.getRadius(), pos, norm)) {
|
|
75
|
+ float newDepth = glm::abs(glm::distance(rs.getCenter(), Camera::getPosition()));
|
|
76
|
+ if ((newDepth < depth) || (depth < 0.0f)) {
|
|
77
|
+ depth = newDepth;
|
|
78
|
+ lastIndexA = i;
|
|
79
|
+ lastIndexB = j;
|
|
80
|
+ lastIntersectPos = pos;
|
|
81
|
+ lastIntersectNorm = norm;
|
|
82
|
+ lastClickedObject = roomSpriteObject;
|
|
83
|
+ foundSomething = true;
|
|
84
|
+ }
|
|
85
|
+ }
|
|
86
|
+ }
|
|
87
|
+ }
|
|
88
|
+ }
|
86
|
89
|
}
|
87
|
90
|
|
88
|
91
|
if (!foundSomething) {
|
|
@@ -94,6 +97,10 @@ void Selector::handleMouseClick(unsigned int x, unsigned int y, KeyboardButton b
|
94
|
97
|
void Selector::displaySelection() {
|
95
|
98
|
if (lastClickedObject == roomModelObject) {
|
96
|
99
|
World::getRoom(lastIndexA).getModel(lastIndexB).displayBoundingSphere(Camera::getProjectionMatrix() * Camera::getViewMatrix(), glm::vec3(1.0f, 0.0f, 0.0f));
|
|
100
|
+ } else if (lastClickedObject == roomSpriteObject) {
|
|
101
|
+ World::getRoom(lastIndexA).getSprite(lastIndexB).displayBoundingSphere(Camera::getProjectionMatrix() * Camera::getViewMatrix(), glm::vec3(1.0f, 0.0f, 0.0f));
|
|
102
|
+ } else {
|
|
103
|
+ lastClickedObject = WorldObjectCount;
|
97
|
104
|
}
|
98
|
105
|
}
|
99
|
106
|
|
|
@@ -106,29 +113,15 @@ void Selector::display() {
|
106
|
113
|
return;
|
107
|
114
|
}
|
108
|
115
|
|
109
|
|
- ImGui::Checkbox("Geometry", &clickOnObject[geometryObject]);
|
110
|
|
- ImGui::SameLine();
|
111
|
116
|
ImGui::Checkbox("RoomModels", &clickOnObject[roomModelObject]);
|
112
|
117
|
ImGui::SameLine();
|
113
|
118
|
ImGui::Checkbox("RoomSprites", &clickOnObject[roomSpriteObject]);
|
114
|
|
- ImGui::Checkbox("Sprites", &clickOnObject[spriteObject]);
|
115
|
|
- ImGui::SameLine();
|
116
|
|
- ImGui::Checkbox("Meshes", &clickOnObject[meshObject]);
|
117
|
|
- ImGui::SameLine();
|
118
|
|
- ImGui::Checkbox("Models", &clickOnObject[modelObject]);
|
119
|
119
|
ImGui::SameLine();
|
120
|
120
|
if (ImGui::Button("Hide Selector")) {
|
121
|
121
|
visible = false;
|
122
|
122
|
}
|
123
|
123
|
ImGui::Separator();
|
124
|
124
|
|
125
|
|
- // Not yet implemented!
|
126
|
|
- clickOnObject[modelObject] = false;
|
127
|
|
- clickOnObject[meshObject] = false;
|
128
|
|
- clickOnObject[spriteObject] = false;
|
129
|
|
- clickOnObject[roomSpriteObject] = false;
|
130
|
|
- clickOnObject[geometryObject] = false;
|
131
|
|
-
|
132
|
125
|
ImGui::Text("Camera: (%.2f %.2f %.2f)", Camera::getPosition().x, Camera::getPosition().y, Camera::getPosition().z);
|
133
|
126
|
ImGui::Text("Last click: (%d %d)", rayScreen.x, rayScreen.y);
|
134
|
127
|
if ((rayScreen.x >= 0) && (rayScreen.y >= 0)) {
|
|
@@ -143,6 +136,11 @@ void Selector::display() {
|
143
|
136
|
if (lastClickedObject == roomModelObject) {
|
144
|
137
|
ImGui::Text("Last Room: %lu", lastIndexA);
|
145
|
138
|
ImGui::Text("Last RoomModel: %lu", lastIndexB);
|
|
139
|
+ } else if (lastClickedObject == roomSpriteObject) {
|
|
140
|
+ ImGui::Text("Last Room: %lu", lastIndexA);
|
|
141
|
+ ImGui::Text("Last RoomSprite: %lu", lastIndexB);
|
|
142
|
+ } else {
|
|
143
|
+ lastClickedObject = WorldObjectCount;
|
146
|
144
|
}
|
147
|
145
|
|
148
|
146
|
ImGui::End();
|