started ScriptedMove
This commit is contained in:
@@ -16,7 +16,7 @@ add_executable(SDL3D src/main.cpp
|
||||
src/types/vertex.h
|
||||
src/types/skybox.h
|
||||
src/types/moby.h
|
||||
src/types/animationSequence.h
|
||||
src/types/animation/scriptedMove.h
|
||||
)
|
||||
|
||||
find_package(OpenGL)
|
||||
|
@@ -1,4 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
#include <cstring>
|
||||
#include <iostream>
|
||||
|
@@ -1,4 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
#include <chrono>
|
||||
#include <thread>
|
||||
#include "engine.h"
|
||||
@@ -13,7 +14,7 @@
|
||||
engine->tickCount++;
|
||||
switch (engine->gameState) {
|
||||
case GAMESTATE::NORMAL:
|
||||
if(engine->frameCount > 0)
|
||||
if(engine->frameCount > 1)
|
||||
getCamera()->update();
|
||||
break;
|
||||
case GAMESTATE::IN_MAIN_MENU:
|
||||
|
45
src/types/animation/scriptedMove.h
Normal file
45
src/types/animation/scriptedMove.h
Normal file
@@ -0,0 +1,45 @@
|
||||
#pragma once
|
||||
|
||||
#include <vector>
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
#include <iostream>
|
||||
#include "../vector3.h"
|
||||
#include "../../engine/engine.h"
|
||||
#include "../entityList.h"
|
||||
//A "scripted move" is a vector of points and angles that function as keyframes.
|
||||
//A moby will follow *and interpolate* between those points.
|
||||
|
||||
class ScriptedMove {
|
||||
public:
|
||||
std::vector<Position> positions;
|
||||
std::vector<Angle> angles;
|
||||
//We won't even need that many positions anyways.
|
||||
uint16_t index = NULL;
|
||||
|
||||
void load(const std::string& filename) {
|
||||
std::ifstream file(filename);
|
||||
if (!file.is_open()) {
|
||||
std::cout << "File not found: " << filename << std::endl;
|
||||
engine->quit();
|
||||
return;
|
||||
}
|
||||
std::string line;
|
||||
while (std::getline(file, line)) {
|
||||
std::istringstream stream(line);
|
||||
std::string prefix;
|
||||
stream >> prefix;
|
||||
|
||||
if (prefix == "position") {
|
||||
float x, y, z;
|
||||
stream >> x >> y >> z;
|
||||
positions.push_back({x, y, z});
|
||||
} else if (prefix == "angle") {
|
||||
float x, y, z;
|
||||
stream >> x >> y >> z;
|
||||
angles.push_back({x, y, z});
|
||||
}
|
||||
}
|
||||
file.close();
|
||||
}
|
||||
};
|
@@ -1,3 +0,0 @@
|
||||
#include <vector>
|
||||
#include "vector3.h"
|
||||
#include "vertex.h"
|
@@ -1,14 +1,17 @@
|
||||
#pragma once
|
||||
|
||||
#include <tuple>
|
||||
#include "entity.h"
|
||||
#include "animation/scriptedMove.h"
|
||||
|
||||
//Movable Object.
|
||||
class Moby : public Entity {
|
||||
public:
|
||||
float velocity = 0;
|
||||
Angle angle = {0,0,0}; //Pitch Yaw Roll, The orientation of the entity in the world,
|
||||
//Angle velAngles = {0,0,0}; //The angle of an entities velocity.
|
||||
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;
|
||||
@@ -51,4 +54,10 @@ public:
|
||||
a.z = -(f.x * upVector.y - f.y * upVector.x);
|
||||
return a;
|
||||
}
|
||||
|
||||
AngPos nextScriptedMove() {
|
||||
//TODO: check if it'd be outside the bounds of the vector.
|
||||
Angle a = scriptedMove.angles[scriptedMove.index+1];
|
||||
Position p = scriptedMove.positions[scriptedMove.index+1];
|
||||
}
|
||||
};
|
@@ -22,7 +22,6 @@ public:
|
||||
Position cameraPoint (float distance) {
|
||||
Position behindPosition = this->position;
|
||||
Angle reverseDirection = this->bAngle();
|
||||
|
||||
behindPosition.x -= reverseDirection.x * distance;
|
||||
behindPosition.y -= reverseDirection.y * distance;
|
||||
behindPosition.z -= reverseDirection.z * distance;
|
||||
@@ -31,7 +30,8 @@ public:
|
||||
}
|
||||
|
||||
void update() {
|
||||
|
||||
//if (engine->tickCount >=10)
|
||||
//std::cout << "Player* Hopefully: " << scriptedMove.parent->position.x;
|
||||
}
|
||||
|
||||
void pre_render() {
|
||||
@@ -42,7 +42,7 @@ public:
|
||||
position.set(0,-2,0);
|
||||
}
|
||||
//Rotate
|
||||
this->angle.y += 75.0*engine->frameDelta;
|
||||
this->angle.y += 200.0*engine->frameDelta;
|
||||
}
|
||||
void render() {
|
||||
glColor3f(0.75,0.75,0.75);
|
||||
|
@@ -12,6 +12,9 @@ public:
|
||||
|
||||
class Angle : public vector3 {
|
||||
public:
|
||||
bool operator==(const Angle& a) const {
|
||||
return (x == a.x) && (y == a.y) && (z == a.z);
|
||||
}
|
||||
void clamp() {
|
||||
if (this->x > 89.0f)
|
||||
this->x = 89.0f;
|
||||
@@ -36,7 +39,9 @@ public:
|
||||
|
||||
class Position : public vector3 {
|
||||
public:
|
||||
|
||||
bool operator==(const Position& p) const {
|
||||
return (x == p.x) && (y == p.y) && (z == p.z);
|
||||
}
|
||||
void set(Position p) {
|
||||
this->x = p.x;
|
||||
this->y = p.y;
|
||||
@@ -71,6 +76,10 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
struct AngPos {
|
||||
Angle angle;
|
||||
Position position;
|
||||
};
|
||||
namespace VectorMath {
|
||||
float distance(Position sP, Position eP) {
|
||||
return sqrt(pow(eP.x - sP.x, 2) + pow(eP.y - sP.y, 2) + pow(eP.z - sP.z, 2));
|
||||
|
@@ -0,0 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
namespace World {
|
||||
|
||||
}
|
Reference in New Issue
Block a user