VC + + Programming to realize the visual effect of simulation flame

Source: Internet
Author: User

Introduction

The basic principles of computer simulation technology are the same, mysterious and complex nuclear explosions with water waves, flames, smoke and other very common natural phenomena in the simulation process is not much different. Are all experienced from the entity object to the physical characteristics of the summary, and then set up a mathematical model and the mathematical model based on the simulation algorithm, and finally through the computer dynamic simulation of a series of steps. In this paper, the flame is used as the simulation object, through the analysis of heat source, heat diffusion and convection, the mathematic model and simulation algorithm are established, in order to give full play to the computer's hardware acceleration of graphics, the simulation results are accelerated by using DirectDraw technology, so that it can be realistic and The dynamic simulation of flame combustion process is carried out smoothly.

Simple Approximate model design

Although flame is a very common natural phenomenon in nature, the flame can be expressed as a complex three-dimensional dynamic fluid system according to the knowledge of fluid mechanics. If we want to make a precise simulation of such a complicated fluid system in the computer, it will need to have a very large and complex mathematical model, and the calculation will be very large, in the existing microcomputer is almost difficult to ensure its dynamic real-time, which also lost the meaning of simulation. As a result, the simplest possible model can be used in simulation to achieve the most realistic results possible.

From the physical point of view, to create a flame, the first to have a fire, followed by the "flame" of the effect, the need to fire as the center of the upward, to the surrounding spread, and as the diffusion process gradually away from the fire, the temperature will gradually decline, performance in the visual is the flame cooling In addition, because of the high temperature of the flame so that the ambient air heating expansion of the proportion of decline, so there will be air convection, which will be the flame upward "blown", so that the flame spread around the distance is far less than the distance upward diffusion. Based on the above understanding, you can take the corresponding simulation measures: the setting of the fire source can be identified with a two-value bitmap, not fire source with low brightness pixel filling, ignition point is set to high brightness pixels, through the pixel value of the image can determine whether the current point is the ignition source.

The temperature of the ignition source can be described by the brightness of its point; for the simulation of flame diffusion, in order to minimize the amount of computation, this simple use of an ignition point (x,y) and its vicinity around four points of the mean value to approximate, that is, Pixel (x,y) = (Pixel (x,y) +pixel (x,y-1) + Pixel (x,y+1) +pixel (x-1,y) +pixel (x+1,y))/5, although the approximation algorithm does not take a positive cosine method of precision, but the operation speed is very fast, and in subsequent experimental results with the method of using the positive cosine almost no difference Because the temperature of the flame is realized by changing its brightness value during the simulation, the cooling of the diffusion process can reduce a fixed brightness value to the pixel point. The magnitude of the decay value depends on the speed of the desired flame cooling, and the direct effect of convection on the flame is to keep the flame burning upwards, so it can be achieved by rolling the current flame up to two pixels. According to the simulation algorithm described above, the flame diffusion and convection can be combined to achieve, which will reduce the computational volume to a certain extent, so that the resulting flame is more realistic in vision. The pseudo code that implements the approximate model above can be roughly designed as follows:

ARRAY_OF_BYTES: buffer1(xsize*ysize),buffer2(xsize*ysize)
While(TRUE){
 for(y=1;y  for(x=1;x   n1 = buffer1(x+1, y) //读取4相临像素值
   n2 = buffer1(x-1, y)
   n3 = buffer1(x, y+1)
   n4 = buffer1(x, y-1)
   p = ((n1+n2+n3+n4+p) /5); //四临像素均值
   p = p-c; //同一固定冷却衰减值相减
   if(p<0)
    p=0
   buffer2(x,y-1)=p
  }
 }
 copy buffer2 to the screen ; //显示下一帧
 copy buffer2 to buffer1; //更新Buffer1
}

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.