 |
RigsofRods
Soft-body Physics Simulation
|
Go to the documentation of this file.
47 if (ImGui::IsMouseClicked(2))
49 ImVec2 mouse_screen = ImGui::GetIO().MousePos / ImGui::GetIO().DisplaySize;
52 float min_dist = std::numeric_limits<float>::max();
53 Vector3 origin = terrain_editor_mouse_ray.getOrigin();
54 Vector3 direction = terrain_editor_mouse_ray.getDirection();
55 for (
int i = 0; i < (int)object_list.size(); i++)
57 Real ray_object_distance = direction.crossProduct(object_list[i]->getPosition() - origin).length();
58 if (ray_object_distance < min_dist)
60 min_dist = ray_object_distance;
61 this->SetSelectedObjectByID(i);
65 if (m_selected_object_id != -1)
67 m_last_object_name = object_list[m_selected_object_id]->name;
71 if (m_selected_object_id == -1)
77 float min_dist = std::numeric_limits<float>::max();
78 for (
int i = 0; i < (int)object_list.size(); i++)
80 float dist = ref_pos.squaredDistance(object_list[i]->getPosition());
83 this->SetSelectedObjectByID(i);
90 m_selected_object_id = -1;
94 m_last_object_name !=
"")
104 catch (std::exception& e)
111 if (object_list.size() > 0)
114 this->SetSelectedObjectByID(i);
119 if (object_list.size() > 0)
122 this->SetSelectedObjectByID(i);
127 std::string axis =
_L(
"ry");
128 if (m_rotation_axis == 0)
133 else if (m_rotation_axis == 1)
138 else if (m_rotation_axis == 2)
143 std::string ssmsg =
_L(
"Rotating: ") + axis;
148 m_object_tracking = !m_object_tracking;
149 std::string ssmsg = m_object_tracking ?
_L(
"Enabled object tracking") :
_L(
"Disabled object tracking");
154 object_list[m_selected_object_id]->setPosition(object_list[m_selected_object_id]->initial_position);
155 object_list[m_selected_object_id]->setRotation(object_list[m_selected_object_id]->initial_rotation);
159 Vector3 translation = Vector3::ZERO;
160 float rotation = 0.0f;
172 translation.y += 0.5f;
176 translation.y -= 0.5f;
180 translation.x += 0.5f;
184 translation.x -= 0.5f;
188 translation.z += 0.5f;
192 translation.z -= 0.5f;
195 if (translation != Vector3::ZERO || rotation != 0.0f)
201 Ogre::Vector3 new_position = object_list[m_selected_object_id]->getPosition();
202 new_position += translation * scale * dt;
203 object_list[m_selected_object_id]->setPosition(new_position);
205 Ogre::Vector3 new_rotation = object_list[m_selected_object_id]->getRotation();
206 new_rotation[m_rotation_axis] += rotation * scale * dt;
207 object_list[m_selected_object_id]->setRotation(new_rotation);
209 if (m_object_tracking)
214 else if (m_object_tracking &&
App::GetGameContext()->GetPlayerCharacter()->getPosition() != object_list[m_selected_object_id]->getPosition())
216 object_list[m_selected_object_id]->setPosition(
App::GetGameContext()->GetPlayerCharacter()->getPosition());
249 fmt::format(
"Cannot export terrain editor changes - terrain is not a project"));
254 for (
size_t i = 0; i < terrain->
getObjectManager()->GetTobjCache().size(); i++)
258 tobj->objects.clear();
259 tobj->vehicles.clear();
262 if (src->tobj_cache_id == i)
275 tobj->objects.push_back(dst);
283 dst.
type = src->special_object_type;
285 tobj->vehicles.push_back(dst);
292 Ogre::DataStreamPtr stream
293 = Ogre::ResourceGroupManager::getSingleton().createResource(
300 fmt::format(
"Error saving file '{}' to resource group '{}'",
314 if (
id == m_selected_object_id)
319 m_selected_object_id = id;
328 String ssmsg =
_L(
"Selected object: [") +
TOSTRING(m_selected_object_id) +
"/" +
TOSTRING(object_list.size()) +
"] (" + object_list[m_selected_object_id]->name +
")";
330 if (m_object_tracking)
337 ROR_ASSERT(
object != TERRAINEDITOROBJECTPTR_NULL);
346 return m_selected_object_id;
353 return TERRAINEDITOROBJECTPTR_NULL;
357 ROR_ASSERT(m_selected_object_id < (
int)object_list.size());
358 if (m_selected_object_id >= (
int)object_list.size())
360 LOG(
fmt::format(
"[RoR|TerrainEditor] INTERNAL ERROR - `m_selected_object_id` '{}' >= `(int)object_list.size()` '{}'",
361 m_selected_object_id, (
int)object_list.size()));
362 return TERRAINEDITOROBJECTPTR_NULL;
365 return object_list[m_selected_object_id];
409 if (static_object_node)
411 static_object_node->setPosition(pos);
422 if (static_object_node)
424 static_object_node->setOrientation(Quaternion(Degree(rot.x), Vector3::UNIT_X) * Quaternion(Degree(rot.y), Vector3::UNIT_Y) * Quaternion(Degree(rot.z), Vector3::UNIT_Z));
425 static_object_node->pitch(Degree(-90));
440 return instance_name;
450 return special_object_type;
455 special_object_type = type;
460 return actor_instance_id;
465 actor_instance_id = instance_id;
#define ROR_ASSERT(_EXPR)
Game state manager and message-queue provider.
std::string resource_bundle_type
Archive type recognized by OGRE resource system: 'FileSystem' or 'Zip'.
Ogre::Vector3 const & getPosition()
void setPosition(Ogre::Vector3 position)
void UpdateInputEvents(float dt)
@ MSG_SIM_MODIFY_ACTOR_REQUESTED
Payload = RoR::ActorModifyRequest* (owner)
void SetSelectedObjectByID(TerrainEditorObjectID_t id)
@ CONSOLE_MSGTYPE_TERRN
Parsing/spawn/simulation messages for terrain.
static const ActorPtr ACTORPTR_NULL
void setPosition(Ogre::Vector3 const &pos)
std::string comments
Comment line(s) preceding the object-line in the .TOBJ file.
CameraManager * GetCameraManager()
Ogre::Vector3 const & getRotation()
ActorInstanceID_t ar_instance_id
Static attr; session-unique ID.
@ REFRESH_VISUALS
Forces a synchronous update of visuals from any context - i.e. from terrain editor mode or with sleep...
static const TerrainEditorObjectID_t TERRAINEDITOROBJECTID_INVALID
std::string getTerrainFileResourceGroup()
Truck file format(technical spec)
TerrainObjectManager * getObjectManager()
static const TerrainEditorObjectPtr TERRAINEDITOROBJECTPTR_NULL
void HandleGenericException(const std::string &from, BitMask_t flags)
Character * GetPlayerCharacter()
char instance_name[TObj::STR_LEN]
System integration layer; inspired by OgreBites::ApplicationContext.
void putMessage(MessageArea area, MessageType type, std::string const &msg, std::string icon="")
void TerrainEditorObjectRefreshActorVisual(TerrainEditorObjectPtr obj)
void destroyObject(const Ogre::String &instancename)
bool LoadTerrainObject(const Ogre::String &name, const Ogre::Vector3 &pos, const Ogre::Vector3 &rot, const Ogre::String &instancename, const Ogre::String &type, float rendering_distance=0, bool enable_collisions=true, int scripthandler=-1, bool uniquifyMaterial=false)
char odef_name[TObj::STR_LEN]
Ogre::SceneNode * GetCameraNode()
std::string const & getType()
ActorInstanceID_t amr_actor
CameraBehaviors GetCurrentBehavior() const
enum Script2Game::inputEvents KC_LSHIFT
Ogre::Camera * GetCamera()
int ActorInstanceID_t
Unique sequentially generated ID of an actor in session. Use ActorManager::GetActorById()
Ogre::Quaternion amr_softrespawn_rotation
Rotation to use with SOFT_RESPAWN; use TObjParser::CalcRotation() to calculate quaternion from XYZ li...
void ClearSelectedObject()
std::shared_ptr< TObjDocument > TObjDocumentPtr
Ogre::Vector3 tobj_rotation
Original rotation specified in .TOBJ file.
ActorInstanceID_t getActorInstanceId()
static const ActorInstanceID_t ACTORINSTANCEID_INVALID
void PushMessage(Message m)
Doesn't guarantee order! Use ChainMessage() if order matters.
bool GetEditorObjectFlagRotYXZ(TerrainEditorObjectPtr const &object)
CharacterFactory * GetCharacterFactory()
const TerrainEditorObjectPtr & FetchSelectedObject()
enum Script2Game::inputEvents KC_SPACE
GameContext * GetGameContext()
TerrainEditorObjectID_t GetSelectedObjectID() const
Ogre::Vector3 getPosition()
TerrainEditorObjectPtrVec & GetEditorObjects()
Ogre::Vector3 amr_softrespawn_position
Position to use with SOFT_RESPAWN.
@ CONSOLE_SYSTEM_REPLY
Success.
static Ogre::Quaternion CalcRotation(Ogre::Vector3 const &rot, bool rot_yxz)
std::string const & getInstanceName()
int TerrainEditorObjectID_t
Offset into RoR::TerrainObjectManager::m_editor_objects, use RoR::TERRAINEDITOROBJECTID_INVALID as em...
@ SOFT_RESPAWN
Like hard reset, but positions the actor like spawn process does - using the relative positions from ...
TObjSpecialObject getSpecialObjectType()
Unified game event system - all requests and state changes are reported using a message.
std::string const & getName()
void WriteToStream(TObjDocumentPtr doc, Ogre::DataStreamPtr stream)
@ MSG_EDI_LEAVE_TERRN_EDITOR_REQUESTED
CacheEntryPtr getCacheEntry()
InputEngine * GetInputEngine()
@ CONSOLE_MSGTYPE_INFO
Generic message.
void setRotation(Ogre::Vector3 const &rot)
void setActorInstanceId(ActorInstanceID_t instance_id)
const ActorPtr & GetActorById(ActorInstanceID_t actor_id)
std::vector< TObjDocumentPtr > & GetTobjCache()
ActorManager * GetActorManager()
void setSpecialObjectType(TObjSpecialObject type)
@ HANDLEGENERICEXCEPTION_CONSOLE
void SpawnSinglePredefinedActor(TerrainEditorObjectPtr const &object)
const TerrainPtr & GetTerrain()