mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-03-22 15:05:03 +01:00
3-axis rotation, and some corrections in editor mode
This commit is contained in:
@@ -659,8 +659,9 @@ TAnimModel::export_as_text_( std::ostream &Output ) const {
|
||||
Output
|
||||
<< location().x << ' '
|
||||
<< location().y << ' '
|
||||
<< location().z << ' '
|
||||
<< vAngle.y << ' ';
|
||||
<< location().z << ' ';
|
||||
Output
|
||||
<< "0 " ;
|
||||
// 3d shape
|
||||
auto modelfile { (
|
||||
pModel ?
|
||||
@@ -698,6 +699,11 @@ TAnimModel::export_as_text_( std::ostream &Output ) const {
|
||||
Output << "notransition" << ' ';
|
||||
}
|
||||
// footer
|
||||
Output << "angles "
|
||||
<< vAngle.x << ' '
|
||||
<< vAngle.y << ' '
|
||||
<< vAngle.z << ' ';
|
||||
// footer
|
||||
Output
|
||||
<< "endmodel"
|
||||
<< "\n";
|
||||
|
||||
100
editormode.cpp
100
editormode.cpp
@@ -246,16 +246,34 @@ editor_mode::on_cursor_pos( double const Horizontal, double const Vertical ) {
|
||||
m_editor.translate( m_node, mouseworldposition, mode_snap() );
|
||||
}
|
||||
}
|
||||
else {
|
||||
// rotate selected node
|
||||
auto const rotation { glm::vec3 { mousemove.y, mousemove.x, 0 } * 0.25f };
|
||||
auto const quantization { (
|
||||
mode_snap() ?
|
||||
15.f : // TODO: put quantization value in a variable
|
||||
0.f ) };
|
||||
m_editor.rotate( m_node, rotation, quantization );
|
||||
}
|
||||
else if (mode_rotationY())
|
||||
{
|
||||
// rotate selected node
|
||||
// auto const rotation{glm::vec3{mousemove.y, mousemove.x, 0} * 0.25f};
|
||||
auto const rotation{glm::vec3{0, mousemove.x, 0} * 0.25f};
|
||||
auto const quantization{(mode_snap() ? 5.f : // TODO: put quantization value in a variable
|
||||
0.f)};
|
||||
m_editor.rotate(m_node, rotation, quantization);
|
||||
}
|
||||
else if (mode_rotationZ())
|
||||
{
|
||||
// rotate selected node
|
||||
|
||||
// auto const rotation{glm::vec3{mousemove.y, mousemove.x, 0} * 0.25f};
|
||||
auto const rotation{glm::vec3{0, 0, mousemove.x} * 0.25f};
|
||||
auto const quantization{(mode_snap() ? 5.f : // TODO: put quantization value in a variable
|
||||
0.f)};
|
||||
m_editor.rotate(m_node, rotation, quantization);
|
||||
}
|
||||
else if (mode_rotationX())
|
||||
{
|
||||
// rotate selected node
|
||||
// auto const rotation{glm::vec3{mousemove.y, mousemove.x, 0} * 0.25f};
|
||||
auto const rotation{glm::vec3{mousemove.y, 0, 0} * 0.25f};
|
||||
auto const quantization{(mode_snap() ? 5.f : // TODO: put quantization value in a variable
|
||||
0.f)};
|
||||
m_editor.rotate(m_node, rotation, quantization);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -303,9 +321,8 @@ editor_mode::on_mouse_button( int const Button, int const Action, int const Mods
|
||||
|
||||
m_node = nullptr;
|
||||
|
||||
GfxRenderer->Pick_Node_Callback([this, mode](scene::basic_node *node)
|
||||
{
|
||||
editor_ui *ui = static_cast<editor_ui*>( m_userinterface.get() );
|
||||
GfxRenderer->Pick_Node_Callback([this, mode,Action,Button](scene::basic_node *node) {
|
||||
editor_ui *ui = static_cast<editor_ui *>(m_userinterface.get());
|
||||
|
||||
if (mode == nodebank_panel::MODIFY) {
|
||||
if (!m_dragging)
|
||||
@@ -316,7 +333,7 @@ editor_mode::on_mouse_button( int const Button, int const Action, int const Mods
|
||||
Application.set_cursor( GLFW_CURSOR_DISABLED );
|
||||
else
|
||||
m_dragging = false;
|
||||
ui->set_node( m_node );
|
||||
ui->set_node(m_node);
|
||||
}
|
||||
else if (mode == nodebank_panel::COPY) {
|
||||
if (node && typeid(*node) == typeid(TAnimModel)) {
|
||||
@@ -360,6 +377,45 @@ editor_mode::on_mouse_button( int const Button, int const Action, int const Mods
|
||||
m_takesnapshot = true;
|
||||
}
|
||||
}
|
||||
if (Button == GLFW_MOUSE_BUTTON_RIGHT)
|
||||
{
|
||||
|
||||
/*if (Action == GLFW_PRESS)
|
||||
{
|
||||
// left button press
|
||||
auto const mode = static_cast<editor_ui *>(m_userinterface.get())->mode();
|
||||
|
||||
m_node = nullptr;
|
||||
|
||||
GfxRenderer->Pick_Node_Callback([this, mode](scene::basic_node *node) {
|
||||
editor_ui *ui = static_cast<editor_ui *>(m_userinterface.get());
|
||||
|
||||
if (mode == nodebank_panel::MODIFY)
|
||||
{
|
||||
if (!m_dragging)
|
||||
return;
|
||||
|
||||
m_node = node;
|
||||
if (m_node)
|
||||
Application.set_cursor(GLFW_CURSOR_DISABLED);
|
||||
else
|
||||
m_dragging = false;
|
||||
ui->set_node(m_node);
|
||||
}
|
||||
});
|
||||
|
||||
m_dragging = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
// left button release
|
||||
if (m_node)
|
||||
Application.set_cursor(GLFW_CURSOR_NORMAL);
|
||||
m_dragging = false;
|
||||
// prime history stack for another snapshot
|
||||
m_takesnapshot = true;
|
||||
}*/
|
||||
}
|
||||
|
||||
m_input.mouse.button( Button, Action );
|
||||
}
|
||||
@@ -388,14 +444,24 @@ editor_mode::mode_translation_vertical() const {
|
||||
return ( true == Global.shiftState );
|
||||
}
|
||||
|
||||
bool
|
||||
editor_mode::mode_rotation() const {
|
||||
bool editor_mode::mode_rotationY() const
|
||||
{
|
||||
|
||||
return ( true == Global.altState );
|
||||
return ((true == Global.altState) && (false == Global.ctrlState) && (false == Global.shiftState));
|
||||
}
|
||||
bool editor_mode::mode_rotationX() const
|
||||
{
|
||||
|
||||
return ((true == Global.altState) && (true == Global.ctrlState) && (false == Global.shiftState));
|
||||
}
|
||||
bool editor_mode::mode_rotationZ() const
|
||||
{
|
||||
|
||||
return ((true == Global.altState) && (true == Global.ctrlState) && (true == Global.shiftState));
|
||||
}
|
||||
|
||||
bool
|
||||
editor_mode::mode_snap() const {
|
||||
|
||||
return ( true == Global.ctrlState );
|
||||
return ((false == Global.altState) && (true == Global.ctrlState) && (false == Global.shiftState));
|
||||
}
|
||||
|
||||
@@ -73,7 +73,11 @@ private:
|
||||
bool
|
||||
mode_translation_vertical() const;
|
||||
bool
|
||||
mode_rotation() const;
|
||||
mode_rotationY() const;
|
||||
bool
|
||||
mode_rotationX() const;
|
||||
bool
|
||||
mode_rotationZ() const;
|
||||
bool
|
||||
mode_snap() const;
|
||||
// members
|
||||
|
||||
@@ -68,8 +68,10 @@ itemproperties_panel::update( scene::basic_node const *Node ) {
|
||||
|
||||
auto const *subnode = static_cast<TAnimModel const *>( node );
|
||||
|
||||
textline = "angle: " + to_string( clamp_circular( subnode->vAngle.y, 360.f ), 2 ) + " deg";
|
||||
textline += "; lights: ";
|
||||
textline = "angle_x: " + to_string(clamp_circular(subnode->vAngle.x, 360.f), 2) + " deg, " +
|
||||
"angle_y: " + to_string(clamp_circular(subnode->vAngle.y, 360.f), 2) + " deg, " +
|
||||
"angle_z: " + to_string(clamp_circular(subnode->vAngle.z, 360.f), 2) + " deg";
|
||||
textline += ";\nlights: ";
|
||||
if( subnode->iNumLights > 0 ) {
|
||||
textline += '[';
|
||||
for( int lightidx = 0; lightidx < subnode->iNumLights; ++lightidx ) {
|
||||
@@ -150,7 +152,7 @@ itemproperties_panel::update( scene::basic_node const *Node ) {
|
||||
+ to_string( path.points[ segment_data::point::start ].x, 3 ) + ", "
|
||||
+ to_string( path.points[ segment_data::point::start ].y, 3 ) + ", "
|
||||
+ to_string( path.points[ segment_data::point::start ].z, 3 ) + "]->"
|
||||
+ "["
|
||||
+ " ["
|
||||
+ to_string( path.points[ segment_data::point::end ].x, 3 ) + ", "
|
||||
+ to_string( path.points[ segment_data::point::end ].y, 3 ) + ", "
|
||||
+ to_string( path.points[ segment_data::point::end ].z, 3 ) + "] ";
|
||||
@@ -353,6 +355,42 @@ nodebank_panel::nodebank_panel( std::string const &Name, bool const Isopen ) : u
|
||||
return ( Left.first < Right.first ); } );
|
||||
}
|
||||
}
|
||||
void
|
||||
nodebank_panel::nodebank_reload(){
|
||||
m_nodebank.clear();
|
||||
std::ifstream file;
|
||||
file.open("nodebank.txt", std::ios_base::in | std::ios_base::binary);
|
||||
std::string line;
|
||||
while (std::getline(file, line))
|
||||
{
|
||||
if (line.size() < 4)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
auto const labelend{line.find("node")};
|
||||
auto const nodedata{
|
||||
(labelend == std::string::npos ? "" : labelend == 0 ? line : line.substr(labelend))};
|
||||
auto const label{
|
||||
(labelend == std::string::npos ?
|
||||
line :
|
||||
labelend == 0 ? generate_node_label(nodedata) : line.substr(0, labelend))};
|
||||
|
||||
m_nodebank.push_back({label, std::make_shared<std::string>(nodedata)});
|
||||
}
|
||||
// sort alphabetically content of each group
|
||||
auto groupbegin{m_nodebank.begin()};
|
||||
auto groupend{groupbegin};
|
||||
while (groupbegin != m_nodebank.end())
|
||||
{
|
||||
groupbegin = std::find_if(groupend, m_nodebank.end(), [](auto const &Entry) {
|
||||
return (false == Entry.second->empty());
|
||||
});
|
||||
groupend = std::find_if(groupbegin, m_nodebank.end(),
|
||||
[](auto const &Entry) { return (Entry.second->empty()); });
|
||||
std::sort(groupbegin, groupend,
|
||||
[](auto const &Left, auto const &Right) { return (Left.first < Right.first); });
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
nodebank_panel::render() {
|
||||
@@ -378,11 +416,19 @@ nodebank_panel::render() {
|
||||
|
||||
if( true == ImGui::Begin( panelname.c_str(), nullptr, flags ) ) {
|
||||
|
||||
ImGui::RadioButton("modify node", (int*)&mode, MODIFY);
|
||||
ImGui::RadioButton("Modify node", (int*)&mode, MODIFY);
|
||||
ImGui::SameLine();
|
||||
ImGui::RadioButton("insert from bank", (int*)&mode, ADD);
|
||||
ImGui::RadioButton("Insert from bank", (int*)&mode, ADD);
|
||||
ImGui::SameLine();
|
||||
ImGui::RadioButton("Brush", (int*)&mode, BRUSH);
|
||||
ImGui::SameLine();
|
||||
ImGui::RadioButton( "copy to bank", (int*)&mode, COPY );
|
||||
ImGui::RadioButton( "Copy to bank", (int*)&mode, COPY );
|
||||
ImGui::SameLine();
|
||||
if (ImGui::Button("Reload Nodebank"))
|
||||
{
|
||||
nodebank_reload();
|
||||
}
|
||||
|
||||
|
||||
ImGui::PushItemWidth(-1);
|
||||
ImGui::InputTextWithHint( "Search", "Search node bank", m_nodesearch, IM_ARRAYSIZE( m_nodesearch ) );
|
||||
|
||||
@@ -54,13 +54,13 @@ public:
|
||||
enum edit_mode {
|
||||
MODIFY,
|
||||
COPY,
|
||||
ADD
|
||||
ADD,
|
||||
BRUSH
|
||||
};
|
||||
|
||||
edit_mode mode = MODIFY;
|
||||
|
||||
nodebank_panel( std::string const &Name, bool const Isopen );
|
||||
|
||||
void nodebank_reload();
|
||||
void render() override;
|
||||
void add_template(const std::string &desc);
|
||||
const std::string* get_active_template();
|
||||
|
||||
@@ -137,7 +137,7 @@ basic_editor::translate_memorycell( TMemCell *Memorycell, float const Offset ) {
|
||||
void
|
||||
basic_editor::rotate( scene::basic_node *Node, glm::vec3 const &Angle, float const Quantization ) {
|
||||
|
||||
glm::vec3 rotation { 0, Angle.y, 0 };
|
||||
glm::vec3 rotation{Angle.x, Angle.y, Angle.z};
|
||||
|
||||
// quantize resulting angle if requested and type of the node allows it
|
||||
// TBD, TODO: angle quantization for types other than instanced models
|
||||
|
||||
Reference in New Issue
Block a user