Ticket #923: Hinge2.pym

File Hinge2.pym, 4.1 KB (added by SaraKazemi, 2 years ago)
Line 
1# PySoy joints.Hinge2 Class
2#
3# Copyright (C) 2006,2007,2008,2009 PySoy Group
4#
5#  This program is free software; you can redistribute it and/or modify
6#  it under the terms of the GNU Affero General Public License as published
7#  by the Free Software Foundation, either version 3 of the License, or
8#  (at your option) any later version.
9#
10#  This program is distributed in the hope that it will be useful,
11#  but WITHOUT ANY WARRANTY; without even the implied warranty of
12#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13#  GNU Affero General Public License for more details.
14#
15#  You should have received a copy of the GNU Affero General Public License
16#  along with this program; if not, see http://www.gnu.org/licenses
17#
18# $Id: Hinge2.pym 1393 2008-12-31 23:51:25Z ArcRiley $
19
20cdef class Hinge2 (Joint) :
21  '''PySoy Hinge2 Joint
22
23    a double hinge :class:`~soy.joints.Joint`
24  '''
25
26  ############################################################################
27  #
28  # Python functions
29  #
30 
31  def __init__(self, parent, body1, body2, position, axis1, axis2) :
32    self._scene._stepLock()
33    self._jointID = ode.dJointCreateHinge2(self._scene._worldID, NULL)
34    ode.dJointAttach(self._jointID, self._body1._bodyID, self._body2._bodyID)
35    self.position = position
36    self.axis1 = axis1
37    self.axis2 = axis2
38    self._scene._joints._append(<void*> self)
39    self._scene._stepUnLock()
40
41  def addTorque(self, torque1, torque2) :
42        '''Hinge2.addTorque
43       
44        this is applies torque to the two hinge joints
45        the two hinge joints may have distinct torque values
46        '''
47    ode.dJointAddHinge2Torques(self._jointID, torque1, torque2)
48
49  ############################################################################
50  #
51  # Properties
52  #
53 
54  property position :
55    '''Hinge2.position
56   
57    this is the current position of the joint's anchor
58    '''
59    def __set__(self, anchor) :
60      ode.dJointSetHinge2Anchor(self._jointID, anchor[0], anchor[1], anchor[2])
61    def __get__(self) :
62      cdef ode.dVector3 anchor
63      ode.dJointGetHinge2Anchor(self._jointID, anchor)
64      return (anchor[0], anchor[1], anchor[2])
65 
66  property axis1 :
67    '''Hinge2.axis1
68
69    this is the first axis of the double hinge joint
70    '''
71    def __set__(self, axis) :
72      ode.dJointSetHinge2Axis1(self._jointID, axis[0], axis[1], axis[2])
73    def __get__(self) :
74      cdef ode.dVector3 axis
75      ode.dJointGetHinge2Axis1(self._jointID, axis)
76      return (axis[0], axis[1], axis[2])
77
78  property axis2 :
79    '''Hinge2.axis2
80
81    this is the second axis of the double hinge joint
82    '''
83    def __set__(self, axis) :
84      ode.dJointSetHinge2Axis2(self._jointID, axis[0], axis[1], axis[2])
85    def __get__(self) :
86      cdef ode.dVector3 axis
87      ode.dJointGetHinge2Axis2(self._jointID, axis)
88      return (axis[0], axis[1], axis[2])
89
90  property angle :
91    '''Hinge2.angle
92
93    this is the angle of the hinge
94    '''
95    def __get__(self) :
96      return ode.dJointGetHinge2Angle1(self._jointID)
97
98  property stops :
99    '''Hinge2.stops
100
101    this is the minimum and maximum angle of the hinge
102    '''
103    def __set__(self, angle) :
104      ode.dJointSetHinge2Param(self._jointID, ode.dParamLoStop, angle[0])
105      ode.dJointSetHinge2Param(self._jointID, ode.dParamHiStop, angle[1])
106    def __get__(self) :
107      cdef ode.dReal loangle
108      cdef ode.dReal hiangle
109      loangle = ode.dJointGetHinge2Param(self._jointID, ode.dParamLoStop)
110      hiangle = ode.dJointGetHinge2Param(self._jointID, ode.dParamHiStop)
111      if loangle < -3.1416 or hiangle > 3.1416 :
112        return None
113      else :
114        return (loangle, hiangle)
115    def __del__(self) :
116      ode.dJointSetHinge2Param(self._jointID, ode.dParamLoStop, -ode.dInfinity)
117      ode.dJointSetHinge2Param(self._jointID, ode.dParamHiStop,  ode.dInfinity)
118
119  property bounce :
120    '''Hinge2.bounce
121
122    bounciness of stops, between 0.0 and 1.0
123    '''
124    def __set__(self, bounce) :
125      if bounce < 0.0 or bounce > 1.0 :
126        raise(ValueError('0.0 to 1.0 only'))
127      ode.dJointSetHinge2Param(self._jointID, ode.dParamBounce, bounce)
128    def __get__(self) :
129      return ode.dJointGetHinge2Param(self._jointID, ode.dParamBounce)
130