From native to Web (4), NaCl Study Notes: Physical Engine

Source: Internet
Author: User
The choice of the physical engine is mentioned above. This series is for C ++ & 3D, so it is excluded from the 2D engine, such as box2d. 3D version. Currently, three of the most popular ones are:
  • Havok
  • Physx
  • Bullet: Open-source. I want to be cross-platform or open-source. It's more reliable and everything is under control. Some people have done some migration of NaCl.

This is the demonstration of bullet's NaCl version: http://bulletphysics.org/nacl/

Code here: https://github.com/erwincoumans/experiments.git

The dependent version is old, so you need to get pepper_15:

I want to swear by this. If you say you want to open a Sparta, you should open it. Why don't we write a program ~

If you do not understand it, it will be harmonious.

Find another version in chrome store:

Find the code: https://github.com/johnmccutchan/NaClAMBase.git from the instruction

If you are interested, take a look at this video to explain: Native client acceleration modules, HTML5 + NaCl

We only care about how bullet is used in NaCl.

Compile and run
  1. Clone from GitHub
  2. Open naclambase/naclam. sln
  3. There is no ppapi in configuration, and vs debugging cannot be used. Therefore, add a configuration.
  4. Set naclambullet as the startup project, change the other several to Lib for compilation, and add its dependencies.
  5. Refer to the configuration of nacl64 to set the include directory.
  6. Compilation found that <sys/time. h> could not be found under ppapi, so write a substitute:
    #if defined(_MSC_VER) || defined(_WINDOWS_)#include <windows.h>   #include <time.h>#else   #include <sys/time.h>#endif #if defined(_MSC_VER) || defined(_WINDOWS_)   inline int gettimeofday(struct timeval* tv, void*)    {      union {         long long ns100;         FILETIME ft;      } now;           GetSystemTimeAsFileTime (&now.ft);      tv->tv_usec = (long) ((now.ns100 / 10LL) % 1000000LL);      tv->tv_sec = (long) ((now.ns100 - 116444736000000000LL) / 10000000LL);     return (0);   }#endif
  7. OK, debug and run:
Summary

The rendering part of this demo is made of HTML5. The communication between page interaction and C ++ is in JSON format. It is a good case. This idea is worth using for reference: the high-performance part uses NaCl, which indicates that some Web developers are more familiar with HTML5. However, if you want to achieve high controllability, you should also use NaCl to implement the 3D part, vs2010 Attribute Table configuration is really convenient. After installing the NaCl plug-in, there will be nacl32 in c: \ Users \ [username] \ appdata \ Local \ Microsoft \ msbuild \ v4.0, nacl64, ppapi configuration. therefore, to convert an existing C ++ project to a version of NaCl, you only need to add the corresponding configuration, which is very convenient.

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.