Added lookat function. Fixed various coordinate missmatches and issues. Fixed camera movement. Added some input functions. I need some way to log fps and find those hitches

This commit is contained in:
MitchellHansen
2016-12-30 21:02:04 -08:00
parent 58867415c7
commit bb9fab6305
8 changed files with 189 additions and 105 deletions

View File

@@ -7,6 +7,9 @@
#include "Vector4.hpp"
#include <bitset>
#include <string>
#include <math.h>
#include <iterator>
const double PI = 3.141592653589793238463;
const float PI_F = 3.14159265358979f;
@@ -125,6 +128,20 @@ inline sf::Vector3f CartToSphere(sf::Vector3f in) {
return r;
};
inline sf::Vector2f CartToNormalizedSphere(sf::Vector3f in) {
auto r = sf::Vector2f(
atan2(sqrt(in.x * in.x + in.y * in.y), in.z),
atan2(in.y, in.x)
);
return r;
}
inline sf::Vector3f FixOrigin(sf::Vector3f base, sf::Vector3f head) {
return head - base;
}
inline sf::Vector3f Normalize(sf::Vector3f in) {
@@ -202,4 +219,59 @@ inline void DumpLog(std::stringstream* ss, std::string file_name) {
log_file.close();
}
inline std::string sfml_get_input(sf::RenderWindow *window) {
std::stringstream ss;
sf::Event event;
while (window->pollEvent(event)) {
if (event.type == sf::Event::TextEntered) {
ss << event.text.unicode;
}
else if (event.type == sf::Event::KeyPressed) {
if (event.key.code == sf::Keyboard::Return) {
return ss.str();
}
}
}
}
inline std::vector<float> sfml_get_float_input(sf::RenderWindow *window) {
std::stringstream ss;
sf::Event event;
while (true) {
if (window->pollEvent(event)) {
if (event.type == sf::Event::TextEntered) {
if (event.text.unicode > 47 && event.text.unicode < 58 || event.text.unicode == 32)
ss << static_cast<char>(event.text.unicode);
}
else if (event.type == sf::Event::KeyPressed) {
if (event.key.code == sf::Keyboard::Return) {
break;
}
}
}
}
std::istream_iterator<std::string> begin(ss);
std::istream_iterator<std::string> end;
std::vector<std::string> vstrings(begin, end);
std::vector<float> ret;
for (auto i: vstrings) {
ret.push_back(std::stof(i));
}
return ret;
}