The particle editor in specialeffect [read Code]

Source: Internet
Author: User

Running Process

1. Entry winmain

2. cmyd3dapplication d3dapp-uses the DirectX demo framework.

3. cmyd3dapplication inherited from cd3dapplication

4. cmyd3dapplication Constructor

5. cd3dapplication Constructor

6. cgroundplane ()-ground Constructor

7. cusercontrolledcamera () camera

8. Because cmyd3dapplication is used, you can focus on this type of application.

Cmyd3dapplciation Constructor

Confirmdevice-hardware capability support

Onetimesceneinit and finalcleanup are paired

Initdeviceobjects () and deletedeviceobjects are paired

Let's look at the sequence between framemove restoredeviceobjects render.

Restoredeviceobjects () --> framemove () --> render () -->

This is the order.

Let's look at the invalidatedeviceobjects () finalcleanup () deletedeviceobjects () sequence.

Invalidatedeviceobjects () --> deletedeviceobjects () --> finalcleanup ()

The basic cmyd3dapplication has a vague understanding.

Next, go to the object and implementation details of the particle editor.

Objects in the cmyd3dapplication class: Except cd3dfont *, they are generally newly added visible objects. The author simplified the DX framework and reduced unnecessary items.

Because it is a read code, it is natural to speculate on the code based on the name. If we cannot speculate on the random name, we can speculate on it based on the context or set the breakpoint and dynamic variable data value, it can be seen that a good naming method is easier to read, but a bad naming method is not an excuse for us to read. The key is what it implements.

///--------------------------------------------------------

Cgroundplane m_ground-the ground is managed at first glance, but how to manage it is unknown

Cusercontrolledcamera m_camera;-used for cameras, that is, lenses

Cinputmanaguer m_inputmanager;-manage Input

Cparticleemitter m_partsys;-particle Transmitter

Hwnd m_hwndpropdlg;-adjust the handle of the non-modal dialog box for particle attributes

Bool m_bshowground-use bool value to control whether the ground is displayed

In addition to the objects in cmyd3dapplication, some global objects exist.

G_pd3dapp is the default in the DX framework

Cparticleemitter * g_thesystem = NULL;-the usage of a global pointer seems to be intermediate.

Now that the particle editor looks at the vertex settings of the particle, typdef struct {d3dxvector3 position; float pointsize; d3dcolor color;} vertex_particle;

D3dfvf_psize In the vertex Genie and flexible vertices

Some experience: When I started using psize, it was easy to forget the format order of the structure and the value of filling size in render. This is the cause of failure to get the correct result, correct and flexible vertex use psize should be pos-> size-> color. If it is reversed, you cannot get what you want. In addition, it is caused by forgetting to turn off the light lighting, and the screen is black or other colors. Okay, this is the vertex structure.

Here, the blendingmode structure controls the mixed color mode.

Typedef struct {char name [25]; // name int mode; // value} blendingmode;

Easy to understand

There is also a particle structure with texture coordinates. You will not use the wizard.

Typedef struct {d3dxvector3 position; d3dcolor color; float tu, TV;} vertex_xyz_diffuse_tex1;

I have seen that psize is used, and there is a limit on the size of the dot genie. What if we use texture coordinates, there may be no limit? This is speculation.

Now that the structure is complete, let's continue with the breakpoint tracking.

Because all implementations are implemented in cmyd3dapplication, the object here cannot be run. I set a breakpoint for every method in cmyd3dapplicaiton for tracking.

Constructor of cmyd3dappliation, m_strwindowtitle window title, m_busedepthbuffer depth buffer, m_pfont m_pfontsmall create font object

In initdeviceobjects (), the font is initialized and nothing is done.

Resotredeviceobjects () has something, which is originally here. Setwindowlong-change the window to a new style

M_inputmanager.createdevices, initialize the directinput Device

M_camera.setposition: sets the camera position

M_ground.restoredeviceobjects ()-create a ground to obtain the d3d device.

Then initialize the particle transmitter, including-setspawndir1. According to the name, I don't know what spawndir means, so I had to change the value. I changed the second parameter Y from-2.0f to-1000.0f. In order to make the result obvious, I tried to select a value that is much different from a value that is similar to a value that is greater than a value that is not visible to the camera. Fortunately, the position is usually used to control the position, according to the changes, the spawndir controls the particle movement speed. Reading other books is velocity, which is poor in English. Because the particle Editor supports dynamic changes and then changes the spawndir value, it knows not only to control the speed reading of particles but also to control the direction. When the value is large, the speed is fast, and spawndir1 and spawndir2 constitute a range, each of which is the XYZ vector. Therefore, each XYZ has a positive or negative score, that is, the 3x3x2 has 18 different results, the matching interval seems ever-changing.

Well, startcolor1 and startcolor2 constitute the color change interval. There are two color ranges in total, which seem to be a constant color. You are a gradient color Based on Motion changes, I used fadecolor to indicate that startcolor1 startendcolor1 is used.

Setpos: Specifies the position and position of the transmitter or particle. It is assumed that setpos (d3dxvector3 (0.0f, 2.0f, 0.0f) is the position of the transmitter, generally, particles are randomly generated based on a range and then moved within a certain XYZ range. after moving to a moving point, they are reset.

Setlifetime sets the particle lifetime, and settexture sets the texture.

The result is that POS is the position of the transmitter.

Next, call the restoredeviceobjects method of the transmitter. Generally, it initializes all the particles of the transmitter, creates the vertex buffer, and then delivers the transmitter address to the global pointer.

In the create dialog box, assign the handle to m_hwndprodlg and display it.

Then, the d3d program, like a general one, must pass through the world matrix, view, and projection transformation process to raster the original d3d image information into a 2D plane.

You can also control materials through the original Fixed rendering pipeline.

This completes the restoredeviceobject. Next, go to the framemove function. Here, to update a particle beyond the specified motion range, it will be updated. In fact, the particles are obtained based on the initial number, and will not increase or decrease, but will change the state, if it is visible or invisible, it is because the position is changed.

In framemove, The m_ftime and m_felapsedtime parameters are continuously input, and the particle motion is constantly changed based on these two parameters.

By default, this particle constantly changes its position and state when it moves in a straight line in a certain direction. There is no complex path movement, for example, pointsprint in dx sdk also uses cos sin for bending motion. Now, the center is placed in the main part of particle editing. We follow up.

When creating a non-modal dialog box, the callback function prodlgproc is the key for editing. The GUI of the dialog box is designed and implemented as needed, and interacts with the transmitter, it is controlled by a global transmitter pointer. Because the global transmitter pointer obtains the transmitter address, it can change the status information of the transmitter.

Let's take a look at the propdlgproc code.

Cmyd3dapplicaiton * APP = (cmyd3dapplication *) g_pd3dapp; static bool bturnoffupdates = false; Switch (umsg) {Case wm_initdialog: break ;}

There are two types of messages in the dialog box: the initialization dialog box and the command execution message.

Wm_initdialog: And wm_command:

Let's set a breakpoint in wm_command:

By intercept, switch (WID) is blocked by modifying the data in the edit box. destroywindow (m_hwndpropdlg); Delete the dialog box.

The settings of the dialog box are detailed. In the "processing" dialog box, a series of texts are obtained and set, and conversion of characters and numbers is also involved. When to call propdlgproc again, the dialog box may be a window started with the main window, so it will not be closed automatically without closing it. So propdlgproc is constantly receiving messages. For details about dialog, refer to the section and add the editing function to other places.

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.