DGL https://delphigl.com/forum/ |
|
Bezier Curve - how to reference all points in the curve? https://delphigl.com/forum/viewtopic.php?f=19&t=6831 |
Seite 1 von 1 |
Autor: | dpm_dpmartin [ So Aug 19, 2007 13:44 ] |
Betreff des Beitrags: | Bezier Curve - how to reference all points in the curve? |
Hello, I had the idea that certain UI components of my project could 'fly away' when I decided to move to another screen. Sure, I could just send them along a straight +X or +Y line until they disappeared from the screen, but I thought that it would be very nice looking to have them follow a flight plan that was described by a curve - maybe even a random curve - but a curve anyway. So, I've started educating myself about OpenGL and calculating and drawing Bezier curves. Here is the entirety of my code - it is pretty straightforward and will run easily (just a TForm, with a client-aligned TPanel and a TTimer). This code calculates a curve via four control points and is able to display it on the screen - as well as displaying each point on the curve and the control points connected via a thin red line. What I'm curious about is the code at lines 137 and 148 - the lines that use glEvalCoord1f to apparently draw out a GL_POINT (or a part of a LINE_LOOP) by referencing some values it seems to have pre-calculated with the call to glMap1f earlier - or is calculating on the fly. While calculating my curve, I would prefer to be able pre-calculate and store the X, Y and Z of each point on the curve in an array - so I can look them up later - glEvalCoord1f is obviously pulling out the correct details - but 1) I don't really know where it is getting them from and 2) I don't know if I can access them in code so I can use glVertex3f to display things. Is there a way of 1) setting up my control points, 2) setting a number of segments (level of detail), 3) calculating the curve according to the control points and number of segments (level of detail) I want and 4) storing the values of each point on the curve in X, Y and Z format in an array, so that I can then 5) reference them so my moving objects can follow some kind of flight plan? glEvalCoord1f is great in that it obviously returns or uses some form of X, Y and Z values for the LINE_LOOP and GL_POINTs loop it is being used in - but it is not a function, so I don't know how to get my X, Y and Z values from it... does that make sense? Code:
|
Autor: | i0n0s [ So Aug 19, 2007 14:26 ] |
Betreff des Beitrags: | |
Casteljau: b_k^n (x) := x_k, k = 0,..., n; b_k^(j+1) (x) := u_o(x|I) b_k^j (x) + u_1(x|I) b_(k+1)^j (x), k = 0,..., n - j - 1; where u_0 and u_1 are "baryzentrische Koordinaten" which meens: u_0(x|I) := (t_1 - x) / (t_1 - t_0) and u_1(x|I) := (x - t_0) / (t_1 - t_0) where t_0 and t_1 are the points at the border of the interval I. b_0^n(x) is the value of the bezier curve at point x. |
Autor: | dpm_dpmartin [ So Aug 19, 2007 14:27 ] |
Betreff des Beitrags: | Success! |
S'OK... got it. Not exactly got it figured out - but got it working anyway with: Code:
...and: Code:
Do I fully understand it? No. Do I understand that it does what I want? Yes. Am I happy with it? Yes. |
Seite 1 von 1 | Alle Zeiten sind UTC + 1 Stunde |
Powered by phpBB® Forum Software © phpBB Group https://www.phpbb.com/ |