Files |  Tutorials |  Articles |  Links |  Home |  Team |  Forum |  Wiki |  Impressum

Aktuelle Zeit: Di Jul 15, 2025 15:01

Foren-Übersicht » English » English Programming Forum
Unbeantwortete Themen | Aktive Themen



Ein neues Thema erstellen Auf das Thema antworten  [ 13 Beiträge ] 
Autor Nachricht
 Betreff des Beitrags: Dynamic Collision Detection
BeitragVerfasst: Mi Aug 18, 2004 23:09 
Offline
DGL Member
Benutzeravatar

Registriert: Mi Jul 21, 2004 22:39
Beiträge: 360
Wohnort: UK, Scotland
Im wondering if anyone knows any decent(free) resources on Dynamic collision detection(3d not 2d). I basicaly need to work out if the players box has hit a face of a entity.

_________________
Free Map Editor - Game Requirements - Stucuk.Net
-Stu


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags:
BeitragVerfasst: Do Aug 19, 2004 09:22 
Offline
DGL Member
Benutzeravatar

Registriert: Di Jul 01, 2003 18:59
Beiträge: 887
Wohnort: (The Netherlands)
Programmiersprache: fpc/delphi/java/c#
There are some threads on the topic here on the german language boards.

Basicly you have to do some bounding sphere checking. For some better results you could do boundix box checking.

Think of the camera as a sphere, then:
You know the camera position also you can say the size of the camera.
Also you know the positions of your objects in the world, and the sizes of them (calculate them in advance).
Now you can check all bounding spheres with your camere sphere.

Before starting collision detection be sure to understand frustum culling.

_________________
http://3das.noeska.com - create adventure games without programming


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags:
BeitragVerfasst: Do Aug 19, 2004 16:30 
Offline
DGL Member
Benutzeravatar

Registriert: Mi Jul 21, 2004 22:39
Beiträge: 360
Wohnort: UK, Scotland
The current system i made is basic

Code:
  1.  
  2. function TQuake3BSP.CheckCollisionEntitys2(Pos : TVector3f) : boolean;
  3. var
  4. i,x,y,z : integer;
  5. Min,Max : TVector3f;
  6. EntityObject : TEntityObject;
  7. begin
  8.  
  9. Result := false;
  10.  
  11. for i := 0 to numOfBSPCollisionEntitys-1 do
  12. if not CollisionEntitys[i].passable then
  13. begin
  14.  
  15. if CollisionEntitys[i].EoId > -1 then
  16. begin
  17. EntityObject := EntityObjects.EntityObject[CollisionEntitys[i].EoId];
  18. Max := AddVector(AddVector(Models[EntityObject.ModelId].Max,EntityObject.Position),EntityObject.ParentOffset);
  19. Min := AddVector(AddVector(Models[EntityObject.ModelId].Min,EntityObject.Position),EntityObject.ParentOffset);
  20. end
  21. else
  22. begin
  23. Max := CollisionEntitys[i].Max;
  24. Min := CollisionEntitys[i].Min;
  25. end;
  26.  
  27. for x := trunc(Pos.X-Player_Box.X) to trunc(Pos.X+Player_Box.X) do
  28. If (x > Min.X) and (x < Max.X) then
  29. for z := trunc(Pos.Z-Player_Box.Z) to trunc(Pos.Z+Player_Box.Z) do
  30. If (z > Min.Z) and (z < Max.Z) then
  31. for y := trunc(Pos.Y-Player_Box.Y) to trunc(Pos.Y) do
  32. If (y > Min.Y) and (y < Max.Y) then
  33. begin
  34. Result := true;
  35.  
  36. if CollisionEntitys[i].TouchEnabled then
  37. CollisionEntitys[i].Touch(CollisionEntitys[i],nil); // touching it
  38. exit;
  39. end;
  40. end;
  41.  
  42. end;
  43.  


It works fine for cubes but even if i wanted a cube only world, it wouldn't work with entitys that are rotated. Frustrum culling to my knowlage is basicaly working out an area in 3d space that is around the camera, if a point of an object is inside the area it can b seen.

_________________
Free Map Editor - Game Requirements - Stucuk.Net
-Stu


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags:
BeitragVerfasst: Do Aug 19, 2004 18:19 
Offline
DGL Member
Benutzeravatar

Registriert: Di Jul 01, 2003 18:59
Beiträge: 887
Wohnort: (The Netherlands)
Programmiersprache: fpc/delphi/java/c#
getting speedy collison detecting requires you to check as little as possible.

