LightWrap++
AC++wrapperfortheLightWave3DSDK
camera_handler.h
Go to the documentation of this file.
1 #ifndef LWPP_CAMERA_HANDLER_H
2 #define LWPP_CAMERA_HANDLER_H
3 
4 #if (LW_SDK >= 95)
5 
6 #include "lwpp/plugin_handler.h"
7 #include <lwcamera.h>
8 
9 namespace lwpp
10 {
12  class CameraHandler : public InstanceHandler, public ItemHandler, public RenderHandler
13  {
14  public:
15  CameraHandler(void* g, void* context, LWError* err) : InstanceHandler(g,context,err)
16  {
17  ;
18  }
19  virtual ~CameraHandler() {;}
20  virtual bool Preview (double lpx, double lpy,LWDMatrix4 projection,const LWCameraAccess* camaccess)
21  {
22  return false; //Return 1, yes, we have returned a valid matrix
23  }
24 
25  virtual LWError NewFrame (const LWFrameInfo* frameinfo, const LWCameraAccess* camaccess)
26  {
27  return 0;
28  }
29 
30  virtual int Evaluate(double fpx, double fpy, double lpx, double lpy, double fractime, LWCameraRay* ray, const LWCameraAccess* camaccess)
31  {
32  return LWCAMTYPEEVAL_NO_RAY; //By default, no rays are cast
33  }
34 
35  virtual int Flags()
36  {
37  return 0; //says This Plugin doesn't use DOF by default
38  }
39  };
40 
42  template <class T>
43  class CameraAdaptor : public InstanceAdaptor <T>, public ItemAdaptor <T>, public RenderAdaptor <T>
44  {
45  public:
46  CameraAdaptor(const char *name, ServerTagInfo *tags)
47  {
48  LWServer::AddPlugin(LWCAMERA_HCLASS, name, Activate, tags);
49  }
50  static int Activate (int version , GlobalFunc* global, LWInstance inst, void* serverData)
51  {
52  if(version!=LWCAMERA_VERSION) return AFUNC_BADVERSION;
53  lwpp::SetSuperGlobal(global);
54 
55  LWCameraHandler* plugin = static_cast<LWCameraHandler*>(inst);
56  InstanceAdaptor<T>::Activate(plugin->inst);
57  ItemAdaptor<T>::Activate(plugin->item);
58  RenderAdaptor<T>::Activate(plugin->rend);
59 
60  plugin->preview = CameraAdaptor::Preview;
61  plugin->newFrame = CameraAdaptor::NewFrame;
62  plugin->evaluate = CameraAdaptor::Evaluate;
63  plugin->flags = CameraAdaptor::Flags;
64 
65  UNUSED(serverData);
66  return AFUNC_OK;
67  }
68 
69  private:
70  static int Preview (LWInstance inst, double lpx, double lpy, LWDMatrix4 projection, const LWCameraAccess* camaccess)
71  {
72  T* plugin = static_cast<T*>(inst);
73  return plugin->Preview(lpx,lpy,projection,camaccess) ? 1 : 0;
74  }
75  static LWError NewFrame (LWInstance inst, const LWFrameInfo* frameinfo, const LWCameraAccess* camaccess)
76  {
77  T* plugin = static_cast<T*>(inst);
78  return plugin->NewFrame(frameinfo, camaccess);
79  }
80  static int Evaluate (LWInstance inst, double fpx, double fpy, double lpx, double lpy, double fractime, LWCameraRay* ray, const LWCameraAccess* camaccess)
81  {
82  T* plugin = static_cast<T*>(inst);
83  return plugin->Evaluate(fpx,fpy,lpx,lpy,fractime,ray,camaccess);
84  }
85  static unsigned int Flags (LWInstance inst)
86  {
87  T* plugin = static_cast<T*>(inst);
88  return plugin->Flags();
89  }
90  };
91 
92  /* GUI Classes */
97 
98 
100  public:
101  LWPanelCameraHandler(void *g, void *context, LWError *err) : CameraHandler(g, context, err)
102  {
103  ;
104  }
105  };
106 
107  template <class T>
108  class LWPanelCameraAdaptor : public CameraAdaptor<T>, public LWPanelAdaptor<T>
109  {
110  ;
111  };
112 }
113 #endif // version check
114 #endif //CAMERA_HANDLER_H