Class: CP::Body
- Inherits:
-
Object
- Object
- CP::Body
- Defined in:
- lib/chipmunk-ffi/body.rb
Instance Attribute Summary collapse
-
#struct ⇒ Object
readonly
Returns the value of attribute struct.
Instance Method Summary collapse
- #a ⇒ Object (also: #angle)
- #a=(pa) ⇒ Object (also: #angle=)
- #apply_force(f, r) ⇒ Object
- #apply_impulse(j, r) ⇒ Object
- #f ⇒ Object (also: #force)
- #f=(pf) ⇒ Object (also: #force=)
- #i ⇒ Object (also: #moment)
- #i=(pi) ⇒ Object (also: #moment=)
- #i_inv ⇒ Object (also: #moment_inv)
-
#initialize(*args) ⇒ Body
constructor
A new instance of Body.
- #local2world(v) ⇒ Object
- #m ⇒ Object (also: #mass)
- #m=(pm) ⇒ Object (also: #mass=)
- #m_inv ⇒ Object (also: #mass_inv)
- #p ⇒ Object (also: #pos)
- #p=(new_p) ⇒ Object (also: #pos=)
- #reset_forces ⇒ Object
- #rot ⇒ Object
- #t ⇒ Object (also: #torque)
- #t=(pt) ⇒ Object (also: #torque=)
- #update_position(dt) ⇒ Object
- #update_velocity(g, dmp, dt) ⇒ Object
- #v ⇒ Object (also: #vel)
- #v=(pv) ⇒ Object (also: #vel=)
- #v_limit ⇒ Object (also: #vel_limit)
- #v_limit=(new_v_limit) ⇒ Object (also: #vel_limit=)
- #w ⇒ Object (also: #ang_vel)
- #w=(pw) ⇒ Object (also: #ang_vel=)
- #w_limit ⇒ Object (also: #ang_vel_limit)
- #w_limit=(new_w_limit) ⇒ Object (also: #ang_vel_limit=)
- #world2local(v) ⇒ Object
Constructor Details
#initialize(*args) ⇒ Body
Returns a new instance of Body.
50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/chipmunk-ffi/body.rb', line 50 def initialize(*args) case args.size when 1 @struct = args.first when 2 ptr = CP.cpBodyNew(*args) @struct = BodyStruct.new ptr else raise "wrong number of args for Body, got #{args.size}, but expected 2" end end |
Instance Attribute Details
#struct ⇒ Object (readonly)
Returns the value of attribute struct.
49 50 51 |
# File 'lib/chipmunk-ffi/body.rb', line 49 def struct @struct end |
Instance Method Details
#a ⇒ Object Also known as: angle
120 121 122 |
# File 'lib/chipmunk-ffi/body.rb', line 120 def a @struct.a end |
#a=(pa) ⇒ Object Also known as: angle=
123 124 125 |
# File 'lib/chipmunk-ffi/body.rb', line 123 def a=(pa) CP.cpBodySetAngle(@struct.pointer, pa) end |
#apply_force(f, r) ⇒ Object
181 182 183 |
# File 'lib/chipmunk-ffi/body.rb', line 181 def apply_force(f,r) CP.cpBodyApplyForce(@struct.pointer,f.struct,r.struct) end |
#apply_impulse(j, r) ⇒ Object
185 186 187 |
# File 'lib/chipmunk-ffi/body.rb', line 185 def apply_impulse(j,r) CP.cpBodyApplyImpulse(@struct.pointer,j.struct,r.struct) end |
#f ⇒ Object Also known as: force
110 111 112 |
# File 'lib/chipmunk-ffi/body.rb', line 110 def f Vec2.new @struct.f end |
#f=(pf) ⇒ Object Also known as: force=
113 114 115 116 |
# File 'lib/chipmunk-ffi/body.rb', line 113 def f=(pf) @struct.f.pointer.put_bytes 0, pf.struct.to_bytes, 0,Vect.size self end |
#i ⇒ Object Also known as: moment
76 77 78 |
# File 'lib/chipmunk-ffi/body.rb', line 76 def i @struct.i end |
#i=(pi) ⇒ Object Also known as: moment=
79 80 81 |
# File 'lib/chipmunk-ffi/body.rb', line 79 def i=(pi) CP.cpBodySetMoment(@struct.pointer, pi) end |
#i_inv ⇒ Object Also known as: moment_inv
85 86 87 |
# File 'lib/chipmunk-ffi/body.rb', line 85 def i_inv @struct.i_inv end |
#local2world(v) ⇒ Object
169 170 171 |
# File 'lib/chipmunk-ffi/body.rb', line 169 def local2world(v) Vec2.new CP.cpBodyLocal2World(@struct.pointer,v.struct) end |
#m ⇒ Object Also known as: mass
62 63 64 |
# File 'lib/chipmunk-ffi/body.rb', line 62 def m @struct.m end |
#m=(pm) ⇒ Object Also known as: mass=
65 66 67 |
# File 'lib/chipmunk-ffi/body.rb', line 65 def m=(pm) CP.cpBodySetMass(@struct.pointer, pm) end |
#m_inv ⇒ Object Also known as: mass_inv
71 72 73 |
# File 'lib/chipmunk-ffi/body.rb', line 71 def m_inv @struct.m_inv end |
#p ⇒ Object Also known as: pos
90 91 92 |
# File 'lib/chipmunk-ffi/body.rb', line 90 def p Vec2.new @struct.p end |
#p=(new_p) ⇒ Object Also known as: pos=
93 94 95 96 |
# File 'lib/chipmunk-ffi/body.rb', line 93 def p=(new_p) @struct.p.pointer.put_bytes 0, new_p.struct.to_bytes, 0,Vect.size self end |
#reset_forces ⇒ Object
177 178 179 |
# File 'lib/chipmunk-ffi/body.rb', line 177 def reset_forces CP.cpBodyResetForces(@struct.pointer) end |
#rot ⇒ Object
147 148 149 |
# File 'lib/chipmunk-ffi/body.rb', line 147 def rot Vec2.new @struct.rot end |
#t ⇒ Object Also known as: torque
138 139 140 |
# File 'lib/chipmunk-ffi/body.rb', line 138 def t @struct.t end |
#t=(pt) ⇒ Object Also known as: torque=
141 142 143 |
# File 'lib/chipmunk-ffi/body.rb', line 141 def t=(pt) @struct.t = pt end |
#update_position(dt) ⇒ Object
193 194 195 |
# File 'lib/chipmunk-ffi/body.rb', line 193 def update_position(dt) CP.cpBodyUpdatePosition(@struct.pointer,dt) end |
#update_velocity(g, dmp, dt) ⇒ Object
189 190 191 |
# File 'lib/chipmunk-ffi/body.rb', line 189 def update_velocity(g,dmp,dt) CP.cpBodyUpdateVelocity(@struct.pointer,g.struct,dmp,dt) end |
#v ⇒ Object Also known as: vel
100 101 102 |
# File 'lib/chipmunk-ffi/body.rb', line 100 def v Vec2.new @struct.v end |
#v=(pv) ⇒ Object Also known as: vel=
103 104 105 106 |
# File 'lib/chipmunk-ffi/body.rb', line 103 def v=(pv) @struct.v.pointer.put_bytes 0, pv.struct.to_bytes, 0,Vect.size self end |
#v_limit ⇒ Object Also known as: vel_limit
151 152 153 |
# File 'lib/chipmunk-ffi/body.rb', line 151 def v_limit @struct.v_limit end |
#v_limit=(new_v_limit) ⇒ Object Also known as: vel_limit=
154 155 156 |
# File 'lib/chipmunk-ffi/body.rb', line 154 def v_limit=(new_v_limit) @struct.v_limit = new_v_limit end |
#w ⇒ Object Also known as: ang_vel
129 130 131 |
# File 'lib/chipmunk-ffi/body.rb', line 129 def w @struct.w end |
#w=(pw) ⇒ Object Also known as: ang_vel=
132 133 134 |
# File 'lib/chipmunk-ffi/body.rb', line 132 def w=(pw) @struct.w = pw end |
#w_limit ⇒ Object Also known as: ang_vel_limit
160 161 162 |
# File 'lib/chipmunk-ffi/body.rb', line 160 def w_limit @struct.w_limit end |
#w_limit=(new_w_limit) ⇒ Object Also known as: ang_vel_limit=
163 164 165 |
# File 'lib/chipmunk-ffi/body.rb', line 163 def w_limit=(new_w_limit) @struct.w_limit = new_w_limit end |