我想渲染圍繞3d曲線每個點的圓圈。基本上試圖爲曲線創建一個像結構一樣的管。但是如圖所示,圓的方向是錯誤的。下面是我計算frenet幀後計算圓形對象的模型矩陣。我哪裏錯了? 作爲參考,綠線是切線,藍色是正常的,紅色是正常。沿着3d曲線渲染圓形
Frenet Frame Calculations
:
glm::vec3 pointback = curve_points[i-1];
glm::vec3 pointmid = curve_points[i];
glm::vec3 pointforward = curve_points[i+1];
glm::vec3 forward_tangent_vector = glm::vec3(glm::normalize(pointforward - pointmid)) ;
glm::vec3 backward_tangent_vector = glm::vec3(glm::normalize(pointmid - pointback)) ;
glm::vec3 second_order_tangent = glm::normalize(forward_tangent_vector - backward_tangent_vector);
glm::vec3 binormal = glm::normalize(glm::cross(forward_tangent_vector, second_order_tangent));
glm::vec3 normal = glm::normalize(glm::cross(binormal, forward_tangent_vector));
Model Matrix for Circle calculations
glm::mat3 tbn = glm::mat3(forward_tangent_vector,binormal,normal);
glm::vec3 normal_axis = glm::vec3(0, 1, 0);
//normal_axis = forward_tangent_vector;
glm::vec3 circleNormal = glm::normalize(tbn * normal_axis);
glm::vec3 rotationAxis = glm::cross(normal_axis, circleNormal);
float rotationAngle = glm::acos(glm::dot(normal_axis, circleNormal));
R = glm::rotate(R, glm::degrees(rotationAngle), rotationAxis);
T = glm::translate(T, pointmid);
glm::mat4 Model = T*R;
圓圈必須建立從正常和副法向量。 –
我不確定我是否關注你。你能否詳細說明一下? – jaykumarark
看來,他們目前似乎是從切線和法線向量構建的。 –