Files |  Tutorials |  Articles |  Links |  Home |  Team |  Forum |  Wiki |  Impressum

Aktuelle Zeit: Sa Jul 05, 2025 22:44

Foren-Übersicht » English » English Programming Forum
Unbeantwortete Themen | Aktive Themen



Ein neues Thema erstellen Auf das Thema antworten  [ 4 Beiträge ] 
Autor Nachricht
BeitragVerfasst: Mo Nov 12, 2007 21:47 
Offline
DGL Member
Benutzeravatar

Registriert: Di Jul 01, 2003 18:59
Beiträge: 887
Wohnort: (The Netherlands)
Programmiersprache: fpc/delphi/java/c#
Currently i writing a 2D vector gui system. So far basic shapes like rectangles and circles are working fine even with radial gradients without using textures. Now i want to move to adding polygon shapes. This raises the following questions for me:
1) should i use glutesselation functions
or
2) should i write my own triangulation library
or
3) has this already been invented for delphi/pascal

As always thanks for your answers in advance.


Dateianhänge:
Dateikommentar: ScreenShot with some testing going on.
vg.jpg
vg.jpg [ 30.63 KiB | 4700-mal betrachtet ]

_________________
http://3das.noeska.com - create adventure games without programming
Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags:
BeitragVerfasst: Do Nov 15, 2007 17:37 
Offline
DGL Member
Benutzeravatar

Registriert: Mo Jan 31, 2005 11:02
Beiträge: 432
Wohnort: Rheinlandpfalz
Take a look at this post by Tak2004:
http://www.delphigl.com/forum/viewtopic.php?t=6919
Maybe that helps you to implement an own tesselation algorithm for your gui, because it's the same problem as yours. ;)

Greetings,
MatReno

_________________
http://texelviews.delphigl.com


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags:
BeitragVerfasst: Mo Jan 21, 2008 20:16 
Offline
DGL Member
Benutzeravatar

Registriert: Di Jul 01, 2003 18:59
Beiträge: 887
Wohnort: (The Netherlands)
Programmiersprache: fpc/delphi/java/c#
I tried to go for an simpler version first namely tesselate a triangle.

For that i found the following c code on the inet:
Code:
  1.  
  2. // p0, p1, p2: triangle tesselation
  3. void TriangleTesselation(CVector &p0, CVector &p1, CVector &p2, int nTesselation)
  4. {
  5.     CVector dv1 = (p2 - p0) / nTesselation;
  6.     CVector dv2 = (p2 - p1) / nTesselation;
  7.  
  8.     for (int j=0; j<nTesselation; j++)
  9.     {
  10.         CVector x1  = p0 + j*dv1;
  11.         CVector x2  = p0 + (j+1)*dv1;
  12.         CVector dx1 = ((p1-p0) + (dv2-dv1)*j);
  13.         CVector dx2 = ((p1-p0) + (dv2-dv1)*(j+1));
  14.  
  15.         glBegin(GL_TRIANGLE_STRIP);
  16.         for (int i=0; i<nTesselation-j; i++)
  17.         {
  18.             CVector u1 = x1 + ((float) i / (nTesselation-j))*dx1;
  19.             CVector u2 = x2;
  20.             if (nTesselation-j-1 != 0)
  21.                 u2 += ((float) i / (nTesselation-j-1))*dx2;
  22.  
  23.             glVertex3fv(u1.arr);
  24.             glVertex3fv(u2.arr);
  25.         }
  26.         glVertex3fv((x1+dx1).arr);
  27.  
  28.         glEnd();
  29.  
  30.     }
  31. }
  32.  