i use bounding boxes for my meshes inside a scene.
so first i check against frustum so i only render the visible items also for these visible objects i do boundinx box checking
if a collsions is determined i go some deeper and go face checking.

so 1. check against frustum
2. do boundix box check
3. do face check

But i see you use bsp so you should be able to skip step 1. and 2. As you alreade render a small part of the bsp. And can use that same part for collision checking.

Also you seem to have collision checking code? What is it that you do not understand?

I think it is best you ask your question at the quake to delphi project.

_________________
http://3das.noeska.com - create adventure games without programming


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags:
BeitragVerfasst: Fr Aug 20, 2004 00:25 
Offline
DGL Member
Benutzeravatar

Registriert: Mi Jul 21, 2004 22:39
Beiträge: 360
Wohnort: UK, Scotland
the collision detection for the actual level is perectly fine. But entitys are another matter. Entitys can move around the map, so u need a system thats dynamic, the code i posted is for entity collision only and is basic. It doesn't allow for the entity to rotate, say u have a train, it goes around a corner, it doesn't keep facing the same way, it rotates. with the current system the collision side would think of it as if it hadn't rotated, thus rotated entitys are imposible, and if the entity was a cylendar then it would act like a cube.

_________________
Free Map Editor - Game Requirements - Stucuk.Net
-Stu


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags:
BeitragVerfasst: Fr Aug 20, 2004 13:33 
Offline
DGL Member
Benutzeravatar

Registriert: Di Jul 01, 2003 18:59
Beiträge: 887
Wohnort: (The Netherlands)
Programmiersprache: fpc/delphi/java/c#
For a dynamic entity with bounding box you need te have:
- its position in the world
- its size
- the rotation (not needed when using a boundingsphere for the entity)
Also you need to know the camera position (i asume you use a bounding sphere for your camera).

Now you can do some math:
- First subtract the camara pos from the object pos
- With the outcome of the previous step do the rotation calculation.
- now you can check if the sphere and the cube collide using something like
Code:
  1. sqrt(calcposition*calcposition) < entitysize + camsize

Of course the above has to be split up in x y z
That should be it. Next you can check on individual faces. It goes the same way as for the bounding box method, but the calcuation has to be done many times. I personaly don't care a lot about face checking i rather split up my meshes in more smaller meshes.

_________________
http://3das.noeska.com - create adventure games without programming


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags:
BeitragVerfasst: Fr Aug 20, 2004 16:21 
Offline
DGL Member
Benutzeravatar

Registriert: Mi Jul 21, 2004 22:39
Beiträge: 360
Wohnort: UK, Scotland
Zitat:
- With the outcome of the previous step do the rotation calculation.
- now you can check if the sphere and the cube collide using something like
Code:
  1.  
  2. sqrt(calcposition*calcposition) < entitysize + camsize
  3.  



What do u mean by rotation calculation, from the code u posted it doesn't look like it factors in rotation.... Also with the "size" wouldn't that mean that the Bounding Box would have to have the exact same dimentions for its width, height, depth.......... Camera's box isn't a box as such eather:

Code:
  1.  
  2. Player_Stand := SetVector(8, 45, 8);
  3. Player_Crouch := SetVector(8, 16, 8);
  4. Player_Box := Player_Stand;
  5.  

_________________
Free Map Editor - Game Requirements - Stucuk.Net
-Stu


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags:
BeitragVerfasst: Fr Aug 20, 2004 20:42 
Offline
DGL Member
Benutzeravatar

