Collision Detection Overview__structure

Source: Internet
Author: User
Collision Detection Overview Overview of the collision-detection–related functionality provided by the XNA Framework.

Collision detection is the process of determining whether objects to a game world overlap The XNA Framework provides several classes and methods to speed implementation of collision detection. Bounding Volume Classes non-bounding Volume Classes Contains and intersects Methods adding NEW collision Data Structures c2> bounding Volume Classes

The XNA Framework has three classes that represent three-dimensional to the world. You can use the bounding volume classes to approximate the volume occupied by models with shapes that are less expensive t o Do collision checks with. All of the bounding volume classes support intersection and containment tests with each other and the plane and Ray Classe S.

Use the bounding Volume class to approximate the three-dimensional space of model, and then we can use them to do some efficient collision detection. bounding Sphere

The Boundingsphere Structure represents occupied by a sphere.

There are several benefits of using a bounding sphere for collision.

The benefits of using bouding sphere are

fast . To check for collision between two spheres, the distance between the centers of the spheres is compared to the sum of the Radii of both spheres. If the distance is less than the combined radii of both spheres, the spheres intersect. The Boundingsphere Structure class is compact . It stores only a vector, representing its center, and its radius. Unlike a bounding box, a bounding sphere doesn ' t need to be recreated if the model Rotat Es. If the model being bounded rotates, the bounding sphere'll still is large to enough it. You don't have to re-create bounding sphere when you rotate, because it's very simple because he's round. Moving a bounding sphere is inexpensive . Just add a value to the center.

There is one major drawback to using the bounding sphere class for collision. Deficiencies. Unless the object being approximated is sphere shaped, the bounding sphere would have some empty spaces, which could result In false positive results. Long narrow objects would have the most empty spaces in their bounding. Use Bouding sphere, first the shape of this model should be a round, otherwise there will be a lot of space, for example, collision occurred, but model actually did not contact each other. bounding Box

The BoundingBox Structure represents the space occupied by a box. The bounding box class is axis aligned. Each face of the bounding box was perpendicular to the x-axis, the y-axis, or the z-axis.

There are several benefits of using the bounding box for collision detection.

The benefits of using the bounding box are the

there are a few drawbacks of using the bounding box for collision detection. Deficiencies. Rotating a bounding box causes it to no longer being axis aligned. Because of this, if you are rotate a model being bounded, you'll need to recreate the bounding box. Doing so can is slow , since all the points in a object are iterated through to get the bounding box. If the model has not changed orientation, you can translate the bounding box instead of recreating it. Note: If the direction does not change, we do not need to re-create bounding box, only need to convert location. If the model being bounded is isn't aligned to the axis, the bounding box would have some space. The amount of empty space would be greatest when the object is rotated to degrees from a axis. Empty spaces in the bounding box can, false positives when checking for collision. or a blank question. bounding frustum

you can use Boundingfrustum Class to create a bounding volume this corresponds to the spaces visible to T He camera. You create a bounding frustum from the combined view and projection matrix This camera is using currently. If the camera moves or rotates, you are need to recreate the bounding frustum. The bounding frustum isn ' t used to determine when two objects-collide, but rather when the Volume of spaces viewable by the camera. Objects that does not intersect and are is contained by the bounding frustum are not visible to the camera and don ' t need t o be drawn. For complex models, this can save the graphics card a lot of work. non-bounding Volume Classes Plane

The

the Plane Structure describes a Plane in space. The plane is defined by a vector perpendicular to the plane and a point on the plane. The plane class supports intersection tests with the bounding volume. The plane class ' s intersection test returns the tested object ' s position relative to the plane. The return value indicates whether the object intersects the plane. If the object does not intersect the plane, the return value indicates whether the object was on the plane ' s front side or Back side. Ray

the Ray Structure describes a ray starting at point A. The ray structure supports intersection tests with the bounding volume. The return value of the "ray intersection tests is the distance" intersection occurred at, or null if no intersection OC Curred. model In addition to the information needed to draw a model, the model Class contains Bounding volumes for its parts. When a model was imported, the content pipeline calculates the bounding sphere for each of the model ' s parts. To check for collision between two models, you can compare the bounding spheres for one model to all of the bounding spher Es of the other model. Contains and intersects Methods

bounding volume classes have methods to support two-types of collision tests:intersection tests and con Tainment tests. The intersects methods check whether the two objects being the tested in any overlap. As soon as the test finds that objects does intersect, it returns without to trying the determine of the degree tion. The contains methods determine whether the objects simply intersect or whether one of the objects is completely contained By the other. Since the intersects methods need only determine whether a intersection occurred, they tend to be faster than the contain S methods. Use the "contains methods only" the degree of intersection is relevant. adding New collision Data Structures

when implementing other bounding volume classes and intersection tests, your'll probably need to add a Custom Content Pipeline processor. For example, your game might need to use convex for hulls. You are could use a custom processor to determine the convex hull and then place it in the model ' s tag field. Then, when the "model is loaded" at run time, the convex hull information would are available in the model. For more information, extending a XNA Framework Standard Processor.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.