Ticket #923: Piston.pym

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