47 |
48 | #ifdef _WIN32
49 | #define GLH_FUNC extern "C" __declspec(dllexport)
50 | #else
51 | #define GLH_FUNC
52 | #endif
53 |
54 |
55 | namespace glh
56 | {
57 |
58 | struct library_handle
59 | {
60 | #ifdef _WIN32
61 | bool init(const char * name)
62 | {
63 | lib = GetModuleHandle(name);
64 | if(lib) return true;
65 | std::string n(name);
66 | n += ".exe";
67 | lib = GetModuleHandle(n.c_str());
68 |
69 | return lib != 0;
70 | }
71 | void call_func(const char k, int x, int y)
72 | {
73 | std::string entry_name("key__");
74 | entry_name += k;
75 | void (*entry)(int, int) = (void (*)(int, int))GetProcAddress(lib, entry_name.c_str());
76 | if(entry)
77 | (*entry)(x, y);
78 | }
79 | HMODULE lib;
80 | #endif
81 | };
82 |
83 | }
84 |
85 | #endif
86 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | JBKinectHacks
2 | =============
3 | http://github.com/johnboiles/JBKinectHacks
4 |
5 | A collection of sample projects and code snippets using OpenNI and the Kinect.
6 | Only tested on OSX.
7 |
8 | To build using the included makefiles, libOpenNI.dylib must be
9 | installed in /usr/lib and the OpenNI includes must be in /usr/include/ni.
10 |
11 | To build using the xcode project, you must symlink /usr/include/ni and
12 | /usr/lib/libOpenNI.dylib to the appropriate places in your developer install.
13 | AFAIK there's not an elegant way to get xcode to use the standard /usr/include
14 | and /usr/lib paths. For my installation I ran the following commands:
15 |
16 | sudo ln -s /usr/lib/libOpenNI.dylib /Developer/SDKs/MacOSX10.6.sdk/usr/lib/libOpenNI.dylib
17 |
18 | sudo ln -s /usr/include/ni /Developer/SDKs/MacOSX10.6.sdk/usr/include/ni
19 |
20 | Note that the binaries expect a file named SamplesConfig.xml to be in the present working
21 | directory when they are run.
22 |
23 | To Install OpenNI for Mac
24 | -------------------------
25 | 1. Get OpenNI
26 | git clone git://github.com/OpenNI/OpenNI.git
27 |
28 | 2. Switch to unstable branch (only unstable supports osx atm)
29 | git checkout unstable
30 |
31 | 3. Follow the installation instructions in the Readme (they're pretty good)
32 |
33 | 4. Get the unstable forked version of the PrimeSense/Sensor module working
34 | git clone git://github.com/ros-pkg-git/Sensor.git
35 |
36 | 5. Follow the installation instructions in the Readme (they're also pretty good)
37 |
38 | 6. Get the PrimeSense NITE binaries here:
39 | http://www.openni.org/component/search/?searchword=nite&ordering=&searchphrase=all
40 |
41 | 7. Run the install script included with the NITE binaries
42 | sudo ./install.sh
43 |
44 | 8. Use License code
45 | 0KOIk2JeIBYClPWVnMoRKn5cdY4=
46 |
47 | To Run the Garry's Mod Example
48 | ------------------------------
49 | 1. Download Garry's Mod (Duh) from Steam
50 |
51 | 2. Change directories to the GMod directory
52 | cd GMod
53 |
54 | 3. Run make install to copy scripts/entities/binary modules to the right places
55 | make install STEAM_USERNAME=yourusername
56 |
57 | 4. Build and run the UDPBackend example (sends skeletal data over UDP)
58 | cd ../UDPBackend
59 | make
60 | cd ..
61 | ./Bin/Release/UDPBackend
62 | Note that you must execute UDPBackend with SamplesConfig.xml in the present working
63 | directory. So from the base directory of this project, use ./Bin/Release/UDPBackend
64 |
65 | 5. Open Garry's Mod and start a new game (multiplayer or singleplayer)
66 |
67 | 6. Enable console access from Options->Keyboard->Advanced->Enable Developer Console
68 |
69 | 7. Press ~ to open the developer's console
70 |
71 | 8. Execute trashmonster script to connect to UDPBackend
72 | lua_openscript trashmonster.lua
73 |
74 | 9. Do the calibration pose in front of the Kinect
75 |
76 | 10. Modified hoverballs will be placed in positions corresponding to your joints.
--------------------------------------------------------------------------------
/GMod/Zmq/ZmqLuaBindings/examples/ev_subscriber.lua:
--------------------------------------------------------------------------------
1 | -- Copyright (c) 2010 Aleksey Yeschenko
2 | --
3 | -- Permission is hereby granted, free of charge, to any person obtaining a copy
4 | -- of this software and associated documentation files (the "Software"), to deal
5 | -- in the Software without restriction, including without limitation the rights
6 | -- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7 | -- copies of the Software, and to permit persons to whom the Software is
8 | -- furnished to do so, subject to the following conditions:
9 | --
10 | -- The above copyright notice and this permission notice shall be included in
11 | -- all copies or substantial portions of the Software.
12 | --
13 | -- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 | -- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 | -- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 | -- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 | -- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18 | -- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19 | -- THE SOFTWARE.
20 |
21 | require("zmq")
22 | local ev = require'ev'
23 | local loop = ev.Loop.default
24 |
25 | -- define a sub_worker class
26 | local sub_worker_mt = {}
27 | function sub_worker_mt:close(...)
28 | self.s_io_idle:stop(self.loop)
29 | self.s_io_read:stop(self.loop)
30 | return self.socket:close(...)
31 | end
32 | function sub_worker_mt:bind(...)
33 | return self.socket:bind(...)
34 | end
35 | function sub_worker_mt:connect(...)
36 | return self.socket:connect(...)
37 | end
38 | function sub_worker_mt:sub(topic)
39 | return self.socket:setopt(zmq.SUBSCRIBE, topic)
40 | end
41 | function sub_worker_mt:unsub(topic)
42 | return self.socket:setopt(zmq.UNSUBSCRIBE, topic)
43 | end
44 | sub_worker_mt.__index = sub_worker_mt
45 |
46 | local function sub_worker(loop, ctx, msg_cb)
47 | local s = ctx:socket(zmq.SUB)
48 | local self = { loop = loop, socket = s, msg_cb = msg_cb }
49 | setmetatable(self, sub_worker_mt)
50 | -- create ev callbacks for recving data.
51 | -- need idle watcher since ZeroMQ sockets are edge-triggered instead of level-triggered
52 | local s_io_idle
53 | local s_io_read
54 | s_io_idle = ev.Idle.new(function()
55 | local msg, err = s:recv(zmq.NOBLOCK)
56 | if err == 'timeout' then
57 | -- need to block on read IO
58 | s_io_idle:stop(loop)
59 | s_io_read:start(loop)
60 | return
61 | end
62 | self:msg_cb(msg)
63 | end)
64 | s_io_idle:start(loop)
65 | s_io_read = ev.IO.new(function()
66 | s_io_idle:start(loop)
67 | s_io_read:stop(loop)
68 | end, s:getopt(zmq.FD), ev.READ)
69 | self.s_io_idle = s_io_idle
70 | self.s_io_read = s_io_read
71 | return self
72 | end
73 |
74 | local ctx = zmq.init(1)
75 |
76 | -- message handling function.
77 | local function handle_msg(worker, msg)
78 | local msg_id = tonumber(msg)
79 | if math.mod(msg_id, 10000) == 0 then print(worker.id, msg_id) end
80 | end
81 |
82 | local sub1 = sub_worker(loop, ctx, handle_msg)
83 | sub1.id = 'sub1'
84 | sub1:sub('')
85 | sub1:connect("tcp://localhost:5555")
86 | local sub2 = sub_worker(loop, ctx, handle_msg)
87 | sub2.id = 'sub2'
88 | sub2:sub('')
89 | sub2:connect("tcp://localhost:5555")
90 |
91 | loop:loop()
92 |
93 |
--------------------------------------------------------------------------------
/GMod/Scripts/humancontrol.lua:
--------------------------------------------------------------------------------
1 | require("oosocks")
2 |
3 | local connection = OOSock(IPPROTO_UDP);
4 |
5 | Kleiner = ents.Create("prop_ragdoll")
6 | Kleiner:SetModel("models/Kleiner.mdl")
7 | Kleiner:Spawn()
8 |
9 | ControlNodes = {}
10 |
11 | /* For Human Models (excepting Eli)
12 | 0 = pelvis
13 | 1 = chest
14 | 2 = right upper arm
15 | 3 = left upper arm
16 | 4 = left forearm
17 | 5 = left hand
18 | 6 = right forearm
19 | 7 = right hand
20 | 8 = right thigh
21 | 9 = right calf
22 | 10 = head
23 | 11 = left thigh
24 | 12 = left calf
25 | 13 = left foot
26 | 14 = right foot
27 | */
28 |
29 | PhysicsObjectToNameForKleiner = {lh=5, rh=7, ls=3, rs=2, lk=12, rk=9, hh=10, lf=13, rf=14, le=4, re=6 }
30 | ScaleFactor = 0.056
31 |
32 | function WeldKleinerBoneToNode(Bone, NodeName)
33 | local node
34 | if (!ControlNodes[NodeName]) then
35 | node = ents.Create("positiontracker")
36 | // Collide does wierd things when you put hoverballs inside ragdolls, disable it
37 | node:SetCollisionGroup( COLLISION_GROUP_NONE )
38 | node.CollisionGroup = COLLISION_GROUP_NONE
39 | node:SetStrength(0.001)
40 | node:Spawn()
41 | ControlNodes[NodeName] = node
42 | else
43 | node = ControlNodes[NodeName]
44 | end
45 | local physObject = Kleiner:GetPhysicsObjectNum(Bone)
46 | node:SetPos(physObject:GetPos())
47 | Msg("Setting " .. NodeName .. " to ")
48 | MsgN(physObject)
49 | constraint.Weld(node, Kleiner, 0, Bone, 0 ,true)
50 | end
51 |
52 | function UnWeldNode(NodeName)
53 | constraint.RemoveAll(ControlNodes[NodeName])
54 | end
55 |
56 | function UnWeldAll()
57 | for joint, index in pairs(PhysicsObjectToNameForKleiner) do
58 | UnWeldNode(joint)
59 | end
60 | end
61 |
62 | function RemoveNode(NodeName)
63 | ControlNodes[NodeName]:Remove()
64 | ControlNodes[NodeName] = nil
65 | end
66 |
67 | function RemoveAll()
68 | for joint, index in pairs(PhysicsObjectToNameForKleiner) do
69 | RemoveNode(joint)
70 | end
71 | Kleiner:Remove()
72 | end
73 |
74 | function WeldBones()
75 | for joint, index in pairs(PhysicsObjectToNameForKleiner) do
76 | WeldKleinerBoneToNode(index, joint)
77 | end
78 | //ControlNodes['hh']:SetStrength(2)
79 | end
80 |
81 | WeldBones()
82 |
83 | function UpdateSkeleton(skeleton)
84 | -- Figure out how much to adjust the position of the ground based on the current position of the feet
85 | local zoffset = math.min(skeleton['lf'].z, skeleton['rf'].z)
86 | for joint, point in pairs(skeleton) do
87 | skeleton[joint].z = skeleton[joint].z - zoffset
88 | end
89 | // Some corrections specific to humans
90 | // TODO: make a pelvis point that's right between the hips
91 | pelvis = skeleton['ri'] + skeleton['li']
92 | pelvis = pelvis / 2
93 | skeleton['pp'] = pelvis
94 | for joint, point in pairs(skeleton) do
95 | if (ControlNodes[joint]) then
96 | ControlNodes[joint]:SetTargetPosition(point)
97 | end
98 | end
99 | end
100 |
101 | connection:SetCallback(function(socket, callType, callId, err, data, peer, peerPort)
102 | if(callType == SCKCALL_BIND && err == SCKERR_OK) then
103 | print("Bound.");
104 | --connection:Send("rofl", "127.0.0.1", 50007);
105 | connection:ReceiveDatagram();
106 | end
107 |
108 | if(callType == SCKCALL_SEND && err == SCKERR_OK) then
109 | print("Sent.");
110 | end
111 |
112 | if(callType == SCKCALL_REC_DATAGRAM && err == SCKERR_OK) then
113 | Msg("Got '" .. data .. "' from " .. peer .. ":" .. tostring(peerPort));
114 | --socket:Close()
115 | local point
116 |
117 | skeleton = {}
118 | for k, x, y, z in string.gmatch(tostring(data), "([a-z][a-z])x([-.0-9]*)y([-.0-9]*)z([-.0-9]*)") do
119 | skeleton[k] = Vector(-tonumber(x), tonumber(z), tonumber(y)) * ScaleFactor
120 | end
121 | UpdateSkeleton(skeleton)
122 |
123 | connection:ReceiveDatagram();
124 | end
125 |
126 | if(err != SCKERR_OK) then
127 | --socket:Close()
128 | end
129 | end);
130 |
131 | Msg("Gmod UDP Module loaded\n")
132 | -- an IP of "" binds to all interfaces.
133 | connection:Bind("", 50125);
--------------------------------------------------------------------------------
/GMod/Scripts/dogcontrol.lua:
--------------------------------------------------------------------------------
1 | require("oosocks")
2 |
3 | local connection = OOSock(IPPROTO_UDP);
4 |
5 | Dog = ents.Create("prop_ragdoll")
6 | Dog:SetModel("models/dog.mdl")
7 | --I'm not sure if friction > 1 actually does anything
8 | Dog:SetFriction(100)
9 | Dog:Spawn()
10 |
11 | ControlNodes = {}
12 |
13 | PhysicsObjectToNameForDog = { pp=0, le=4, lh=5, re=7, rh=8, lk=13, lf=14, rk=10, rf=11, hh=15}
14 | ScaleFactor = 0.10
15 |
16 | function WeldDogBoneToNode(Bone, NodeName)
17 | local node
18 | if (!ControlNodes[NodeName]) then
19 | node = ents.Create("positiontracker")
20 | // Collide does wierd things when you put hoverballs inside ragdolls, disable it
21 | node:SetCollisionGroup( COLLISION_GROUP_NONE )
22 | node.CollisionGroup = COLLISION_GROUP_NONE
23 | node:Spawn()
24 | ControlNodes[NodeName] = node
25 | else
26 | node = ControlNodes[NodeName]
27 | end
28 | local physObject = Dog:GetPhysicsObjectNum(Bone)
29 | node:SetPos(physObject:GetPos())
30 | Msg("Setting " .. NodeName .. " to ")
31 | MsgN(physObject)
32 | constraint.Weld(node, Dog, 0, Bone, 0 ,true)
33 | end
34 |
35 | function UnWeldNode(NodeName)
36 | constraint.RemoveAll(ControlNodes[NodeName])
37 | end
38 |
39 | function UnWeldAll()
40 | for joint, index in pairs(PhysicsObjectToNameForDog) do
41 | UnWeldNode(joint)
42 | end
43 | end
44 |
45 | function RemoveNode(NodeName)
46 | ControlNodes[NodeName]:Remove()
47 | ControlNodes[NodeName] = nil
48 | end
49 |
50 | function RemoveAll()
51 | for joint, index in pairs(PhysicsObjectToNameForDog) do
52 | RemoveNode(joint)
53 | end
54 | end
55 |
56 | function RemoveDog()
57 | Dog:Remove()
58 | end
59 |
60 | function WeldBones()
61 | for joint, index in pairs(PhysicsObjectToNameForDog) do
62 | WeldDogBoneToNode(index, joint)
63 | end
64 | ControlNodes['hh']:SetStrength(2)
65 | end
66 |
67 | WeldBones()
68 |
69 | function UpdateSkeleton(skeleton)
70 | -- Figure out how much to adjust the position of the ground based on the current position of the feet
71 | local zoffset = math.min(skeleton['lf'].z, skeleton['rf'].z) + 10
72 | for joint, point in pairs(skeleton) do
73 | skeleton[joint].z = skeleton[joint].z - zoffset
74 | end
75 | // Some corrections specific to dog
76 | skeleton['lf'].z = skeleton['lf'].z + 12
77 | skeleton['rf'].z = skeleton['rf'].z + 12
78 | skeleton['lk'].z = skeleton['lk'].z + 10
79 | skeleton['rk'].z = skeleton['rk'].z + 10
80 | skeleton['lh'].z = skeleton['lh'].z - 10
81 | skeleton['rh'].z = skeleton['rh'].z - 10
82 | skeleton['hh'].y = skeleton['hh'].y - 20
83 | skeleton['hh'].z = skeleton['hh'].z - 10
84 | // TODO: make a pelvis point that's right between the hips
85 | pelvis = skeleton['ri'] + skeleton['li']
86 | pelvis = pelvis / 2
87 | skeleton['pp'] = pelvis
88 | for joint, point in pairs(skeleton) do
89 | if (ControlNodes[joint]) then
90 | ControlNodes[joint]:SetTargetPosition(point)
91 | end
92 | end
93 | end
94 |
95 | connection:SetCallback(function(socket, callType, callId, err, data, peer, peerPort)
96 | if(callType == SCKCALL_BIND && err == SCKERR_OK) then
97 | print("Bound.");
98 | --connection:Send("rofl", "127.0.0.1", 50007);
99 | connection:ReceiveDatagram();
100 | end
101 |
102 | if(callType == SCKCALL_SEND && err == SCKERR_OK) then
103 | print("Sent.");
104 | end
105 |
106 | if(callType == SCKCALL_REC_DATAGRAM && err == SCKERR_OK) then
107 | Msg("Got '" .. data .. "' from " .. peer .. ":" .. tostring(peerPort));
108 | --socket:Close()
109 | local point
110 |
111 | skeleton = {}
112 | for k, x, y, z in string.gmatch(tostring(data), "([a-z][a-z])x([-.0-9]*)y([-.0-9]*)z([-.0-9]*)") do
113 | skeleton[k] = Vector(-tonumber(x), tonumber(z), tonumber(y)) * ScaleFactor
114 | end
115 | UpdateSkeleton(skeleton)
116 |
117 | connection:ReceiveDatagram();
118 | end
119 |
120 | if(err != SCKERR_OK) then
121 | --socket:Close()
122 | end
123 | end);
124 |
125 | Msg("Gmod UDP Module loaded\n")
126 | -- an IP of "" binds to all interfaces.
127 | connection:Bind("", 50125);
--------------------------------------------------------------------------------
/GMod/Zmq/BasicZmq/include/ILuaObject.h:
--------------------------------------------------------------------------------
1 | //=============================================================================//
2 | // ___ ___ _ _ _ __ _ ___ ___ __ __
3 | // |_ _|| __| / \ | \_/ | / _| / \ | o \ o \\ V /
4 | // | | | _| | o || \_/ | ( |_n| o || / / \ /
5 | // |_| |___||_n_||_| |_| \__/|_n_||_|\\_|\\ |_| 2008
6 | //
7 | //=============================================================================//
8 |
9 | #include "ILuaInterface.h"
10 |
11 | #ifndef ILUAOBJECT_H
12 | #define ILUAOBJECT_H
13 |
14 | #ifdef _WIN32
15 | #pragma once
16 | #endif
17 |
18 | class ILuaObject;
19 |
20 | //////////////////////////////////////////////////////////////////////////
21 | // Name: ILuaObject_001
22 | //////////////////////////////////////////////////////////////////////////
23 | class ILuaObject_001
24 | {
25 | public:
26 |
27 | virtual void Set( ILuaObject* obj ) = 0;
28 | virtual void SetFromStack( int i ) = 0;
29 | virtual void UnReference() = 0;
30 |
31 | virtual int GetType( void ) = 0;
32 |
33 | virtual const char* GetString( void ) = 0;
34 | virtual float GetFloat( void ) = 0;
35 | virtual int GetInt( void ) = 0;
36 | virtual void* GetUserData( void ) = 0;
37 |
38 | virtual void SetMember( const char* name ) = 0;
39 | virtual void SetMember( const char* name, ILuaObject* obj ) = 0; // ( This is also used to set nil by passing NULL )
40 | virtual void SetMember( const char* name, float val ) = 0;
41 | virtual void SetMember( const char* name, bool val ) = 0;
42 | virtual void SetMember( const char* name, const char* val ) = 0;
43 | virtual void SetMember( const char* name, CLuaFunction f ) = 0;
44 |
45 | virtual bool GetMemberBool( const char* name, bool b = true ) = 0;
46 | virtual int GetMemberInt( const char* name, int i = 0 ) = 0;
47 | virtual float GetMemberFloat( const char* name, float f = 0.0f ) = 0;
48 | virtual const char* GetMemberStr( const char* name, const char* = "" ) = 0;
49 | virtual void* GetMemberUserData( const char* name, void* = 0 ) = 0;
50 | virtual void* GetMemberUserData( float name, void* = 0 ) = 0;
51 | virtual ILuaObject* GetMember( const char* name ) = 0;
52 | virtual ILuaObject* GetMember( ILuaObject* ) = 0;
53 |
54 | virtual void SetMetaTable( ILuaObject* obj ) = 0;
55 | virtual void SetUserData( void* obj ) = 0;
56 |
57 | virtual void Push( void ) = 0;
58 |
59 | virtual bool isNil() = 0;
60 | virtual bool isTable() = 0;
61 | virtual bool isString() = 0;
62 | virtual bool isNumber() = 0;
63 | virtual bool isFunction() = 0;
64 | virtual bool isUserData() = 0;
65 |
66 | virtual ILuaObject* GetMember( float fKey ) = 0;
67 |
68 | virtual void* Remove_Me_1( const char* name, void* = 0 ) = 0;
69 |
70 | virtual void SetMember( float fKey ) = 0;
71 | virtual void SetMember( float fKey, ILuaObject* obj ) = 0;
72 | virtual void SetMember( float fKey, float val ) = 0;
73 | virtual void SetMember( float fKey, bool val ) = 0;
74 | virtual void SetMember( float fKey, const char* val ) = 0;
75 | virtual void SetMember( float fKey, CLuaFunction f ) = 0;
76 |
77 | virtual const char* GetMemberStr( float name, const char* = "" ) = 0;
78 |
79 | virtual void SetMember( ILuaObject* k, ILuaObject* v ) = 0;
80 | virtual bool GetBool( void ) = 0;
81 |
82 | };
83 |
84 |
85 | //////////////////////////////////////////////////////////////////////////
86 | // Name: ILuaObject
87 | //////////////////////////////////////////////////////////////////////////
88 | class ILuaObject : public ILuaObject_001
89 | {
90 | public:
91 |
92 | // Push members to table from stack
93 | virtual bool PushMemberFast( int iStackPos ) = 0;
94 | virtual void SetMemberFast( int iKey, int iValue ) = 0;
95 |
96 | virtual void SetFloat( float val ) = 0;
97 | virtual void SetString( const char* val ) = 0;
98 |
99 | // Return members of table
100 | #ifndef NO_SDK
101 | virtual CUtlLuaVector* GetMembers( void ) = 0;
102 | #else
103 | virtual void* GetMembers( void ) = 0;
104 | #endif
105 |
106 | // Set member 'pointer'. No GC, no metatables.
107 | virtual void SetMemberUserDataLite( const char* strKeyName, void* pData ) = 0;
108 | virtual void* GetMemberUserDataLite( const char* strKeyName ) = 0;
109 | };
110 |
111 | #endif // ILUAOBJECT_H
112 |
--------------------------------------------------------------------------------
/GMod/Zmq/ZmqLuaBindings/include/ILuaObject.h:
--------------------------------------------------------------------------------
1 | //=============================================================================//
2 | // ___ ___ _ _ _ __ _ ___ ___ __ __
3 | // |_ _|| __| / \ | \_/ | / _| / \ | o \ o \\ V /
4 | // | | | _| | o || \_/ | ( |_n| o || / / \ /
5 | // |_| |___||_n_||_| |_| \__/|_n_||_|\\_|\\ |_| 2008
6 | //
7 | //=============================================================================//
8 |
9 | #include "ILuaInterface.h"
10 |
11 | #ifndef ILUAOBJECT_H
12 | #define ILUAOBJECT_H
13 |
14 | #ifdef _WIN32
15 | #pragma once
16 | #endif
17 |
18 | class ILuaObject;
19 |
20 | //////////////////////////////////////////////////////////////////////////
21 | // Name: ILuaObject_001
22 | //////////////////////////////////////////////////////////////////////////
23 | class ILuaObject_001
24 | {
25 | public:
26 |
27 | virtual void Set( ILuaObject* obj ) = 0;
28 | virtual void SetFromStack( int i ) = 0;
29 | virtual void UnReference() = 0;
30 |
31 | virtual int GetType( void ) = 0;
32 |
33 | virtual const char* GetString( void ) = 0;
34 | virtual float GetFloat( void ) = 0;
35 | virtual int GetInt( void ) = 0;
36 | virtual void* GetUserData( void ) = 0;
37 |
38 | virtual void SetMember( const char* name ) = 0;
39 | virtual void SetMember( const char* name, ILuaObject* obj ) = 0; // ( This is also used to set nil by passing NULL )
40 | virtual void SetMember( const char* name, float val ) = 0;
41 | virtual void SetMember( const char* name, bool val ) = 0;
42 | virtual void SetMember( const char* name, const char* val ) = 0;
43 | virtual void SetMember( const char* name, CLuaFunction f ) = 0;
44 |
45 | virtual bool GetMemberBool( const char* name, bool b = true ) = 0;
46 | virtual int GetMemberInt( const char* name, int i = 0 ) = 0;
47 | virtual float GetMemberFloat( const char* name, float f = 0.0f ) = 0;
48 | virtual const char* GetMemberStr( const char* name, const char* = "" ) = 0;
49 | virtual void* GetMemberUserData( const char* name, void* = 0 ) = 0;
50 | virtual void* GetMemberUserData( float name, void* = 0 ) = 0;
51 | virtual ILuaObject* GetMember( const char* name ) = 0;
52 | virtual ILuaObject* GetMember( ILuaObject* ) = 0;
53 |
54 | virtual void SetMetaTable( ILuaObject* obj ) = 0;
55 | virtual void SetUserData( void* obj ) = 0;
56 |
57 | virtual void Push( void ) = 0;
58 |
59 | virtual bool isNil() = 0;
60 | virtual bool isTable() = 0;
61 | virtual bool isString() = 0;
62 | virtual bool isNumber() = 0;
63 | virtual bool isFunction() = 0;
64 | virtual bool isUserData() = 0;
65 |
66 | virtual ILuaObject* GetMember( float fKey ) = 0;
67 |
68 | virtual void* Remove_Me_1( const char* name, void* = 0 ) = 0;
69 |
70 | virtual void SetMember( float fKey ) = 0;
71 | virtual void SetMember( float fKey, ILuaObject* obj ) = 0;
72 | virtual void SetMember( float fKey, float val ) = 0;
73 | virtual void SetMember( float fKey, bool val ) = 0;
74 | virtual void SetMember( float fKey, const char* val ) = 0;
75 | virtual void SetMember( float fKey, CLuaFunction f ) = 0;
76 |
77 | virtual const char* GetMemberStr( float name, const char* = "" ) = 0;
78 |
79 | virtual void SetMember( ILuaObject* k, ILuaObject* v ) = 0;
80 | virtual bool GetBool( void ) = 0;
81 |
82 | };
83 |
84 |
85 | //////////////////////////////////////////////////////////////////////////
86 | // Name: ILuaObject
87 | //////////////////////////////////////////////////////////////////////////
88 | class ILuaObject : public ILuaObject_001
89 | {
90 | public:
91 |
92 | // Push members to table from stack
93 | virtual bool PushMemberFast( int iStackPos ) = 0;
94 | virtual void SetMemberFast( int iKey, int iValue ) = 0;
95 |
96 | virtual void SetFloat( float val ) = 0;
97 | virtual void SetString( const char* val ) = 0;
98 |
99 | // Return members of table
100 | #ifndef NO_SDK
101 | virtual CUtlLuaVector* GetMembers( void ) = 0;
102 | #else
103 | virtual void* GetMembers( void ) = 0;
104 | #endif
105 |
106 | // Set member 'pointer'. No GC, no metatables.
107 | virtual void SetMemberUserDataLite( const char* strKeyName, void* pData ) = 0;
108 | virtual void* GetMemberUserDataLite( const char* strKeyName ) = 0;
109 | };
110 |
111 | #endif // ILUAOBJECT_H
112 |
--------------------------------------------------------------------------------
/GMod/Examples/BinaryModule/include/ILuaObject.h:
--------------------------------------------------------------------------------
1 | //=============================================================================//
2 | // ___ ___ _ _ _ __ _ ___ ___ __ __
3 | // |_ _|| __| / \ | \_/ | / _| / \ | o \ o \\ V /
4 | // | | | _| | o || \_/ | ( |_n| o || / / \ /
5 | // |_| |___||_n_||_| |_| \__/|_n_||_|\\_|\\ |_| 2008
6 | //
7 | //=============================================================================//
8 |
9 | #include "ILuaInterface.h"
10 |
11 | #ifndef ILUAOBJECT_H
12 | #define ILUAOBJECT_H
13 |
14 | #ifdef _WIN32
15 | #pragma once
16 | #endif
17 |
18 | class ILuaObject;
19 |
20 | //////////////////////////////////////////////////////////////////////////
21 | // Name: ILuaObject_001
22 | //////////////////////////////////////////////////////////////////////////
23 | class ILuaObject_001
24 | {
25 | public:
26 |
27 | virtual void Set( ILuaObject* obj ) = 0;
28 | virtual void SetFromStack( int i ) = 0;
29 | virtual void UnReference() = 0;
30 |
31 | virtual int GetType( void ) = 0;
32 |
33 | virtual const char* GetString( void ) = 0;
34 | virtual float GetFloat( void ) = 0;
35 | virtual int GetInt( void ) = 0;
36 | virtual void* GetUserData( void ) = 0;
37 |
38 | virtual void SetMember( const char* name ) = 0;
39 | virtual void SetMember( const char* name, ILuaObject* obj ) = 0; // ( This is also used to set nil by passing NULL )
40 | virtual void SetMember( const char* name, float val ) = 0;
41 | virtual void SetMember( const char* name, bool val ) = 0;
42 | virtual void SetMember( const char* name, const char* val ) = 0;
43 | virtual void SetMember( const char* name, CLuaFunction f ) = 0;
44 |
45 | virtual bool GetMemberBool( const char* name, bool b = true ) = 0;
46 | virtual int GetMemberInt( const char* name, int i = 0 ) = 0;
47 | virtual float GetMemberFloat( const char* name, float f = 0.0f ) = 0;
48 | virtual const char* GetMemberStr( const char* name, const char* = "" ) = 0;
49 | virtual void* GetMemberUserData( const char* name, void* = 0 ) = 0;
50 | virtual void* GetMemberUserData( float name, void* = 0 ) = 0;
51 | virtual ILuaObject* GetMember( const char* name ) = 0;
52 | virtual ILuaObject* GetMember( ILuaObject* ) = 0;
53 |
54 | virtual void SetMetaTable( ILuaObject* obj ) = 0;
55 | virtual void SetUserData( void* obj ) = 0;
56 |
57 | virtual void Push( void ) = 0;
58 |
59 | virtual bool isNil() = 0;
60 | virtual bool isTable() = 0;
61 | virtual bool isString() = 0;
62 | virtual bool isNumber() = 0;
63 | virtual bool isFunction() = 0;
64 | virtual bool isUserData() = 0;
65 |
66 | virtual ILuaObject* GetMember( float fKey ) = 0;
67 |
68 | virtual void* Remove_Me_1( const char* name, void* = 0 ) = 0;
69 |
70 | virtual void SetMember( float fKey ) = 0;
71 | virtual void SetMember( float fKey, ILuaObject* obj ) = 0;
72 | virtual void SetMember( float fKey, float val ) = 0;
73 | virtual void SetMember( float fKey, bool val ) = 0;
74 | virtual void SetMember( float fKey, const char* val ) = 0;
75 | virtual void SetMember( float fKey, CLuaFunction f ) = 0;
76 |
77 | virtual const char* GetMemberStr( float name, const char* = "" ) = 0;
78 |
79 | virtual void SetMember( ILuaObject* k, ILuaObject* v ) = 0;
80 | virtual bool GetBool( void ) = 0;
81 |
82 | };
83 |
84 |
85 | //////////////////////////////////////////////////////////////////////////
86 | // Name: ILuaObject
87 | //////////////////////////////////////////////////////////////////////////
88 | class ILuaObject : public ILuaObject_001
89 | {
90 | public:
91 |
92 | // Push members to table from stack
93 | virtual bool PushMemberFast( int iStackPos ) = 0;
94 | virtual void SetMemberFast( int iKey, int iValue ) = 0;
95 |
96 | virtual void SetFloat( float val ) = 0;
97 | virtual void SetString( const char* val ) = 0;
98 |
99 | // Return members of table
100 | #ifndef NO_SDK
101 | virtual CUtlLuaVector* GetMembers( void ) = 0;
102 | #else
103 | virtual void* GetMembers( void ) = 0;
104 | #endif
105 |
106 | // Set member 'pointer'. No GC, no metatables.
107 | virtual void SetMemberUserDataLite( const char* strKeyName, void* pData ) = 0;
108 | virtual void* GetMemberUserDataLite( const char* strKeyName ) = 0;
109 | };
110 |
111 | #endif // ILUAOBJECT_H
112 |
--------------------------------------------------------------------------------
/GMod/Zmq/BasicZmq/module.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2010 John Boiles
3 | *
4 | * Permission is hereby granted, free of charge, to any person obtaining a copy
5 | * of this software and associated documentation files (the "Software"), to deal
6 | * in the Software without restriction, including without limitation the rights
7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 | * copies of the Software, and to permit persons to whom the Software is
9 | * furnished to do so, subject to the following conditions:
10 | *
11 | * The above copyright notice and this permission notice shall be included in
12 | * all copies or substantial portions of the Software.
13 | *
14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 | * THE SOFTWARE.
21 | */
22 |
23 | #include "Module.h"
24 | #include "GMLuaModule.h"
25 | #include
26 |
27 | // Module definition
28 | GMOD_MODULE( Init, Shutdown );
29 |
30 | LUA_FUNCTION( PrintSomething )
31 | {
32 | g_Lua->Msg( "Hello, there!\n" );
33 | return 0;
34 | }
35 |
36 | LUA_FUNCTION( ZmqVersion )
37 | {
38 | int major, minor, patch;
39 | zmq_version(&major, &minor, &patch);
40 | char string[100];
41 | sprintf(string, "major %d minor %d patch %d\n", major, minor, patch);
42 | g_Lua->Msg( string );
43 | return 0;
44 | }
45 |
46 | // May be able to increase the number of threads here
47 |
48 | zmq::context_t context(5);
49 | zmq::socket_t socket(context, ZMQ_REP);
50 |
51 | LUA_FUNCTION( ZmqInit )
52 | {
53 | errno = zmq_errno();
54 | if (errno) {
55 | g_Lua->Msg( "Error: %d %s\n", errno, zmq_strerror(errno));
56 | }
57 | // Receiving data using connect seems to hang and never do anything
58 | //socket.connect("tcp://127.0.0.1:5555");
59 | // Bind only seems to receive data when polling
60 | socket.bind("tcp://127.0.0.1:5555");
61 | }
62 |
63 | LUA_FUNCTION( ZmqReceive )
64 | {
65 | try {
66 | g_Lua->Msg( "Receiving Data!\n" );
67 | zmq::message_t receivedMessage(100);
68 | zmq_pollitem_t items [1];
69 | items[0].socket = &socket;
70 | items[0].events = ZMQ_POLLIN;
71 | // Setting the last param of poll to -1 causes it block while waiting for data,
72 | // Nonblocking never seems to get data though
73 | //if (zmq::poll(items, 1, -1)) {
74 | // socket.recv(&receivedMessage, 0);
75 | // I'm not sure why the NOBLOCK flag never seems to get data
76 | socket.recv(&receivedMessage, ZMQ_NOBLOCK);
77 | g_Lua->Msg( "Got some data: %s\n", (const char *)receivedMessage.data() );
78 | //} else {
79 | // g_Lua->Msg( "No Data\n" );
80 | //}
81 |
82 | //zmq::message_t sentMessage((void *)"thanks for the data", 19, 0);
83 | //socket.send(sentMessage, 0);
84 | } catch (zmq::error_t error) {
85 | int errno;
86 | errno = zmq_errno();
87 | if (errno) {
88 | g_Lua->Msg( "Error: %d %s\n", errno, zmq_strerror(errno));
89 | }
90 | }
91 | return 0;
92 | }
93 |
94 | LUA_FUNCTION( ZmqSend )
95 | {
96 | g_Lua->Msg( "Sending Data!\n" );
97 | // May be able to increase the number of threads here
98 | zmq::context_t context(3);
99 | zmq::socket_t socket(context, ZMQ_REQ);
100 | socket.connect("tcp://127.0.0.1:5555");
101 | zmq::message_t sentMessage((void *)"hello from gmod", 15, 0);
102 | socket.send(sentMessage, ZMQ_NOBLOCK);
103 | int errno;
104 | errno = zmq_errno();
105 | if (errno) {
106 | g_Lua->Msg( "Error: %d %s\n", errno, zmq_strerror(errno));
107 | }
108 | return 0;
109 | }
110 |
111 | // Initialization
112 | int Init( lua_State *L )
113 | {
114 | g_Lua->SetGlobal( "PrintSomething", PrintSomething );
115 | g_Lua->SetGlobal( "ZmqVersion", ZmqVersion );
116 | g_Lua->SetGlobal( "ZmqReceive", ZmqReceive );
117 | g_Lua->SetGlobal( "ZmqSend", ZmqSend );
118 | g_Lua->SetGlobal( "ZmqInit", ZmqInit );
119 | g_Lua->Msg( "Simple Zmq Module Loaded!\n" );
120 | return 0;
121 | }
122 |
123 | // Shutdown
124 | int Shutdown( lua_State *L )
125 | {
126 | g_Lua->Msg("Module Unloaded!\n");
127 | return 0;
128 | }
--------------------------------------------------------------------------------
/GMod/Entities/positiontracker/init.lua:
--------------------------------------------------------------------------------
1 | AddCSLuaFile( "shared.lua" )
2 | include('shared.lua')
3 |
4 | local MODEL = Model( "models/dav0r/hoverball.mdl" )
5 |
6 | /*---------------------------------------------------------
7 | Name: Initialize
8 | ---------------------------------------------------------*/
9 | function ENT:Initialize()
10 | Msg("Initializing TR4$HM0NSTRR")
11 | // Use the helibomb model just for the shadow (because it's about the same size)
12 | self:SetModel( MODEL )
13 |
14 | // Don't use the model's physics object, create a perfect sphere
15 | --self:PhysicsInitSphere( 8, "metal_bouncy" )
16 | self:PhysicsInitSphere( 1 )
17 |
18 | // Wake up our physics object so we don't start asleep
19 | local phys = self:GetPhysicsObject()
20 | if ( phys:IsValid() ) then
21 | phys:SetMass( 150 )
22 | phys:EnableGravity( false )
23 | phys:Wake()
24 | end
25 |
26 | // Start the motion controller (so PhysicsSimulate gets called)
27 | self:StartMotionController()
28 |
29 | self.TargetVelocity = Vector(0,0,0)
30 | self.dt.TargetPosition = self:GetPos()
31 | end
32 |
33 | function ENT:OnRestore()
34 |
35 | self.TargetVelocity = Vector(0,0,0)
36 |
37 | end
38 |
39 | /*---------------------------------------------------------
40 | Name: OnTakeDamage
41 | ---------------------------------------------------------*/
42 | function ENT:OnTakeDamage( dmginfo )
43 |
44 | //self:TakePhysicsDamage( dmginfo )
45 | Msg("Oww")
46 |
47 | end
48 |
49 |
50 | /*---------------------------------------------------------
51 | Name: Think
52 | ---------------------------------------------------------*/
53 | function ENT:Think()
54 |
55 | self:NextThink( CurTime() + 0.25 )
56 | return true
57 |
58 | end
59 |
60 |
61 |
62 | /*---------------------------------------------------------
63 | Name: Use
64 | ---------------------------------------------------------*/
65 | function ENT:Use( activator, caller )
66 |
67 | end
68 |
69 | /*---------------------------------------------------------
70 | Name: Simulate
71 | ---------------------------------------------------------*/
72 | function ENT:PhysicsSimulate( phys, deltatime )
73 |
74 | --Is this necessary?
75 | self:GetPhysicsObject():Wake()
76 |
77 | phys:Wake()
78 |
79 | local Pos = phys:GetPos()
80 | local Vel = phys:GetVelocity()
81 | local Distance = self.dt.TargetPosition - Pos
82 |
83 | if ( Distance == Vector(0,0,0) ) then return end
84 |
85 | local Exponent = Vector(Distance.x^2, Distance.y^2, Distance.z^2)
86 | --Msg(string.format( "Exponent: (%.2f, %.2f, %.2f)\n", Exponent.x, Exponent.y, Exponent.z))
87 |
88 | if ( Distance.x < 0 ) then
89 | Exponent.x = Exponent.x * -1
90 | end
91 |
92 | if ( Distance.y < 0 ) then
93 | Exponent.y = Exponent.y * -1
94 | end
95 |
96 | if ( Distance.z < 0 ) then
97 | Exponent.z = Exponent.z * -1
98 | end
99 | --Msg(string.format( "Distance: (%.2f, %.2f, %.2f)\n", Distance.x, Distance.y, Distance.z))
100 | Exponent = Exponent * deltatime * 300
101 |
102 | local physVel = phys:GetVelocity()
103 |
104 | Exponent = Exponent - (physVel * deltatime * 600 )
105 | --Msg(string.format( "physVel: (%.2f, %.2f, %.2f)\n", physVel.x, physVel.y, physVel.z))
106 | // The higher you make this 300 the less it will flop about
107 | // I'm thinking it should actually be relative to any objects we're connected to
108 | // Since it seems to flop more and more the heavier the object
109 |
110 | Exponent.x = math.Clamp( Exponent.x, -5000, 5000 )
111 | Exponent.y = math.Clamp( Exponent.y, -5000, 5000 )
112 | Exponent.z = math.Clamp( Exponent.z, -5000, 5000 )
113 |
114 | local Linear = Exponent
115 | local Angular = Vector(0,0,0)
116 | --Msg(string.format( "Linear force: (%.2f, %.2f, %.2f)\n", Linear.x, Linear.y, Linear.z))
117 |
118 | return Angular, Linear, SIM_GLOBAL_ACCELERATION
119 |
120 | end
121 |
122 | function ENT:SetTargetPosition( position )
123 | self:GetPhysicsObject():Wake()
124 | self.dt.TargetPosition = position
125 | end
126 |
127 | function ENT:SetTargetVelocity( velocity )
128 | Msg(string.format( "Setting velocity to: (%.2f, %.2f, %.2f)\n", velocity.x, velocity.y, velocity.z))
129 | if ( z != Vector(0,0,0) ) then
130 | self:GetPhysicsObject():Wake()
131 | end
132 |
133 | -- self.Velocity = velocity * FrameTime() * 5000
134 | self.TargetVelocity = velocity * 0.033 * 5000
135 | Msg(string.format( "Self.Velocity is now: (%.2f, %.2f, %.2f) frametime was %.2f\n", self.TargetVelocity.x, self.TargetVelocity.y, self.TargetVelocity.z, FrameTime()))
136 | end
137 |
138 | /*---------------------------------------------------------
139 | SetStrength
140 | ---------------------------------------------------------*/
141 | function ENT:SetStrength( strength )
142 |
143 | local phys = self:GetPhysicsObject()
144 | if ( phys:IsValid() ) then
145 | phys:SetMass( 150 * strength )
146 | end
147 |
148 | self:UpdateLabel()
149 |
150 | end
151 |
152 |
--------------------------------------------------------------------------------
/ZmqPub/zhelpers.hpp:
--------------------------------------------------------------------------------
1 | /* =========================================================================
2 | zhelpers.h - ZeroMQ helpers for example applications
3 |
4 | Copyright (c) 1991-2010 iMatix Corporation and contributors
5 |
6 | This is free software; you can redistribute it and/or modify it under
7 | the terms of the Lesser GNU General Public License as published by
8 | the Free Software Foundation; either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | This software is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | Lesser GNU General Public License for more details.
15 |
16 | You should have received a copy of the Lesser GNU General Public License
17 | along with this program. If not, see .
18 | =========================================================================
19 | */
20 |
21 | // Olivier Chamoux
22 |
23 |
24 | #ifndef __ZHELPERS_HPP_INCLUDED__
25 | #define __ZHELPERS_HPP_INCLUDED__
26 |
27 | // Include a bunch of headers that we will need in the examples
28 |
29 | #include
30 |
31 | //#include
32 | #include
33 | //#include
34 |
35 | //#include
36 | //#include
37 | //#include
38 | //#include
39 | //#include // random() RAND_MAX
40 | #include
41 |
42 | // Bring Windows MSVC up to C99 scratch
43 | //#if (defined (__WINDOWS__))
44 | //typedef unsigned long ulong;
45 | //typedef unsigned int uint;
46 | //typedef __int64 int64_t;
47 | //#endif
48 |
49 | // Provide random number from 0..(num-1)
50 | //#define within(num) (int) ((float) (num) * random () / (RAND_MAX + 1.0))
51 | /*
52 | // Receive 0MQ string from socket and convert into string
53 | static std::string *
54 | s_recv (zmq::socket_t & socket) {
55 |
56 | zmq::message_t message;
57 | socket.recv(&message);
58 |
59 | std::string * string = new std::string(static_cast(message.data()), message.size());
60 |
61 | return (string);
62 | }
63 | */
64 | // Convert string to 0MQ string and send to socket
65 | static bool
66 | s_send (zmq::socket_t & socket, const std::string & string) {
67 |
68 | zmq::message_t message(string.size());
69 | memcpy(message.data(), string.data(), string.size());
70 |
71 | bool rc = socket.send(message);
72 | return (rc);
73 | }
74 |
75 | // Sends string as 0MQ string, as multipart non-terminal
76 | static bool
77 | s_sendmore (zmq::socket_t & socket, const std::string & string) {
78 |
79 | zmq::message_t message(string.size());
80 | memcpy(message.data(), string.data(), string.size());
81 |
82 | bool rc = socket.send(message, ZMQ_SNDMORE);
83 | return (rc);
84 | }
85 | /*
86 | // Receives all message parts from socket, prints neatly
87 | //
88 | static void
89 | s_dump (zmq::socket_t & socket)
90 | {
91 | std::cout << "----------------------------------------" << std::endl;
92 |
93 | while (1) {
94 | // Process all parts of the message
95 |
96 | zmq::message_t message;
97 | socket.recv(&message);
98 |
99 | // Dump the message as text or binary
100 | std::string data(static_cast(message.data()));
101 | int size = message.size();
102 |
103 | bool is_text = true;
104 |
105 | int char_nbr;
106 | unsigned char byte;
107 | for (char_nbr = 0; char_nbr < size; char_nbr++) {
108 | byte = data [char_nbr];
109 | if (byte < 32 || byte > 127)
110 | is_text = false;
111 | }
112 |
113 | printf ("[%03d] ", size);
114 |
115 | for (char_nbr = 0; char_nbr < size; char_nbr++) {
116 | if (is_text)
117 | printf ("%c", data [char_nbr]);
118 | else
119 | printf ("%02X", (unsigned char) data [char_nbr]);
120 | }
121 | printf ("\n");
122 |
123 | int64_t more; // Multipart detection
124 | size_t more_size = sizeof (more);
125 | socket.getsockopt(ZMQ_RCVMORE, &more, &more_size);
126 |
127 | if (!more)
128 | break; // Last message part
129 | }
130 | }
131 |
132 | // Set simple random printable identity on socket
133 | //
134 | static void
135 | s_set_id (zmq::socket_t & socket)
136 | {
137 | char identity [10];
138 | sprintf (identity, "%04X-%04X", within (0x10000), within (0x10000));
139 | socket.setsockopt(ZMQ_IDENTITY, identity, strlen (identity));
140 | }
141 |
142 | // Report 0MQ version number
143 | //
144 | static void
145 | s_version (void)
146 | {
147 | int major, minor, patch;
148 | zmq_version (&major, &minor, &patch);
149 | printf ("Current 0MQ version is %d.%d.%d\n", major, minor, patch);
150 | }
151 | */
152 | #endif
--------------------------------------------------------------------------------
/ZmqPub/glh/glh_mipmaps.h:
--------------------------------------------------------------------------------
1 | /*
2 | glh - is a platform-indepenedent C++ OpenGL helper library
3 |
4 |
5 | Copyright (c) 2000 Cass Everitt
6 | Copyright (c) 2000, 2001 NVIDIA Corporation
7 | All rights reserved.
8 |
9 | Redistribution and use in source and binary forms, with or
10 | without modification, are permitted provided that the following
11 | conditions are met:
12 |
13 | * Redistributions of source code must retain the above
14 | copyright notice, this list of conditions and the following
15 | disclaimer.
16 |
17 | * Redistributions in binary form must reproduce the above
18 | copyright notice, this list of conditions and the following
19 | disclaimer in the documentation and/or other materials
20 | provided with the distribution.
21 |
22 | * The names of contributors to this software may not be used
23 | to endorse or promote products derived from this software
24 | without specific prior written permission.
25 |
26 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
27 | ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
28 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
29 | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
30 | REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
31 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
32 | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
33 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
34 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
35 | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
36 | ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37 | POSSIBILITY OF SUCH DAMAGE.
38 |
39 |
40 | Cass Everitt - cass@r3.nu
41 | */
42 |
43 | /*
44 | gluBuild2DMipmaps cannot build mipmaps for textures whose
45 | "format" it does not recognize. This is primarily because
46 | it infers the number of components and how to average them
47 | from the format. This helper eliminates that problem by
48 | factoring out that functionality.
49 |
50 | Cass Everitt
51 | 1-9-01
52 |
53 | */
54 |
55 | #ifndef GLH_MIPMAPS_H
56 | #define GLH_MIPMAPS_H
57 |
58 | #ifdef _WIN32
59 | # include
60 | #endif
61 |
62 | #ifdef MACOS
63 | #include
64 | #else
65 | #include
66 | #endif
67 |
68 | namespace glh
69 | {
70 |
71 | template
72 | class tex_indexer2
73 | {
74 | public:
75 | tex_indexer2(int width, int height, int tuple_size, T * data) :
76 | w(width), h(height), n(tuple_size), d(data) {}
77 |
78 | T * operator()(int i, int j)
79 | { return d + n * (w * j + i); }
80 | private:
81 | int w, h, n;
82 | T * d;
83 | };
84 |
85 | template
86 | struct generic_filter
87 | {
88 | typedef T element_type;
89 |
90 | generic_filter(int tuplesize, GLenum gltype) :
91 | gl_type(gltype), tuple_size(tuplesize) {}
92 |
93 | void average( T * out,
94 | const T * a, const T * b,
95 | const T * c, const T * d)
96 | {
97 | for(int i=0; i < tuple_size; i++)
98 | {
99 | double in = double(a[i]) + double(b[i]) + double(c[i]) + double(d[i]);
100 | in /= 4;
101 | out[i] = T(in);
102 | }
103 | }
104 |
105 | const GLenum gl_type;
106 | const int tuple_size;
107 | };
108 |
109 | // fixme: supports non-square textures!
110 | template
111 | void build_2D_mipmaps( GLenum target, GLenum internal_format,
112 | GLsizei w, GLsizei h, GLenum format,
113 | F filter, const void * vdata)
114 | {
115 |
116 | typedef typename F::element_type DataType;
117 | const DataType * in_data = (const DataType *)vdata;
118 | DataType * data = new DataType [w * h * filter.tuple_size];
119 |
120 | glTexImage2D(target, 0, internal_format, w, h, 0, format, filter.gl_type, (const DataType *)vdata);
121 |
122 | int level = 1;
123 | if( w >= 2 ) w /= 2;
124 | if( h >= 2 ) h /= 2;
125 | bool done = false;
126 | while(! done)
127 | {
128 | tex_indexer2 bg(w*2, h*2, filter.tuple_size, in_data);
129 | tex_indexer2 sm(w , h , filter.tuple_size, data);
130 | for(int j=0; j < h; j++)
131 | {
132 | int J = j * 2;
133 | for(int i=0; i < w; i++)
134 | {
135 | int I = i*2;
136 | filter.average( sm(i,j),
137 | bg(I , J ), bg(I+1, J ),
138 | bg(I , J+1), bg(I+1, J+1));
139 | }
140 | }
141 |
142 | glTexImage2D(target, level, internal_format, w, h, 0, format, filter.gl_type, data);
143 |
144 | if(w == 1 && h == 1) done = true;
145 |
146 | if( w >= 2 ) w /= 2;
147 | if( h >= 2 ) h /= 2;
148 | level++;
149 | in_data = data;
150 | }
151 |
152 | delete [] data;
153 | }
154 |
155 | }
156 |
157 | #endif
158 |
--------------------------------------------------------------------------------
/ZmqPub/glh/glh_glut_text.h:
--------------------------------------------------------------------------------
1 | /*
2 | glh - is a platform-indepenedent C++ OpenGL helper library
3 |
4 |
5 | Copyright (c) 2000 Cass Everitt
6 | Copyright (c) 2000 NVIDIA Corporation
7 | All rights reserved.
8 |
9 | Redistribution and use in source and binary forms, with or
10 | without modification, are permitted provided that the following
11 | conditions are met:
12 |
13 | * Redistributions of source code must retain the above
14 | copyright notice, this list of conditions and the following
15 | disclaimer.
16 |
17 | * Redistributions in binary form must reproduce the above
18 | copyright notice, this list of conditions and the following
19 | disclaimer in the documentation and/or other materials
20 | provided with the distribution.
21 |
22 | * The names of contributors to this software may not be used
23 | to endorse or promote products derived from this software
24 | without specific prior written permission.
25 |
26 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
27 | ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
28 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
29 | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
30 | REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
31 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
32 | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
33 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
34 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
35 | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
36 | ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37 | POSSIBILITY OF SUCH DAMAGE.
38 |
39 |
40 | Cass Everitt - cass@r3.nu
41 | */
42 |
43 | #ifndef GLH_GLUT_TEXT_H
44 | #define GLH_GLUT_TEXT_H
45 |
46 | #include
47 | #include
48 |
49 | #ifdef MACOS
50 | #include
51 | #else
52 | #include
53 | #endif
54 |
55 | namespace glh
56 | {
57 |
58 | struct glut_stroke_roman : font
59 | {
60 | glut_stroke_roman() : initialized(false) {}
61 |
62 | virtual ~glut_stroke_roman() { }
63 |
64 | struct glyph
65 | {
66 | float width;
67 | display_list dl;
68 | };
69 |
70 |
71 | // get font metrics
72 | virtual float get_ascent()
73 | { return 119.05f; }
74 | virtual float get_descent()
75 | { return 33.33f; }
76 | virtual float get_width(int i)
77 | {
78 | if(32 <= i && i <= 127)
79 | {
80 | if(! initialized) init();
81 | return glyphs[i].width;
82 | }
83 | return 0;
84 | }
85 |
86 | // draw
87 | virtual void render(int i)
88 | {
89 | if(32 <= i && i <= 127)
90 | {
91 | if(! initialized) init();
92 | glyphs[i].dl.call_list();
93 | }
94 | }
95 |
96 | virtual void initialize() { if(! initialized) init(); }
97 |
98 | bool initialized;
99 | glyph glyphs[128];
100 |
101 | private:
102 |
103 | void init()
104 | {
105 | initialized = true;
106 | GLfloat m[16];
107 | glColorMask(0,0,0,0);
108 | glDepthMask(0);
109 | glStencilMask(0);
110 | for(int i=32; i < 128; i++)
111 | {
112 | glPushMatrix();
113 | glLoadIdentity();
114 |
115 | // build display list
116 | glyphs[i].dl.new_list(GL_COMPILE_AND_EXECUTE);
117 | glutStrokeCharacter(GLUT_STROKE_ROMAN, i);
118 | glyphs[i].dl.end_list();
119 | // get *float* character width (glut only returns integer width)
120 | glGetFloatv(GL_MODELVIEW_MATRIX, m);
121 | glyphs[i].width = m[12];
122 |
123 | glPopMatrix();
124 | }
125 | glColorMask(1,1,1,1);
126 | glDepthMask(1);
127 | glStencilMask(1);
128 | }
129 |
130 | };
131 |
132 |
133 | struct glut_stroke_mono_roman : font
134 | {
135 | glut_stroke_mono_roman() : initialized(false) {}
136 |
137 | virtual ~glut_stroke_mono_roman() { }
138 |
139 | struct glyph
140 | {
141 | display_list dl;
142 | };
143 |
144 |
145 | // get font metrics
146 | virtual float get_ascent()
147 | { return 119.05f; }
148 | virtual float get_descent()
149 | { return 33.33f; }
150 | virtual float get_width(int i)
151 | {
152 | if(32 <= i && i <= 127)
153 | {
154 | if(! initialized) init();
155 | return 104.76;
156 | }
157 | return 0;
158 | }
159 |
160 | // draw
161 | virtual void render(int i)
162 | {
163 | if(32 <= i && i <= 127)
164 | {
165 | if(! initialized) init();
166 | glyphs[i].dl.call_list();
167 | }
168 | }
169 |
170 | virtual void initialize() { if(! initialized) init(); }
171 |
172 | bool initialized;
173 | glyph glyphs[128];
174 |
175 | private:
176 |
177 | void init()
178 | {
179 | initialized = true;
180 | for(int i=32; i < 128; i++)
181 | {
182 | // build display list
183 | glyphs[i].dl.new_list(GL_COMPILE);
184 | glutStrokeCharacter(GLUT_STROKE_MONO_ROMAN, i);
185 | glyphs[i].dl.end_list();
186 | }
187 | }
188 |
189 | };
190 |
191 |
192 |
193 | }
194 |
195 | #endif
196 |
--------------------------------------------------------------------------------
/ZmqPub/glh/glh_text.h:
--------------------------------------------------------------------------------
1 | /*
2 | glh - is a platform-indepenedent C++ OpenGL helper library
3 |
4 |
5 | Copyright (c) 2000 Cass Everitt
6 | Copyright (c) 2000 NVIDIA Corporation
7 | All rights reserved.
8 |
9 | Redistribution and use in source and binary forms, with or
10 | without modification, are permitted provided that the following
11 | conditions are met:
12 |
13 | * Redistributions of source code must retain the above
14 | copyright notice, this list of conditions and the following
15 | disclaimer.
16 |
17 | * Redistributions in binary form must reproduce the above
18 | copyright notice, this list of conditions and the following
19 | disclaimer in the documentation and/or other materials
20 | provided with the distribution.
21 |
22 | * The names of contributors to this software may not be used
23 | to endorse or promote products derived from this software
24 | without specific prior written permission.
25 |
26 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
27 | ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
28 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
29 | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
30 | REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
31 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
32 | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
33 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
34 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
35 | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
36 | ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37 | POSSIBILITY OF SUCH DAMAGE.
38 |
39 |
40 | Cass Everitt - cass@r3.nu
41 | */
42 |
43 | #ifndef GLH_TEXT_H
44 | #define GLH_TEXT_H
45 |
46 | #include
47 |
48 | #ifdef _WIN32
49 | # include
50 | #endif
51 |
52 | #ifdef MACOS
53 | #include
54 | #else
55 | #include
56 | #endif
57 |
58 | #include
59 |
60 | namespace glh
61 | {
62 |
63 | struct font
64 | {
65 | // build display lists and the like
66 | virtual void initialize() = 0;
67 | // get font metrics
68 | virtual float get_ascent() = 0;
69 | virtual float get_descent() = 0;
70 | virtual float get_width(int i) = 0;
71 |
72 | // draw
73 | virtual void render(int i) = 0;
74 | };
75 |
76 | inline float string_width(font * f, string text)
77 | {
78 | float w = 0;
79 | for(unsigned int i=0; i < text.size(); i++)
80 | {
81 | w += f->get_width(text[i]);
82 | }
83 | return w;
84 | }
85 | // skip a line
86 | inline void next_line(font * f)
87 | {
88 | glTranslatef(0, - (f->get_ascent() + f->get_descent()), 0);
89 | }
90 |
91 | // renders text horizontally
92 | inline void render_single_line(font * f, string text)
93 | {
94 | glPushMatrix();
95 | for(unsigned int i=0; i < text.size(); i++)
96 | {
97 | f->render(text[i]);
98 | }
99 | glPopMatrix();
100 | }
101 |
102 |
103 | // render text on multiple lines (based on newlines)
104 | struct simple_multi_line_text
105 | {
106 | public:
107 | simple_multi_line_text() : f(0), line_spacing(1.1f) {}
108 |
109 |
110 | void render()
111 | {
112 | if(!f) return;
113 | if(dirty)
114 | {
115 | dirty = false;
116 | dl.new_list(GL_COMPILE);
117 | make_render_calls();
118 | dl.end_list();
119 | }
120 | dl.call_list();
121 | }
122 | void get_dimensions(float & width, float & height)
123 | {
124 | if(!f) return;
125 | if(dirty)
126 | {
127 | dirty = false;
128 | dl.new_list(GL_COMPILE);
129 | make_render_calls();
130 | dl.end_list();
131 | }
132 | width = w;
133 | height = h;
134 | }
135 | void set_font(font * new_font)
136 | {
137 | dirty = true;
138 | f = new_font;
139 | }
140 | void set_text(const string & new_text)
141 | {
142 | dirty = true;
143 | text = new_text;
144 | }
145 | font * get_font() { return f; }
146 | const string & get_text() { return text; }
147 | private:
148 | // skip a line
149 | void next_line()
150 | {
151 | glTranslatef(0, - (f->get_ascent() + f->get_descent()) * line_spacing, 0);
152 | }
153 |
154 | void make_render_calls()
155 | {
156 | w = h = 0;
157 | float curr_width = 0;
158 | float font_height = f->get_ascent() + f->get_descent();
159 | int lines = 0;
160 |
161 | if(text.size() != 0) lines++;
162 |
163 | glPushMatrix(); // vertical translation
164 | glPushMatrix(); // horizontal translation
165 | for(unsigned int i=0; i < text.size(); i++)
166 | {
167 | if(text[i] == '\n')
168 | {
169 | lines++;
170 | if(curr_width > w) w = curr_width;
171 | curr_width = 0;
172 |
173 | glPopMatrix(); // back to beginning of line
174 | next_line(); // translate futher down
175 | glPushMatrix();
176 | }
177 | f->render(text[i]);
178 | curr_width += f->get_width(text[i]);
179 | }
180 | glPopMatrix();
181 | glPopMatrix();
182 | if(curr_width > w) w = curr_width;
183 | h = lines * font_height * line_spacing;
184 | }
185 |
186 | font * f;
187 | string text;
188 | display_list dl;
189 | float w, h;
190 | bool dirty;
191 | float line_spacing;
192 | };
193 |
194 |
195 | }
196 |
197 | #endif
198 |
--------------------------------------------------------------------------------
/ZmqPub/glh/glh_interactors.h:
--------------------------------------------------------------------------------
1 | /*
2 | glh - is a platform-indepenedent C++ OpenGL helper library
3 |
4 |
5 | Copyright (c) 2000 Cass Everitt
6 | Copyright (c) 2001 NVIDIA Corporation
7 | All rights reserved.
8 |
9 | Redistribution and use in source and binary forms, with or
10 | without modification, are permitted provided that the following
11 | conditions are met:
12 |
13 | * Redistributions of source code must retain the above
14 | copyright notice, this list of conditions and the following
15 | disclaimer.
16 |
17 | * Redistributions in binary form must reproduce the above
18 | copyright notice, this list of conditions and the following
19 | disclaimer in the documentation and/or other materials
20 | provided with the distribution.
21 |
22 | * The names of contributors to this software may not be used
23 | to endorse or promote products derived from this software
24 | without specific prior written permission.
25 |
26 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
27 | ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
28 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
29 | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
30 | REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
31 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
32 | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
33 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
34 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
35 | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
36 | ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37 | POSSIBILITY OF SUCH DAMAGE.
38 |
39 |
40 | Cass Everitt - cass@r3.nu
41 | */
42 |
43 | #ifndef GLH_INTERACTORS_H
44 | #define GLH_INTERACTORS_H
45 |
46 | #include
47 |
48 | namespace glh
49 | {
50 |
51 | class translator
52 | {
53 | public:
54 | translator()
55 | {
56 | scale = .01f;
57 | invert_increment = false;
58 | parent_rotation = 0;
59 | }
60 |
61 | void pan (int dx, int dy) { update(dx, dy, 0); }
62 | void dolly(int dz) { update( 0, 0, dz); }
63 |
64 | void update(int dx, int dy, int dz)
65 | {
66 | vec3f v(dx, dy, dz);
67 |
68 | // apply parent rotation
69 | if(parent_rotation != 0)
70 | parent_rotation->mult_vec(v);
71 |
72 | if(invert_increment)
73 | t -= v * scale;
74 | else
75 | t += v * scale;
76 | }
77 |
78 |
79 | matrix4f get_transform()
80 | {
81 | matrix4f m;
82 | m.set_translate(t);
83 | return m;
84 | }
85 |
86 | matrix4f get_inverse_transform()
87 | {
88 | matrix4f m;
89 | m.set_translate(-t);
90 | return m;
91 | }
92 |
93 | bool invert_increment;
94 | const rotationf * parent_rotation;
95 | vec3f t;
96 | float scale;
97 | };
98 |
99 |
100 |
101 | class trackball
102 | {
103 | public:
104 | trackball()
105 | {
106 | r = rotationf(vec3f(0, 1, 0), 0);
107 | centroid = vec3f(0,0,0);
108 | scale = -.01f;
109 | invert_increment = false;
110 | parent_rotation = 0;
111 | legacy_mode = false;
112 | }
113 |
114 | void rotate(int x0, int y0, int x1, int y1)
115 | { update(x0, y0, x1, y1); }
116 |
117 | void update(int x0, int y0, int x1, int y1)
118 | {
119 | int dx = x1 - x0;
120 | int dy = y1 - y0;
121 | if(dx == 0 && dy == 0)
122 | {
123 | incr = rotationf();
124 | return;
125 | }
126 |
127 | if(legacy_mode)
128 | {
129 | vec3f v(dy, -dx, 0);
130 | float len = v.normalize();
131 | if(parent_rotation != 0)
132 | parent_rotation->mult_vec(v);
133 | //r.mult_dir(vec3f(v), v);
134 | if(invert_increment)
135 | incr.set_value(v, -len * scale);
136 | else
137 | incr.set_value(v, len * scale);
138 | }
139 | else
140 | {
141 | vec3f a(x0, y0, 0);
142 | vec3f b(x1, y1, 0);
143 | a -= offset;
144 | b -= offset;
145 | a /= radius;
146 | b /= radius;
147 |
148 | float tmpscale = 1;
149 | a[2] = pow(2.0f, -0.5f * a.length());
150 | a.normalize();
151 | b[2] = pow(2.0f, -0.5f * b.length());
152 | b.normalize();
153 |
154 |
155 |
156 | vec3f axis = a.cross(b);
157 | axis.normalize();
158 |
159 | float angle = acos(a.dot(b));
160 |
161 | if(parent_rotation != 0) parent_rotation->mult_vec(axis);
162 |
163 | if(invert_increment)
164 | incr.set_value(axis, -angle * tmpscale);
165 | else
166 | incr.set_value(axis, angle * tmpscale);
167 |
168 | }
169 |
170 | // fixme: shouldn't operator*() preserve 'r' in this case?
171 | if(incr[3] != 0)
172 | r = incr * r;
173 | }
174 |
175 | void increment_rotation()
176 | {
177 | // fixme: shouldn't operator*() preserve 'r' in this case?
178 | if(incr[3] != 0)
179 | r = incr * r;
180 | }
181 |
182 | matrix4f get_transform()
183 | {
184 | matrix4f mt, mr, minvt;
185 | mt.set_translate(centroid);
186 | r.get_value(mr);
187 | minvt.set_translate(-centroid);
188 | return mt * mr * minvt;
189 | }
190 |
191 | matrix4f get_inverse_transform()
192 | {
193 | matrix4f mt, mr, minvt;
194 | mt.set_translate(centroid);
195 | r.inverse().get_value(mr);
196 | minvt.set_translate(-centroid);
197 | return mt * mr * minvt;
198 | }
199 |
200 | bool invert_increment;
201 | const rotationf * parent_rotation;
202 | rotationf r;
203 | vec3f centroid;
204 | float scale;
205 | bool legacy_mode;
206 | rotationf incr;
207 | float radius;
208 | vec3f offset;
209 | };
210 |
211 | }
212 |
213 | #endif
214 |
--------------------------------------------------------------------------------
/ZmqPub/glh/glh_convenience.h:
--------------------------------------------------------------------------------
1 | /*
2 | glh - is a platform-indepenedent C++ OpenGL helper library
3 |
4 |
5 | Copyright (c) 2000 Cass Everitt
6 | Copyright (c) 2000 NVIDIA Corporation
7 | All rights reserved.
8 |
9 | Redistribution and use in source and binary forms, with or
10 | without modification, are permitted provided that the following
11 | conditions are met:
12 |
13 | * Redistributions of source code must retain the above
14 | copyright notice, this list of conditions and the following
15 | disclaimer.
16 |
17 | * Redistributions in binary form must reproduce the above
18 | copyright notice, this list of conditions and the following
19 | disclaimer in the documentation and/or other materials
20 | provided with the distribution.
21 |
22 | * The names of contributors to this software may not be used
23 | to endorse or promote products derived from this software
24 | without specific prior written permission.
25 |
26 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
27 | ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
28 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
29 | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
30 | REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
31 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
32 | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
33 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
34 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
35 | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
36 | ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37 | POSSIBILITY OF SUCH DAMAGE.
38 |
39 |
40 | Cass Everitt - cass@r3.nu
41 | */
42 |
43 | #ifndef GLH_CONVENIENCE_H
44 | #define GLH_CONVENIENCE_H
45 |
46 | // Convenience methods for using glh_linear objects
47 | // with opengl...
48 |
49 |
50 |
51 | // debugging hack...
52 | #include
53 |
54 | using namespace std;
55 |
56 | #ifdef MACOS
57 | #include
58 | #else
59 | #include
60 | #endif
61 |
62 | #include
63 | #include
64 |
65 |
66 | namespace glh
67 | {
68 |
69 | // matrix helpers
70 |
71 | inline matrix4f get_matrix(GLenum matrix)
72 | {
73 | GLfloat m[16];
74 | glGetFloatv(matrix, m);
75 | return matrix4f(m);
76 | }
77 |
78 | // transform helpers
79 |
80 | inline void glh_rotate(const quaternionf & r)
81 | {
82 | float angle;
83 | vec3f axis;
84 | r.get_value(axis, angle);
85 | glRotatef(to_degrees(angle), axis.v[0], axis.v[1], axis.v[2]);
86 | }
87 |
88 | // inverse of camera_lookat
89 | inline matrix4f object_lookat(const vec3f & from, const vec3f & to, const vec3f & Up)
90 | {
91 | vec3f look = to - from;
92 | look.normalize();
93 | vec3f up(Up);
94 | up -= look * look.dot(up);
95 | up.normalize();
96 |
97 | quaternionf r(vec3f(0,0,-1), vec3f(0,1,0), look, up);
98 | matrix4f m;
99 | r.get_value(m);
100 | m.set_translate(from);
101 | return m;
102 | }
103 |
104 |
105 | // inverse of object_lookat
106 | inline matrix4f camera_lookat(const vec3f & eye, const vec3f & lookpoint, const vec3f & Up)
107 | {
108 | vec3f look = lookpoint - eye;
109 | look.normalize();
110 | vec3f up(Up);
111 | up -= look * look.dot(up);
112 | up.normalize();
113 |
114 | matrix4f t;
115 | t.set_translate(-eye);
116 |
117 | quaternionf r(vec3f(0,0,-1), vec3f(0,1,0), look, up);
118 | r.invert();
119 | matrix4f rm;
120 | r.get_value(rm);
121 | return rm*t;
122 | }
123 |
124 |
125 | inline matrix4f frustum(float left, float right,
126 | float bottom, float top,
127 | float zNear, float zFar)
128 | {
129 | matrix4f m;
130 | m.make_identity();
131 |
132 | m(0,0) = (2*zNear) / (right - left);
133 | m(0,2) = (right + left) / (right - left);
134 |
135 | m(1,1) = (2*zNear) / (top - bottom);
136 | m(1,2) = (top + bottom) / (top - bottom);
137 |
138 | m(2,2) = -(zFar + zNear) / (zFar - zNear);
139 | m(2,3) = -2*zFar*zNear / (zFar - zNear);
140 |
141 | m(3,2) = -1;
142 | m(3,3) = 0;
143 |
144 | return m;
145 | }
146 |
147 | inline matrix4f frustum_inverse(float left, float right,
148 | float bottom, float top,
149 | float zNear, float zFar)
150 | {
151 | matrix4f m;
152 | m.make_identity();
153 |
154 | m(0,0) = (right - left) / (2 * zNear);
155 | m(0,3) = (right + left) / (2 * zNear);
156 |
157 | m(1,1) = (top - bottom) / (2 * zNear);
158 | m(1,3) = (top + bottom) / (2 * zNear);
159 |
160 | m(2,2) = 0;
161 | m(2,3) = -1;
162 |
163 | m(3,2) = -(zFar - zNear) / (2 * zFar * zNear);
164 | m(3,3) = (zFar + zNear) / (2 * zFar * zNear);
165 |
166 | return m;
167 | }
168 |
169 | inline matrix4f perspective(float fovy, float aspect, float zNear, float zFar)
170 | {
171 | double tangent = tan(to_radians(fovy/2.0f));
172 | float y = (float)tangent * zNear;
173 | float x = aspect * y;
174 | return frustum(-x, x, -y, y, zNear, zFar);
175 | }
176 |
177 | inline matrix4f perspective_inverse(float fovy, float aspect, float zNear, float zFar)
178 | {
179 | double tangent = tan(to_radians(fovy/2.0f));
180 | float y = (float)tangent * zNear;
181 | float x = aspect * y;
182 | return frustum_inverse(-x, x, -y, y, zNear, zFar);
183 | }
184 |
185 |
186 |
187 | // are these names ok?
188 |
189 | inline void set_texgen_planes(GLenum plane_type, const matrix4f & m)
190 | {
191 | GLenum coord[] = {GL_S, GL_T, GL_R, GL_Q };
192 | for(int i = 0; i < 4; i++)
193 | {
194 | vec4f row;
195 | m.get_row(i,row);
196 | glTexGenfv(coord[i], plane_type, row.v);
197 | }
198 | }
199 |
200 | // handy for register combiners
201 | inline vec3f range_compress(const vec3f & v)
202 | { vec3f vret(v); vret *= .5f; vret += .5f; return vret; }
203 |
204 | inline vec3f range_uncompress(const vec3f & v)
205 | { vec3f vret(v); vret -= .5f; vret *= 2.f; return vret; }
206 |
207 | } // namespace glh
208 |
209 | #endif
210 |
--------------------------------------------------------------------------------
/Common/OpenNICommonMakefile:
--------------------------------------------------------------------------------
1 | #############################################################################
2 | # Primesense template makefile.
3 | # This file should not be made, but only included from other makefiles.
4 | # By default, this makefile compiles in release. To compile a debug version:
5 | # make CFG=Debug
6 | #
7 | # Project makefile should define the following BEFORE including this file:
8 | # SRC_FILES - a list of all source files
9 | # Output name under one of the following:
10 | # EXE_NAME (executable),
11 | # LIB_NAME (dynamic library) or
12 | # SLIB_NAME (static library) or
13 | # NETLIB_NAME (.net module) or
14 | # NETEXE_NAME (.net executable)
15 | # BIN_DIR - Bin directory (output dir)
16 | # INC_DIRS - a list of additional include directories
17 | # LIB_DIRS - a list of additional library directories
18 | # USED_LIBS - a list of libraries to link with
19 | # DEFINES - [Optional] additional preprocessor defines
20 | # CFLAGS - [Optional] additional flags for the compiler
21 | # LDFLAGS - [Optional] additional flags for the linker
22 | # CSFLAGS - [Optional] additional flags for mono compiler
23 | # NET_WIN_FORMS - [Optional] when 1, application uses WinForms
24 | # SSE_GENERATION - [Optional] The SSE generation to use (default is 3)
25 | # TARGET_SYS_ROOT - [Optional] The path to the root of the target
26 | # NI_CONF_DIR - [Optional] configuration dir to be registered with OpenNI
27 | #############################################################################
28 |
29 | # some defaults
30 | ifndef SSE_GENERATION
31 | SSE_GENERATION = 3
32 | endif
33 |
34 | ifndef CFG
35 | CFG = Release
36 | endif
37 |
38 | ifndef TARGET_SYS_ROOT
39 | TARGET_SYS_ROOT = /
40 | endif
41 |
42 | # tools
43 | RM = rm -rf
44 | CP = cp
45 |
46 | # expand file list
47 | SRC_FILES_LIST = $(wildcard $(SRC_FILES))
48 |
49 | OSTYPE := $(shell uname -s)
50 |
51 | # change c struct alignment options to be compatable with Win32
52 | ifneq ("$(OSTYPE)","Darwin")
53 | CFLAGS += -malign-double
54 | else
55 | CFLAGS += -arch i386 -arch x86_64
56 | LDFLAGS += -arch i386 -arch x86_64
57 | endif
58 |
59 | # tell compiler to use the target system root
60 | ifneq ("$(TARGET_SYS_ROOT)","/")
61 | CFLAGS += --sysroot=$(TARGET_SYS_ROOT)
62 | LDFLAGS += --sysroot=$(TARGET_SYS_ROOT)
63 | endif
64 |
65 | # define the intermediate directory
66 | INT_DIR = $(CFG)
67 |
68 | # define output directory
69 | OUT_DIR = $(BIN_DIR)/$(CFG)
70 |
71 | # define a function to figure .o file for each source file (placed under intermediate directory)
72 | SRC_TO_OBJ = $(addprefix ./$(INT_DIR)/,$(addsuffix .o,$(notdir $(basename $1))))
73 |
74 | # create a list of all object files
75 | OBJ_FILES = $(call SRC_TO_OBJ,$(SRC_FILES_LIST))
76 |
77 | # define a function to translate any source file to its dependency file (note that the way we create
78 | # dep files, as a side affect of compilation, always puts the files in the INT_DIR with suffix .d)
79 | SRC_TO_DEP = $(addprefix ./$(INT_DIR)/,$(addsuffix .d,$(notdir $(basename $1))))
80 |
81 | # create a list of all dependency files
82 | DEP_FILES = $(call SRC_TO_DEP,$(SRC_FILES_LIST))
83 |
84 | # append the -I switch to each include directory
85 | INC_DIRS_OPTION = $(foreach dir,$(INC_DIRS),-I$(dir))
86 |
87 | # append the -L switch to each library directory
88 | LIB_DIRS_OPTION = $(foreach dir,$(LIB_DIRS),-L$(dir)) -L$(OUT_DIR)
89 |
90 | # append the -l switch to each library used
91 | USED_LIBS_OPTION = $(foreach lib,$(USED_LIBS),-l$(lib))
92 |
93 | # create -r option to mcs
94 | USED_NETLIBS_OPTION = $(foreach lib,$(USED_LIBS),-r:$(OUT_DIR)/$(lib).dll)
95 |
96 | ifeq "$(NET_WIN_FORMS)" "1"
97 | USED_NETLIBS_OPTION += -r:System.Windows.Forms.dll -r:System.Drawing.dll
98 | endif
99 |
100 | # append the -D switch to each define
101 | DEFINES_OPTION = $(foreach def,$(DEFINES),-D$(def))
102 |
103 | # some lib / exe specifics
104 | ifneq "$(LIB_NAME)" ""
105 | OUTPUT_NAME = lib$(LIB_NAME).so
106 | CFLAGS += -fPIC -fvisibility=hidden
107 | ifneq ("$(OSTYPE)","Darwin")
108 | OUTPUT_NAME = lib$(LIB_NAME).so
109 | OUTPUT_COMMAND = $(CXX) -o $(OUTPUT_FILE) $(OBJ_FILES) $(LDFLAGS) -shared
110 | else
111 | OUTPUT_NAME = lib$(LIB_NAME).dylib
112 | OUTPUT_COMMAND = $(CXX) -o $(OUTPUT_FILE) $(OBJ_FILES) $(LDFLAGS) -dynamiclib -headerpad_max_install_names
113 | endif
114 | endif
115 | ifneq "$(EXE_NAME)" ""
116 | OUTPUT_NAME = $(EXE_NAME)
117 | OUTPUT_COMMAND = $(CXX) -o $(OUTPUT_FILE) $(OBJ_FILES) $(LDFLAGS)
118 | endif
119 | ifneq "$(SLIB_NAME)" ""
120 | OUTPUT_NAME = lib$(SLIB_NAME).a
121 | OUTPUT_COMMAND = $(AR) $(OUTPUT_FILE) $(OBJ_FILES)
122 | endif
123 | ifneq "$(NETLIB_NAME)" ""
124 | OUTPUT_NAME = $(NETLIB_NAME).dll
125 | OUTPUT_COMMAND = gmcs -out:$(OUTPUT_FILE) -target:library $(CSFLAGS) $(USED_NETLIBS_OPTION) $(SRC_FILES)
126 | NET = 1
127 | endif
128 | ifneq "$(NETEXE_NAME)" ""
129 | OUTPUT_NAME = $(NETEXE_NAME).exe
130 | OUTPUT_COMMAND = gmcs -out:$(OUTPUT_FILE) -target:winexe $(CSFLAGS) $(USED_NETLIBS_OPTION) $(SRC_FILES)
131 | NET = 1
132 | endif
133 |
134 | # full path to output file
135 | OUTPUT_FILE = $(OUT_DIR)/$(OUTPUT_NAME)
136 |
137 | # set Debug / Release flags
138 | ifeq "$(CFG)" "Debug"
139 | CFLAGS += -g
140 | endif
141 | ifeq "$(CFG)" "Release"
142 | CFLAGS += -O2 -DNDEBUG
143 |
144 | ifeq ($(SSE_GENERATION), 2)
145 | CFLAGS += -msse2
146 | else
147 | ifeq ($(SSE_GENERATION), 3)
148 | CFLAGS += -msse3
149 | else
150 | ($error "Only SSE2 and SSE3 are supported")
151 | endif
152 | endif
153 |
154 | CSFLAGS += -o+
155 | endif
156 |
157 | CFLAGS += $(INC_DIRS_OPTION) $(DEFINES_OPTION)
158 | LDFLAGS += $(LIB_DIRS_OPTION) $(USED_LIBS_OPTION)
159 |
160 | ifeq "$(NET)" "1"
161 | define CREATE_SRC_TARGETS
162 | $(call SRC_TO_OBJ,$1) : $1 | $(INT_DIR)
163 | touch $(call SRC_TO_OBJ,$1)
164 | endef
165 | else
166 | define CREATE_SRC_TARGETS
167 | # create a target for the object file (the CXX command creates both an .o file
168 | # and a .d file)
169 | ifneq ("$(OSTYPE)","Darwin")
170 | $(call SRC_TO_OBJ,$1) : $1 | $(INT_DIR)
171 | $(CXX) -MD -MP -MT "$(call SRC_TO_DEP,$1) $$@" -c $(CFLAGS) -o $$@ $$<
172 | else
173 | $(call SRC_TO_OBJ,$1) : $1 | $(INT_DIR)
174 | $(CXX) -c $(CFLAGS) -o $$@ $$<
175 | endif
176 | endef
177 | endif
178 |
179 | #############################################################################
180 | # Targets
181 | #############################################################################
182 | .PHONY: all clean
183 |
184 | # define the target 'all' (it is first, and so, default)
185 | all: $(OUTPUT_FILE)
186 |
187 | # Intermediate directory
188 | $(INT_DIR):
189 | mkdir -p $(INT_DIR)
190 |
191 | # create targets for each source file
192 | $(foreach src,$(SRC_FILES_LIST),$(eval $(call CREATE_SRC_TARGETS,$(src))))
193 |
194 | # include all dependency files (we don't need them the first time, so we can use -include)
195 | -include $(DEP_FILES)
196 |
197 | # Output directory
198 | $(OUT_DIR):
199 | mkdir -p $(OUT_DIR)
200 |
201 | # Final output file
202 | $(OUTPUT_FILE): $(OBJ_FILES) | $(OUT_DIR)
203 | $(OUTPUT_COMMAND)
204 |
205 | clean:
206 | $(RM) $(OUTPUT_FILE) $(OBJ_FILES) $(DEP_FILES)
207 |
208 |
--------------------------------------------------------------------------------
/ZmqPub/glh/glh_array.h:
--------------------------------------------------------------------------------
1 | /*
2 | glh - is a platform-indepenedent C++ OpenGL helper library
3 |
4 | Copyright (c) 2000 Cass Everitt
5 | Copyright (c) 2000 NVIDIA Corporation
6 | All rights reserved.
7 |
8 | Redistribution and use in source and binary forms, with or
9 | without modification, are permitted provided that the following
10 | conditions are met:
11 |
12 | * Redistributions of source code must retain the above
13 | copyright notice, this list of conditions and the following
14 | disclaimer.
15 |
16 | * Redistributions in binary form must reproduce the above
17 | copyright notice, this list of conditions and the following
18 | disclaimer in the documentation and/or other materials
19 | provided with the distribution.
20 |
21 | * The names of contributors to this software may not be used
22 | to endorse or promote products derived from this software
23 | without specific prior written permission.
24 |
25 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26 | ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
28 | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
29 | REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
30 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
31 | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
32 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
33 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34 | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
35 | ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 | POSSIBILITY OF SUCH DAMAGE.
37 |
38 | Cass Everitt - cass@r3.nu
39 | */
40 |
41 | // Simple array template.
42 | // Copyright (c) Cass W. Everitt 1999
43 | // Copyright (c) NVIDIA 2000
44 |
45 | #ifndef _GLH_ARRAY_H_
46 | #define _GLH_ARRAY_H_
47 |
48 | namespace glh
49 | {
50 | //
51 | // Template for array2
52 | //
53 |
54 | template class array2
55 | {
56 | public:
57 | typedef T value_type;
58 |
59 | array2(int width=1, int height=1)
60 | {
61 | w = width;
62 | h = height;
63 | data = new T [w * h];
64 | clear(T());
65 | }
66 |
67 | array2(const array2 & t)
68 | {
69 | w = h = 0;
70 | data=0;
71 | (*this) = t;
72 | }
73 |
74 | // intentionally non-virtual
75 | ~array2() { delete [] data; }
76 |
77 | const array2 & operator = (const array2 & t)
78 | {
79 | if(w != t.w || h != t.h) set_size(t.w, t.h);
80 | int sz = w * h;
81 | for(int i = 0; i < sz; i++) data[i] = t.data[i];
82 | return *this;
83 | }
84 |
85 |
86 | void set_size(int width, int height)
87 |
88 | {
89 |
90 | if(w == width && h == height) return;
91 |
92 | delete [] data;
93 |
94 | w = width;
95 |
96 | h = height;
97 |
98 | data = new T [w * h];
99 |
100 | }
101 |
102 |
103 | T & operator () (int i, int j)
104 | { return data[i + j * w]; }
105 |
106 | const T & operator () (int i, int j) const
107 | { return data[i + j * w]; }
108 |
109 |
110 | int get_width() const { return w; }
111 |
112 | int get_height() const { return h; }
113 |
114 | void clear(const T & val)
115 | {
116 | int sz = w * h;
117 | for(int i = 0; i < sz; i++) data[i] = val;
118 | }
119 |
120 |
121 | void copy(const array2 & src, int i_offset = 0, int j_offset = 0,
122 | int width = 0, int height = 0)
123 |
124 | {
125 |
126 | int io = i_offset;
127 |
128 | int jo = j_offset;
129 |
130 | if(width == 0) width = src.get_width();
131 |
132 | if(height == 0) height = src.get_height();
133 |
134 | if(io + width > w) return;
135 |
136 | if(jo + height > h) return;
137 |
138 | for(int i=0; i < width; i++)
139 |
140 | for(int j=0; j < height; j++)
141 |
142 | (*this)(io+i, jo+j) = src(i,j);
143 |
144 | }
145 |
146 |
147 |
148 | T * get_pointer() { return data; }
149 |
150 | const T * get_pointer() const { return data; }
151 | private:
152 |
153 | int w, h;
154 | T * data;
155 | };
156 |
157 | //
158 | // Template for array3
159 | //
160 |
161 | template class array3
162 | {
163 | public:
164 | typedef T value_type;
165 |
166 | array3(int width=1, int height=1, int depth=1)
167 | {
168 | w = width;
169 | h = height;
170 | d = depth;
171 | data = new T [w * h * d];
172 | clear(T());
173 | }
174 |
175 | array3(const array3 & t)
176 | {
177 | w = h = d = 0;
178 | data=0;
179 | (*this) = t;
180 | }
181 |
182 | // intentionally non-virtual
183 | ~array3() { delete [] data; }
184 |
185 | const array3 & operator = (const array3 & t)
186 | {
187 | if(w != t.w || h != t.h || d != t.d)
188 | set_size(t.w, t.h, t.d);
189 | int sz = w * h * d;
190 | for(int i = 0; i < sz; i++)
191 | data[i] = t.data[i];
192 | return *this;
193 | }
194 |
195 |
196 | void set_size(int width, int height, int depth)
197 |
198 | {
199 | if(w == width && h == height && d == depth)
200 | return;
201 |
202 | delete [] data;
203 |
204 | w = width;
205 | h = height;
206 | d = depth;
207 |
208 | data = new T [w * h * d];
209 | }
210 |
211 |
212 | T & operator () (int i, int j, int k)
213 | { return data[i + j * w + k * w * h]; }
214 |
215 | const T & operator () (int i, int j, int k) const
216 | { return data[i + j * w + k * w * h]; }
217 |
218 |
219 | int get_width() const
220 | { return w; }
221 |
222 | int get_height() const
223 | { return h; }
224 |
225 | int get_depth() const
226 | { return d; }
227 |
228 | void clear(const T & val)
229 | {
230 | int sz = w * h * d;
231 | for(int i = 0; i < sz; i++)
232 | data[i] = val;
233 | }
234 |
235 |
236 | void copy(const array3 & src,
237 | int i_offset = 0, int j_offset = 0, int k_offset = 0,
238 | int width = 0, int height = 0, int depth = 0)
239 | {
240 |
241 | int io = i_offset;
242 | int jo = j_offset;
243 | int ko = k_offset;
244 |
245 | if(width == 0)
246 | width = src.get_width();
247 | if(height == 0)
248 | height = src.get_height();
249 | if(depth == 0)
250 | depth = src.get_depth();
251 |
252 | if(io + width > w || jo + height > h || ko + depth > d)
253 | return;
254 |
255 | for(int i=0; i < width; i++)
256 | for(int j=0; j < height; j++)
257 | for(int k=0; k < depth; k++)
258 | (*this)(io+i, jo+j, ko+k) = src(i,j,k);
259 | }
260 |
261 |
262 |
263 | T * get_pointer()
264 | { return data; }
265 |
266 | const T * get_pointer() const
267 | { return data; }
268 |
269 | private:
270 | int w, h, d;
271 | T * data;
272 | }; // template class array3
273 | } // namespace glh
274 | #endif
275 |
--------------------------------------------------------------------------------
/ZmqPub/CommonMakefile:
--------------------------------------------------------------------------------
1 | #############################################################################
2 | # Primesense template makefile.
3 | # This file should not be made, but only included from other makefiles.
4 | # By default, this makefile compiles in release. To compile a debug version:
5 | # make CFG=Debug
6 | #
7 | # Project makefile should define the following BEFORE including this file:
8 | # SRC_FILES - a list of all source files
9 | # Output name under one of the following:
10 | # EXE_NAME (executable),
11 | # LIB_NAME (dynamic library) or
12 | # SLIB_NAME (static library) or
13 | # NETLIB_NAME (.net module) or
14 | # NETEXE_NAME (.net executable)
15 | # BIN_DIR - Bin directory (output dir)
16 | # INC_DIRS - a list of additional include directories
17 | # LIB_DIRS - a list of additional library directories
18 | # USED_LIBS - a list of libraries to link with
19 | # DEFINES - [Optional] additional preprocessor defines
20 | # CFLAGS - [Optional] additional flags for the compiler
21 | # LDFLAGS - [Optional] additional flags for the linker
22 | # CSFLAGS - [Optional] additional flags for mono compiler
23 | # NET_WIN_FORMS - [Optional] when 1, application uses WinForms
24 | # SSE_GENERATION - [Optional] The SSE generation to use (default is 3)
25 | # TARGET_SYS_ROOT - [Optional] The path to the root of the target
26 | # NI_CONF_DIR - [Optional] configuration dir to be registered with OpenNI
27 | #############################################################################
28 |
29 | # some defaults
30 | ifndef SSE_GENERATION
31 | SSE_GENERATION = 3
32 | endif
33 |
34 | ifndef CFG
35 | CFG = Release
36 | endif
37 |
38 | ifndef TARGET_SYS_ROOT
39 | TARGET_SYS_ROOT = /
40 | endif
41 |
42 | # tools
43 | RM = rm -rf
44 | CP = cp
45 |
46 | # expand file list
47 | SRC_FILES_LIST = $(wildcard $(SRC_FILES))
48 |
49 | OSTYPE := $(shell uname -s)
50 |
51 | # change c struct alignment options to be compatable with Win32
52 | ifneq ("$(OSTYPE)","Darwin")
53 | CFLAGS += -malign-double
54 | else
55 | #CFLAGS += -arch i386 -arch x86_64
56 | #LDFLAGS += -arch i386 -arch x86_64
57 | CFLAGS += -arch x86_64
58 | LDFLAGS += -arch x86_64
59 | endif
60 |
61 | # tell compiler to use the target system root
62 | ifneq ("$(TARGET_SYS_ROOT)","/")
63 | CFLAGS += --sysroot=$(TARGET_SYS_ROOT)
64 | LDFLAGS += --sysroot=$(TARGET_SYS_ROOT)
65 | endif
66 |
67 | # define the intermediate directory
68 | INT_DIR = $(CFG)
69 |
70 | # define output directory
71 | OUT_DIR = $(BIN_DIR)/$(CFG)
72 |
73 | # define a function to figure .o file for each source file (placed under intermediate directory)
74 | SRC_TO_OBJ = $(addprefix ./$(INT_DIR)/,$(addsuffix .o,$(notdir $(basename $1))))
75 |
76 | # create a list of all object files
77 | OBJ_FILES = $(call SRC_TO_OBJ,$(SRC_FILES_LIST))
78 |
79 | # define a function to translate any source file to its dependency file (note that the way we create
80 | # dep files, as a side affect of compilation, always puts the files in the INT_DIR with suffix .d)
81 | SRC_TO_DEP = $(addprefix ./$(INT_DIR)/,$(addsuffix .d,$(notdir $(basename $1))))
82 |
83 | # create a list of all dependency files
84 | DEP_FILES = $(call SRC_TO_DEP,$(SRC_FILES_LIST))
85 |
86 | # append the -I switch to each include directory
87 | INC_DIRS_OPTION = $(foreach dir,$(INC_DIRS),-I$(dir))
88 |
89 | # append the -L switch to each library directory
90 | LIB_DIRS_OPTION = $(foreach dir,$(LIB_DIRS),-L$(dir)) -L$(OUT_DIR)
91 |
92 | # append the -l switch to each library used
93 | USED_LIBS_OPTION = $(foreach lib,$(USED_LIBS),-l$(lib))
94 |
95 | # create -r option to mcs
96 | USED_NETLIBS_OPTION = $(foreach lib,$(USED_LIBS),-r:$(OUT_DIR)/$(lib).dll)
97 |
98 | ifeq "$(NET_WIN_FORMS)" "1"
99 | USED_NETLIBS_OPTION += -r:System.Windows.Forms.dll -r:System.Drawing.dll
100 | endif
101 |
102 | # append the -D switch to each define
103 | DEFINES_OPTION = $(foreach def,$(DEFINES),-D$(def))
104 |
105 | # some lib / exe specifics
106 | ifneq "$(LIB_NAME)" ""
107 | OUTPUT_NAME = lib$(LIB_NAME).so
108 | CFLAGS += -fPIC -fvisibility=hidden
109 | ifneq ("$(OSTYPE)","Darwin")
110 | OUTPUT_NAME = lib$(LIB_NAME).so
111 | OUTPUT_COMMAND = $(CXX) -o $(OUTPUT_FILE) $(OBJ_FILES) $(LDFLAGS) -shared
112 | else
113 | OUTPUT_NAME = lib$(LIB_NAME).dylib
114 | OUTPUT_COMMAND = $(CXX) -o $(OUTPUT_FILE) $(OBJ_FILES) $(LDFLAGS) -dynamiclib -headerpad_max_install_names
115 | endif
116 | endif
117 | ifneq "$(EXE_NAME)" ""
118 | OUTPUT_NAME = $(EXE_NAME)
119 | OUTPUT_COMMAND = $(CXX) -o $(OUTPUT_FILE) $(OBJ_FILES) $(LDFLAGS)
120 | endif
121 | ifneq "$(SLIB_NAME)" ""
122 | OUTPUT_NAME = lib$(SLIB_NAME).a
123 | OUTPUT_COMMAND = $(AR) $(OUTPUT_FILE) $(OBJ_FILES)
124 | endif
125 | ifneq "$(NETLIB_NAME)" ""
126 | OUTPUT_NAME = $(NETLIB_NAME).dll
127 | OUTPUT_COMMAND = gmcs -out:$(OUTPUT_FILE) -target:library $(CSFLAGS) $(USED_NETLIBS_OPTION) $(SRC_FILES)
128 | NET = 1
129 | endif
130 | ifneq "$(NETEXE_NAME)" ""
131 | OUTPUT_NAME = $(NETEXE_NAME).exe
132 | OUTPUT_COMMAND = gmcs -out:$(OUTPUT_FILE) -target:winexe $(CSFLAGS) $(USED_NETLIBS_OPTION) $(SRC_FILES)
133 | NET = 1
134 | endif
135 |
136 | # full path to output file
137 | OUTPUT_FILE = $(OUT_DIR)/$(OUTPUT_NAME)
138 |
139 | # set Debug / Release flags
140 | ifeq "$(CFG)" "Debug"
141 | CFLAGS += -g
142 | endif
143 | ifeq "$(CFG)" "Release"
144 | CFLAGS += -O2 -DNDEBUG
145 |
146 | ifeq ($(SSE_GENERATION), 2)
147 | CFLAGS += -msse2
148 | else
149 | ifeq ($(SSE_GENERATION), 3)
150 | CFLAGS += -msse3
151 | else
152 | ($error "Only SSE2 and SSE3 are supported")
153 | endif
154 | endif
155 |
156 | CSFLAGS += -o+
157 | endif
158 |
159 | CFLAGS += $(INC_DIRS_OPTION) $(DEFINES_OPTION)
160 | LDFLAGS += $(LIB_DIRS_OPTION) $(USED_LIBS_OPTION)
161 |
162 | ifeq "$(NET)" "1"
163 | define CREATE_SRC_TARGETS
164 | $(call SRC_TO_OBJ,$1) : $1 | $(INT_DIR)
165 | touch $(call SRC_TO_OBJ,$1)
166 | endef
167 | else
168 | define CREATE_SRC_TARGETS
169 | # create a target for the object file (the CXX command creates both an .o file
170 | # and a .d file)
171 | ifneq ("$(OSTYPE)","Darwin")
172 | $(call SRC_TO_OBJ,$1) : $1 | $(INT_DIR)
173 | $(CXX) -MD -MP -MT "$(call SRC_TO_DEP,$1) $$@" -c $(CFLAGS) -o $$@ $$<
174 | else
175 | $(call SRC_TO_OBJ,$1) : $1 | $(INT_DIR)
176 | $(CXX) -c $(CFLAGS) -o $$@ $$<
177 | endif
178 | endef
179 | endif
180 |
181 | #############################################################################
182 | # Targets
183 | #############################################################################
184 | .PHONY: all clean
185 |
186 | # define the target 'all' (it is first, and so, default)
187 | all: $(OUTPUT_FILE)
188 |
189 | # Intermediate directory
190 | $(INT_DIR):
191 | mkdir -p $(INT_DIR)
192 |
193 | # create targets for each source file
194 | $(foreach src,$(SRC_FILES_LIST),$(eval $(call CREATE_SRC_TARGETS,$(src))))
195 |
196 | # include all dependency files (we don't need them the first time, so we can use -include)
197 | -include $(DEP_FILES)
198 |
199 | # Output directory
200 | $(OUT_DIR):
201 | mkdir -p $(OUT_DIR)
202 |
203 | # Final output file
204 | $(OUTPUT_FILE): $(OBJ_FILES) | $(OUT_DIR)
205 | $(OUTPUT_COMMAND)
206 |
207 | clean:
208 | $(RM) $(OUTPUT_FILE) $(OBJ_FILES) $(DEP_FILES)
209 |
210 |
--------------------------------------------------------------------------------
/ZmqPub/glh/glh_glut_replay.h:
--------------------------------------------------------------------------------
1 | /*
2 | glh - is a platform-indepenedent C++ OpenGL helper library
3 |
4 |
5 | Copyright (c) 2000 Cass Everitt
6 | Copyright (c) 2000 NVIDIA Corporation
7 | All rights reserved.
8 |
9 | Redistribution and use in source and binary forms, with or
10 | without modification, are permitted provided that the following
11 | conditions are met:
12 |
13 | * Redistributions of source code must retain the above
14 | copyright notice, this list of conditions and the following
15 | disclaimer.
16 |
17 | * Redistributions in binary form must reproduce the above
18 | copyright notice, this list of conditions and the following
19 | disclaimer in the documentation and/or other materials
20 | provided with the distribution.
21 |
22 | * The names of contributors to this software may not be used
23 | to endorse or promote products derived from this software
24 | without specific prior written permission.
25 |
26 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
27 | ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
28 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
29 | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
30 | REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
31 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
32 | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
33 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
34 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
35 | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
36 | ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37 | POSSIBILITY OF SUCH DAMAGE.
38 |
39 |
40 | Cass Everitt - cass@r3.nu
41 | */
42 |
43 | #ifndef GLH_GLUT_REPLAY_H
44 | #define GLH_GLUT_REPLAY_H
45 |
46 | // a facility for recording and playing back glut events
47 |
48 | #include
49 | #include
50 |
51 | namespace glh
52 | {
53 |
54 |
55 | struct glut_event
56 | {
57 | enum event_type
58 | {
59 | DISPLAY, IDLE, KEYBOARD, MENU_STATUS, MOTION, MOUSE,
60 | PASSIVE_MOTION, RESHAPE, SPECIAL, TIMER, VISIBILITY
61 | };
62 | glut_event(event_type t) : type(t) {}
63 | virtual ~glut_event() {}
64 | virtual void dispatch() = 0;
65 | const event_type type;
66 | };
67 |
68 | struct glut_display_event : public glut_event
69 | {
70 | glut_display_event() : glut_event(DISPLAY) {}
71 | virtual void dispatch() { glut_display_function(); }
72 | };
73 |
74 | struct glut_idle_event : public glut_event
75 | {
76 | glut_idle_event() : glut_event(IDLE) {}
77 | virtual void dispatch() { glut_idle_function(); }
78 | };
79 |
80 | struct glut_keyboard_event : public glut_event
81 | {
82 | glut_keyboard_event(unsigned char key, int xpos, int ypos)
83 | : glut_event(KEYBOARD), k(key), x(xpos), y(ypos)
84 | {}
85 | virtual void dispatch() { glut_keyboard_function(k,x,y); }
86 | unsigned char k;
87 | int x, y;
88 | };
89 |
90 | struct glut_menu_status_event : public glut_event
91 | {
92 | glut_menu_status_event(int status, int xpos, int ypos)
93 | : glut_event(MENU_STATUS), s(status), x(xpos), y(ypos)
94 | {}
95 | virtual void dispatch() { glut_menu_status_function(s,x,y); }
96 | int s, x, y;
97 | };
98 |
99 | struct glut_motion_event : public glut_event
100 | {
101 | glut_motion_event(int xpos, int ypos)
102 | : glut_event(MOTION), x(xpos), y(ypos)
103 | {}
104 | virtual void dispatch() { glut_motion_function(x,y); }
105 | int x, y;
106 | };
107 |
108 | struct glut_mouse_event : public glut_event
109 | {
110 | glut_mouse_event(int button, int state, int xpos, int ypos)
111 | : glut_event(MOUSE), b(button), s(state), x(xpos), y(ypos)
112 | {}
113 | virtual void dispatch() { glut_mouse_function(b,s,x,y); }
114 | int b, s, x, y;
115 | };
116 |
117 | struct glut_passive_motion_event : public glut_event
118 | {
119 | glut_passive_motion_event(int xpos, int ypos)
120 | : glut_event(PASSIVE_MOTION), x(xpos), y(ypos)
121 | {}
122 | virtual void dispatch() { glut_passive_motion_function(x,y); }
123 | int x, y;
124 | };
125 |
126 | struct glut_reshape_event : public glut_event
127 | {
128 | glut_reshape_event(int width, int height)
129 | : glut_event(RESHAPE), w(width), h(height)
130 | {}
131 | virtual void dispatch() { glut_reshape_function(w,h); }
132 | int w, h;
133 | };
134 |
135 | struct glut_special_event : public glut_event
136 | {
137 | glut_special_event(int key, int xpos, int ypos)
138 | : glut_event(SPECIAL), k(key), x(xpos), y(ypos)
139 | {}
140 | virtual void dispatch() { glut_special_function(k,x,y); }
141 | int k, x, y;
142 | };
143 |
144 | struct glut_timer_event : public glut_event
145 | {
146 | glut_timer_event(int value)
147 | : glut_event(TIMER), v(value)
148 | {}
149 | virtual void dispatch() { glut_timer_function(v); }
150 | int v;
151 | };
152 |
153 | struct glut_visibility_event : public glut_event
154 | {
155 | glut_visibility_event(int visibility)
156 | : glut_event(VISIBILITY), v(visibility)
157 | {}
158 | virtual void dispatch() { glut_visibility_function(v); }
159 | int v;
160 | };
161 |
162 |
163 |
164 | struct glut_replay : public glut_interactor
165 | {
166 | enum recorder_mode
167 | {
168 | RECORD, PLAY, STOP
169 | };
170 |
171 | glut_replay()
172 | {
173 | it = event_list.end();
174 | mode = STOP;
175 | paused = false;
176 | }
177 |
178 | virtual ~glut_replay()
179 | { erase(); }
180 |
181 | virtual void display()
182 | {
183 | if(enabled && RECORD == mode && ! paused)
184 | event_list.push_back(new glut_display_event());
185 | }
186 | virtual void idle()
187 | {
188 | if(enabled && RECORD == mode && ! paused)
189 | event_list.push_back(new glut_idle_event());
190 | }
191 | virtual void keyboard(unsigned char key, int x, int y)
192 | {
193 | if(enabled && RECORD == mode && ! paused)
194 | event_list.push_back(new glut_keyboard_event(key,x,y));
195 | }
196 | virtual void menu_status(int status, int x, int y)
197 | {
198 | if(enabled && RECORD == mode && ! paused)
199 | event_list.push_back(new glut_menu_status_event(status,x,y));
200 | }
201 | virtual void motion(int x, int y)
202 | {
203 | if(enabled && RECORD == mode && ! paused)
204 | event_list.push_back(new glut_motion_event(x,y));
205 | }
206 | virtual void mouse(int button, int state, int x, int y)
207 | {
208 | if(enabled && RECORD == mode && ! paused)
209 | event_list.push_back(new glut_mouse_event(button,state,x,y));
210 | }
211 | virtual void passive_motion(int x, int y)
212 | {
213 | if(enabled && RECORD == mode && ! paused)
214 | event_list.push_back(new glut_passive_motion_event(x,y));
215 | }
216 | virtual void reshape(int w, int h)
217 | {
218 | if(enabled && RECORD == mode && ! paused)
219 | event_list.push_back(new glut_reshape_event(w,h));
220 | }
221 | virtual void special(int key, int x, int y)
222 | {
223 | if(enabled)
224 | {
225 | if (key == GLUT_KEY_F6)
226 | { mode = RECORD; glut_event_processed(); erase(); }
227 | else if(key == GLUT_KEY_F7)
228 | { mode = PLAY; glut_event_processed(); glutPostRedisplay(); }
229 | else if(key == GLUT_KEY_F8)
230 | { mode = STOP; glut_event_processed(); }
231 | else if(key == GLUT_KEY_F9)
232 | { paused = !paused; glut_event_processed(); glutPostRedisplay(); }
233 | else if(RECORD == mode)
234 | { event_list.push_back(new glut_special_event(key,x,y)); }
235 | }
236 | }
237 | virtual void timer(int value)
238 | {
239 | if(enabled && RECORD == mode && ! paused)
240 | event_list.push_back(new glut_timer_event(value));
241 | }
242 | virtual void visibility(int v)
243 | {
244 | if(enabled && RECORD == mode && ! paused)
245 | event_list.push_back(new glut_visibility_event(v));
246 | }
247 |
248 |
249 | // other methods
250 |
251 | bool playing() { return mode == PLAY; }
252 |
253 | void dispatch_accumulated_events()
254 | {
255 | if(mode == PLAY && ! paused)
256 | {
257 | while(it != event_list.end() && (*it)->type != glut_event::DISPLAY)
258 | {
259 | (*it)->dispatch();
260 | it++;
261 | }
262 | if(it == event_list.end())
263 | {
264 | mode = STOP;
265 | it = event_list.begin();
266 | }
267 | else if ((*it)->type == glut_event::DISPLAY)
268 | {
269 | it++;
270 | }
271 | }
272 | }
273 |
274 | void erase()
275 | {
276 | while(event_list.begin() != event_list.end())
277 | {
278 | glut_event * e = event_list.back();
279 | event_list.pop_back();
280 | delete e;
281 | }
282 | }
283 |
284 | std::list event_list;
285 | std::list::iterator it;
286 | recorder_mode mode;
287 | bool paused;
288 | };
289 |
290 | }
291 |
292 | #endif
293 |
--------------------------------------------------------------------------------
/ZmqPub/glh/glh_extensions.h:
--------------------------------------------------------------------------------
1 | // Comments:
2 | //
3 | // The trick with GLH_EXT_SINGLE_FILE is that you need to have it defined in
4 | // exactly one cpp file because it piggy-backs the function implementations in
5 | // the header. You don't want multiple implementations defined or the linker
6 | // gets mad, but one file must have the implementations in it or the linker
7 | // gets mad for different reasons.
8 | //
9 | // The goal was to avoid having this helper require a separate cpp file. One
10 | // thing you could do is just have a glh_extensions.cpp that did
11 | //
12 | // #define GLH_EXT_SINGLE_FILE
13 | // #include
14 | //
15 | // and make it the only file that ever defines GLH_EXT_SINGLE_FILE.
16 |
17 | #ifndef GLH_EXTENSIONS
18 | #define GLH_EXTENSIONS
19 |
20 | #include
21 | #include
22 | #include
23 |
24 |
25 | #if defined(WIN32)
26 | # include
27 | #endif
28 |
29 | #if _MSC_VER > 1500
30 | # include
31 | #endif
32 |
33 | #ifdef MACOS
34 | #include
35 | #else
36 | #include
37 | #endif
38 |
39 | #ifdef WIN32
40 | # include
41 | #endif
42 |
43 | #define CHECK_MEMORY(ptr) \
44 | if (NULL == ptr) { \
45 | printf("Error allocating memory in file %s, line %d\n", __FILE__, __LINE__); \
46 | exit(-1); \
47 | }
48 |
49 | #ifdef GLH_EXT_SINGLE_FILE
50 | # define GLH_EXTENSIONS_SINGLE_FILE // have to do this because glh_genext.h unsets GLH_EXT_SINGLE_FILE
51 | #endif
52 |
53 | #if (defined(WIN32) || defined(UNIX))
54 | #include "glh_genext.h"
55 | #elif defined(MACOS)
56 | #include
57 | #else
58 | #include
59 | #endif
60 |
61 | #ifdef __cplusplus
62 | extern "C" {
63 | #endif
64 |
65 | #ifdef GLH_EXTENSIONS_SINGLE_FILE
66 | static char *unsupportedExts = NULL;
67 | static char *sysExts = NULL;
68 | #ifndef GL_SHADER_CONSISTENT_NV
69 | #define GL_SHADER_CONSISTENT_NV 0x86DD
70 | #endif
71 | #ifndef GL_TEXTURE_SHADER_NV
72 | #define GL_TEXTURE_SHADER_NV 0x86DE
73 | #endif
74 | #ifndef GL_SHADER_OPERATION_NV
75 | #define GL_SHADER_OPERATION_NV 0x86DF
76 | #endif
77 |
78 | static int ExtensionExists(const char* extName, const char* sysExts)
79 | {
80 | char *padExtName = (char*)malloc(strlen(extName) + 2);
81 | strcat(strcpy(padExtName, extName), " ");
82 |
83 | if (0 == strcmp(extName, "GL_VERSION_1_2")) {
84 | const char *version = (const char*)glGetString(GL_VERSION);
85 | if (strstr(version, "1.0") == version || strstr(version, "1.1") == version) {
86 | return GL_FALSE;
87 | } else {
88 | return GL_TRUE;
89 | }
90 | }
91 | if (0 == strcmp(extName, "GL_VERSION_1_3")) {
92 | const char *version = (const char*)glGetString(GL_VERSION);
93 | if (strstr(version, "1.0") == version ||
94 | strstr(version, "1.1") == version ||
95 | strstr(version, "1.2") == version) {
96 | return GL_FALSE;
97 | } else {
98 | return GL_TRUE;
99 | }
100 | }
101 | if (0 == strcmp(extName, "GL_VERSION_1_4")) {
102 | const char *version = (const char*)glGetString(GL_VERSION);
103 | if (strstr(version, "1.0") == version ||
104 | strstr(version, "1.1") == version ||
105 | strstr(version, "1.2") == version ||
106 | strstr(version, "1.3") == version) {
107 | return GL_FALSE;
108 | } else {
109 | return GL_TRUE;
110 | }
111 | }
112 | if (0 == strcmp(extName, "GL_VERSION_1_5")) {
113 | const char *version = (const char*)glGetString(GL_VERSION);
114 | if (strstr(version, "1.0") == version ||
115 | strstr(version, "1.1") == version ||
116 | strstr(version, "1.2") == version ||
117 | strstr(version, "1.3") == version ||
118 | strstr(version, "1.4") == version) {
119 | return GL_FALSE;
120 | } else {
121 | return GL_TRUE;
122 | }
123 | }
124 | if (strstr(sysExts, padExtName)) {
125 | free(padExtName);
126 | return GL_TRUE;
127 | } else {
128 | free(padExtName);
129 | return GL_FALSE;
130 | }
131 | }
132 |
133 | static const char* EatWhiteSpace(const char *str)
134 | {
135 | for (; *str && (' ' == *str || '\t' == *str || '\n' == *str); str++);
136 | return str;
137 | }
138 |
139 | static const char* EatNonWhiteSpace(const char *str)
140 | {
141 | for (; *str && (' ' != *str && '\t' != *str && '\n' != *str); str++);
142 | return str;
143 | }
144 |
145 | int glh_init_extensions(const char *origReqExts)
146 | {
147 | // Length of requested extensions string
148 | size_t reqExtsLen;
149 | char *reqExts;
150 | // Ptr for individual extensions within reqExts
151 | char *reqExt;
152 | int success = GL_TRUE;
153 | // build space-padded extension string
154 | if (NULL == sysExts) {
155 | const char *extensions = (const char*)glGetString(GL_EXTENSIONS);
156 | size_t sysExtsLen = strlen(extensions);
157 | const char *winsys_extensions = "";
158 | size_t winsysExtsLen = 0;
159 | #if defined(WIN32)
160 | {
161 | PFNWGLGETEXTENSIONSSTRINGARBPROC wglGetExtensionsStringARB = 0;
162 | wglGetExtensionsStringARB = (PFNWGLGETEXTENSIONSSTRINGARBPROC)wglGetProcAddress("wglGetExtensionsStringARB");
163 | if(wglGetExtensionsStringARB)
164 | {
165 | winsys_extensions = wglGetExtensionsStringARB(wglGetCurrentDC());
166 | winsysExtsLen = strlen(winsys_extensions);
167 | }
168 | }
169 | #elif defined(UNIX)
170 | {
171 |
172 | winsys_extensions = glXQueryExtensionsString (glXGetCurrentDisplay(),DefaultScreen(glXGetCurrentDisplay())) ;
173 | winsysExtsLen = strlen (winsys_extensions);
174 | }
175 | #endif
176 | // Add 2 bytes, one for padding space, one for terminating NULL
177 | sysExts = (char*)malloc(sysExtsLen + winsysExtsLen + 3);
178 | CHECK_MEMORY(sysExts);
179 | strcpy(sysExts, extensions);
180 | sysExts[sysExtsLen] = ' ';
181 | sysExts[sysExtsLen + 1] = 0;
182 | strcat(sysExts, winsys_extensions);
183 | sysExts[sysExtsLen + 1 + winsysExtsLen] = ' ';
184 | sysExts[sysExtsLen + 1 + winsysExtsLen + 1] = 0;
185 | }
186 |
187 | if (NULL == origReqExts)
188 | return GL_TRUE;
189 | reqExts = strdup(origReqExts);
190 | reqExtsLen = strlen(reqExts);
191 | if (NULL == unsupportedExts) {
192 | unsupportedExts = (char*)malloc(reqExtsLen + 2);
193 | } else if (reqExtsLen > strlen(unsupportedExts)) {
194 | unsupportedExts = (char*)realloc(unsupportedExts, reqExtsLen + 2);
195 | }
196 | CHECK_MEMORY(unsupportedExts);
197 | *unsupportedExts = 0;
198 |
199 | // Parse requested extension list
200 | for (reqExt = reqExts;
201 | (reqExt = (char*)EatWhiteSpace(reqExt)) && *reqExt;
202 | reqExt = (char*)EatNonWhiteSpace(reqExt))
203 | {
204 | char *extEnd = (char*)EatNonWhiteSpace(reqExt);
205 | char saveChar = *extEnd;
206 | *extEnd = (char)0;
207 |
208 | #if (defined(WIN32) || defined(UNIX))
209 | if (!ExtensionExists(reqExt, sysExts) || !glh_init_extension(reqExt)) {
210 | #elif defined(MACOS)
211 | if (!ExtensionExists(reqExt, sysExts)) { // don't try to get function pointers if on MacOS
212 | #endif
213 | // add reqExt to end of unsupportedExts
214 | strcat(unsupportedExts, reqExt);
215 | strcat(unsupportedExts, " ");
216 | success = GL_FALSE;
217 | }
218 | *extEnd = saveChar;
219 | }
220 | free(reqExts);
221 | return success;
222 | }
223 |
224 | const char* glh_get_unsupported_extensions()
225 | {
226 | return (const char*)unsupportedExts;
227 | }
228 |
229 | void glh_shutdown_extensions()
230 | {
231 | if (unsupportedExts)
232 | {
233 | free(unsupportedExts);
234 | unsupportedExts = NULL;
235 | }
236 | if (sysExts)
237 | {
238 | free(sysExts);
239 | sysExts = NULL;
240 | }
241 | }
242 |
243 | int glh_extension_supported(const char *extension)
244 | {
245 | static const GLubyte *extensions = NULL;
246 | const GLubyte *start;
247 | GLubyte *where, *terminator;
248 |
249 | // Extension names should not have spaces.
250 | where = (GLubyte *) strchr(extension, ' ');
251 | if (where || *extension == '\0')
252 | return 0;
253 |
254 | if (!extensions)
255 | extensions = glGetString(GL_EXTENSIONS);
256 |
257 | // It takes a bit of care to be fool-proof about parsing the
258 | // OpenGL extensions string. Don't be fooled by sub-strings,
259 | // etc.
260 | start = extensions;
261 | for (;;)
262 | {
263 | where = (GLubyte *) strstr((const char *) start, extension);
264 | if (!where)
265 | break;
266 | terminator = where + strlen(extension);
267 | if (where == start || *(where - 1) == ' ')
268 | {
269 | if (*terminator == ' ' || *terminator == '\0')
270 | {
271 | return 1;
272 | }
273 | }
274 | start = terminator;
275 | }
276 | return 0;
277 | }
278 |
279 | #else
280 | int glh_init_extensions(const char *origReqExts);
281 | const char* glh_get_unsupported_extensions();
282 | void glh_shutdown_extensions();
283 | int glh_extension_supported(const char *extension);
284 | #endif /* GLH_EXT_SINGLE_FILE */
285 |
286 | #ifdef __cplusplus
287 | }
288 | #endif
289 |
290 | #endif /* GLH_EXTENSIONS */
291 |
--------------------------------------------------------------------------------
/ZmqPub/glh/glh_cube_map.h:
--------------------------------------------------------------------------------
1 | /*
2 | glh - is a platform-indepenedent C++ OpenGL helper library
3 |
4 |
5 | Copyright (c) 2000 Cass Everitt
6 | Copyright (c) 2000 NVIDIA Corporation
7 | All rights reserved.
8 |
9 | Redistribution and use in source and binary forms, with or
10 | without modification, are permitted provided that the following
11 | conditions are met:
12 |
13 | * Redistributions of source code must retain the above
14 | copyright notice, this list of conditions and the following
15 | disclaimer.
16 |
17 | * Redistributions in binary form must reproduce the above
18 | copyright notice, this list of conditions and the following
19 | disclaimer in the documentation and/or other materials
20 | provided with the distribution.
21 |
22 | * The names of contributors to this software may not be used
23 | to endorse or promote products derived from this software
24 | without specific prior written permission.
25 |
26 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
27 | ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
28 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
29 | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
30 | REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
31 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
32 | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
33 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
34 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
35 | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
36 | ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37 | POSSIBILITY OF SUCH DAMAGE.
38 |
39 |
40 | Cass Everitt - cass@r3.nu
41 | */
42 |
43 | // some helper classes for making
44 | // and using cube maps
45 |
46 | #ifndef GLH_CUBE_MAP_H
47 | #define GLH_CUBE_MAP_H
48 |
49 | #ifdef MACOS
50 | #include
51 | #else
52 | #include
53 | #endif
54 |
55 | #include
56 | #include
57 | #include
58 |
59 | namespace glh
60 | {
61 |
62 | # ifdef GL_ARB_texture_cube_map
63 | # define GLH_CUBE_MAP_POSITIVE_X GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
64 | # define GLH_CUBE_MAP_POSITIVE_Y GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
65 | # define GLH_CUBE_MAP_POSITIVE_Z GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
66 | # define GLH_CUBE_MAP_NEGATIVE_X GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
67 | # define GLH_CUBE_MAP_NEGATIVE_Y GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
68 | # define GLH_CUBE_MAP_NEGATIVE_Z GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
69 | # elif GL_EXT_texture_cube_map
70 | # define GLH_CUBE_MAP_POSITIVE_X GL_TEXTURE_CUBE_MAP_POSITIVE_X_EXT
71 | # define GLH_CUBE_MAP_POSITIVE_Y GL_TEXTURE_CUBE_MAP_POSITIVE_Y_EXT
72 | # define GLH_CUBE_MAP_POSITIVE_Z GL_TEXTURE_CUBE_MAP_POSITIVE_Z_EXT
73 | # define GLH_CUBE_MAP_NEGATIVE_X GL_TEXTURE_CUBE_MAP_NEGATIVE_X_EXT
74 | # define GLH_CUBE_MAP_NEGATIVE_Y GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_EXT
75 | # define GLH_CUBE_MAP_NEGATIVE_Z GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_EXT
76 | # endif
77 |
78 | # if GL_EXT_texture_cube_map || GL_ARB_texture_cube_map
79 | // make a cube map from a functor
80 | template
81 | void make_cube_map(FunctionOfDirection & f, GLenum internal_format,
82 | int size, int level = 0)
83 | {
84 | typedef typename FunctionOfDirection::Type Type;
85 | int components = f.components;
86 | GLenum type = f.type;
87 | GLenum format = f.format;
88 | Type * image = new Type[size*size*components];
89 | Type * ip;
90 |
91 | float offset = .5;
92 | float delta = 1;
93 | float halfsize = size/2.f;
94 | vec3f v;
95 |
96 | // positive x image
97 | {
98 | ip = image;
99 | for(int j = 0; j < size; j++)
100 | {
101 | for(int i=0; i < size; i++)
102 | {
103 | v[2] = -(i*delta + offset - halfsize);
104 | v[1] = -(j*delta + offset - halfsize);
105 | v[0] = halfsize;
106 | v.normalize();
107 | f(v, ip);
108 | ip += components;
109 | }
110 | }
111 | glTexImage2D(GLH_CUBE_MAP_POSITIVE_X,
112 | level, internal_format, size, size, 0, format, type, image);
113 | }
114 | // negative x image
115 | {
116 | ip = image;
117 | for(int j = 0; j < size; j++)
118 | {
119 | for(int i=0; i < size; i++)
120 | {
121 | v[2] = (i*delta + offset - halfsize);
122 | v[1] = -(j*delta + offset - halfsize);
123 | v[0] = -halfsize;
124 | v.normalize();
125 | f(v, ip);
126 | ip += components;
127 | }
128 | }
129 | glTexImage2D(GLH_CUBE_MAP_NEGATIVE_X,
130 | level, internal_format, size, size, 0, format, type, image);
131 | }
132 |
133 | // positive y image
134 | {
135 | ip = image;
136 | for(int j = 0; j < size; j++)
137 | {
138 | for(int i=0; i < size; i++)
139 | {
140 | v[0] = (i*delta + offset - halfsize);
141 | v[2] = (j*delta + offset - halfsize);
142 | v[1] = halfsize;
143 | v.normalize();
144 | f(v, ip);
145 | ip += components;
146 | }
147 | }
148 | glTexImage2D(GLH_CUBE_MAP_POSITIVE_Y,
149 | level, internal_format, size, size, 0, format, type, image);
150 | }
151 | // negative y image
152 | {
153 | ip = image;
154 | for(int j = 0; j < size; j++)
155 | {
156 | for(int i=0; i < size; i++)
157 | {
158 | v[0] = (i*delta + offset - halfsize);
159 | v[2] = -(j*delta + offset - halfsize);
160 | v[1] = -halfsize;
161 | v.normalize();
162 | f(v, ip);
163 | ip += components;
164 | }
165 | }
166 | glTexImage2D(GLH_CUBE_MAP_NEGATIVE_Y,
167 | level, internal_format, size, size, 0, format, type, image);
168 | }
169 |
170 | // positive z image
171 | {
172 | ip = image;
173 | for(int j = 0; j < size; j++)
174 | {
175 | for(int i=0; i < size; i++)
176 | {
177 | v[0] = (i*delta + offset - halfsize);
178 | v[1] = -(j*delta + offset - halfsize);
179 | v[2] = halfsize;
180 | v.normalize();
181 | f(v, ip);
182 | ip += components;
183 | }
184 | }
185 | glTexImage2D(GLH_CUBE_MAP_POSITIVE_Z,
186 | level, internal_format, size, size, 0, format, type, image);
187 | }
188 | // negative z image
189 | {
190 | ip = image;
191 | for(int j = 0; j < size; j++)
192 | {
193 | for(int i=0; i < size; i++)
194 | {
195 | v[0] = -(i*delta + offset - halfsize);
196 | v[1] = -(j*delta + offset - halfsize);
197 | v[2] = -halfsize;
198 | v.normalize();
199 | f(v, ip);
200 | ip += components;
201 | }
202 | }
203 | glTexImage2D(GLH_CUBE_MAP_NEGATIVE_Z,
204 | level, internal_format, size, size, 0, format, type, image);
205 | }
206 | delete [] image;
207 | }
208 | # endif
209 |
210 | struct normalize_vector
211 | {
212 | typedef GLfloat Type;
213 | int components;
214 | GLenum type;
215 | GLenum format;
216 | normalize_vector() : components(3), type(GL_FLOAT), format(GL_RGB) {}
217 |
218 | void operator() (const vec3f & v, Type * t)
219 | {
220 | vec3f v2 = v;
221 | v2 *= .5;
222 | v2 += .5;
223 | t[0] = v2[0];
224 | t[1] = v2[1];
225 | t[2] = v2[2];
226 | }
227 | };
228 |
229 | struct cube_map_unextended
230 | {
231 | cube_map_unextended() :
232 | POSITIVE_X(0), NEGATIVE_X(1),
233 | POSITIVE_Y(2), NEGATIVE_Y(3),
234 | POSITIVE_Z(4), NEGATIVE_Z(5),
235 | lightnum(GL_LIGHT0), angle(90.0)
236 | {}
237 |
238 | // angle is > 90 degrees because we need a border to cull with
239 | void set_angle(GLint width)
240 | { angle = to_degrees((float)atan2(width/2.0f, width/2.0f-1.0f)) * 2.0f; }
241 |
242 |
243 | void cull_for_projection(int i)
244 | {
245 | GLfloat plane[6][4] =
246 | {
247 | { 1, 0, 0, 0 },
248 | {-1, 0, 0, 0 },
249 | { 0, 1, 0, 0 },
250 | { 0,-1, 0, 0 },
251 | { 0, 0, 1, 0 },
252 | { 0, 0,-1, 0 }
253 | };
254 | //glClipPlane(GL_CLIP_PLANE0, plane[i]);
255 | glLightf(GL_LIGHT0, GL_SPOT_CUTOFF, 90);
256 | glLightfv(GL_LIGHT0, GL_SPOT_DIRECTION, plane[i]);
257 | }
258 |
259 | void cull_for_reflection(int i)
260 | {
261 | GLfloat dir[6][4] =
262 | {
263 | { 1, 0, 0, 0 },
264 | {-1, 0, 0, 0 },
265 | { 0, 1, 0, 0 },
266 | { 0,-1, 0, 0 },
267 | { 0, 0, 1, 0 },
268 | { 0, 0,-1, 0 }
269 | };
270 | glLightfv(GL_LIGHT0, GL_POSITION, dir[i]);
271 | }
272 |
273 | matrix4f get_matrix(int cubeface)
274 | {
275 | matrix4f m;
276 | m = perspective((float)angle, 1.0f, 0.5f, 1.5f);
277 | switch(cubeface)
278 | {
279 | case 0:
280 | m *= camera_lookat(vec3f(0,0,0), vec3f( 1, 0, 0), vec3f(0,-1, 0));
281 | return m;
282 | case 1:
283 | m *= camera_lookat(vec3f(0,0,0), vec3f(-1, 0, 0), vec3f(0,-1, 0));
284 | return m;
285 | case 2:
286 | m *= camera_lookat(vec3f(0,0,0), vec3f( 0, 1, 0), vec3f(0, 0, 1));
287 | return m;
288 | case 3:
289 | m *= camera_lookat(vec3f(0,0,0), vec3f( 0,-1, 0), vec3f(0, 0,-1));
290 | return m;
291 | case 4:
292 | m *= camera_lookat(vec3f(0,0,0), vec3f( 0, 0, 1), vec3f(0,-1, 0));
293 | return m;
294 | case 5:
295 | m *= camera_lookat(vec3f(0,0,0), vec3f( 0, 0,-1), vec3f(0,-1, 0));
296 | return m;
297 | default:
298 | return matrix4f();
299 | }
300 | }
301 |
302 | matrix4f get_matrix_inverse(int cubeface)
303 | {
304 | matrix4f m;
305 | switch(cubeface)
306 | {
307 | case 0:
308 | m = object_lookat(vec3f(0,0,0), vec3f( 1, 0, 0), vec3f(0,-1, 0));
309 | break;
310 | case 1:
311 | m = object_lookat(vec3f(0,0,0), vec3f(-1, 0, 0), vec3f(0,-1, 0));
312 | break;
313 | case 2:
314 | m = object_lookat(vec3f(0,0,0), vec3f( 0, 1, 0), vec3f(0, 0, 1));
315 | break;
316 | case 3:
317 | m = object_lookat(vec3f(0,0,0), vec3f( 0,-1, 0), vec3f(0, 0,-1));
318 | break;
319 | case 4:
320 | m = object_lookat(vec3f(0,0,0), vec3f( 0, 0, 1), vec3f(0,-1, 0));
321 | break;
322 | case 5:
323 | m = object_lookat(vec3f(0,0,0), vec3f( 0, 0,-1), vec3f(0,-1, 0));
324 | break;
325 | default:
326 | break;
327 | }
328 | return m * perspective_inverse((float)angle, 1.0f, 0.5f, 1.5f);
329 | }
330 | const int POSITIVE_X;
331 | const int NEGATIVE_X;
332 | const int POSITIVE_Y;
333 | const int NEGATIVE_Y;
334 | const int POSITIVE_Z;
335 | const int NEGATIVE_Z;
336 |
337 | GLenum lightnum;
338 | tex_object_2D face[6];
339 | double angle;
340 |
341 | matrix4f rotation;
342 |
343 | };
344 |
345 | } // namespace glh
346 | #endif
347 |
348 |
--------------------------------------------------------------------------------
/DimletController/main-DimletController.cpp:
--------------------------------------------------------------------------------
1 | /*****************************************************************************
2 | * *
3 | * OpenNI 1.0 Alpha *
4 | * Copyright (C) 2010 PrimeSense Ltd. *
5 | * *
6 | * This file is part of OpenNI. *
7 | * *
8 | * OpenNI is free software: you can redistribute it and/or modify *
9 | * it under the terms of the GNU Lesser General Public License as published *
10 | * by the Free Software Foundation, either version 3 of the License, or *
11 | * (at your option) any later version. *
12 | * *
13 | * OpenNI is distributed in the hope that it will be useful, *
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16 | * GNU Lesser General Public License for more details. *
17 | * *
18 | * You should have received a copy of the GNU Lesser General Public License *
19 | * along with OpenNI. If not, see . *
20 | * *
21 | *****************************************************************************/
22 |
23 | //---------------------------------------------------------------------------
24 | // Includes
25 | //---------------------------------------------------------------------------
26 | #include
27 | #include
28 | #include
29 | #include "SceneDrawer.h"
30 | #include "SendUDP.h"
31 | #include "Shared.h"
32 |
33 | //---------------------------------------------------------------------------
34 | // Globals
35 | //---------------------------------------------------------------------------
36 | xn::Context g_Context;
37 | xn::DepthGenerator g_DepthGenerator;
38 | xn::UserGenerator g_UserGenerator;
39 |
40 | XnBool g_bNeedPose = FALSE;
41 | XnChar g_strPose[20] = "";
42 | XnBool g_bDrawBackground = TRUE;
43 | XnBool g_bDrawPixels = TRUE;
44 | XnBool g_bDrawSkeleton = TRUE;
45 | XnBool g_bPrintID = TRUE;
46 | XnBool g_bPrintState = TRUE;
47 |
48 | #if (XN_PLATFORM == XN_PLATFORM_MACOSX)
49 | #include
50 | #else
51 | #include
52 | #endif
53 |
54 | #define GL_WIN_SIZE_X 720
55 | #define GL_WIN_SIZE_Y 480
56 |
57 | XnBool g_bPause = false;
58 | XnBool g_bRecord = false;
59 |
60 | XnBool g_bQuit = false;
61 |
62 | //---------------------------------------------------------------------------
63 | // Code
64 | //---------------------------------------------------------------------------
65 |
66 | void CleanupExit()
67 | {
68 | g_Context.Shutdown();
69 |
70 | exit (1);
71 | }
72 |
73 | // Callback: New user was detected
74 | void XN_CALLBACK_TYPE User_NewUser(xn::UserGenerator& generator, XnUserID nId, void* pCookie)
75 | {
76 | printf("New User %d\n", nId);
77 | // New user found
78 | if (g_bNeedPose)
79 | {
80 | g_UserGenerator.GetPoseDetectionCap().StartPoseDetection(g_strPose, nId);
81 | }
82 | else
83 | {
84 | g_UserGenerator.GetSkeletonCap().RequestCalibration(nId, TRUE);
85 | }
86 | }
87 | // Callback: An existing user was lost
88 | void XN_CALLBACK_TYPE User_LostUser(xn::UserGenerator& generator, XnUserID nId, void* pCookie)
89 | {
90 | printf("Lost user %d\n", nId);
91 | }
92 | // Callback: Detected a pose
93 | void XN_CALLBACK_TYPE UserPose_PoseDetected(xn::PoseDetectionCapability& capability, const XnChar* strPose, XnUserID nId, void* pCookie)
94 | {
95 | printf("Pose %s detected for user %d\n", strPose, nId);
96 | g_UserGenerator.GetPoseDetectionCap().StopPoseDetection(nId);
97 | g_UserGenerator.GetSkeletonCap().RequestCalibration(nId, TRUE);
98 | }
99 | // Callback: Started calibration
100 | void XN_CALLBACK_TYPE UserCalibration_CalibrationStart(xn::SkeletonCapability& capability, XnUserID nId, void* pCookie)
101 | {
102 | printf("Calibration started for user %d\n", nId);
103 | }
104 | // Callback: Finished calibration
105 | void XN_CALLBACK_TYPE UserCalibration_CalibrationEnd(xn::SkeletonCapability& capability, XnUserID nId, XnBool bSuccess, void* pCookie)
106 | {
107 | if (bSuccess)
108 | {
109 | // Calibration succeeded
110 | printf("Calibration complete, start tracking user %d\n", nId);
111 | g_UserGenerator.GetSkeletonCap().StartTracking(nId);
112 | }
113 | else
114 | {
115 | // Calibration failed
116 | printf("Calibration failed for user %d\n", nId);
117 | if (g_bNeedPose)
118 | {
119 | g_UserGenerator.GetPoseDetectionCap().StartPoseDetection(g_strPose, nId);
120 | }
121 | else
122 | {
123 | g_UserGenerator.GetSkeletonCap().RequestCalibration(nId, TRUE);
124 | }
125 | }
126 | }
127 |
128 | unsigned char Charify(float toChar)
129 | {
130 | int value = (int) toChar;
131 | if (value > 255) {value = 255;}
132 | if (value < 0) {value = 0;}
133 | return value = (unsigned char) value;
134 | }
135 |
136 | void SendCommandToLights(float light1, float light2, float light3, float light4)
137 | {
138 | // Send the accelerometer data
139 | // We do all the mathematics at this end so there is less to send
140 | unsigned char message[5];
141 |
142 | //DMX protocol starts with 0. I'm not calling this DMX yet, but maybe working
143 | //that way
144 | message[0] = 0;
145 | message[1] = Charify(light1 * 255);
146 | message[2] = Charify(light2 * 255);
147 | message[3] = Charify(light3 * 255);
148 | message[4] = Charify(light4 * 255);
149 | printf("Sending command %d %d %d %d\n", message[0], message[1], message[2], message[3]);
150 | SUDP_SendMsg((char*)message,5);
151 | }
152 |
153 | void ControlLightsWithHands(XnUserID player) {
154 | int min = -300;
155 | int max = 700;
156 | XnSkeletonJoint eJoint1 = XN_SKEL_LEFT_HAND;
157 | XnSkeletonJoint eJoint2 = XN_SKEL_RIGHT_HAND;
158 |
159 | if (!g_UserGenerator.GetSkeletonCap().IsTracking(player))
160 | {
161 | printf("not tracked!\n");
162 | return;
163 | }
164 |
165 | XnSkeletonJointPosition joint1, joint2;
166 | // Looks like this is how you get the skeleton position for the player
167 | g_UserGenerator.GetSkeletonCap().GetSkeletonJointPosition(player, eJoint1, joint1);
168 | g_UserGenerator.GetSkeletonCap().GetSkeletonJointPosition(player, eJoint2, joint2);
169 |
170 | if (joint1.fConfidence < 0.5 || joint2.fConfidence < 0.5)
171 | {
172 | return;
173 | }
174 |
175 | XnPoint3D pt[2];
176 | pt[0] = joint1.position;
177 | pt[1] = joint2.position;
178 |
179 | float output0 = (pt[0].Y - min) / (max - min);
180 | float output1 = (pt[1].Y - min) / (max - min);
181 | // printf("Circuit 1: %0.1f Circuit2 : %0.1f\n", output0, output1);
182 | SendCommandToLights(output0, output1, 0, 0);
183 | }
184 |
185 | // this function is called each frame
186 | void glutDisplay (void)
187 | {
188 |
189 | glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
190 |
191 | // Setup the OpenGL viewpoint
192 | glMatrixMode(GL_PROJECTION);
193 | glPushMatrix();
194 | glLoadIdentity();
195 |
196 | xn::SceneMetaData sceneMD;
197 | xn::DepthMetaData depthMD;
198 | g_DepthGenerator.GetMetaData(depthMD);
199 | glOrtho(0, depthMD.XRes(), depthMD.YRes(), 0, -1.0, 1.0);
200 |
201 | glDisable(GL_TEXTURE_2D);
202 |
203 | if (!g_bPause)
204 | {
205 | // Read next available data
206 | g_Context.WaitAndUpdateAll();
207 | }
208 |
209 | // Process the data
210 | g_DepthGenerator.GetMetaData(depthMD);
211 | g_UserGenerator.GetUserPixels(0, sceneMD);
212 | DrawDepthMap(depthMD, sceneMD);
213 |
214 | glutSwapBuffers();
215 |
216 | XnUserID trackingUser = FirstTrackingUser(g_UserGenerator);
217 | ControlLightsWithHands(trackingUser);
218 | }
219 |
220 | void glutIdle (void)
221 | {
222 | if (g_bQuit) {
223 | CleanupExit();
224 | }
225 |
226 | // Display the frame
227 | glutPostRedisplay();
228 | }
229 |
230 | void glutKeyboard (unsigned char key, int x, int y)
231 | {
232 | switch (key)
233 | {
234 | case 27:
235 | CleanupExit();
236 | case 'b':
237 | // Draw background?
238 | g_bDrawBackground = !g_bDrawBackground;
239 | break;
240 | case 'x':
241 | // Draw pixels at all?
242 | g_bDrawPixels = !g_bDrawPixels;
243 | break;
244 | case 's':
245 | // Draw Skeleton?
246 | g_bDrawSkeleton = !g_bDrawSkeleton;
247 | break;
248 | case 'i':
249 | // Print label?
250 | g_bPrintID = !g_bPrintID;
251 | break;
252 | case 'l':
253 | // Print ID & state as label, or only ID?
254 | g_bPrintState = !g_bPrintState;
255 | break;
256 | case'p':
257 | g_bPause = !g_bPause;
258 | break;
259 | }
260 | }
261 | void glInit (int * pargc, char ** argv)
262 | {
263 | glutInit(pargc, argv);
264 | glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
265 | glutInitWindowSize(GL_WIN_SIZE_X, GL_WIN_SIZE_Y);
266 | glutCreateWindow ("Prime Sense User Tracker Viewer");
267 | //glutFullScreen();
268 | glutSetCursor(GLUT_CURSOR_NONE);
269 |
270 | glutKeyboardFunc(glutKeyboard);
271 | glutDisplayFunc(glutDisplay);
272 | glutIdleFunc(glutIdle);
273 |
274 | glDisable(GL_DEPTH_TEST);
275 | glEnable(GL_TEXTURE_2D);
276 |
277 | glEnableClientState(GL_VERTEX_ARRAY);
278 | glDisableClientState(GL_COLOR_ARRAY);
279 | }
280 |
281 | #define SAMPLE_XML_PATH "./SamplesConfig.xml"
282 |
283 | #define CHECK_RC(nRetVal, what) \
284 | if (nRetVal != XN_STATUS_OK) \
285 | { \
286 | printf("%s failed: %s\n", what, xnGetStatusString(nRetVal));\
287 | return nRetVal; \
288 | }
289 |
290 | int main(int argc, char **argv)
291 | {
292 | XnStatus nRetVal = XN_STATUS_OK;
293 |
294 | if (argc > 1)
295 | {
296 | nRetVal = g_Context.Init();
297 | CHECK_RC(nRetVal, "Init");
298 | nRetVal = g_Context.OpenFileRecording(argv[1]);
299 | if (nRetVal != XN_STATUS_OK)
300 | {
301 | printf("Can't open recording %s: %s\n", argv[1], xnGetStatusString(nRetVal));
302 | return 1;
303 | }
304 | }
305 | else
306 | {
307 | xn::EnumerationErrors errors;
308 | nRetVal = g_Context.InitFromXmlFile(SAMPLE_XML_PATH, &errors);
309 | if (nRetVal == XN_STATUS_NO_NODE_PRESENT)
310 | {
311 | XnChar strError[1024];
312 | errors.ToString(strError, 1024);
313 | printf("%s\n", strError);
314 | return (nRetVal);
315 | }
316 | else if (nRetVal != XN_STATUS_OK)
317 | {
318 | printf("Open failed: %s\n", xnGetStatusString(nRetVal));
319 | return (nRetVal);
320 | }
321 | }
322 |
323 | nRetVal = g_Context.FindExistingNode(XN_NODE_TYPE_DEPTH, g_DepthGenerator);
324 | CHECK_RC(nRetVal, "Find depth generator");
325 | nRetVal = g_Context.FindExistingNode(XN_NODE_TYPE_USER, g_UserGenerator);
326 | if (nRetVal != XN_STATUS_OK)
327 | {
328 | nRetVal = g_UserGenerator.Create(g_Context);
329 | CHECK_RC(nRetVal, "Find user generator");
330 | }
331 |
332 | XnCallbackHandle hUserCallbacks, hCalibrationCallbacks, hPoseCallbacks;
333 | if (!g_UserGenerator.IsCapabilitySupported(XN_CAPABILITY_SKELETON))
334 | {
335 | printf("Supplied user generator doesn't support skeleton\n");
336 | return 1;
337 | }
338 | g_UserGenerator.RegisterUserCallbacks(User_NewUser, User_LostUser, NULL, hUserCallbacks);
339 | g_UserGenerator.GetSkeletonCap().RegisterCalibrationCallbacks(UserCalibration_CalibrationStart, UserCalibration_CalibrationEnd, NULL, hCalibrationCallbacks);
340 |
341 | if (g_UserGenerator.GetSkeletonCap().NeedPoseForCalibration())
342 | {
343 | g_bNeedPose = TRUE;
344 | if (!g_UserGenerator.IsCapabilitySupported(XN_CAPABILITY_POSE_DETECTION))
345 | {
346 | printf("Pose required, but not supported\n");
347 | return 1;
348 | }
349 | g_UserGenerator.GetPoseDetectionCap().RegisterToPoseCallbacks(UserPose_PoseDetected, NULL, NULL, hPoseCallbacks);
350 | g_UserGenerator.GetSkeletonCap().GetCalibrationPose(g_strPose);
351 | }
352 |
353 | g_UserGenerator.GetSkeletonCap().SetSkeletonProfile(XN_SKEL_PROFILE_ALL);
354 |
355 | nRetVal = g_Context.StartGeneratingAll();
356 | CHECK_RC(nRetVal, "StartGenerating");
357 |
358 | glInit(&argc, argv);
359 | SUDP_Init("192.168.1.20");
360 | SendCommandToLights(0, 0, 0, 0);
361 | glutMainLoop();
362 |
363 | }
364 |
--------------------------------------------------------------------------------
/GMod/Zmq/BasicZmq/include/ILuaInterface.h:
--------------------------------------------------------------------------------
1 | //=============================================================================//
2 | // ___ ___ _ _ _ __ _ ___ ___ __ __
3 | // |_ _|| __| / \ | \_/ | / _| / \ | o \ o \\ V /
4 | // | | | _| | o || \_/ | ( |_n| o || / / \ /
5 | // |_| |___||_n_||_| |_| \__/|_n_||_|\\_|\\ |_| 2008
6 | //
7 | //=============================================================================//
8 |
9 | #ifndef NO_SDK
10 | #include "tier1/utlvector.h"
11 | #endif
12 |
13 | #if defined(UNICODE) && defined(_WIN32)
14 | #undef GetObject
15 | #endif
16 |
17 | #ifndef ILUAINTERFACE_H
18 | #define ILUAINTERFACE_H
19 |
20 | #ifdef _WIN32
21 | #pragma once
22 | #endif
23 |
24 | // Forward Definitions
25 | class ILuaObject;
26 | class ILuaModuleManager;
27 | struct lua_State;
28 |
29 | // This struct is used to get a Lua table from Lua to C++
30 | struct LuaKeyValue
31 | {
32 | ILuaObject* pKey;
33 | ILuaObject* pValue;
34 | };
35 |
36 | #ifndef NO_SDK
37 | typedef CUtlVector CUtlLuaVector;
38 | #endif
39 |
40 | typedef void (*VoidFunction) ( void );
41 | typedef int (*CLuaFunction) (lua_State*);
42 |
43 | // REDUNDANT. But removing will break backwards compatibility.
44 | class LArgList;
45 |
46 | namespace GLua
47 | {
48 | enum
49 | {
50 | TYPE_INVALID = -1,
51 | TYPE_NIL,
52 | TYPE_STRING,
53 | TYPE_NUMBER,
54 | TYPE_TABLE,
55 | TYPE_BOOL,
56 | TYPE_FUNCTION,
57 | TYPE_THREAD,
58 |
59 | // UserData
60 | TYPE_ENTITY,
61 | TYPE_VECTOR,
62 | TYPE_ANGLE,
63 | TYPE_PHYSOBJ,
64 | TYPE_SAVE,
65 | TYPE_RESTORE,
66 | TYPE_DAMAGEINFO,
67 | TYPE_EFFECTDATA,
68 | TYPE_MOVEDATA,
69 | TYPE_RECIPIENTFILTER,
70 | TYPE_USERCMD,
71 | TYPE_SCRIPTEDVEHICLE,
72 |
73 | // Client Only
74 | TYPE_MATERIAL,
75 | TYPE_PANEL,
76 | TYPE_PARTICLE,
77 | TYPE_PARTICLEEMITTER,
78 | TYPE_TEXTURE,
79 | TYPE_USERMSG,
80 |
81 | TYPE_CONVAR,
82 | TYPE_IMESH,
83 | TYPE_MATRIX,
84 | TYPE_SOUND,
85 | TYPE_PIXELVISHANDLE,
86 | TYPE_DLIGHT,
87 | TYPE_AISCHEDULE,
88 |
89 | TYPE_HTTPGET,
90 |
91 | TYPE_LIGHTUSERDATA,
92 |
93 | TYPE_COUNT
94 | };
95 | }
96 |
97 | //////////////////////////////////////////////////////////////////////////
98 | // Name: ILuaCallback
99 | //////////////////////////////////////////////////////////////////////////
100 | class ILuaCallback
101 | {
102 | public:
103 |
104 | virtual ILuaObject* CreateLuaObject() = 0;
105 | virtual void DestroyLuaObject( ILuaObject* pObject) = 0;
106 |
107 | virtual void ErrorPrint( const char* strError ) = 0;
108 | virtual void Msg( const char* strMsg ) = 0;
109 |
110 | virtual bool CanRunScript( const char* strFilename, unsigned long CRC ) = 0;
111 | virtual void onRunScript( const char* strFilename, bool bRun, const char* strScriptContents ) = 0;
112 | };
113 |
114 |
115 | //////////////////////////////////////////////////////////////////////////
116 | // Name: ILuaInterface001
117 | //////////////////////////////////////////////////////////////////////////
118 | class ILuaInterface001
119 | {
120 | public:
121 |
122 | virtual int GetIRef( void ) = 0;
123 | virtual bool Init( void ) = 0;
124 |
125 | virtual void Shutdown( void ) = 0;
126 | virtual void Cycle( void ) = 0;
127 | virtual void* GetLuaState() = 0;
128 |
129 | // Stack
130 | virtual void Pop( int i=1 ) = 0;
131 |
132 | // Get
133 | virtual void GetGlobal( ILuaObject* obj, const char* name ) = 0;
134 | virtual ILuaObject* GetGlobal( const char* name ) = 0;
135 |
136 | virtual ILuaObject* GetObject( int i = -1 ) = 0;
137 | virtual const char* GetString( int i = -1 ) = 0;
138 | virtual int GetInteger( int i = -1 ) = 0;
139 | virtual float GetNumber( int i = -1 ) = 0;
140 | virtual bool GetBool( int i = -1 ) = 0;
141 |
142 | virtual void** GetUserDataPtr( int i = -1 ) = 0;
143 | virtual void* GetUserData( int i = -1 ) = 0;
144 |
145 |
146 | virtual void GetTable( int i = -1 ) = 0;
147 |
148 | // References
149 | virtual int GetReference( int i = -1, bool bPopValue = false ) = 0;
150 | virtual void FreeReference( int i ) = 0;
151 | virtual void PushReference( int i ) = 0;
152 |
153 | // Push
154 | virtual void Push( ILuaObject* ) = 0;
155 | virtual void Push( const char* str ) = 0;
156 | virtual void PushVA( const char* str, ... ) = 0;
157 | virtual void Push( float f ) = 0;
158 | virtual void Push( bool b ) = 0;
159 | virtual void Push( CLuaFunction f ) = 0;
160 |
161 | virtual void SetGlobal( const char* namename, ILuaObject* obj = 0 ) = 0;
162 | virtual void SetGlobal( const char* namename, bool b ) = 0;
163 | virtual void SetGlobal( const char* namename, float f ) = 0;
164 | virtual void SetGlobal( const char* namename, const char* s ) = 0;
165 | virtual void SetGlobal( const char* namename, CLuaFunction f ) = 0;
166 | virtual void NewTable( void ) = 0;
167 |
168 | virtual void LuaError( const char*, int argument = -1 ) = 0;
169 | virtual void TypeError( const char* name, int argument ) = 0;
170 | virtual int GetType( int iStackPos ) = 0;
171 | virtual const char* GetTypeName( int iType ) = 0;
172 |
173 | virtual bool Call( int args, int returns = 0 ) = 0;
174 | virtual bool Call( ILuaObject* func, LArgList* in, LArgList* out = 0 ) = 0;
175 | virtual bool Call( ILuaObject* func, LArgList* in, ILuaObject* member ) = 0;
176 |
177 | virtual void SetMember( ILuaObject* table, const char* name ) = 0;
178 | virtual void SetMember( ILuaObject* table, const char* namename, ILuaObject* member ) = 0;
179 |
180 | virtual int Top( void ) = 0;
181 |
182 | virtual ILuaObject* NewUserData( ILuaObject* obj ) = 0;
183 | virtual void PushUserData( ILuaObject* metatable, void * v ) = 0;
184 |
185 | virtual void NewGlobalTable( const char* ) = 0;
186 | virtual ILuaObject* NewTemporaryObject( void ) = 0;
187 |
188 | virtual bool isUserData( int i = -1 ) = 0;
189 |
190 | // GetMetaTable creates the meta table if it doesn't exist. Make sure type is unique to your
191 | // meta type. The default types are defined above (TYPE_INVALID etc). You should ideally make your type
192 | // some random large number that is in the 1000's - to be sure that it won't conflict with the base
193 | // meta types when more are added at a later date. Name isn't so important - it's just used for GetTypeName
194 | // and in Lua using type().
195 | virtual ILuaObject* GetMetaTable( const char* strName, int Type ) = 0;
196 | virtual ILuaObject* GetMetaTable( int i ) = 0; // Returns the metatable of an object on the stack
197 | virtual void SetMetaTable( ILuaObject* obj, ILuaObject* metatable ) = 0;
198 | virtual void CheckType( int i, int iType ) = 0;
199 |
200 | virtual ILuaObject* GetReturn( int iNum ) = 0;
201 |
202 | // Added 10th December 2006
203 | virtual bool IsServer( void ) = 0;
204 | virtual bool IsClient( void ) = 0;
205 | virtual bool IsDedicatedServer( void ) = 0;
206 |
207 | // Added 20th December 2006
208 | virtual void SetMember( ILuaObject* table, float name ) = 0;
209 | virtual void SetMember( ILuaObject* table, float namename, ILuaObject* member ) = 0;
210 |
211 | // Added 30th December 2006
212 | virtual ILuaObject* GetNewTable( void ) = 0; // Makes a new table and returns it
213 |
214 | // Added 09/Jan/2007
215 | virtual void SetMember( ILuaObject* table, ILuaObject* key, ILuaObject* value ) = 0;
216 |
217 | // Added 12/01/2007
218 | virtual void DebugPoint( void ) = 0;
219 | };
220 |
221 |
222 | //////////////////////////////////////////////////////////////////////////
223 | // Name: ILuaInterface
224 | //////////////////////////////////////////////////////////////////////////
225 | class ILuaInterface002 : public ILuaInterface001
226 | {
227 | public:
228 |
229 | // See IModuleManager.h
230 | virtual ILuaModuleManager* GetModuleManager( void ) = 0;
231 |
232 | // Set whether this is serverside, which prevents things like filename translating
233 | virtual void SetIsServer( bool b ) = 0;
234 |
235 | // Pushes a LONG (CRCs etc)
236 | virtual void PushLong( long f ) = 0;
237 | // Pushes value on stack to the top of the stack
238 | virtual void PushValue( int i ) = 0;
239 | // Pushes a nil onto the stack
240 | virtual void PushNil( void ) = 0;
241 | // Returns a number. Item at stackpos can be a table, in which case all the
242 | // numbers in the table will be |'d together to make the flag
243 | virtual int GetFlags( int iStackPos ) = 0;
244 |
245 | // Quickly searches metatable of iObject for members iKey
246 | virtual bool FindOnObjectsMetaTable( int iObject, int iKey ) = 0;
247 | // Quickly searches table using item on stack
248 | virtual bool FindObjectOnTable( int iTable, int iKey ) = 0;
249 | // Quickly sets table member using items on the stack
250 | virtual void SetMemberFast( ILuaObject* table, int iKey, int iValue ) = 0;
251 |
252 | // If bRun is false the string is converted to a function, which is left on top of the stack.
253 | virtual bool RunString( const char* strFilename, const char* strPath, const char* strStringToRun, bool bRun, bool bShowErrors ) = 0;
254 |
255 | // Returns true if the objects are equal. May call metatables.
256 | virtual bool IsEqual( ILuaObject* pObjectA, ILuaObject* pObjectB ) = 0;
257 |
258 | // Throws an error. Interrupts execution.
259 | virtual void Error( const char* strError ) = 0;
260 |
261 | // Throws a type error if the string is NULL..
262 | virtual const char* GetStringOrError( int i ) = 0;
263 |
264 |
265 | // C++ equivilent of 'require'
266 | virtual bool RunModule( const char* strName ) = 0;
267 |
268 | // Finds and runs a script.
269 | // If bRun is false, the script isn't run, but the 'function' block is left on the stack, ready to be run
270 | // Returns false if run was not successful
271 | virtual bool FindAndRunScript( const char* strFilename, bool bRun, bool bReportErrors ) = 0;
272 |
273 | // Internal use. Sets the search path ID to load Lua from.
274 | virtual void SetPathID( const char* ) = 0;
275 | virtual const char* GetPathID( void ) = 0;
276 |
277 | // Errors in the console without actually stopping the code from running
278 | virtual void ErrorNoHalt( const char* fmt, ... ) = 0;
279 |
280 | // Returns the Lua string length of string on stack. Lua strings can have NULLs.
281 | virtual int StringLength( int i ) = 0;
282 |
283 | // Simply sets the named global to nil
284 | virtual void RemoveGlobal( const char* strName ) = 0;
285 |
286 | // How many items are there on the stack
287 | virtual int GetStackTop( void ) = 0;
288 |
289 | // Gets the members from table on stack
290 | // Note: You MUST free the result when you're done using DeleteLuaVector.
291 | #ifndef NO_SDK
292 | virtual CUtlLuaVector* GetAllTableMembers( int iTable ) = 0;
293 | virtual void DeleteLuaVector( CUtlLuaVector* pVector ) = 0;
294 | #else
295 | virtual void* GetAllTableMembers( int iTable ) = 0;
296 | virtual void DeleteLuaVector( void* pVector ) = 0;
297 | #endif
298 | // Simple Lua Msg. Is redirected to the ILuaCallback class, which
299 | // will display the text differently depending on which Lua instrance you're using.
300 | virtual void Msg( const char* fmt, ... ) = 0;
301 |
302 | // Used to push the path of the current folder onto a stack.
303 | // This allows us to load files relative to that folder.
304 | virtual void PushPath( const char* strPath ) = 0;
305 | virtual void PopPath( void ) = 0;
306 | virtual const char* GetPath( void ) = 0;
307 |
308 | // Used by the Lua file loading logic to determine whether it should
309 | // try to use downloaded files or just the regular ones.
310 | virtual bool ShouldTranslateLuaNames() = 0;
311 | virtual void SetShouldTranslateLuaNames( bool bTranslate ) = 0;
312 |
313 | // Push/Get a simple pointer. Not garbage collected, no metatables.
314 | virtual void PushLightUserData( void* pData ) = 0;
315 | virtual void* GetLightUserData( int i ) = 0;
316 |
317 | };
318 |
319 | //////////////////////////////////////////////////////////////////////////
320 | // Name: ILuaInterface
321 | //////////////////////////////////////////////////////////////////////////
322 | class ILuaInterface : public ILuaInterface002
323 | {
324 | public:
325 |
326 | // Thread safety.
327 | virtual void Lock() = 0;
328 | virtual void UnLock() = 0;
329 |
330 | virtual void SetGlobalDouble( const char* namename, double iValue ) = 0;
331 |
332 | virtual double GetDouble( int iPos ) = 0;
333 | virtual void PushDouble( double iInt ) = 0;
334 |
335 | // ScriptEnforcer "private" methods
336 | };
337 |
338 | #endif // ILUAINTERFACE_H
339 |
--------------------------------------------------------------------------------