aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/libraries/ode-0.9/contrib/DotNetManaged/JointHinge.cpp
blob: 85d420bdffc4a14231293eb5de1174c64cc7509c (plain)
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
#include "stdafx.h"

#include <ode/ode.h>
#include "jointhinge.h"

namespace ODEManaged
{

	//Constructors

		JointHinge::JointHinge(void) : Joint(){}


		JointHinge::JointHinge(World &world)
		{
			if(this->_id) dJointDestroy(this->_id);
			_id = dJointCreateHinge(world.Id(), 0);
		}

		
		JointHinge::JointHinge(World &world, JointGroup &jointGroup)
		{
			if(this->_id) dJointDestroy(this->_id);
			_id = dJointCreateHinge(world.Id(), jointGroup.Id());
		}


	//Destructor

		JointHinge::~JointHinge(void){}


	//Methods

		//Overloaded Create 
		void JointHinge::Create(World &world, JointGroup &jointGroup)
		{
			if(this->_id) dJointDestroy(this->_id);
			_id = dJointCreateHinge(world.Id(), jointGroup.Id());
		}

		void JointHinge::Create(World &world)
		{
			if(this->_id) dJointDestroy(this->_id);
			_id = dJointCreateHinge(world.Id(), 0);
		}


		//Overloaded Attach 
		void JointHinge::Attach(Body &body1, Body &body2)
		{
			dJointAttach(this->_id, body1.Id(), body2.Id());
		}

		void JointHinge::Attach(Body &body1)
		{
			dJointAttach(this->_id, body1.Id(), 0);
		}


		//SetAxis
		void JointHinge::SetAxis(double x, double y, double z)
		{
			dJointSetHingeAxis(this->_id, x, y, z);
		}

		//GetAxis
		Vector3 JointHinge::GetAxis(void)
		{
			Vector3 retVal;
			dVector3 temp;
			dJointGetHingeAxis(this->_id, temp);
			retVal.x = temp[0];
			retVal.y = temp[1];
			retVal.z = temp[2];
			return retVal;
		}


		//SetAnchor
		void JointHinge::SetAnchor(double x, double y, double z)
		{
			dJointSetHingeAnchor(this->_id, x, y, z);
		}

		//GetAnchor
		Vector3 JointHinge::GetAnchor(void)
		{
			Vector3 retVal;
			dVector3 temp;
			dJointGetHingeAnchor(this->_id, temp);
			retVal.x = temp[0];
			retVal.y = temp[1];
			retVal.z = temp[2];
			return retVal;
		}


	//Movement Parameters

		//SetAllMovParams
		void JointHinge::SetAllMovParams(double LoStop, double HiStop,
										 double Velocity, double MaxForce,
										 double FudgeFactor, double Bounce,
										 double StopERP, double StopCFM)
		{
			if (LoStop > -3.141592653 && LoStop <= 0) 
				dJointSetHingeParam(this->_id, dParamLoStop, LoStop);

			if (HiStop < 3.141592653 && HiStop >= 0)
				dJointSetHingeParam(this->_id, dParamHiStop, HiStop);

			dJointSetHingeParam(this->_id, dParamVel, Velocity);
			dJointSetHingeParam(this->_id, dParamFMax, MaxForce);
			dJointSetHingeParam(this->_id, dParamFudgeFactor, FudgeFactor);
			dJointSetHingeParam(this->_id, dParamBounce, Bounce);
			dJointSetHingeParam(this->_id, dParamStopERP, StopERP);
			dJointSetHingeParam(this->_id, dParamStopCFM, StopCFM);
		}
				
}