Anyone experienced with ODE? I found difficulty using trimesh collision detect algo.
Anyone can help how to know if some triangle collide with a geometri shape?
I wonder if someone can see my mistake here.
I got a list of vertex, for example, 120 vertex. Each vertex have 3 floating points.
I want to create triangles with that, and for doing it, I need to form a list of indexs.
So, for example:
If I had a list of vertexs like this:
vertexs
- ={1.000000 0.999999 1.000000
1.000000 1.000000 -1.000000 0.000000
-1.000000 1.000000 -1.000000 0.000000
1.000000 0.999999 1.000000 0.000000
-1.000000 1.000000 -1.000000 0.000000
-1.000000 1.000000 1.000000 0.000000
-1.000000 -1.000000 -1.000000
-1.000000 -1.000000 1.000000
-1.000000 1.000000 1.000000 }
To form a triangle I need to create a index array like this:
index = [0,1,2,3,4,5,6,7,8]
which mean, 0,1,2, will form the first triangle where 0,1,2 mean position of the vertex in memory, and 3,4,5 will form the second triangle and so on.
So I created this function:
fODECreateTriMesh proc uses esi spaceID:dword,worldID:dword,lpTri:dword
LOCAL data,data_offset:dword
LOCAL index,index_offset:dword
LOCAL trimesh:dword
LOCAL nv,geom,tm_data:dword
LOCAL dMass:dword
LOCAL bID:dword
LOCAL ind_lim:dword
; Allocate a memory
; rewrite the data
;
mov esi,lpTri
mov ecx,[esi].fTri.nVertex
xor edx,edx
mov eax,12
mul ecx
invoke mAlloc,eax
mov data,eax
xor ecx,ecx
mov data_offset,0
loop_data:
pushad
inc ecx
invoke fTriGetVertexData,lpTri,ecx
mov ecx,data
add ecx,data_offset
fld [eax].fTriData.PositionX
fstp dword ptr[ecx]
fld [eax].fTriData.PositionY
fstp dword ptr[ecx+4]
fld [eax].fTriData.PositionZ
fstp dword ptr[ecx+8]
add data_offset,12
popad
inc ecx
cmp ecx,[esi].fTri.nVertex
jl loop_data
mov ecx,[esi].fTri.nVertex
xor edx,edx
mov eax,3*4
mul ecx
invoke mAlloc,eax
mov index,eax
xor edx,edx
mov eax,[esi].fTri.nVertex
mov ecx,3
mul ecx
mov ind_lim,eax
xor ecx,ecx
mov index_offset,ecx
loop_index:
pushad
mov edx,index
add edx,index_offset
push ecx
pop dword ptr [edx]
add index_offset,4
popad
inc ecx
cmp ecx,ind_lim
jl loop_index
invoke fODEdGeomTriMeshDataCreate
mov tm_data,eax
;invoke fODEdGeomTriMeshDataBuildSimple,eax,data,[esi].fTri.nVertex,index,[esi].fTri.nVertex
invoke fODEdGeomTriMeshDataBuildSingle,tm_data,data,12,[esi].fTri.nVertex,index,ind_lim,12
;invoke fODEdGeomTriMeshDataBuildSimple,tm_data,data,[esi].fTri.nVertex,index,ind_lim
;push eax
invoke fODEdCreateTriMesh,spaceID,tm_data,0,0,0
mov geom,eax
;invoke fODEdGeomSetData,eax,CADD("Plane")
;pop eax
invoke fODEdGeomSetData,geom,tm_data
; invoke mAlloc,2048
; mov dMass,eax
; invoke fODEdBodyCreate,worldID
; mov bID,eax
; invoke fODEdMassSetTrimesh,dMass,CFLT(1.0),geom
; invoke fODEdGeomSetBody,geom,bID
;invoke fODEdBodySetMass,bID,dMass
mov eax,geom
ret
fODECreateTriMesh endp
And the problem is, it does not detect all the triangle, and I guess Im making mistake on the indexs array. If you had any idea where is my mistake, please tell me since I got no clue how to solve it.