44 if (ImGui::IsMouseClicked(2))
46 ImVec2 mouse_screen = ImGui::GetIO().MousePos / ImGui::GetIO().DisplaySize;
49 float min_dist = std::numeric_limits<float>::max();
50 Vector3 origin = terrain_editor_mouse_ray.getOrigin();
51 Vector3 direction = terrain_editor_mouse_ray.getDirection();
52 for (
int i = 0; i < (int)object_list.size(); i++)
54 Real ray_object_distance = direction.crossProduct(object_list[i].node->getPosition() - origin).length();
55 if (ray_object_distance < min_dist)
57 min_dist = ray_object_distance;
58 update = (m_object_index != i);
63 if (m_object_index != -1)
65 m_last_object_name = object_list[m_object_index].name;
69 if (m_object_index == -1)
75 float min_dist = std::numeric_limits<float>::max();
76 for (
int i = 0; i < (int)object_list.size(); i++)
78 float dist = ref_pos.squaredDistance(object_list[i].node->getPosition());
93 m_last_object_name !=
"")
103 catch (std::exception& e)
110 if (object_list.size() > 0)
112 m_object_index = (m_object_index + 1 + (int)object_list.size()) % object_list.size();
118 if (object_list.size() > 0)
120 m_object_index = (m_object_index - 1 + (int)object_list.size()) % object_list.size();
126 UTFString axis =
_L(
"ry");
127 if (m_rotation_axis == 0)
132 else if (m_rotation_axis == 1)
137 else if (m_rotation_axis == 2)
142 UTFString ssmsg =
_L(
"Rotating: ") + axis;
147 m_object_tracking = !m_object_tracking;
148 UTFString ssmsg = m_object_tracking ?
_L(
"Enabled object tracking") :
_L(
"Disabled object tracking");
151 if (m_object_index != -1 && update)
153 String ssmsg =
_L(
"Selected object: [") +
TOSTRING(m_object_index) +
"/" +
TOSTRING(object_list.size()) +
"] (" + object_list[m_object_index].name +
")";
155 if (m_object_tracking)
162 SceneNode* sn = object_list[m_object_index].node;
164 object_list[m_object_index].position = object_list[m_object_index].initial_position;
165 sn->setPosition(object_list[m_object_index].position);
167 object_list[m_object_index].rotation = object_list[m_object_index].initial_rotation;
168 Vector3 rot = object_list[m_object_index].rotation;
169 sn->setOrientation(Quaternion(Degree(rot.x), Vector3::UNIT_X) * Quaternion(Degree(rot.y), Vector3::UNIT_Y) * Quaternion(Degree(rot.z), Vector3::UNIT_Z));
170 sn->pitch(Degree(-90));
174 SceneNode* sn = object_list[m_object_index].node;
176 Vector3 translation = Vector3::ZERO;
177 float rotation = 0.0f;
189 translation.y += 0.5f;
193 translation.y -= 0.5f;
197 translation.x += 0.5f;
201 translation.x -= 0.5f;
205 translation.z += 0.5f;
209 translation.z -= 0.5f;
212 if (translation != Vector3::ZERO || rotation != 0.0f)
218 object_list[m_object_index].position += translation * scale * dt;
219 sn->setPosition(object_list[m_object_index].position);
221 object_list[m_object_index].rotation[m_rotation_axis] += rotation * scale * dt;
222 Vector3 rot = object_list[m_object_index].rotation;
223 sn->setOrientation(Quaternion(Degree(rot.x), Vector3::UNIT_X) * Quaternion(Degree(rot.y), Vector3::UNIT_Y) * Quaternion(Degree(rot.z), Vector3::UNIT_Z));
224 sn->pitch(Degree(-90));
226 if (m_object_tracking)
231 else if (m_object_tracking &&
App::GetGameContext()->GetPlayerCharacter()->getPosition() != sn->getPosition())
254 const char* filename =
"editor_out.log";
258 Ogre::DataStreamPtr stream
259 = Ogre::ResourceGroupManager::getSingleton().createResource(
262 for (
auto object :
App::GetGameContext()->GetTerrain()->getObjectManager()->GetEditorObjects())
264 SceneNode* sn =
object.node;
267 String pos =
StringUtil::format(
"%8.3f, %8.3f, %8.3f" ,
object.position.x,
object.position.y,
object.position.z);
268 String rot =
StringUtil::format(
"% 6.1f, % 6.1f, % 6.1f",
object.rotation.x,
object.rotation.y,
object.rotation.z);
270 String line = pos +
", " + rot +
", " +
object.name +
"\n";
271 stream->write(line.c_str(), line.length());
277 for (
int i = 0; i < num_roads; i++)
283 stream->write(
"\nbegin_procedural_roads\n", 24);
285 stream->write(smoothing_line.c_str(), smoothing_line.length());
286 for (
int j = 0; j < num_points; j++)
289 std::string type_str;
297 case RoadType::ROAD_BRIDGE: type_str = (point->pillartype == 1) ?
"bridge" :
"bridge_no_pillars";
break;
302 "\t{:13f}, {:13f}, {:13f}, 0, {:13f}, 0, {:13f}, {:13f}, {:13f}, {}\n",
303 point->position.x, point->position.y, point->position.z,
304 point->rotation.getYaw().valueDegrees(),
305 point->width, point->bwidth, point->bheight, type_str);
306 stream->write(line.c_str(), line.length());
308 stream->write(
"end_procedural_roads\n", 21);
312 catch (std::exception& e)
315 "Error saving file '%s' (resource group '%s'), message: '%s'",