電腦遊戲製作開發設計論壇 首頁 電腦遊戲製作開發設計論壇
任何可以在PC上跑的遊戲都可以討論,主要以遊戲之製作開發為主軸,希望讓台灣的遊戲人有個討論、交流、教學、經驗傳承的園地
 
 常見問題常見問題   搜尋搜尋   會員列表會員列表   會員群組會員群組   會員註冊會員註冊 
 個人資料個人資料   登入檢查您的私人訊息登入檢查您的私人訊息   登入登入 

Google
[求助]使用directx來生成圓錐體,誰能幫我將下列程式之演算法,對應到圖上來表示是如何分析計算的

 
發表新主題   回覆主題    電腦遊戲製作開發設計論壇 首頁 -> 遊戲程式高級班:DirectX、OpenGL及各種圖型函式庫
上一篇主題 :: 下一篇主題  
發表人 內容
enzopower
稍嫌羞澀的路人


註冊時間: 2010-08-10
文章: 1

44.84 果凍幣

發表發表於: 2010-8-11, AM 12:43 星期三    文章主題: [求助]使用directx來生成圓錐體,誰能幫我將下列程式之演算法,對應到圖上來表示是如何分析計算的 引言回覆

http://thumbsnap.com/s/twzPMokU.jpg



bool CCone::UpdateVertices()
{
CONE_CUSTOMVERTEX* pVertex;
WORD* pIndices;
WORD wVertexIndex = 0;
int nCurrentSegment;

//Lock the vertex buffer
if(FAILED(m_pVertexBuffer->Lock(0, 0, (BYTE**)&pVertex, 0)))
{
LogError("<li>CCone: Unable to lock vertex buffer.");
return false;
}

//Lock the index buffer
if(FAILED(m_pIndexBuffer->Lock(0, m_dwNumOfIndices, (BYTE**)&pIndices, 0)))
{
LogError("<li>CCone: Unable to lock index buffer.");
return false;
}

float rDeltaSegAngle = (2.0f * D3DX_PI / m_nSegments);
float rSegmentLength = 1.0f / (float)m_nSegments;
float ny0 = (90.0f - (float)D3DXToDegree(atan(m_rHeight / m_rRadius))) / 90.0f;

//For each segment, add a triangle to the sides triangle list
for(nCurrentSegment = 0; nCurrentSegment < m_nSegments; nCurrentSegment++)
{
float x0 = m_rRadius * sinf(nCurrentSegment * rDeltaSegAngle);
float z0 = m_rRadius * cosf(nCurrentSegment * rDeltaSegAngle);//<=====這個zo為什麼是用cosf來算:什麼數學原理


pVertex->x = 0.0f;
pVertex->y = 0.0f + (m_rHeight / 2.0f);//<=======為什麼除2.0f來算
pVertex->z = 0.0f;
pVertex->nx = x0;
pVertex->ny = ny0; //
pVertex->nz = z0;
pVertex->tu = 1.0f - (rSegmentLength * (float)nCurrentSegment);
pVertex->tv = 0.0f;
pVertex++;


pVertex->x = x0;
pVertex->y = 0.0f - (m_rHeight / 2.0f);//
pVertex->z = z0;
pVertex->nx = x0;
pVertex->ny = ny0;
pVertex->nz = z0;
pVertex->tu = 1.0f - (rSegmentLength * (float)nCurrentSegment);
pVertex->tv = 1.0f;
pVertex++;

//Set three indices (1 triangle) per segment
*pIndices = wVertexIndex;
pIndices++;
wVertexIndex++;

*pIndices = wVertexIndex;
pIndices++;
wVertexIndex += 2;

if(nCurrentSegment == m_nSegments - 1)
{
*pIndices =1;
pIndices++;
wVertexIndex--;
}
else
{
*pIndices = wVertexIndex;
pIndices++;
wVertexIndex--;
}
}

//Create the bottom triangle fan: Center vertex
pVertex->x = 0.0f;
pVertex->y = 0.0f - (m_rHeight / 2.0f);
pVertex->z = 0.0f;
pVertex->nx = 0.0f;
pVertex->ny = -1.0f;
pVertex->nz = 0.0f;
pVertex->tu = 0.5f;
pVertex->tv = 0.5f;
pVertex++;

//Create the bottom triangle fan: Edge vertices
for(nCurrentSegment = m_nSegments; nCurrentSegment >= 0; nCurrentSegment--)
{
float x0 = m_rRadius * sinf(nCurrentSegment * rDeltaSegAngle);
float z0 = m_rRadius * cosf(nCurrentSegment * rDeltaSegAngle);

pVertex->x = x0;
pVertex->y = 0.0f - (m_rHeight / 2.0f);
pVertex->z = z0;
pVertex->nx = 0.0f;
pVertex->ny = -1.0f;
pVertex->nz = 0.0f;

float tu0 = (0.5f * sinf(nCurrentSegment * rDeltaSegAngle)) + 0.5f;
float tv0 = (0.5f * cosf(nCurrentSegment * rDeltaSegAngle)) + 0.5f;

pVertex->tu = tu0;
pVertex->tv = tv0;
pVertex++;
}

if(FAILED(m_pVertexBuffer->Unlock()))
{
LogError("<li>CCone: Unable to unlock vertex buffer.");
return false;
}

if(FAILED(m_pIndexBuffer->Unlock()))
{
LogError("<li>CCone: Unable to unlock index buffer.");
return false;
}

return true;
}

_________________
GOODJOB
回頂端
檢視會員個人資料 發送私人訊息
babu61509
散播福音的祭司


註冊時間: 2007-08-26
文章: 142

681.01 果凍幣

發表發表於: 2010-9-3, PM 2:53 星期五    文章主題: 引言回覆

Q: 這個zo為什麼是用cosf來算:什麼數學原理 ?
A: 請參考附圖一,原理就是三角函式...

Q: 為什麼除2.0f來算 ?
A: 請參考附圖二,因為坐標原點在中間...



tt1.png
 描述:
附圖一
 附件大小:  2.36 KB
 觀看次數:  共 4430 次

tt1.png



tt2.png
 描述:
附圖二
 附件大小:  1.88 KB
 觀看次數:  共 4430 次

tt2.png



_________________
已經畢業了!!
回頂端
檢視會員個人資料 發送私人訊息
從之前的文章開始顯示:   
發表新主題   回覆主題    電腦遊戲製作開發設計論壇 首頁 -> 遊戲程式高級班:DirectX、OpenGL及各種圖型函式庫 所有的時間均為 台灣時間 (GMT + 8 小時)
1頁(共1頁)

 
前往:  
無法 在這個版面發表文章
無法 在這個版面回覆文章
無法 在這個版面編輯文章
無法 在這個版面刪除文章
無法 在這個版面進行投票
可以 在這個版面附加檔案
可以 在這個版面下載檔案


Powered by phpBB © 2001, 2005 phpBB Group
正體中文語系由 phpbb-tw 維護製作