Registriert: Mi Jul 21, 2004 22:39
Beiträge: 360
Wohnort: UK, Scotland
Found a rather large bug with just taking the bounding box for collision detection (personaly i don't get how face collisions would work if the player is inside the actual object and not touching a face), i made a nice(ok it looks bad..... just like a Half-Life elevator), but since the system works by the max and min of the object, the player can't get inside the elevator (since it considers everythign between the max and min a sloid part of it). Apart from the fact its compleatly unusable, the "parent - child" thign works (one when the parent entity moves all its "children" are moved with it, i.e buttons and doors on elevators).

If the elevator could b split into several bounding boxes the system could easily b modifyed, but looking at how the thing is stored (array of faces, each "model" has the faceindex and the amount of faces) i don't think its an option.

Code:
  1.  
  2. type TBSPModel = record
  3.   min              : TVector3f;       // The min position for the bounding box
  4.   max              : TVector3f;       // The max position for the bounding box.
  5.   faceIndex        : integer;         // The first face index in the model
  6.   numOfFaces       : integer;         // The number of faces in the model
  7.   brushIndex       : integer;         // The first brush index in the model
  8.   numOfBrushes     : integer;         // The number brushes for the model
  9. end;
  10.  
  11. type TBSPFace = record
  12.   textureID : integer;                   // The index into the texture array
  13.   effect    : integer;                   // The index for the effects (or -1 = n/a)
  14.   FaceType  : integer;                   // 1=polygon, 2=patch, 3=mesh, 4=billboard
  15.   startVertIndex : integer;              // The starting index into this face's first vertex
  16.   numOfVerts     : integer;              // The number of vertices for this face
  17.   meshVertIndex  : integer;              // The index into the first meshvertex
  18.   numMeshVerts   : integer;              // The number of mesh vertices
  19.   lightmapID     : integer;              // The texture index for the lightmap
  20.   lMapCorner : array[0..1] of integer;   // The face's lightmap corner in the image
  21.   lMapSize   : array[0..1] of integer;   // The size of the lightmap section
  22.   lMapPos  : TVector3f;                  // The 3D origin of lightmap.
  23.   lMapVecs : array[0..1] of TVector3f;   // The 3D space for s and t unit vectors.
  24.   Normal  : TVector3f;                  // The face normal.
  25.   Size : array[0..1] of integer;         // The bezier patch dimensions.
  26. end;
  27.  


Dateianhänge:
_0057.jpg [203.61 KiB]
96-mal heruntergeladen

_________________
Free Map Editor - Game Requirements - Stucuk.Net
-Stu
Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags:
BeitragVerfasst: Sa Aug 21, 2004 13:37 
Offline
DGL Member
Benutzeravatar

Registriert: Di Jul 01, 2003 18:59
Beiträge: 887
Wohnort: (The Netherlands)
Programmiersprache: fpc/delphi/java/c#
i did not provide the rotation calculations, only the calculation of the collision after the rotation calculation. Read http://www.delphigl.com/script/do_show. ... 1&action=2 on how to do it.

But if you know how to do the bounding box collision detection you already know how to do the face or even vertice.

- read out a vertice (x,y,z) and (maybe) add the objects world pos to it.
- read out the camera
- the rotation (you can get that from the entity)

Now again
- First subtract the camara pos from the object pos (now face vertice + object pos)
- With the outcome of the previous step do the rotation calculation.
- now you can check if the sphere and the cube collide

and that should be it.

For a much better face collision see: http://www.gametutorials.com/Tutorials/ ... GL_Pg3.htm

_________________
http://3das.noeska.com - create adventure games without programming


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags:
BeitragVerfasst: So Aug 22, 2004 12:47 
Offline
DGL Member
Benutzeravatar

Registriert: Mi Jul 21, 2004 22:39
Beiträge: 360
Wohnort: UK, Scotland
From my understanding of ur code i don't think it would work right with rotations. (see the pic below, black being a cube thats rotated and blue being my guess at the areas of collision detection). Tho it may help with the elevator problem.

EDIT: tryed implementing ur code (face checking), apart from being slow, it only worked when the player is crouched.......

Code:
  1.  
  2. Function CheckFaceCollision(Vertex : Array of TBSPVertex; Amount : Integer; Pos,Collision,Extents : TVector3f) : Boolean;
  3. var
  4. x : integer;
  5. Size,Max,Min,CPos : TVector3f;
  6. begin
  7.  
  8. Max := SetVector(-999999,-999999,-999999);
  9. Min := SetVector(999999,999999,999999);
  10.  
  11. For x := 0 to Amount-1 do
  12. if Vertex[x].Position.X > Max.X then
  13. Max.X := Vertex[x].Position.X
  14. else
  15. if Vertex[x].Position.Y > Max.Y then
  16. Max.Y := Vertex[x].Position.Y
  17. else
  18. if Vertex[x].Position.Z > Max.Z then
  19. Max.Z := Vertex[x].Position.Z
  20. else
  21. if Vertex[x].Position.X < Min.X then
  22. Min.X := Vertex[x].Position.X
  23. else
  24. if Vertex[x].Position.Y < Min.Y then
  25. Min.Y := Vertex[x].Position.Y
  26. else
  27. if Vertex[x].Position.Z < Min.Z then
  28. Min.Z := Vertex[x].Position.Z;
  29.  
  30. Size := SubtractVector(Max,Min);
  31.  
  32. CPos := SubtractVector(Collision,Pos);
  33.  
  34. if Min3f(SqrtVector(ScaleVector3f(CPos,CPos)),AddVector(Size,Extents)) then
  35. Result := True
  36. else
  37. Result := False;
  38.  
  39. end;
  40.  
  41. Function EO_CheckFaceCollision(EOId : Integer) : Boolean;
  42. var
  43. FaceIndex,FaceCount,x,y : Integer;
  44. EntityObject : TEntityObject;
  45. Vertex : Array of TBSPVertex;
  46. begin
  47.  
  48. EntityObject := EntityObjects.EntityObject[Eoid];
  49.  
  50. FaceIndex := Q3Level.Models[EntityObject.ModelId].faceIndex;
  51. FaceCount := Q3Level.Models[EntityObject.ModelId].numOfFaces;
  52.  
  53. Result := False;
  54.  
  55. for x := 0 to FaceCount-1 do
  56. with Q3Level.Faces[FaceIndex+x] do
  57. begin
  58. SetLength(Vertex,numOfVerts);
  59.  
  60. for y := 0 to numOfVerts-1 do
  61. begin
  62. Vertex[y] := Q3Level.Vertices[startVertIndex + y];
  63. //Vertex[y].Position := AddVector(Vertex[y].Position);
  64. end;
  65.  
  66. if CheckFaceCollision(Vertex,numofverts,AddVector(EntityObject.Position,EntityObject.ParentOffset),Camera.position,Player_Box) then
  67. begin
  68. Result := True;
  69. Exit;
  70. end;
  71.  
  72.  
  73. end;
  74.  
  75. end;
  76.  


Dateianhänge:
collision_rot.JPG
collision_rot.JPG [ 10.42 KiB | 7861-mal betrachtet ]

_________________
Free Map Editor - Game Requirements - Stucuk.Net
-Stu
Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags:
BeitragVerfasst: So Aug 22, 2004 18:30 
Offline
DGL Member
Benutzeravatar

Registriert: Di Jul 01, 2003 18:59
Beiträge: 887
Wohnort: (The Netherlands)
Programmiersprache: fpc/delphi/java/c#
i did not say it was fast. But first check with bounding boxes only and if that delivers a collsion do the face check for that entity.

i just noticed you recalculate a bounding box each time? That's bad. You really should precalculate them! Maybe you get a nice speed improvement.

extents is your camera size? What is it set to? try experimenting with that. Also try leaving out y collsion checking for the time being....

also i dont see rotation? With that missing it will not work.

_________________
http://3das.noeska.com - create adventure games without programming


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags:
BeitragVerfasst: So Aug 22, 2004 23:59 
Offline
DGL Member
Benutzeravatar

Registriert: Mi Jul 21, 2004 22:39
Beiträge: 360
Wohnort: UK, Scotland
i never added rotation cos it wouldn't work(to my knowlage anyway) so there was no point coding it. The elevator is made of 5 cubes, thats 5x6 sides which is 40 faces. all the faces should have 4 points so working out the mix/max shouldn't take much time at all.

The extents are as follows

Code:
  1.  
  2. Player_Stand := SetVector(8, 45, 8);
  3. Player_Crouch := SetVector(8, 16, 8);
  4. Player_Box := Player_Stand;
  5.  


Stand and crouch are the only things the player_box can be.

_________________
Free Map Editor - Game Requirements - Stucuk.Net
-Stu


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags:
BeitragVerfasst: Mo Aug 23, 2004 17:21 
Offline
DGL Member
Benutzeravatar

Registriert: Mi Jul 21, 2004 22:39
Beiträge: 360
Wohnort: UK, Scotland
Btw i checked it again and when crouching there is no collision detected at all. Just lags the pc.

_________________
Free Map Editor - Game Requirements - Stucuk.Net
-Stu


Nach oben
 Profil  
Mit Zitat antworten  
Beiträge der letzten Zeit anzeigen:  Sortiere nach  
Ein neues Thema erstellen Auf das Thema antworten  [ 13 Beiträge ] 
Foren-Übersicht » English » English Programming Forum


Wer ist online?

Mitglieder in diesem Forum: 0 Mitglieder und 2 Gäste


Du darfst keine neuen Themen in diesem Forum erstellen.
Du darfst keine Antworten zu Themen in diesem Forum erstellen.
Du darfst deine Beiträge in diesem Forum nicht ändern.
Du darfst deine Beiträge in diesem Forum nicht löschen.
Du darfst keine Dateianhänge in diesem Forum erstellen.

Suche nach:
Gehe zu:  
  Powered by phpBB® Forum Software © phpBB Group
Deutsche Übersetzung durch phpBB.de
[ Time : 0.012s | 18 Queries | GZIP : On ]