The triangulation of Opengl ES line

Source: Internet
Author: User
Tags polyline

This paper mainly discusses the algorithm to extend the line into 2d line surface.

It's easy to extend the P0P1 line into a polygon.

vec2f line = P1-p0

vec2f normal = vec2f (-line.y, line.x). Normalized () .

vec2f A = p0-thickness * normal;vec2f B = p0 + thickness * normal;vec2f c = p1-thickness * normal;vec2f d = p1 + thickness * normal;

If this is a straight line, but if there is a polyline, we also need to calculate the intersection point where

First we'll find out t
vec2fT= ((P2-P1). Normalized () + (P1-P0). normalized ()). Normalized ()
The second is to find out M
vec2f m = vec2f (-T. Y,T. x)
And finally find out the length of D.
float D = Thickness/miter.dot (normal)

You can get all the vertices you want based on the above, and then build triangular patches from those vertices

Roughly as follows:
void Trianglepolyline (const vec2f &p0, const vec2f &AMP;P1, const vec2f &AMP;P2, const vec2f &AMP;P3, Posarray & <span style= "font-family: ' Courier New ', Courier, Monospace;"                >mesh</span>) {if (P1 = = p2) return;                vec2f line = (P2-P1). normalize (); vec2f normal = vec2f (-line. Y, line.                X). normalize (); vec2f Tangent1 = (P0 = = p1)?        Line: ((p1-p0). Normalize () + line). Normalize (); vec2f Tangent2 = (P2 = = p3)?                Line: ((P3-P2). Normalize () + line). Normalize (); vec2f miter1 = vec2f (-tangent1. Y, Tangent1.        X); vec2f miter2 = vec2f (-tangent2. Y, Tangent2.                        X);        float length1 = radius/normal.dotproduct (miter1);                float length2 = radius/normal.dotproduct (Miter2);            if (true) {PUSH (p1-length1 * miter1);            PUSH (P2-LENGTH2 * miter2);            PUSH (p1 + length1 * miter1);        PUSH (p2 + length2 * miter2); }    }
The calling code is as follows
  for (int i = 0;i<vertexes.size (); ++i) {                int a = ((I-1) < 0)? 0: (i-1);                int b = i;                int c = ((i+1) >= vertexes.size ())? Vertexes.size ()-1: (i+1);                int d = ((i+2) >= vertexes.size ())? Vertexes.size ()-1: (i+2);                                Trianglepolyline (Vertexes[a], vertexes[b], vertexes[c], Vertexis[d],<span style= "font-family: ' Courier New ', Courier, Monospace; " >mesh</span>);            }
Vertexes saysPolyline , mesh represents the constructed vertex array number of spoke groups directly drawn with Gl_lines
The effect is roughly as follows


Please note that the above process is relatively small at the angle of the two-segment lineThere will be problems, all please use with caution .

The triangulation of Opengl ES line

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.