File: JointDef.cpp

package info (click to toggle)
box2d 2.0.1%2Bdfsg1-1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze, wheezy
  • size: 1,748 kB
  • ctags: 2,143
  • sloc: cpp: 15,308; xml: 1,249; cs: 648; makefile: 338; ansic: 28
file content (178 lines) | stat: -rw-r--r-- 3,103 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
#pragma once

#include "stdafx.h"
#include "Body.cpp"
#include "Vector.cpp"

using namespace System::Runtime::InteropServices;

namespace Box2D
{
	namespace Net
	{
		//TODO: is there a way to automatically include the b2JointType as an enum here?
		public enum class JointType
		{
			e_unknownJoint = ::e_unknownJoint,
			e_revoluteJoint = ::e_revoluteJoint,
			e_prismaticJoint = ::e_prismaticJoint,

			e_distanceJoint = ::e_distanceJoint,
			e_pulleyJoint = ::e_pulleyJoint,
			e_mouseJoint = ::e_mouseJoint,
			e_gearJoint = ::e_gearJoint
		};

		public ref class JointDef
		{
		internal:
			b2JointDef *def;
			JointDef() : def(new b2JointDef()) { }
			JointDef(b2JointDef *justBuilt) : def(justBuilt) { }
			virtual ~JointDef()
			{
				delete def;
			}

		public:
			property JointType Type
			{
				JointType get()
				{
					return (JointType)def->type;
				}

				void set(JointType value)
				{
					def->type = (b2JointType)value;
				}
			}

			property Object^ UserData
			{
				Object^ get()
				{
					return System::Runtime::InteropServices::GCHandle::FromIntPtr((System::IntPtr)def->userData).Target;
				}

				void set(Object^ value)
				{
					GCHandle^ gch = GCHandle::Alloc(value);					
					def->userData = (void *)gch->ToIntPtr(*gch);
				}
			}

			property Body^ Body1
			{
				Body^ get()
				{
					return gcnew Body(def->body1);
				}

				void set(Body^ value)
				{
					def->body1 = value->body;
				}
			}

			property Body^ Body2
			{
				Body^ get()
				{
					return gcnew Body(def->body2);
				}

				void set(Body^ value)
				{
					def->body2 = value->body;
				}
			}

			property bool CollideConnected
			{
				bool get()
				{
					return def->collideConnected;
				}

				void set(bool value)
				{
					def->collideConnected = value;
				}
			}
		};

		public ref class MouseJointDef : public JointDef
		{
		internal:
			b2MouseJointDef *mouseJoint;
		public:
			MouseJointDef() : JointDef(mouseJoint = new b2MouseJointDef()) { }

			property Vector^ Target
			{
				Vector^ get()
				{
					return gcnew Vector(mouseJoint->target);
				}

				void set(Vector^ value)
				{
					mouseJoint->target = value->getVec2();
				}
			}

			property float32 MaxForce
			{
				float32 get()
				{
					return mouseJoint->maxForce;
				}

				void set(float32 value)
				{
					mouseJoint->maxForce = value;
				}
			}

			property float32 FrequencyHz
			{
				float32 get()
				{
					return mouseJoint->frequencyHz;
				}

				void set(float32 value)
				{
					mouseJoint->frequencyHz = value;
				}
			}

			property float32 DampingRatio
			{
				float32 get()
				{
					return mouseJoint->dampingRatio;
				}

				void set(float32 value)
				{
					mouseJoint->dampingRatio = value;
				}
			}

			property float32 TimeStep
			{
				float32 get()
				{
					return mouseJoint->timeStep;
				}

				void set(float32 value)
				{
					mouseJoint->timeStep = value;
				}
			}
		};
	}
}