嘗試生成由線組成的遞歸樹。我目前的抽獎功能沒有按計劃進行。我演出之前這裏的問題是抽獎代碼:任何有關如何在opengl中正確旋轉/轉換對象的建議,試圖實現以下效果
void _generateTreeBranches(const Point3f& startPoint,
const Point3f& endPoint,
float rotation,
const int depth)
{
if(depth > MAX_DEPTH) return;
cout << "at depth = " << depth << endl;
if(depth == 0)glColor3f(0.0f,1.0f,0.0f);
else glColor3f(1.0f,1.0f,1.0f);
float distanceOfPoint = pointDistance(startPoint, endPoint);
glRotatef(rotation, 0.0f, 0.0f, 1.0f);
glTranslatef(-startPoint.x, 0.0f, 0.0f);
drawLine(startPoint, endPoint);
glTranslatef(startPoint.x, 0.0f, 0.0f);
glRotatef(-rotation, 0.0f, 0.0f, 1.0f);
const float nextLength = distanceOfPoint;
Point3f nextBranchStart = endPoint;
Point3f nextBranchEnd = {endPoint.x + nextLength,endPoint.y,endPoint.z};
_generateTreeBranches(nextBranchStart, nextBranchEnd,45.0f,depth+1);
,吸引了像這樣
/__
的東西,而我試圖把它畫的東西,像這樣
__/
任何幫助實現上述目標?
你有沒有嘗試顛倒你的轉換順序?我發現,由於OpenGL處理它們的方式,我經常會讓它們倒退,而我往往會想到它們。 – user1118321
是的,我認爲我擁有它的方式是在這種情況下opengl的正確順序。如果我繪製了drawLine在原點附近繪製的位置,那麼順序將會顛倒。 – dchhetri
用手做數學運算並使用座標系將其繪製在紙上。 – molbdnilo