0

Today, I do:

  • I'm storing coordernates(x,z) in a std::vector.

  • I move and rotate the same background grid with: glRotatef(angle_value, 0.0f, 0.0f, 1.0f); glTranslatef(posX, posY, zoom_value);

  • I draw line like this: glBegin(GL_LINE_STRIP);

  • The coordenates stored in std::vector I do an iterator: glVertex3f(iterator->x, iterator->y, 1);

Result: enter image description here

My wished: enter image description here

Cleiton Bueno
  • 326
  • 2
  • 10

1 Answers1

0

render quads instead if lines composed from 2 consequent points and distortion of half width of your path to both perpendicular directions. in 2D is that easy just swap coordinates and negate on (dx,dz) -> (-dz,dx) , (dz,-dx) scaled to size of width/2

So if you got 2 consequent 2D points p(i),p(i-1) both with (x,z) coordinates then:

du=p(i)-p(i-1)
dv=(du.z,-du.x)
dv*=width/(2.0*|dv|)

p0 = p(i)-dv
p1 = p(i)+dv
p2 = p(i-1)+dv
p3 = p(i-1)-dv

img

This will create gaps between consequent QUADS however to remedy that use only p0,p1 and QUAD_STRIP ...

hope you know how to compute length of vector (|dv|) if not see:

near bottom ...

Spektre
  • 49,595
  • 11
  • 110
  • 380
  • I'll try! In the place of (x, z) would not be (x, y)? – Cleiton Bueno Mar 21 '18 at 13:29
  • @CleitonBueno I tought you are using `x,z` as you got the first coordinates mentioned as such. It does not matter if you got `x,z` or `x,y` just use them the same across whole program. – Spektre Mar 21 '18 at 16:08