Ticket #923: Universal.pym

File Universal.pym, 4.2 KB (added by SaraKazemi, 2 years ago)
Line 
1# PySoy joints.Universal 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: Universal.pym 1393 2008-12-31 23:51:25Z ArcRiley $
19
20cdef class Universal (Joint) :
21  '''PySoy Universal Joint
22
23    a universal :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.dJointCreateUniversal(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        '''Universal.addTorque
43       
44        this applies torque to the universal joint
45        '''
46    ode.dJointAddUniversalTorques(self._jointID, torque1, torque2)
47 
48  ############################################################################
49  #
50  # Properties
51  #
52 
53  property position :
54    '''Universal.position
55   
56    this is the current position of the joint's anchor
57    '''
58    def __set__(self, anchor) :
59      ode.dJointSetUniversalAnchor(self._jointID,
60                                   anchor[0], anchor[1], anchor[2])
61    def __get__(self) :
62      cdef ode.dVector3 anchor
63      ode.dJointGetUniversalAnchor(self._jointID, anchor)
64      return (anchor[0], anchor[1], anchor[2])
65 
66  property axis1 :
67    '''Universal.axis1
68
69    this is the first axis of the universal joint
70    '''
71    def __set__(self, axis) :
72      ode.dJointSetUniversalAxis1(self._jointID, axis[0], axis[1], axis[2])
73    def __get__(self) :
74      cdef ode.dVector3 axis
75      ode.dJointGetUniversalAxis1(self._jointID, axis)
76      return (axis[0], axis[1], axis[2])
77
78  property axis2 :
79    '''Universal.axis2
80
81    this is the second axis of the universal joint
82    '''
83    def __set__(self, axis) :
84      ode.dJointSetUniversalAxis2(self._jointID, axis[0], axis[1], axis[2])
85    def __get__(self) :
86      cdef ode.dVector3 axis
87      ode.dJointGetUniversalAxis2(self._jointID, axis)
88      return (axis[0], axis[1], axis[2])
89
90  property angle :
91    '''Universal.angle
92
93    angles of the universal joint
94    '''
95    def __get__(self) :
96      return (ode.dJointGetUniversalAngle1(self._jointID), ode.dJointGetUniversalAngle2(self._jointID))
97
98  property stops :
99    '''Universal.stops
100
101    this is the minimum and maximum angle of the universal joint
102    '''
103    def __set__(self, angle) :
104      ode.dJointSetUniversalParam(self._jointID, ode.dParamLoStop, angle[0])
105      ode.dJointSetUniversalParam(self._jointID, ode.dParamHiStop, angle[1])
106    def __get__(self) :
107      cdef ode.dReal loangle
108      cdef ode.dReal hiangle
109      loangle = ode.dJointGetUniversalParam(self._jointID, ode.dParamLoStop)
110      hiangle = ode.dJointGetUniversalParam(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.dJointSetUniversalParam(self._jointID, ode.dParamLoStop, -ode.dInfinity)
117      ode.dJointSetUniversalParam(self._jointID, ode.dParamHiStop,  ode.dInfinity)
118
119  property bounce :
120    '''Universal.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.dJointSetUniversalParam(self._jointID, ode.dParamBounce, bounce)
128    def __get__(self) :
129      return ode.dJointGetUniversalParam(self._jointID, ode.dParamBounce)
130