just a kid...

thx k_szczech hey i got u a question about what u said:

how do i recognize the collision with two objects and a response for this phenomenon?

komat forget the question i made i already made it…

i have another question, tough
how can i make a polygon or line make a curve?

how do i recognize the collision with two objects and a response for this phenomenon?
To test the collision you need to have information about space occupied of both objects (collision geometry). The detailness of collision geometry depends on your objects (both geometry and movement parameters) and what you need to do with the result.
For example if you need to explode rocket on the collision, you can have very simple representation of geometry (e.g. bounding box) while if you do billiard game the collisions should be calculated as exactly as possible. Sometimes you have to find ballance between precision and performance by using simpler collision geometry (e.g. bounding box) that is calculated much faster than the more precise one (e.g. polygonal mesh).
You may have several levels of collision geometry for single object and you test them in the order of increasing test complexity until you find one that says there is no collision or until you find collision in all of them. This way you skip the time consuming tests when one from simpler tests says that objects do not have chance for collision. Example of such order is bounding sphere, bounding box, polygonal geometry. As before, you need to compare the comulated cost of all the tests with cost of doing the last test only. For example if your objects are almost always in collision the precise test will be almost never skipped and you pay additional time for those simpler collision tests.

Some examples of informations about geometry:

  • [li]Bounding sphere/circle. Sphere with such size that the entire object geometry is within it. Sphere center position offten influences its size so it may be desired to offset the sphere from center of the object which somewhat increases the collision calculation complexity so it depends on gains you get from that. For example if you do simple “Asteroids” like shooter where both ship and asteroids have circle like geometry around object position the offset is not necessary and bounding circles are perfectly fine. Bounding sphere is not precise for long tall objects because they need to have big sphere so there is huge difference between both geometries so if you are creating space sim with loong ships, using only spheres is not good idea. Test of collision between two spheres is done by comparing distance between them with sum of theirs radius.[]Bounding cylinder. Usable as first level of test for collisions between projectiles and human like characters. For some weapons it may entirely suffice (e.g. rocket) for some (e.g. pistol bullet) you may need additional test on geometries for individual body parts if cylinder for entire character says there is hit. Otherwise you may get hits from bullets passing say quarter of meter before the character and blood floowing from the air.[]Bounding box. Box around the geometry. There are two types of bounding boxes. First are axis aligned bounding boxes (AABB). Those boxes have theirs sides paralel to some space (often the world space) so test between both AABB is done by comparing ranges between minimal and maximal value on individual axes. If ranges of two boxes intersect in all three axes there is collision. Problem with AABB is that they may be bad fit to the original geometry (e.g. oblique long rod) and they may change with object rotations. The second type are oriented bounding boxes OBB. They are boxes that are rotated and translated so they fit the geometry as close as possible. They are also rotated when geometry rotates. They do not have the mentioned problems of AABB howevever collision testing is not so simple anymore.[*]Meshes in various preprocessed form (e.g. BSP trees, OBB trees,…). For more information about this see[/li] OPCODE , SOLID and RAPID

If your game objects move by small speeds relative to time between tests you can test the end positions only. To test for collision between two objects in this case you do test between their collision geometries for positions from current frame.
If the speed is high (e.g. projectile) or high precision is required (e.g. billiard) you may need to test geometry surrounding the object trajectory because otherwise you may mis a collision. This is much more complicated in general case however if the only high speed things are the small projectiles, you may test the intersection of object geometry at position from current frame with line representing movement of the projectile since the last frame. While this test for projectile may still mis a collision, it will do mostly in situations where that is likely anyway and it is no problem in most such cases.

If you have high number of objects in the scene it may be not feasible to test all pairs. In that case you have to split the scene in parts and test collision between objects that are impinging a same part. For overview of some partioning methods see this lecture . That lecture is in czech however images should be clear.

Once you have determined that objects are in collision you will determine what to do. This greatly depends on your specific game and objects in question (e.g. rocket explodes, billiard balls bounces, player slides along the wall). For some handling you need only the fact that the collision happened (e.g. for rocket hit). For other things you may need to know the place where it happened (e.g. for player hit by bullet) or even how depth is the intersection of those objects (e.g. for “real” physics). Depending on collision geometries and collision testing method some of those informations may be already present. The other additional informations need to be calculated when collision is detected. For first attempts I suggest that you avoid the “real” physics and use simple aproximations. If you wish to get more informations about physics you can look at ODE which is open source physical library.

i have another question, tough
how can i make a polygon or line make a curve?

If you are talking about giving the polygon the look of curved surface, you can use the vertex normals or the per-pixel normals (aka normal maps) together with lighting to give it part of appearance of curved surface. However that is only a optical ilusion which will break if you see polygon from the side or if polygon intersects with other polygon.
You can not get true curve effect without dividing polygon into more polygons that will be positioned along the curve surface. You have to divide the curved surface into such small triangles that it looks good. The extreme is if you divide surface in such way that each triangle has size of pixel. This will get you really curved looking surface likely killing your performance in the process (this is actually done by some offline renderers from 3d modeling packages). The same thing with the division is true for lines.

In GLU library there are helper function that can help you with the subdivision of surface or polygon however I have never used them.

There is Nehe tutorial talking about collisions. I have not read it however it may be helpfull to you.

u know komat is very hard to me to understand NeHe’s tutorials they r just 2 complex, remember dat time i needed a texure mapping tutorial, i didn’t understood NeHe’s i had to read another one more simple, but thc anyway :stuck_out_tongue: :wink:

After learning and understanding the basic concept of physic in programming, you might want to explore the tokomak physic engine. You can integrate it using devcpp and opengl. Try it. Its fun!

i dont understand what u try to say
what is the tokomak physyk?

The correct name is Tokamak http://www.tokamakphysics.com/ It is physics library designed for games. It calculates collisions and physics based movement.

I guess that Novodex is a better API to do physics. My friend in my corporation uses from this API to make the physics of our game. But as we are in our new year-The new year of iranian people- I don’t know where he is :wink: Unfortunately i have not enough knowledge about Novodex. But as i know, new physics cards support this API. My friend has said to me that all the examples of the Novodex SDK use from OpenGL to create the objects. So after learning OpenGL, you can simply learn Novodex.
-Ehsan-