-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
669f0b8
commit 7799b9c
Showing
6 changed files
with
40,718 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#ifndef SAVE_HPP | ||
#define SAVE_HPP | ||
|
||
#include <rapidxml/rapidxml.hpp> | ||
#include <rapidxml/rapidxml_ext.hpp> | ||
#include <rapidxml/rapidxml_print.hpp> | ||
#include "parse.hpp" | ||
#include "Camera.hpp" | ||
|
||
void savetoFile(std::string original_scene, const Camera& cam); | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#include "save.hpp" | ||
|
||
void savetoFile(std::string original_scene, const Camera& cam) { | ||
std::ifstream file(original_scene); | ||
std::string xmlContent((std::istreambuf_iterator<char>(file)), | ||
std::istreambuf_iterator<char>()); | ||
file.close(); | ||
|
||
rapidxml::xml_document<> doc; | ||
doc.parse<0>(&xmlContent[0]); | ||
|
||
rapidxml::xml_node<>* root = doc.first_node("world"); | ||
rapidxml::xml_node<>* camera = root->first_node("camera"); | ||
rapidxml::xml_node<>* position_n = camera->first_node("position"); | ||
rapidxml::xml_node<>* lookat_n = camera->first_node("lookAt"); | ||
|
||
auto set_or_update_attribute = [&doc](rapidxml::xml_node<>* node, const char* attr_name, float value) { | ||
rapidxml::xml_attribute<>* attr = node->first_attribute(attr_name); | ||
if (!attr) { | ||
char* attr_value = doc.allocate_string(std::to_string(value).c_str()); | ||
attr = doc.allocate_attribute(attr_name, attr_value); | ||
node->append_attribute(attr); | ||
} else { | ||
attr->value(doc.allocate_string(std::to_string(value).c_str())); | ||
} | ||
}; | ||
|
||
set_or_update_attribute(position_n, "x", cam.position.x); | ||
set_or_update_attribute(position_n, "y", cam.position.y); | ||
set_or_update_attribute(position_n, "z", cam.position.z); | ||
|
||
glm::vec3 lookat = cam.position + cam.forward; | ||
|
||
set_or_update_attribute(lookat_n, "x", lookat.x); | ||
set_or_update_attribute(lookat_n, "y", lookat.y); | ||
set_or_update_attribute(lookat_n, "z", lookat.z); | ||
|
||
std::ofstream out_file("scenes/last_scene.xml"); | ||
|
||
out_file << doc; | ||
out_file.close(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.