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

Aktuelle Zeit: Do Mai 16, 2024 20:29

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



Ein neues Thema erstellen Auf das Thema antworten  [ 3 Beiträge ] 
Autor Nachricht
 Betreff des Beitrags: polygon clipping (csg) 2d
BeitragVerfasst: So Apr 20, 2008 20:41 
Offline
DGL Member
Benutzeravatar

Registriert: Di Jul 01, 2003 18:59
Beiträge: 887
Wohnort: (The Netherlands)
Programmiersprache: fpc/delphi/java/c#
Delphi 2005 pro
C conversion
Polygon
Clipping
CSG
2D

Hello,

2D gives more chalenges then i expected.
Now i am trying to merge 2 polygon shapes to a new one.
Doing a search on the inet i found the following: http://davis.wpi.edu/~matt/courses/clipping/ That looks doable. But looking at the c source i get somewhat confused again as:

Code:
  1.  
  2. typedef struct _node
  3. {
  4.   int x, y;
  5.   struct _node *next;
  6.   struct _node *prev;
  7.   struct _node *nextPoly;   /* pointer to the next polygon */
  8.   struct _node *neighbor;   /* the coresponding intersection point */
  9.   int intersect;            /* 1 if an intersection point, 0 otherwise */
  10.   int entry;                /* 1 if an entry point, 0 otherwise */
  11.   int visited;              /* 1 if the node has been visited, 0 otherwise */
  12.   float alpha;              /* intersection point placemet */
  13. } node;
  14.  

In delphi that could be written as:
Code:
  1.  
  2. type
  3. tnode = class;
  4. pnode = ^tnode;
  5.  
  6. tnode = class
  7.   x, y: single;
  8.   next: pnode;
  9.   prev: pnode;
  10.   nextPoly: pnode;   // pointer to the next polygon */
  11.   neighbor : pnode;   // the coresponding intersection point */
  12.   intersect: bool;            // 1 if an intersection point, 0 otherwise */
  13.   entry: bool;                // 1 if an entry point, 0 otherwise */
  14.   visited: bool;              // 1 if the node has been visited, 0 otherwise */
  15.   alpha: single;              // intersection point placemet */
  16. end;
  17.  

Now i would rather use a record. But this does not work:
Code:
  1.  
  2. tnode = record;
  3. pnode = ^tnode;
  4.  


Now this is initialized as:
Code:
  1. node *s=0, *c=0, *root=0;

What is happening here assing 0 to record? I gues i have just to create my object and/or record here.
The following also confuses me ( i think i either adds point for polygon a or for polygon b).

Code:
  1.  
  2. void add(Widget w, int which_button, int x, int y, void *data)
  3. {
  4.   node *new;
  5.   if (!DRAW) return;
  6.  
  7.   if (which_button == 1)
  8.   {
  9.         new = malloc(sizeof(node));
  10.         new->x = x;
  11.         new->y = y;
  12.         new->prev = 0;        /* not need to initialize with 0 after malloc ... */
  13.         new->nextPoly = 0;
  14.         new->neighbor = 0;
  15.         new->intersect = 0;
  16.         new->entry = 0;
  17.         new->visited = 0;
  18.         new->alpha = 0.;
  19.         if (DRAW == 1)
  20.         {
  21.                 new->next = s;
  22.                 if (s) s->prev = new;
  23.                 s = new;
  24.         }
  25.         else /* DRAW == 2 */
  26.         {
  27.                 new->next = c;
  28.                 if (c) c->prev = new;
  29.                 c = new;
  30.         }
  31.         redisplay(W[3], X, Y, NULL);
  32.   }
  33.   else if (which_button == 3)
  34.   {
  35.         DRAW = DRAW==1 ? 2:0;
  36.         redisplay(W[3], X, Y, NULL);
  37.   }
  38. }

What is happinging here:
Code:
  1.  
  2.         if (DRAW == 1)
  3.         {
  4.                 new->next = s;
  5.                 if (s) s->prev = new;
  6.                 s = new;
  7.         }

the s that was created empty before is assigned to next.
now the prev of s is compared to new that is the point that is currently added? Or is s compared to prev of s and if that is the case it is made the new value? aarghh....
finaly the new is made the new s. I am getting confused here.
Thank for your help in advance.

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


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags:
BeitragVerfasst: So Apr 20, 2008 21:09 
Offline
DGL Member
Benutzeravatar

Registriert: Di Jul 01, 2003 18:59
Beiträge: 887
Wohnort: (The Netherlands)
Programmiersprache: fpc/delphi/java/c#
for the time being i wrote it like this:
Code:
  1.  
  2. type
  3. pnode = ^tnode;
  4. tnode = record
  5.   x, y: single;
  6.   next: pnode;
  7.   prev: pnode;
  8.   nextPoly: pnode;   // pointer to the next polygon */
  9.   neighbor : pnode;   // the coresponding intersection point */
  10.   intersect: bool;            // 1 if an intersection point, 0 otherwise */
  11.   entry: bool;                // 1 if an entry point, 0 otherwise */
  12.   visited: bool;              // 1 if the node has been visited, 0 otherwise */
  13.   alpha: single;              // intersection point placemet */
  14. end;
  15.  
  16. var
  17.   s: pnode;
  18.  
  19. procedure Add(x,y: single);
  20. var
  21.   newnode : pnode;
  22. begin
  23.         new(newnode);
  24.         newnode.x := x;
  25.         newnode.y := y;
  26.         newnode.prev := nil;        // not need to initialize with 0 after malloc ...
  27.         newnode.nextPoly := nil;
  28.         newnode.neighbor := nil;
  29.         newnode.intersect := false;
  30.         newnode.entry := false;
  31.         newnode.visited := false;
  32.         newnode.alpha := 0.0;
  33.  
  34.         newnode.next := s;
  35.         if (s<>nil) then
  36.           s.prev := newnode;
  37.         s := newnode;
  38. end;

Only to me it seems that prev and next should be named the oposite. e.g. prev should be next and next should be prev?

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


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags:
BeitragVerfasst: Mo Apr 21, 2008 13:12 
Offline
DGL Member
Benutzeravatar

Registriert: Mi Jul 21, 2004 22:39
Beiträge: 360
Wohnort: UK, Scotland
From the looks of things they should be flipped(Next <-> Prev).

_________________
Free Map Editor - Game Requirements - Stucuk.Net
-Stu


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


Wer ist online?

Mitglieder in diesem Forum: 0 Mitglieder und 17 Gäste


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.021s | 17 Queries | GZIP : On ]