Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions include/engine/camera.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include "utils/point3.h"
#include "utils/vector3.h"
#include "deps/tinyxml2.h"

class Camera
{
Expand All @@ -20,6 +21,8 @@ class Camera

Camera(const Point3 &position, const Point3 &lookAt, const Vector3 &up, float fov, float near, float far);

explicit Camera(tinyxml2::XMLElement *cameraElement);

void place();

void reactKey(unsigned char key, int x, int y);
Expand Down
9 changes: 5 additions & 4 deletions include/engine/group.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,24 @@

#include <vector>
#include <memory>
#include "utils/model.h"
#include "engine/transform.h"
#include "engine/model.h"
#include "deps/tinyxml2.h"

class Group
{
private:
std::vector<std::unique_ptr<Transform>> transforms;
std::vector<std::unique_ptr<transform::Transform>> transforms;
std::vector<Model> models;
std::vector<Group> subgroups;

public:
Group() = default;

Group(std::vector<std::unique_ptr<Transform>> transforms, std::vector<Model> models, std::vector<Group> subgroups)
Group(std::vector<std::unique_ptr<transform::Transform>> transforms, std::vector<Model> models, std::vector<Group> subgroups)
: transforms(std::move(transforms)), models(std::move(models)), subgroups(std::move(subgroups)) {}

void initBuffers();
explicit Group(tinyxml2::XMLElement *groupElement);

void draw(float time) const;
};
Expand Down
26 changes: 26 additions & 0 deletions include/engine/model.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#ifndef CG2324_ENGINE_MODEL_H
#define CG2324_ENGINE_MODEL_H


#include "utils/point3.h"

#include <GL/glew.h>
#include <GL/glut.h>
#include <vector>

class Model
{
private:
GLuint buffer{};
GLsizei size{};

public:
Model() = default;

explicit Model(const std::string &filename);

void draw() const;
};


#endif //CG2324_ENGINE_MODEL_H
128 changes: 70 additions & 58 deletions include/engine/transform.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,87 +6,99 @@
#include "utils/vector3.h"
#include "utils/point3.h"

class Transform
namespace transform
{
public:
virtual ~Transform() = default;
class Transform
{
public:
virtual ~Transform() = default;

virtual void apply(float time) noexcept = 0;
};
virtual void apply(float time) noexcept = 0;
};

class Translate : public Transform
{
private:
Vector3 vector;
class Translate : public Transform
{
private:
Vector3 vector;

public:
explicit Translate(Vector3 vector) : vector(vector) {}
public:
explicit Translate(Vector3 vector) : vector(vector) {}

Translate(float x, float y, float z) : vector(x, y, z) {}
Translate(float x, float y, float z) : vector(x, y, z) {}

void apply(float time) noexcept override;
};
explicit Translate(tinyxml2::XMLElement *transformElement);

class TimedTranslate : public Transform
{
private:
float time;
bool align;
bool draw;
std::vector<Point3> points;
std::vector<Point3> curve{};
Vector3 yVector{0, 1, 0};
void apply(float time) noexcept override;
};

public:
TimedTranslate(float time, bool align, bool draw, std::vector<Point3> points);
class TimedTranslate : public Transform
{
private:
float time{};
bool align{};
bool draw{};
std::vector<Point3> points{};
std::vector<Point3> curve{};
Vector3 yVector{0, 1, 0};

void apply(float gt) noexcept override;
public:
TimedTranslate(float time, bool align, bool draw, std::vector<Point3> points);

private:
[[nodiscard]] std::pair<Point3, Vector3> getGlobalCatmullRomPoint(float gt) const;
explicit TimedTranslate(tinyxml2::XMLElement *transformElement);

void drawCurve() const;
void apply(float gt) noexcept override;

};
private:
[[nodiscard]] std::pair<Point3, Vector3> getGlobalCatmullRomPoint(float gt) const;

class Rotate : public Transform
{
private:
float angle;
Vector3 vector;
void drawCurve() const;
};

public:
Rotate(float angle, Vector3 vector) : angle(angle), vector(vector) {}
class Rotate : public Transform
{
private:
float angle{};
Vector3 vector;

Rotate(float angle, float x, float y, float z) : angle(angle), vector(x, y, z) {}
public:
Rotate(float angle, Vector3 vector) : angle(angle), vector(vector) {}

void apply(float time) noexcept override;
};
Rotate(float angle, float x, float y, float z) : angle(angle), vector(x, y, z) {}

class TimedRotate : public Transform
{
private:
float anglePerSecond;
Vector3 vector;
explicit Rotate(tinyxml2::XMLElement *transformElement);

public:
TimedRotate(float time, Vector3 vector);
void apply(float time) noexcept override;
};

TimedRotate(float time, float x, float y, float z);
class TimedRotate : public Transform
{
private:
float anglePerSecond;
Vector3 vector;

void apply(float gt) noexcept override;
};
public:
TimedRotate(float time, Vector3 vector);

class Scale : public Transform
{
private:
float factorX, factorY, factorZ;
TimedRotate(float time, float x, float y, float z);

explicit TimedRotate(tinyxml2::XMLElement *transformElement);

void apply(float gt) noexcept override;
};

class Scale : public Transform
{
private:
float factorX{}, factorY{}, factorZ{};

public:
Scale(float x, float y, float z) : factorX(x), factorY(y), factorZ(z) {}

public:
Scale(float x, float y, float z) : factorX(x), factorY(y), factorZ(z) {}
explicit Scale(tinyxml2::XMLElement *transformElement);

void apply(float time) noexcept override;
};
void apply(float time) noexcept override;
};
}


