LightWrap++
AC++wrapperfortheLightWave3DSDK
environment_handler.h
Go to the documentation of this file.
1 #ifndef LWPP_ENVIRONMENT_HANDLER_H
2 #define LWPP_ENVIRONMENT_HANDLER_H
3 
4 #include "lwpp/plugin_handler.h"
5 #include <lwenviron.h>
6 
7 namespace lwpp
8 {
11  {
12  public:
13  EnvironmentHandler(void* g, void* context, LWError* err) : InstanceHandler(g,context,err){};
14  virtual ~EnvironmentHandler(){};
15 
16  virtual LWError Evaluate (LWEnvironmentAccess *enva)
17  {
18  double x,y,z;
19  x = enva->dir[0];
20  y = enva->dir[1];
21  z = enva->dir[2];
22  enva->color[0]=x/2.0+0.5;
23  enva->color[1]=y/2.0+0.5;
24  enva->color[2]=z/2.0+0.5;
25  return NULL;
26  };
27  virtual unsigned int Flags()
28  {
29  return 0;
30  }
31  };
32 
34  template <class T>
35  class EnvironmentAdaptor : public InstanceAdaptor <T>, public ItemAdaptor <T> , public RenderAdaptor<T>
36  {
37  public:
38  EnvironmentAdaptor(const char *name, ServerTagInfo *tags)
39  {
40  LWServer::AddPlugin(LWENVIRONMENT_HCLASS, name, Activate, tags);
41  }
42  static int Activate (int version , GlobalFunc* global, LWInstance inst, void* serverData)
43  {
44  if(version!=LWENVIRONMENT_VERSION) return AFUNC_BADVERSION;
45  lwpp::SetSuperGlobal(global);
46 
47  LWEnvironmentHandler* plugin = static_cast<LWEnvironmentHandler*>(inst);
48  InstanceAdaptor<T>::Activate(plugin->inst);
49  ItemAdaptor<T>::Activate(plugin->item);
50  RenderAdaptor<T>::Activate(plugin->rend);
51 
52  plugin->evaluate = EnvironmentAdaptor::Evaluate;
53  plugin->flags = EnvironmentAdaptor::Flags;
54 
55  UNUSED(serverData);
56  return AFUNC_OK;
57  }
58  private:
59  static LWError Evaluate (LWInstance inst, LWEnvironmentAccess* ma)
60  {
61  T* plugin = static_cast<T*>(inst);
62  plugin->Evaluate(ma);
63  return NULL;
64  }
65  static unsigned int Flags (LWInstance inst)
66  {
67  T* plugin = static_cast<T*>(inst);
68  return plugin->Flags();
69  }
70  };
71 
72  /* GUI Classes */
81 }
82 #endif //LWPP_ENVIRONMENT_HANDLER_H