Re-introduce tracks.

This commit is contained in:
2024-06-19 20:03:58 -04:00
parent 43b875c1f4
commit b560d8398e
3 changed files with 64 additions and 1 deletions

View File

@@ -0,0 +1,22 @@
#pragma once
#include <vector>
#include <J3ML/LinearAlgebra.h>
class Moby;
struct TrackKeyFrame {
public:
Position position;
Vector3 angle;
};
class Track {
private:
Moby* parent;
bool teleportToStart = false;
bool loop = false;
std::vector<TrackKeyFrame> track;
public:
Track(const std::string& file, Moby* moby);
};

View File

@@ -1,7 +1,6 @@
#include <sstream>
#include <thread>
#include <Redacted3D/engine/engine.h>
#include <Redacted3D/engine/utils/instanceOf.h>
#include <Redacted3D/types/entity/camera.h>
#include <JGL/JGL.h>
#include <JGL/Colors.h>

42
src/types/track.cpp Normal file
View File

@@ -0,0 +1,42 @@
#include <fstream>
#include <Redacted3D/types/track.h>
#include <Redacted3D/engine/engine.h>
#include <Redacted3D/types/entity/moby.h>
#include <jlog/jlog.hpp>
Track::Track(const std::string &file, Moby* moby) {
std::ifstream f(file);
if (!f.is_open()) {
FATAL("Couldn't load track file: " + file)
engine->quit();
}
std::string line;
bool success = true;
while (std::getline(f, line)) {
std::istringstream stream(line);
std::string prefix;
stream >> prefix;
if (prefix == "Teleport: ")
stream >> teleportToStart;
TrackKeyFrame frame;
if (prefix == "Position: ")
success = !success,
stream >> frame.position.x,
stream >> frame.position.y,
stream >> frame.position.z;
if (prefix == "Angle: ")
success = !success,
stream >> frame.angle.x,
stream >> frame.angle.y,
stream >> frame.angle.z;
if (success) {track.push_back(frame); continue;}
WARNING("There is not the same number of Positions and Angles in the track: " + file);
}
parent = moby;
}