Now converted to pascal i think it should look like:
Code:
  1.  
  2. // p0, p1, p2: triangle tesselation
  3. procedure TriangleTesselation(p0: T3DPoint; p1: T3DPoint; p2: T3DPoint; nTesselation: integer);
  4. var
  5.   dv1: T3DPoint;
  6.   dv2: T3DPoint;
  7.   x1: T3DPoint;
  8.   x2: T3DPoint;
  9.   dx1: T3DPoint;
  10.   dx2: T3DPoint;
  11.   u1: T3DPoint;
  12.   u2: T3DPoint;
  13.   e1: T3DPoint;
  14.   j: integer;
  15.   i: integer;
  16. begin
  17.     dv1 := VectorDiv( VectorSubtract(p2,p0) , nTesselation);
  18.     dv2 := VectorDiv( VectorSubtract(p2,p1) , nTesselation);
  19.  
  20.     for j:=0 to nTesselation-1 do
  21.     begin
  22.         x1  := VectorAdd(p0 , VectorMul(dv1, j) );
  23.         x2  := VectorAdd(p0 , VectorMul(dv1, (j+1) ) );
  24.         dx1 := VectorAdd(VectorSubtract(p1,p0) , VectorMul( VectorSubtract(dv2,dv1) ,j));
  25.         dx2 := VectorAdd(VectorSubtract(p1,p0) , VectorMul( VectorSubtract(dv2,dv1) ,(j+1)));
  26.  
  27.         glBegin(GL_TRIANGLE_STRIP);
  28.         for i:=0 to nTesselation-j-1 do
  29.         begin
  30.             u1 := VectorAdd(x1 , VectorMul(dx1, ( i / (nTesselation-j) ) ) );
  31.             u2 := x2;
  32.             if (nTesselation-j-1 <> 0) then
  33.                 u2 := VectorAdd(u2 , VectorDiv(dx2, ( i / (nTesselation-j-1)) ) );
  34.  
  35.             glVertex2f(u1.x, u1.y);
  36.             glVertex2f(u2.x, u2.y);
  37.         end;
  38.                                 e1:=VectorAdd(x1,dx1);
  39.         glVertex2f(e1.x,e1.y);
  40.  
  41.         glEnd();
  42.  
  43.     end;
  44. end;
  45.  


This is how the Vector functions look like:
Code:
  1.  
  2. // returns the difference of two vectors
  3. function VectorSubtract(V1, V2: T3dPoint): T3dPoint; register;
  4. begin
  5.   Result.x := V1.x - V2.x;
  6.   Result.y := V1.y - V2.y;
  7.   Result.z := V1.z - V2.z;
  8. end;
  9.  
  10. // returns the addition of two vectors
  11. function VectorAdd(V1, V2: T3dPoint): T3dPoint; register;
  12. begin
  13.   Result.x := V1.x + V2.x;
  14.   Result.y := V1.y + V2.y;
  15.   Result.z := V1.z + V2.z;
  16. end;
  17.  
  18. // returns the multiplication of a vector with an single
  19. function VectorMul(V: T3DPoint; S: single): T3dPoint; register;
  20. begin
  21.   Result.x := V.x * S;
  22.   Result.y := V.y * S;
  23.   Result.z := V.z * S;
  24. end;
  25.  
  26. // returns the division of a vector with an single
  27. function VectorDiv(V: T3DPoint; S: single): T3dPoint; register;
  28. begin
  29.   Result.x := V.x / S;
  30.   Result.y := V.y / S;
  31.   Result.z := V.z / S;
  32. end;
  33.  


Unfortunately the end result is horrible. The first 2 inner triangles seem to go ok but after that coords go outside the original triangle. Also i am doing something not in the right way, but what?

_________________
http://3das.noeska.com - create adventure games without programming


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags:
BeitragVerfasst: Di Jan 22, 2008 20:24 
Offline
DGL Member
Benutzeravatar

Registriert: Di Mai 18, 2004 16:45
Beiträge: 2623
Wohnort: Berlin
Programmiersprache: Go, C/C++
My final Solution you can find here Link .
The problem on vector based faces are the border. I designed a class TKar_Shape, where you can add vertice/points. Default there is no border and so the shape would draw without rounding but if i add a border and set it to rounding edge then the shape will generate rounded shapes. My solution look for concav and convex angles and decide to divide or not divide the current and their neighbors vertice via berzier. Because not every edge need a subdivide. For a good result you have to divide the shape first and then tesselate. The tesselation can be only correct if you search a convex triangle who is also a ear of the shape and then create a triangle with the neighbors. If you don't test the vertice on ears then you will get overdraw and wrong tesselated meshes.

_________________
"Wer die Freiheit aufgibt um Sicherheit zu gewinnen, der wird am Ende beides verlieren"
Benjamin Franklin

Projekte: https://github.com/tak2004


Nach oben
 Profil  
Mit Zitat antworten  
Beiträge der letzten Zeit anzeigen:  Sortiere nach  
Ein neues Thema erstellen Auf das Thema antworten  [ 4 Beiträge ] 
Foren-Übersicht » English » English Programming Forum


Wer ist online?

Mitglieder in diesem Forum: 0 Mitglieder und 1 Gast


Du darfst keine neuen Themen in diesem Forum erstellen.
Du darfst keine Antworten zu Themen in diesem Forum erstellen.
Du darfst deine Beiträge in diesem Forum nicht ändern.
Du darfst deine Beiträge in diesem Forum nicht löschen.
Du darfst keine Dateianhänge in diesem Forum erstellen.

Suche nach:
Gehe zu:  
  Powered by phpBB® Forum Software © phpBB Group
Deutsche Übersetzung durch phpBB.de
[ Time : 0.009s | 16 Queries | GZIP : On ]