GlistEngine
Loading...
Searching...
No Matches
gBezierQuad.h
Go to the documentation of this file.
1/*
2 * gBezierQuad.h
3 *
4 * Created on: August 7, 2026
5 * Author: Ahmet Kahraman
6 */
7
8#ifndef GRAPHICS_GBEZIERQUAD_H_
9#define GRAPHICS_GBEZIERQUAD_H_
10
11#include "gMesh.h"
12#include <glm/glm.hpp>
13#include <vector>
14
15// Evaluates and renders a standard 4-point (Cubic) Bezier curve.
16class gBezierQuad : public gMesh {
17public:
19 virtual ~gBezierQuad();
20
21 // Sets all control points using 2D vectors.
22 void setPoint(const std::vector<glm::vec2>& pts);
23
24 // Sets all control points using 3D vectors.
25 void setPoint(const std::vector<glm::vec3>& pts);
26
27 // Adds a 2D control point to the curve.
28 void addPoint(glm::vec2 p);
29
30 // Adds a 3D control point to the curve.
31 void addPoint(glm::vec3 p);
32
33 // Updates a 3D control point safely by its index.
34 void setPointAtIndex(int index, glm::vec3 p);
35
36 // Updates a 2D control point safely by its index.
37 void setPointAtIndex(int index, glm::vec2 p);
38
39 // Gets the 3D coordinates of a point by its index.
40 glm::vec3 getPointAtIndex(int index) const;
41
42 // Gets the 2D coordinates of a point by its index.
43 glm::vec2 getPoint2DAtIndex(int index) const;
44
45 // Returns all control points in 3D.
46 std::vector<glm::vec3> getPoints() const;
47
48 // Returns all control points in 2D.
49 std::vector<glm::vec2> getPoints2D() const;
50
51 // Clears all existing control points.
53
54 // Evaluates the 4-point curve at normalized time t [0.0 - 1.0] in 3D.
55 glm::vec3 getPoint(float t) const;
56
57 // Evaluates the 4-point curve at normalized time t [0.0 - 1.0] in 2D.
58 glm::vec2 getPoint2D(float t) const;
59
60 // Sets the drawing resolution (number of line segments).
61 void setResolution(int res);
62
63 // Renders the 4-point curve to the screen automatically.
64 void draw() const;
65
66private:
67 std::vector<glm::vec3> points;
68 int resolution;
69 bool is3D;
70};
71
72#endif /* GRAPHICS_GBEZIERQUAD_H_ */
void draw() const
std::vector< glm::vec3 > getPoints() const
void setPointAtIndex(int index, glm::vec3 p)
void setPoint(const std::vector< glm::vec2 > &pts)
void addPoint(glm::vec3 p)
glm::vec3 getPointAtIndex(int index) const
void setPointAtIndex(int index, glm::vec2 p)
glm::vec2 getPoint2D(float t) const
void clearPoints()
glm::vec2 getPoint2DAtIndex(int index) const
glm::vec3 getPoint(float t) const
void setPoint(const std::vector< glm::vec3 > &pts)
void addPoint(glm::vec2 p)
void setResolution(int res)
virtual ~gBezierQuad()
std::vector< glm::vec2 > getPoints2D() const