Lücken beim zeichnen eines Paths in 3d

  • GM 8

Diese Seite verwendet Cookies. Durch die Nutzung unserer Seite erklären Sie sich damit einverstanden, dass wir Cookies setzen. Weitere Informationen

  • Lücken beim zeichnen eines Paths in 3d

    Habe folgendes Problem:
    Ich wollte eine Strecke entlang des Paths zeichnen lassen. Das Problem besteht darin dass dauernd Lücken in der Strecke entstehen. Ich weiss dass es daran liegt dass die Dreiecke
    mal nach innen, mal nach außen gezeichnet werden. Aber ich bekomme einfach keine korrekte Ausrichtung hin, wenn mal Lücken weg sind, entstehen woanders wieder welche.

    Der Code zum zeichnen der Strecke anhand eines Paths:

    GML-Quellcode

    1. steps = 10/path_get_length(path_Strecke)
    2. dicke = 4
    3. draw_set_color(c_white)
    4. for(i=0;i<=1;i+=steps)
    5. {
    6. pxO = path_get_x(path_Strecke,i-steps)
    7. pyO = path_get_y(path_Strecke,i-steps)
    8. pxA = path_get_x(path_Strecke,i)
    9. pyA = path_get_y(path_Strecke,i)
    10. pxB = path_get_x(path_Strecke,i+steps)
    11. pyB = path_get_y(path_Strecke,i+steps)
    12. pxC = path_get_x(path_Strecke,i+steps+steps)
    13. pyC = path_get_y(path_Strecke,i+steps+steps)
    14. pdA = point_direction(pxA,pyA,pxO,pyO)
    15. pdB = point_direction(pxA,pyA,pxB,pyB)
    16. pdC = point_direction(pxB,pyB,pxA,pyA)
    17. pdD = point_direction(pxB,pyB,pxC,pyC)
    18. dA = (pdA + pdB)/2
    19. dB = (pdC + pdD)/2
    20. d3d_primitive_begin(pr_trianglelist);
    21. d3d_vertex(pxA+lengthdir_x(dicke,dA),pyA+lengthdir_y(dicke,dA),0);
    22. d3d_vertex(pxA-lengthdir_x(dicke,dA),pyA-lengthdir_y(dicke,dA),0);
    23. d3d_vertex(pxB-lengthdir_x(dicke,dB),pyB-lengthdir_y(dicke,dB),0);
    24. d3d_vertex(pxB-lengthdir_x(dicke,dB),pyB-lengthdir_y(dicke,dB),0);
    25. d3d_vertex(pxB+lengthdir_x(dicke,dB),pyB+lengthdir_y(dicke,dB),0);
    26. d3d_vertex(pxA+lengthdir_x(dicke,dA),pyA+lengthdir_y(dicke,dA),0);
    27. d3d_primitive_end();
    28. }
    Alles anzeigen


    Bilder:
    Die Lücken

    Die Ausrichtung der Dreiecke


    Mein Ziel ist es dass die Lücken verschwinden, also dass die Ausrichtung der Dreiecke sich nicht verändert.
    Dateien
    • Rennen.zip

      (9,86 kB, 335 mal heruntergeladen, zuletzt: )

    Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von Chris987 ()

  • Versuch mal pr_trianglestrip.

    GML-Quellcode

    1. steps = 10/path_get_length(path_Strecke)
    2. dicke = 4
    3. draw_set_color(c_white)
    4. for (i=0;i<=1;i+=steps) {
    5. x1 = path_get_x(path_Strecke,i);
    6. y1 = path_get_y(path_Strecke,i);
    7. x2 = path_get_x(path_Strecke,i+steps);
    8. y2 = path_get_y(path_Strecke,i+steps);
    9. dir = point_direction(x1,y1,x2,y2);
    10. d3d_primitive_begin(pr_trianglestrip);
    11. d3d_vertex(x1+lengthdir_x(dicke,dir-90),y1+lengthdir_y(dicke,dir-90),0);
    12. d3d_vertex(x1+lengthdir_x(dicke,dir+90),y1+lengthdir_y(dicke,dir+90),0);
    13. d3d_primitive_end();
    14. }
    Alles anzeigen

    So müsste das funktionieren ...

    EDIT @ unter mir: Hehe, immer diese Leichtsinnsfehler :)
  • Klappt leider nicht. Ich weiss zwar nicht genau wie pr_trianglestrip funktioniert, aber kann man überhaupt mit nur zwei Virtexen zeichnen?

    Ich habe eine Notlösung gefunden:
    Spoiler anzeigen

    GML-Quellcode

    1. steps = 5/path_get_length(path_Strecke)
    2. dicke = 4
    3. draw_set_color(c_white)
    4. for(i=0;i<=1;i+=steps)
    5. {
    6. pxA = path_get_x(path_Strecke,i)
    7. pyA = path_get_y(path_Strecke,i)
    8. pxB = path_get_x(path_Strecke,i+steps)
    9. pyB = path_get_y(path_Strecke,i+steps)
    10. pxC = path_get_x(path_Strecke,i+steps+steps)
    11. pyC = path_get_y(path_Strecke,i+steps+steps)
    12. pdB = point_direction(pxA,pyA,pxB,pyB)
    13. pdD = point_direction(pxB,pyB,pxC,pyC)
    14. dA = pdB + 90
    15. dB = pdD + 90
    16. d3d_primitive_begin(pr_trianglelist);
    17. d3d_vertex(pxA+lengthdir_x(dicke,dA),pyA+lengthdir_y(dicke,dA),0);
    18. d3d_vertex(pxA-lengthdir_x(dicke,dA),pyA-lengthdir_y(dicke,dA),0);
    19. d3d_vertex(pxB-lengthdir_x(dicke,dB),pyB-lengthdir_y(dicke,dB),0);
    20. d3d_vertex(pxB-lengthdir_x(dicke,dB),pyB-lengthdir_y(dicke,dB),0);
    21. d3d_vertex(pxB+lengthdir_x(dicke,dB),pyB+lengthdir_y(dicke,dB),0);
    22. d3d_vertex(pxA+lengthdir_x(dicke,dA),pyA+lengthdir_y(dicke,dA),0);
    23. d3d_primitive_end();
    24. }
    Alles anzeigen


    Ach natürlich. Habs etwas Korrigiert, jetzt funkt's.

    GML-Quellcode

    1. steps = 10/path_get_length(path_Strecke)
    2. dicke = 4
    3. draw_set_color(c_white)
    4. d3d_primitive_begin(pr_trianglestrip);
    5. for (i=0;i<=1;i+=steps) {
    6. x1 = path_get_x(path_Strecke,i);
    7. y1 = path_get_y(path_Strecke,i);
    8. x2 = path_get_x(path_Strecke,i+steps);
    9. y2 = path_get_y(path_Strecke,i+steps);
    10. dir = point_direction(x1,y1,x2,y2);
    11. d3d_vertex(x1+lengthdir_x(dicke,dir-90),y1+lengthdir_y(dicke,dir-90),0);
    12. d3d_vertex(x1+lengthdir_x(dicke,dir+90),y1+lengthdir_y(dicke,dir+90),0);
    13. }
    14. d3d_primitive_end();
    Alles anzeigen

    Dieser Beitrag wurde bereits 2 mal editiert, zuletzt von Chris987 ()

  • Das kommt mir doch bekannt vor....
    Weiß nicht mehr von wem das hier war, hat aber immer ganz gut funktioniert. Ist im Prinzip der gleiche Code:

    GML-Quellcode

    1. //draw_path_textured(path, texture, texture_shift, stretch, width, step)
    2. //arguments:
    3. //path: I'll let you guess this one
    4. //texture: this one too...
    5. //texture_shift (0-1): the position of the texture at the start point
    6. //(use it to give the texture a movement)
    7. //stretch: wether to stretch the texture according to the path speed
    8. //width: the width of the primitive (don't use 0...)
    9. //This scipt takes several points from the path to draw the texture.
    10. //'step' is the distance in pixels between 2 of these points.
    11. var pth, wid, stp, stp_i, xt, xt_i, sgn, a, a_i, xx, yy, x1, y1, x2, y2, i, px, py, nx, ny;
    12. pth = argument0;
    13. if (path_get_length(pth) == 0) exit;
    14. xt = argument2;
    15. stc = argument3;
    16. wid = argument4/2;
    17. stp = argument5;
    18. stp_i = stp/path_get_length(pth);
    19. xt_i = stp/(2*wid);
    20. texture_set_repeat(true);
    21. if path_get_closed(pth){
    22. px = path_get_x(pth,1-stp_i);
    23. py = path_get_y(pth,1-stp_i);
    24. }else{
    25. px = path_get_x(pth,0);
    26. py = path_get_y(pth,0);
    27. }
    28. draw_primitive_begin_texture(pr_trianglestrip, argument1);
    29. for (i=0; i<=1; i+=stp_i) {
    30. xx = px;
    31. yy = py;
    32. nx = path_get_x(pth, i);
    33. ny = path_get_y(pth, i);
    34. dir = point_direction(px,py,nx,ny);
    35. dx = lengthdir_x(wid, dir+90);
    36. dy = lengthdir_y(wid, dir+90);
    37. draw_vertex_texture(xx+dx, yy+dy, xt, 0);
    38. draw_vertex_texture(xx-dx, yy-dy, xt, 1);
    39. px = nx;
    40. py = ny;
    41. if (stc) xt += xt_i/(path_get_speed(pth, i)/100);
    42. else xt += xt_i;
    43. }
    44. draw_primitive_end();
    Alles anzeigen