GlistEngine
Loading...
Searching...
No Matches
gBezier.h
Go to the documentation of this file.
1/*
2 * gBezier.h
3 *
4 * Created On: August 7, 2026
5 * Author: Ahmet Kahraman
6 *
7 */
8#ifndef GRAPHICS_GBEZIER_H_
9#define GRAPHICS_GBEZIER_H_
10
11#include "gMesh.h"
12#include <glm/glm.hpp>
13#include <vector>
14
26
27class gBezier : public gMesh {
28public:
30 virtual ~gBezier();
31 //Sets curve control points, capped at 3
32 void setPoint(const std::vector<glm::vec2>& pts);
33 void setPoint(const std::vector<glm::vec3>& pts);
34
35 // Adds a 2D control point to the end of the curve, up to 3. Z axis defaults to 0.0f.
36 void addPoint(glm::vec2 p);
37
38 //Adds a 3D control point to the end of the curve, up to 3.
39 void addPoint(glm::vec3 p);
40
41 // Updates a specific control point coordinate by its index safely.
42 void setPointAtIndex(int index, glm::vec3 p);
43 void setPointAtIndex(int index, glm::vec2 p);
44
45 // Gets the current 3D coordinates of a specific control point by its index.
46 glm::vec3 getPointAtIndex(int index) const;
47
48 // Gets the current 2D coordinates (X, Y) of a specific control point.
49 glm::vec2 getPoint2DAtIndex(int index) const;
50
51 //Clears all points to reset or reuse the curve.
53
54 //Gets the interpolated point at time t [0.0 - 1.0]. Requires exactly 3 points; returns (0,0,0) otherwise.
55 glm::vec3 getPoint(float t) const;
56
57 glm::vec2 getPoint2D(float t) const;
58
59 //Gets the tangent (derivative) vector at time t [0.0 - 1.0]. Not normalized. Requires exactly 3 points; returns (0,0,0) otherwise.
60 glm::vec3 getTangent(float t) const;
61
62 glm::vec2 getTangent2D(float t) const;
63
64 //Gets the curve's slope angle at time t [0.0 - 1.0], in radians, measured in the XY plane (atan2 of the tangent's Y and X).
65 float getAngle(float t) const;
66
67 //Sets rendering resolution (number of segments).
68 void setResolution(int res);
69
70 //Draws the curve in 2D or 3D based on input points. No-op unless exactly 3 points are set.
71 void draw() const;
72private:
73 std::vector<glm::vec3> points;
74 int resolution;
75 bool is3D;
76};
77
78#endif /* GRAPHICS_GBEZIER_H_ */
glm::vec3 getTangent(float t) const
void addPoint(glm::vec2 p)
void setResolution(int res)
void setPointAtIndex(int index, glm::vec3 p)
void addPoint(glm::vec3 p)
glm::vec2 getTangent2D(float t) const
glm::vec3 getPointAtIndex(int index) const
void clearPoints()
glm::vec2 getPoint2DAtIndex(int index) const
void draw() const
void setPoint(const std::vector< glm::vec2 > &pts)
virtual ~gBezier()
glm::vec2 getPoint2D(float t) const
void setPoint(const std::vector< glm::vec3 > &pts)
float getAngle(float t) const
glm::vec3 getPoint(float t) const
void setPointAtIndex(int index, glm::vec2 p)