#endif //CG2324_TRANSFORM_H
10 changes: 7 additions & 3 deletions include/engine/window.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,20 @@
#define CG2324_WINDOW_H


#include "deps/tinyxml2.h"

class Window
{
public:
int width, height;
char *title;
int x{}, y{};
int width{}, height{};

public:
Window() = default;

Window(int width, int height, char *title) : width(width), height(height), title(title) {};
Window(int x, int y, int width, int height) : x(x), y(y), width(width), height(height) {};

explicit Window(tinyxml2::XMLElement *windowElement);
};


Expand Down
16 changes: 9 additions & 7 deletions include/engine/world.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,28 @@
#define CG2324_WORLD_H


#include <utility>

#include "engine/group.h"
#include "engine/camera.h"
#include "engine/window.h"
#include "deps/tinyxml2.h"

class World
{
public:
Window window{};
Camera camera;
Group group;

public:
World() = default;

explicit World(Window window, Camera camera, Group group) :
window(window), camera(std::move(camera)), group(std::move(group)) {}
World(Camera camera, Group group) : camera(std::move(camera)), group(std::move(group)) {}

explicit World(tinyxml2::XMLElement *worldElement);

void renderScene();

void changeSize(int w, int h) const;

void draw() const;
void processNormalKeys(unsigned char key, int xx, int yy);
};


Expand Down
13 changes: 0 additions & 13 deletions include/engine/xml_world_loader.h

This file was deleted.

2 changes: 1 addition & 1 deletion include/generator/box.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#define CG2324_BOX_H


#include "utils/model.h"
#include "generator/model.h"

class Box : public Model
{
Expand Down
2 changes: 1 addition & 1 deletion include/generator/cone.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#define CG2324_CONE_H


#include "utils/model.h"
#include "generator/model.h"

class Cone : public Model
{
Expand Down
8 changes: 3 additions & 5 deletions include/utils/model.h → include/generator/model.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,25 @@
#include <string>
#include <vector>
#include <ostream>
#include "point3.h"
#include "vector3.h"
#include "utils/point3.h"
#include "utils/vector3.h"

class Model
{
protected:
std::vector<Point3> vertices;
unsigned int buffer{};

protected:
Model() = default;

public:

explicit Model(const std::vector<Point3> &vertices);

explicit Model(const std::vector<Model> &models);

explicit Model(const std::string &filename);

void initBuffer();

void draw() const;

void writeToFile(const std::string &filename) const;
Expand Down
2 changes: 1 addition & 1 deletion include/generator/patch_model.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

#include <vector>
#include "utils/point3.h"
#include "utils/model.h"
#include "generator/model.h"

class PatchModel : public Model
{
Expand Down
2 changes: 1 addition & 1 deletion include/generator/plane.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#define CG2324_PLANE_H


#include "utils/model.h"
#include "generator/model.h"

class Plane : public Model
{
Expand Down
2 changes: 1 addition & 1 deletion include/generator/sphere.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#define CG2324_SPHERE_H


#include "utils/model.h"
#include "generator/model.h"

class Sphere : public Model
{
Expand Down
Loading