Advertisement

Please...help, frustrated with collision

Started by December 18, 2000 01:39 AM
5 comments, last by BlackScar 23 years, 11 months ago
Hi all, A bit depressed here, it seems as though no matter how far I get into a game.... I run into the same damn problems. COLLISION DETECION!!! I''ve read my 3d books over and over, read sites, read papers, read everything! Nothing seems to get me by Ok, enough babbling/whining.... here''s the code : TriVECTOR MakeNormal( TriVECTOR p1, TriVECTOR p2, TriVECTOR p3 ) { TriVECTOR norm, p, q; p.x = p2.x - p1.x; p.y = p2.y - p1.y; p.z = p2.z - p1.y; q.x = p3.x - p1.x; q.y = p3.y - p1.y; q.z = p3.z - p1.y; norm.x = p.y * q.z - p.z * q.y; norm.y = p.x * q.z - p.z * q.x; norm.y = p.x * q.y - p.y * q.x; float m = (float)sqrt((norm.x*norm.x) + (norm.y*norm.y) + (norm.z*norm.z)); norm.x /= m; norm.y /= m; norm.z /= m; return(norm); } Ok, now...I take the first three verticies that I use to draw with and make a normal. The trivector struct is just three floats (x, y, z). Since my engine uses blocks, I have six planes. When I move, I test to see if the destination point is inside a block. So I go through all the blocks in the level and test to see if the point is inside of them. typedef struct { char texture[255]; TriVECTOR vert[8]; TriVECTOR norm[6]; float d[6]; float rgba[4]; float u, v; } RENDERBLOCK; RENDERBLOCK *block; bool PointInBlock( TriVECTOR p, int bnum ) { int i; for( i = 0; i < 6; i++ ) { if( block[bnum].norm.x * p.x + block[bnum].norm.y * p.y + block[bnum].norm.z * p.z + level.block[bnum].d <= 0.0f ) { return false; } } return true; } If it is then reset the position. The problem with this is that I cant move. Why? What am I doing wrong ? <img src="sad.gif" width=15 height=15 align=middle> Please help! I''m about to go nuts/insane/crazy, I dunno… something! hehehe Thanks in advance! <img src="smile.gif" width=15 height=15 align=middle> (P.S I''ll literally love you if you figure this out <img src="smile.gif" width=15 height=15 align=middle> heheh no, I''m serious! heheheh) </i> ~-=-=-=-=-=-=~ ~Justin Eslinger~ ~.."BlackScar"..~ ~-=-=-=-=-=-=~
~-=-=-=-=-=-=~~Justin Eslinger~~.."BlackScar"..~~-=-=-=-=-=-=~
Forgot something, sorry...

In the file, it saves the block''s verticies in this order

// Top of the block
0, 1
2, 3

// Bottom of the block
4, 5
6, 7

And when it loads each block it finds the normals and distances of all 6 planes thus so :

block[blocknum].norm[0] = MakeNormal( block[blocknum].vert[0],
block[blocknum].vert[1],block[blocknum].vert[2] ); // Top

block[blocknum].d[0] = block[blocknum].norm[0].x * block[blocknum].vert[0].x + block[blocknum].norm[0].y * block[blocknum].vert[0].y + block[blocknum].norm[0].z * block[blocknum].vert[0].z;

block[blocknum].norm[1] = MakeNormal( block[blocknum].vert[4], block[blocknum].vert[5], block[blocknum].vert[6] ); // Bottom

block[blocknum].d[1] = block[blocknum].norm[1].x * block[blocknum].vert[4].x + block[blocknum].norm[1].y * block[blocknum].vert[4].y + block[blocknum].norm[1].z * block[blocknum].vert[4].z;

block[blocknum].norm[2] = MakeNormal( block[blocknum].vert[0],
block[blocknum].vert[3],block[blocknum].vert[4] ); // Left
block[blocknum].d[2] = block[blocknum].norm[2].x * block[blocknum].vert[0].x + block[blocknum].norm[2].y * block[blocknum].vert[0].y + block[blocknum].norm[2].z * block[blocknum].vert[0].z;

block[blocknum].norm[3] = MakeNormal( block[blocknum].vert[1],
block[blocknum].vert[2],block[blocknum].vert[5] ); // Right
block[blocknum].d[3] = block[blocknum].norm[3].x * block[blocknum].vert[1].x + block[blocknum].norm[3].y * block[blocknum].vert[1].y + block[blocknum].norm[3].z * block[blocknum].vert[1].z;

block[blocknum].norm[4] = MakeNormal( block[blocknum].vert[2],
block[blocknum].vert[3], block[blocknum].vert[6] ); // Front
block[blocknum].d[4] = block[blocknum].norm[4].x * block[blocknum].vert[2].x + block[blocknum].norm[4].y * block[blocknum].vert[2].y + block[blocknum].norm[4].z * block[blocknum].vert[2].z;

block[blocknum].norm[5] = MakeNormal( block[blocknum].vert[0],
block[blocknum].vert[1],block[blocknum].vert[4] ); // Back
block[blocknum].d[5] = block[blocknum].norm[5].x * block[blocknum].vert[0].x + block[blocknum].norm[5].y * block[blocknum].vert[0].y + block[blocknum].norm[5].z * block[blocknum].vert[0].z;

^- That''s how I make the normals and their distances.

If you would like to see the source code, contact me via email please. Thanks again... bahhh... why must this be so hard?




~-=-=-=-=-=-=~
~Justin Eslinger~
~.."BlackScar"..~
~-=-=-=-=-=-=~
~-=-=-=-=-=-=~~Justin Eslinger~~.."BlackScar"..~~-=-=-=-=-=-=~
Advertisement
I don''t know if you are interested, but check this out.., the best collision detection tutorial i ever seen..

http://www.peroxide.dk/

Bruno
Cool, thanks alot. Checking it out now.... I hope it helps!

*crosses fingers*



~-=-=-=-=-=-=~
~Justin Eslinger~
~.."BlackScar"..~
~-=-=-=-=-=-=~
~-=-=-=-=-=-=~~Justin Eslinger~~.."BlackScar"..~~-=-=-=-=-=-=~
perfect collision/response is impossible on a computer. u will have errors the trick is in how to deal with those errors

http://members.xoom.com/myBollux
quite nice that demo at http://www.peroxide.dk/ but theres a slight problem with it I KEPT GETTING STUCK


http://members.xoom.com/myBollux
Advertisement
Hi Zedgeek,

Well, I decided to go BSP tree. I thought that if I was going to do collision detection and then do BSP trees, might as well kill two birds with one stone and read the BSP article. I''ve read it and added it to my engine, and now I have problems with it! Isn''t 3d programming FUN? hehehhehehehheheheheh Oh well! Once I get that working I can read the collision detection part of it. bleh! Thanks anyhow!



~-=-=-=-=-=-=~
~Justin Eslinger~
~.."BlackScar"..~
~-=-=-=-=-=-=~
~-=-=-=-=-=-=~~Justin Eslinger~~.."BlackScar"..~~-=-=-=-=-=-=~

This topic is closed to new replies.

Advertisement