1
我一直在研究旋轉函數。每個週期點都會輕微移動到旋轉中心。這取決於一個函數來獲取中心與點之間的距離旋轉:旋轉函數奇怪的行爲
struct Vector3F
{
float x, y, z;
};
inline float GetDistance3FX_inline(Vector3F* v1, Vector3F* v2)
{
return v1->x - v2->x;
}
inline float GetDistance3FZ_inline(Vector3F* v1, Vector3F* v2)
{
return v1->z - v2->z;
}
實際的旋轉功能,即確實工作:
void Rotate3FY(Vector3F* point, Vector3F* center, float rad)
{
float x = GetDistance3FX_inline(point, center);
float z = GetDistance3FZ_inline(point, center);
point->x = x * cos(rad) - z * sin(rad) + center->x;
point->z = z * cos(rad) + x * sin(rad) + center->z;
}
是不功能工作:
void Rotate3FY(Vector3F* point, Vector3F* center, float rad)
{
point->x = GetDistance3FX_inline(point, center) * cos(rad) - GetDistance3FZ_inline(point, center) * sin(rad) + center->x;
point->z = GetDistance3FZ_inline(point, center) * cos(rad) + GetDistance3FX_inline(point, center) * sin(rad) + center->z;
}
我不知道這兩者之間有什麼邏輯差異。 感謝您的任何建議。
什麼不行?錯誤的結果? – Downvoter