Coldet - collision normals problem
Blitz3D Forums/Blitz3D Programming/Coldet - collision normals problem
| ||
I'm hoping someone has used coldet here. I've replaced my Blitz3d collisions with Coldet. Collision detection works fine, however the collision normal on impact seem wrong. Please try this, adapted from demo1 (Push the up arrow key to move the sphere into the box) ;DEMO 1 ;Dymamic mesh to static mesh polygon to polygon collision. ;Include helper functions and needed globals Include "coldet.bb" Graphics3D 800,600,0,2 ;activate some global variables coldet_start() cam=CreateCamera() MoveEntity cam,0,3,-5 light=CreateLight() ;------------------------------ ;this will be the dynamic mesh ob1=CreateSphere() PositionEntity ob1,0,0,-3 ScaleEntity ob1, 0.5, 0.5, 0.5 EntityColor ob1,255,255,0 EntityAlpha ob1,.75 EntityFX ob1,16 ;this is the static mesh ob2=CreateCube() RotateEntity ob2,0,0,0 ScaleEntity ob2,1,1,1 EntityColor ob2,255,0,0 ;Make the coldet models and get their pointers ! ;Careful ! Do not use by mistake blitz's pointers. c_ob1 = coldet_make(ob1,1);1=dynamic c_ob2 = coldet_make(ob2,1);0=static ;------------------------------ PointEntity cam,ob2 While Not KeyHit(1) RenderWorld() ;Update your coldet's dynamic object matrix only when it moves or rotates If KeyDown(203) TranslateEntity ob1,-.02,0,0:coldet_setmatrix(ob1,c_ob1) If KeyDown(205) TranslateEntity ob1,.02,0,0:coldet_setmatrix(ob1,c_ob1) If KeyDown(200) TranslateEntity ob1,0,0,.2:coldet_setmatrix(ob1,c_ob1) If KeyDown(208) TranslateEntity ob1,0,0,-.2:coldet_setmatrix(ob1,c_ob1) If coldet_collision (c_ob1,c_ob2);if a collision occurs between model1 and model2 Text 10,10,"1" coldet_collision_point(c_ob1,0);get the collision point Text 10,20,"x: "+collision_point_x() Text 10,30,"y: "+collision_point_y() Text 10,40,"z: "+collision_point_z() Text 10,60,"tri1: "+coldet_colliding_tri(c_ob1,0);model1 colliding tri Text 10,70,"tri2: "+coldet_colliding_tri(c_ob1,1);model2 colliding tri coldet_colliding_verts(c_ob1,1,0);request collidong verts for model1 Text 10,90,"nx: "+colliding_nx1();and aquire the normals of the colliding tri Text 10,100,"ny: "+colliding_ny1() Text 10,110,"nz: "+colliding_nz1() EndIf Text 200,0,"Cursor keys move model1" Flip Wend ;FREE THE COLDET MODELS FROM MEMORY ! coldet_free_model(c_ob1) coldet_free_model(c_ob2) ;free global stuff coldet_end() End In a Blitz collision, the Z normal would be -1 Any ideas? |
| ||
Hmm, I thought I'd try this coldet, because I have trouble with collisions myself. It looks nice. The order in which you are checking the collisions is reverse. The returned normals are from the sphere, not the cube. |
| ||
Ah thanks, so it should be:coldet_colliding_verts(c_ob1,0,1) Text 10,90,"nx: "+colliding_nx2();and aquire the normals of the colliding tri Text 10,100,"ny: "+colliding_ny2() Text 10,110,"nz: "+colliding_nz2() This works fine, but I get normal values from -4 to +4... fair enough I could just divide by 4, but any ideas why? |
| ||
I think these values are not normalized. To normalize, calculate the length of the vector: (I'm really bad with maths, but I think it was like this) lv# = sqr((x*x) + (y*y) + (z*z)) And then divide with it. |
| ||
Hi b32, Where could we get this "colded.bb"? Thanks in advance |
| ||
I found it here: http://www.freewebs.com/elias_t/coldetwrapper.htm It has also a .dll and .decls that should be copied into c:\program files\blitz\userlibs |
| ||
Thanks a lot. |
| ||
b32 - thanks for your advice. When you say 'divide with it' how do you mean? Sorry - my maths is extremely poor :) Say I have a ball moving at angle A towards a block, how would I calculate the new angle B when it bounces? I know its something to do with surface normal of the colliding object... |
| ||
When you say 'divide with it' how do you mean? Sorry - my maths is extremely poor :) Assuming Nx, ny & nz are the normals .. to normalise them so that vector magnitude = 1 do this ... l# = sqr( nx * nx + ny*ny + nz*nz ) nx = nx / l ny = ny/ l nz = nz/ l Say I have a ball moving at angle A towards a block, how would I calculate the new angle B when it bounces? I know its something to do with surface normal of the colliding object... Take a look at this .. http://www.blitzbasic.com/codearcs/codearcs.php?code=670 Stevie |
| ||
Great, thanks Stevie :) |
| ||
Ok that does work fine - however there's now a new issue I'm not sure if I can fix When the ball travels at certain speeds (not stupidly fast, just fairly quick), towards a large object, I get bad data (e.g. no Z value) returned from: coldet_colliding_verts I'm not sure if there's a bug in coldet or the wrapper, but it's consistent and only occurs at certain speeds. I'm going to try this dynamic lib in the code archives to see how that fares: http://www.blitzmax.com/codearcs/codearcs.php?code=898 |
| ||
Are you using MoveEntity or PositionEntity ? It could be that when the speed it too big, the collisions are not noticed, because the mesh will not be in a colliding position during the movement. I had this problem when I was using EntityDistance to measure collisions. |
| ||
TranslateEntity |
| ||
:/ ah, hmm nm than |