目前我正在研究ADAS项目,使用ROS和OGRE(面向对象的图形渲染引擎)可视化道路模型(车道中心,车道边界等)。输入是几何点(x,y,z)。
我可以使用Ogre :: RenderOperation :: OT_TRIANGLE_STRIP绘制线条。 我创造了独特可视化实线,虚线谎言,双实线等材料。 如何找到这些几何点的纹理坐标?
当前代码如下所示:
geometry_msgs::Point p0 = _msg.shape_points.front();
for(int i = 1; i < _msg.shape_points.size(); ++i)
{
const geometry_msgs::Point& p1(_msg.shape_points[i]);
const float dx = p1.x - p0.x;
const float dy = p1.y - p0.y;
const float phi = atan2(dy, dx);
const float wx = sin(phi) * lane_mark_width_;
const float wy = -cos(phi) * lane_mark_width_;
if (i == 1)
{
lane_boundary_->position(p0.x - wx, p0.y - wy, p0.z);
lane_boundary_->textureCoord(p0.x , p0.y);
lane_boundary_->position(p0.x + wx, p0.y + wy, p0.z);
lane_boundary_->textureCoord(p0.x, p0.y);
}
lane_boundary_->position(p1.x - wx, p1.y - wy, p1.z);
lane_boundary_->textureCoord(p1.x, p1.y);
lane_boundary_->position(p1.x + wx, p1.y + wy, p1.z);
lane_boundary_->textureCoord(p1.x, p1.y);
p0 = p1;
}
谢谢
答案 0 :(得分:0)
纹理坐标必须在[0,1]范围内。 其中[0,0]位于纹理的左上角,[1,1]位于右下角。
我假设您希望纹理沿y轴(纹理中的垂直轴,Y坐标范围)映射到一个条纹。我还假设您的坐标生成是按行排序的。
geometry_msgs::Point p0 = _msg.shape_points.front();
//Offset in between two points is fixed
const float uv_step = 1.0f / _msg.shape_points.size();
for(int i = 1; i < _msg.shape_points.size(); ++i)
{
const geometry_msgs::Point& p1(_msg.shape_points[i]);
const float dx = p1.x - p0.x;
const float dy = p1.y - p0.y;
const float phi = atan2(dy, dx);
const float wx = sin(phi) * lane_mark_width_;
const float wy = -cos(phi) * lane_mark_width_;
//Compute the vertical texture coordinate
const float v = i * uv_step;
if (i == 1)
{
lane_boundary_->position(p0.x - wx, p0.y - wy, p0.z);
//First point is at the top left corner
lane_boundary_->textureCoord(0.0f, 0.0f);
lane_boundary_->position(p0.x + wx, p0.y + wy, p0.z);
//Second point is a the the top right corner
lane_boundary_->textureCoord(1.0f, 0.0f);
}
lane_boundary_->position(p1.x - wx, p1.y - wy, p1.z);
//Along the y axis on the left
lane_boundary_->textureCoord(0.0f, v);
lane_boundary_->position(p1.x + wx, p1.y + wy, p1.z);
//Along the Y axis on the right
lane_boundary_->textureCoord(1.0f, v);
p0 = p1;
}
确保您需要相同类型的纹理映射。如果纹理或坐标不在右轴上,只需调整代码以在所需轴上进行插值。