buggy but working scripted move.
This commit is contained in:
@@ -1 +1,7 @@
|
||||
start 1.0 -1.0 1.0
|
||||
start 0.01 -2.0 -4.0
|
||||
velocity 2
|
||||
position 0.1 -2.0 0.0
|
||||
position 0.01 -2.0 -4.0
|
||||
position 2.0 -2.0 -4.0
|
||||
position -2.0 -2.0 -4.0
|
||||
position 0.01 -2.0 -4.0
|
||||
|
@@ -44,8 +44,8 @@ void pre_render() {
|
||||
engine->initGL();
|
||||
auto camera = new(Camera);
|
||||
storeEntity(camera);
|
||||
getCamera()->position.set(0.0f,0.0f,5.0f);
|
||||
getCamera()->angle.y = 180.0f;
|
||||
getCamera()->position.set(0.0f,-2.0f,-5.0f);
|
||||
getCamera()->angle.y = 0.0f;
|
||||
getCamera()->scriptedMove.load("../scriptedMove/default.smov");
|
||||
auto skybox = new(Skybox);
|
||||
skybox->draw = true;
|
||||
|
@@ -15,8 +15,9 @@ public:
|
||||
std::vector<Position> positions;
|
||||
std::vector<Angle> angles;
|
||||
//We won't even need that many positions anyways.
|
||||
uint16_t index = NULL;
|
||||
int16_t index = -1;
|
||||
Position start = {NULL,NULL,NULL};
|
||||
float velocity;
|
||||
|
||||
void load(const std::string& filename) {
|
||||
std::ifstream file(filename);
|
||||
@@ -44,11 +45,15 @@ public:
|
||||
else if (prefix == "start") {
|
||||
float x, y, z;
|
||||
stream >> x >> y >> z;
|
||||
std::cout << x << " " << y << " " << z << std::endl;
|
||||
start.x = x;
|
||||
start.y = y;
|
||||
start.z = z;
|
||||
}
|
||||
else if (prefix == "velocity") {
|
||||
float x;
|
||||
stream >> x;
|
||||
velocity = x;
|
||||
}
|
||||
}
|
||||
file.close();
|
||||
}
|
||||
|
@@ -7,11 +7,12 @@
|
||||
//Movable Object.
|
||||
class Moby : public Entity {
|
||||
public:
|
||||
float velocity = 0;
|
||||
//float velocity = 0;
|
||||
Angle angle = {0,0,0}; //Pitch Yaw Roll, The orientation of the entity in the world,
|
||||
Angle velAngle = {0,0,0}; //The angle of an entities velocity.
|
||||
vector3 upVector = {0.0f,1.0f,0.0f};
|
||||
ScriptedMove scriptedMove;
|
||||
|
||||
void move(Angle a, float speed) {
|
||||
this->position.z += (speed*engine->frameDelta) * a.x;
|
||||
this->position.y += (speed*engine->frameDelta) * a.y;
|
||||
@@ -55,17 +56,28 @@ public:
|
||||
return a;
|
||||
}
|
||||
|
||||
Movement nextScriptedMove() {
|
||||
//TODO: check if it'd be outside the bounds of the vector.
|
||||
Angle a = scriptedMove.angles[scriptedMove.index];
|
||||
Position p = scriptedMove.positions[scriptedMove.index];
|
||||
}
|
||||
void doScriptedMovement() {
|
||||
//If the movement has a set starting position, Then teleport the moby there
|
||||
//Before the first movement.
|
||||
if (scriptedMove.index == 0 && scriptedMove.start.x != NULL)
|
||||
//If the movement has a set starting position, Then teleport there.
|
||||
if (scriptedMove.index == -1) {
|
||||
this->position = scriptedMove.start;
|
||||
scriptedMove.index++;
|
||||
}
|
||||
scriptedMove.start = position;
|
||||
|
||||
//We've reached the end of the movement script.
|
||||
if (scriptedMove.index + 1 > scriptedMove.positions.size())
|
||||
return;
|
||||
|
||||
Angle a = VectorMath::calcAngle(this->position, scriptedMove.positions[scriptedMove.index]).movementAngle();
|
||||
move(a,scriptedMove.velocity);
|
||||
|
||||
//TODO: Fix this later, This will break at high speed or if the framerate is low.
|
||||
//We'll have to detect if the next movement would make us go passed it.
|
||||
//If it's *super* close just teleport it.
|
||||
if (VectorMath::distance(this->position,scriptedMove.positions[scriptedMove.index]) <= 0.002) {
|
||||
this->position = scriptedMove.positions[scriptedMove.index];
|
||||
scriptedMove.index++;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@@ -32,9 +32,18 @@ public:
|
||||
if(this->z <= -360.0f)
|
||||
this->z = 0.0;
|
||||
}
|
||||
|
||||
[[nodiscard]] float length() const {
|
||||
return sqrt(x * x + y * y + z * z);
|
||||
}
|
||||
|
||||
Angle movementAngle() {
|
||||
Angle a;
|
||||
a.x = (cos(glm::radians(y)) * cos(glm::radians(x)));
|
||||
a.y = -sin(glm::radians(x));
|
||||
a.z = (sin(glm::radians(y)) * cos(glm::radians(x)));
|
||||
return a;
|
||||
}
|
||||
};
|
||||
|
||||
class Position : public vector3 {
|
||||
|
Reference in New Issue
Block a user