Re-introduce tracks.
This commit is contained in:
22
include/Redacted3D/types/track.h
Normal file
22
include/Redacted3D/types/track.h
Normal 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);
|
||||
};
|
@@ -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
42
src/types/track.cpp
Normal 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;
|
||||
}
|
Reference in New Issue
Block a user