gpt4 book ai didi

c++ - Ogre 中的纹理坐标

转载 作者:太空宇宙 更新时间:2023-11-04 13:02:02 28 4
gpt4 key购买 nike

目前我正在从事 ADAS 项目,使用 ROS 和 OGRE(面向对象的图形渲染引擎)可视化道路模型(车道中心、车道边界等)。输入是几何点 (x,y,z)。

我可以使用 Ogre::RenderOperation::OT_TRIANGLE_STRIP 绘制线条。我已经创建了 Material 来独特地可视化实线、虚线、双实线等。如何找到这些几何点的纹理坐标?

当前代码如下所示:

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, 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;
}

确保您需要相同类型的纹理贴图。如果纹理或坐标不在右轴上,只需调整代码以在所需轴上进行插值。

关于c++ - Ogre 中的纹理坐标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43737075/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com