Imported Upstream version 2.81
[platform/upstream/libbullet.git] / Demos / NativeClient / tumbler.h
1 // Copyright (c) 2011 The Native Client Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef EXAMPLES_TUMBLER_TUMBLER_H_
6 #define EXAMPLES_TUMBLER_TUMBLER_H_
7
8 #include <pthread.h>
9 #include <map>
10 #include <vector>
11
12 #include "cube.h"
13 #include "opengl_context.h"
14 #include "opengl_context_ptrs.h"
15 #include "scripting_bridge.h"
16 #include "ppapi/cpp/instance.h"
17
18 namespace tumbler {
19
20 class Tumbler : public pp::Instance {
21  public:
22   explicit Tumbler(PP_Instance instance);
23
24   // The dtor makes the 3D context current before deleting the cube view, then
25   // destroys the 3D context both in the module and in the browser.
26   virtual ~Tumbler();
27
28   // Called by the browser when the NaCl module is loaded and all ready to go.
29   virtual bool Init(uint32_t argc, const char* argn[], const char* argv[]);
30
31   // Called whenever the in-browser window changes size.
32   virtual void DidChangeView(const pp::Rect& position, const pp::Rect& clip);
33
34   // Called by the browser to handle the postMessage() call in Javascript.
35   virtual void HandleMessage(const pp::Var& message);
36
37   // Bind and publish the module's methods to JavaScript.
38   void InitializeMethods(ScriptingBridge* bridge);
39
40   // Set the camera orientation to the quaternion in |args[0]|.  |args| must
41   // have length at least 1; the first element is expeted to be an Array
42   // object containing 4 floating point number elements (the quaternion).
43   // This method is bound to the JavaScript "setCameraOrientation" method and
44   // is called like this:
45   //     module.setCameraOrientation([0.0, 1.0, 0.0, 0.0]);
46   void SetCameraOrientation(
47     const tumbler::ScriptingBridge& bridge,
48     const tumbler::MethodParameter& parameters);
49
50   // Called to draw the contents of the module's browser area.
51   void DrawSelf();
52
53  private:
54   // Browser connectivity and scripting support.
55   ScriptingBridge scripting_bridge_;
56
57   SharedOpenGLContext opengl_context_;
58   // Wouldn't it be awesome if we had boost::scoped_ptr<>?
59   Cube* cube_;
60 };
61
62 }  // namespace tumbler
63
64 #endif  // EXAMPLES_TUMBLER_TUMBLER_H_