NeHe OpenGL Lesson39-Introduction to Physical Simulations

Source: Internet
Author: User

This sample gives us some basics information about Physical Simulations. Some terminologies like Mass, Force, acceleration, velocity, time, position and the relationships among them are described here.
For the simulation part, we need to use another delta time-simulation delta time instead of application delta time. the idea is that any given application delta time will be compared with the simulation threshold (the minimum delta time that cocould be acceptable), if the application delta time longer than this threshold, the application delta time will be separated into a several small delta time (the total value of those delta time will equal the application delta time), the code just like the following:

// milliseconds is the application delta timefloat dt = milliseconds / 1000.0f;                             float maxPossible_dt = 0.1f;    int numOfIterations = (int)(dt / maxPossible_dt) + 1; // seperate into the simulation delta timeif (numOfIterations != 0)    dt = dt / numOfIterations;     for (int a = 0; a < numOfIterations; ++a)    {    constantVelocity->operate(dt);    motionUnderGravitation->operate(dt);        massConnectedWithSpring->operate(dt);}

Then there are 3 different simulations provided:

1) moving with constant speed, no external force applied, no acceleration;

2) moving with the certain initial speed under the gravity, constant external force applied, constant acceleration;

3) moving with the spring model, varous external force applied based on the distance, the acceleration also become vary as the distance changing.

When you set up the simulation model, one thing need to take special care is the unit choose. Make sure all element choose the correct and consistent unit.

 

The source code cocould be found here.

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.