顯示具有 [ODE 3D 物理引擎]教學 標籤的文章。 顯示所有文章
顯示具有 [ODE 3D 物理引擎]教學 標籤的文章。 顯示所有文章

2013年10月27日 星期日

ODE教學<四>矩陣資料

The Matrix Details



The ODE library uses a 3x3 matrix in mathematical notation, i.e. row first, column second. However, internally ODE stores
its matrices as a 4x4 ordered matrix, padded with 0's. The good news is that the dBodyGetRotation function we used to 
retrieve the rotation matrix in DrawGeom above returns a 4x3 rotation matrix. So the ODEtoOGL function transposes the
elements over to the OpenGL order (column first, row second) and plugs in the position vector into the 12th, 13th and
14th elements. 

ODE教學<三>幾何繪圖

Drawing The Geoms

At the end of the SimLoop function, after advancing the simulation one step and then deleting the contact joints, we called a function called DrawGeom. This function serves as a generic rendering routine for all types of geoms, using a different rendering function for each class of geom. In keeping with the examples that came with the ODE library, the DrawGeom function takes four parameters. The first is the geom's ID, then its position vector, rotation matrix and lastly a flag used to toggle the rendering of the geoms axis aligned bounding box. 

ODE教學<二>模擬迴圈simLoop

The simulation loop

要更新每個模擬畫面的函數我們叫做SimLoop,簡單來說,他負責計算幾何物件的碰撞然後重新顯示目前的幾何形狀 

void SimLoop()
{
    // dSpaceCollide負責計算空間中兩個幾何物件的可能的碰撞,
    // 我們必須提供callback函數的位置讓他來計算這些資料。
    // callback函數負責在加入碰撞節點前,評估可能的交互作用,碰撞節點的群組叫做contactgroup
    // 這讓我們在把碰撞節點加入到群組前,可以設定其可能行為
    // 第二個參數則是個指標指向任何我們想傳入callback函數的資料。
    // 下個章節我們會講到nearCallback。
    dSpaceCollide(Space, 0, &nearCallback);

    // 現在我們使用dWorldQuickStep來進行進階的模擬,這是dWorldStep的快速版本,但精確度會稍低。
    // 除了World物件ID之外,我們也將step size傳入,每個 step 會根據一個固定的數字的最小step或迭代來
    //更新模擬。
    // 預設次數為 20 但妳可以用dWorldSetQuickStepNumIterations來改變數值
    dWorldQuickStep(World, 0.05);

    //移除所有world中已發生過的暫時性的碰撞節點
    dJointGroupEmpty(contactgroup);

    // 當我們呼掉 DrawGeom 時,會根據物件的幾何形狀來繪出畫面
    DrawGeom(Object.Geom[0], 0, 0, 0);
}

Callback函數

ODE教學<一>初始化ODE



目前正在翻譯這篇,要轉載或幫忙翻譯請跟我說....
原文http://www.alsprogrammingresource.com/basic_ode.html


ODE是個物理的函數庫可以在虛擬世界模擬真實的物理現象,ODE的全名是Open Dynamics Engine而作者是Russell Smith,
是個開放程式碼的計畫,在此的ODE範例將會用免費的Dev-cpp來編譯。


這是個簡單的一個物件-一個盒子掉在一個平坦的表面,我們晚點再來講關節的部份,先來講ode include的部份。
#inlcude <ode/ode.h>