I have a set of points , which is in shape of a line.
How can we create new set of points which would be at a offset distance from the current set of points and using GL_TRIANGLE_STRIP we would be able to create a polygon shape.
This is my current code but I could not get any meaningful result from it.
// outlineVertices are existing set of points from which we would generate the offsetPoints
for (int i = 0; i < outlineVertices.size() - 3 ; i += 3) {
finalVertices.push_back(outlineVertices[i]);
finalVertices.push_back(outlineVertices[i + 1]);
finalVertices.push_back(outlineVertices[i + 2]);
glm::vec3 point1 = glm::vec3(outlineVertices[i], outlineVertices[i + 1], outlineVertices[i + 2]);
glm::vec3 point2 = glm::vec3(outlineVertices[i + 7], outlineVertices[i + 1 + 7], outlineVertices[i + 2 + 7]);
glm::vec4 directionVector = GetPerpendicularVectorDirection(point1, point2);
finalVertices.push_back(outlineVertices[i] - (directionVector.x * outlineWidth ));
finalVertices.push_back(outlineVertices[i + 1] + (directionVector.y * outlineWidth));
finalVertices.push_back(outlineVertices[i + 2]);
finalVertices.push_back(outlineVertices[i + 3]);
}
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
glm::vec4 RectangleOutline::GetPerpendicularVectorDirection(glm::vec3 point1, glm::vec3 point2) {
glm::vec3 Direction = glm::normalize(point1 - point2);
float x, y;
x = Direction.x;
Direction.x = -y;
Direction.y = x;
return glm::vec4(Direction, 0);
}