DX10 Engine Planning 0314--02

Source: Internet
Author: User

The main content of this paper is about the mechanism of pick-up, I in my engine in each mesh class to add a pickup mechanism, when the object opens the pickup switch, it will respond to pick, while drawing an auxiliary external body, is picked up, the object carries on a simple rotation around its own y-axis action.

(I have the mouse projection matrix is rewritten, on the original basis to adjust the center of the screen as the origin, so as to reduce the amount of computation when the coordinate system conversion, mouse system I use their own definition of the dxinput system, so can do so.) )

Attach some:

(Don't worry about some details)

On the mechanism of pick-up, the Dragon book has been very detailed, but there are some key points not mentioned. In the online can search for some of the box of external pick-up discussion. Not very detailed, and not high-efficiency. cannot be used for actual use. ( In fact, the Dragon book has grazing all the knowledge will give us )

I thought for a moment and found a relatively quick and easy way to master it:

Pick the core of the part, is the determination of the pick Ray, here a little bit, we assume that the screen directly shows the distance from the camera is 1.0f of the surface, not ( -1.0f, 1.0f) of the surface. So the calculations are based on this surface. Wit's cheese a little bit of knowledge can be written quickly.

New ray structure struct rayline{D3dxvector3 pos, dir;}, the Ray is pickrayline.

By multiplying a series of matrices, we find the pickup ray equation in the world coordinate system and then enter our topic today: (This article only discusses the general situation)

  

Assume that the 2D space Ray is Ray (RX, RY);

Before discussing 3D space, first discuss the contents of 2D space, as shown in the above sketch, if you want to determine whether the ray through the multi-deformation, first to determine the two boundary lines, OA, OC. Here's how:

the OA, OB, OC, OD do the unit processing , and then find the new node mmin= (x, Y,), Mmax = (A, b, c); The minimum value in the three components of the four vertices is stored in mmin.

(Pickrayline also need to do the unit treatment.) )

Then the Rays pass through the polygon when the ray meets the following conditions:

if (Rx > x && Rx < a)

if (RY > y && RY < b)

Through the rectangle

Well, the situation of 2D space to this analysis is complete, now we go to 3D space, cuboid, need to calculate a few more vertices, more than one component on it.

Now go to our program, if you want to implement the above algorithm, there are two scenarios, 1. The interaction of the pickup ray and the object is carried out in the world space; 2. The pickup ray is converted into the object space.

Using Method 1 o'clock, we need to create an object in an extra space to create an array of box add-in vertices, and then transform all the vertices into a world coordinate system, a total of 8 vertices need to be transformed. is really a fee space time method Ah, decisively abandoned!

Look at Method 2, we only need to do one-step conversion-ray into the object local coordinate system, and, do not need to use extra space to store the external body, you are not mistaken, only need a like the Dragon book example used two variables mmin, Mmax can be. I will not mention the specific method. Believe it's not a problem for smart-minded people.

Ok....

*********************************************

  Supplemental knowledge

Object pickup is a very time-consuming task, so you can minimize pick-up operations. The load of the scene should be loaded in a step-by-step, using additional threads for background loading. Load and delete objects progressively. This is the first level, and then an active variable is added inside the object, and if the object is not up to the point of the player, it should not participate in pickup. This is the second pass.

*********************************************

All right, here's the end of the article. Tomorrow start to do a small game to play, remember that there is a man on the internet on the point 100, with their own slag engine to achieve the following try it.

DX10 Engine Planning 0314--02

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.