///
///
/**
* Creates a new line object
* @param {vec2} pStart
* @param {vec2} pEnd
* @param {WebGLRenderingContext} pGl
*/
function line2(pStart, pEnd, pGl, pColor, pThickness) {
const lDiffVector = subVec2(pEnd, pStart);
const lBuffer = pGl.createBuffer();
pGl.bindBuffer(pGl.ARRAY_BUFFER, lBuffer);
var lBufferedData = [
pStart.x, pStart.y, pColor.x, pColor.y, pColor.z, pColor.w,
pEnd.x, pEnd.y, pColor.x, pColor.y, pColor.z, pColor.w
];
pGl.bufferData(pGl.ARRAY_BUFFER, new Float32Array(lBufferedData), pGl.STATIC_DRAW)
pGl.bindBuffer(pGl.ARRAY_BUFFER, undefined);
var lSlope = (pEnd.y - pStart.y) / (pEnd.x - pStart.x);
return {
buffer: lBuffer,
start: pStart,
end: pEnd,
slope: lSlope,
angle: Math.atan(lSlope),
length: length2(lDiffVector),
direction: normalize2(lDiffVector)
};
}
function renderLine2(pGl, pProgramInfo, pLine) {
pGl.uniformMatrix4fv(pProgramInfo.uniformLocations.model, false, mat4()); // Model on a line is always default matrix
pGl.bindBuffer(pGl.ARRAY_BUFFER, pLine.buffer);
{
pGl.enableVertexAttribArray(pProgramInfo.attributeLocations.position);
pGl.vertexAttribPointer(pProgramInfo.attributeLocations.position, 2, pGl.FLOAT, false, BYTES_PER_FLOAT * 6, 0);
pGl.enableVertexAttribArray(pProgramInfo.attributeLocations.color);
pGl.vertexAttribPointer(pProgramInfo.attributeLocations.color, 4, pGl.FLOAT, false, BYTES_PER_FLOAT * 6, BYTES_PER_FLOAT * 2);
}
pGl.drawArrays(pGl.LINES, 0, 2);
}