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=)
- #position_func ⇒ Object
- #position_func=(l) ⇒ Object
- #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=)
- #velocity_func ⇒ Object
- #velocity_func=(l) ⇒ Object
- #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 61 62 63 |
# 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 set_data_pointer else raise "wrong number of args for Body, got #{args.size}, but expected 2" end set_default_velocity_lambda set_default_position_lambda 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
123 124 125 |
# File 'lib/chipmunk-ffi/body.rb', line 123 def a @struct.a end |
#a=(pa) ⇒ Object Also known as: angle=
126 127 128 |
# File 'lib/chipmunk-ffi/body.rb', line 126 def a=(pa) CP.cpBodySetAngle(@struct.pointer, pa) end |
#apply_force(f, r) ⇒ Object
184 185 186 |
# File 'lib/chipmunk-ffi/body.rb', line 184 def apply_force(f,r) CP.cpBodyApplyForce(@struct.pointer,f.struct,r.struct) end |
#apply_impulse(j, r) ⇒ Object
188 189 190 |
# File 'lib/chipmunk-ffi/body.rb', line 188 def apply_impulse(j,r) CP.cpBodyApplyImpulse(@struct.pointer,j.struct,r.struct) end |
#f ⇒ Object Also known as: force
113 114 115 |
# File 'lib/chipmunk-ffi/body.rb', line 113 def f Vec2.new @struct.f end |
#f=(pf) ⇒ Object Also known as: force=
116 117 118 119 |
# File 'lib/chipmunk-ffi/body.rb', line 116 def f=(pf) @struct.f.pointer.put_bytes 0, pf.struct.to_bytes, 0,Vect.size self end |
#i ⇒ Object Also known as: moment
79 80 81 |
# File 'lib/chipmunk-ffi/body.rb', line 79 def i @struct.i end |
#i=(pi) ⇒ Object Also known as: moment=
82 83 84 |
# File 'lib/chipmunk-ffi/body.rb', line 82 def i=(pi) CP.cpBodySetMoment(@struct.pointer, pi) end |
#i_inv ⇒ Object Also known as: moment_inv
88 89 90 |
# File 'lib/chipmunk-ffi/body.rb', line 88 def i_inv @struct.i_inv end |
#local2world(v) ⇒ Object
172 173 174 |
# File 'lib/chipmunk-ffi/body.rb', line 172 def local2world(v) Vec2.new CP.cpBodyLocal2World(@struct.pointer,v.struct) end |
#m ⇒ Object Also known as: mass
65 66 67 |
# File 'lib/chipmunk-ffi/body.rb', line 65 def m @struct.m end |
#m=(pm) ⇒ Object Also known as: mass=
68 69 70 |
# File 'lib/chipmunk-ffi/body.rb', line 68 def m=(pm) CP.cpBodySetMass(@struct.pointer, pm) end |
#m_inv ⇒ Object Also known as: mass_inv
74 75 76 |
# File 'lib/chipmunk-ffi/body.rb', line 74 def m_inv @struct.m_inv end |
#p ⇒ Object Also known as: pos
93 94 95 |
# File 'lib/chipmunk-ffi/body.rb', line 93 def p Vec2.new @struct.p end |
#p=(new_p) ⇒ Object Also known as: pos=
96 97 98 99 |
# File 'lib/chipmunk-ffi/body.rb', line 96 def p=(new_p) @struct.p.pointer.put_bytes 0, new_p.struct.to_bytes, 0,Vect.size self end |
#position_func ⇒ Object
217 218 219 |
# File 'lib/chipmunk-ffi/body.rb', line 217 def position_func @user_level_position_lambda end |
#position_func=(l) ⇒ Object
221 222 223 224 225 226 227 228 229 230 231 232 |
# File 'lib/chipmunk-ffi/body.rb', line 221 def position_func=(l) @user_level_position_lambda = l # We keep the lambda in an ivar to keep it from being GCed @body_position_lambda = Proc.new do |body_ptr,dt| body_struct = BodyStruct.new(body_ptr) obj_id = body_struct.data.get_long(0) body = ObjectSpace._id2ref(obj_id) l.call(body,dt) end @struct.position_func = @body_position_lambda end |
#reset_forces ⇒ Object
180 181 182 |
# File 'lib/chipmunk-ffi/body.rb', line 180 def reset_forces CP.cpBodyResetForces(@struct.pointer) end |
#rot ⇒ Object
150 151 152 |
# File 'lib/chipmunk-ffi/body.rb', line 150 def rot Vec2.new @struct.rot end |
#t ⇒ Object Also known as: torque
141 142 143 |
# File 'lib/chipmunk-ffi/body.rb', line 141 def t @struct.t end |
#t=(pt) ⇒ Object Also known as: torque=
144 145 146 |
# File 'lib/chipmunk-ffi/body.rb', line 144 def t=(pt) @struct.t = pt end |
#update_position(dt) ⇒ Object
196 197 198 |
# File 'lib/chipmunk-ffi/body.rb', line 196 def update_position(dt) CP.cpBodyUpdatePosition(@struct.pointer,dt) end |
#update_velocity(g, dmp, dt) ⇒ Object
192 193 194 |
# File 'lib/chipmunk-ffi/body.rb', line 192 def update_velocity(g,dmp,dt) CP.cpBodyUpdateVelocity(@struct.pointer,g.struct,dmp,dt) end |
#v ⇒ Object Also known as: vel
103 104 105 |
# File 'lib/chipmunk-ffi/body.rb', line 103 def v Vec2.new @struct.v end |
#v=(pv) ⇒ Object Also known as: vel=
106 107 108 109 |
# File 'lib/chipmunk-ffi/body.rb', line 106 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
154 155 156 |
# File 'lib/chipmunk-ffi/body.rb', line 154 def v_limit @struct.v_limit end |
#v_limit=(new_v_limit) ⇒ Object Also known as: vel_limit=
157 158 159 |
# File 'lib/chipmunk-ffi/body.rb', line 157 def v_limit=(new_v_limit) @struct.v_limit = new_v_limit end |
#velocity_func ⇒ Object
200 201 202 |
# File 'lib/chipmunk-ffi/body.rb', line 200 def velocity_func @user_level_velocity_lambda end |
#velocity_func=(l) ⇒ Object
204 205 206 207 208 209 210 211 212 213 214 215 |
# File 'lib/chipmunk-ffi/body.rb', line 204 def velocity_func=(l) @user_level_velocity_lambda = l # We keep the lambda in an ivar to keep it from being GCed @body_velocity_lambda = Proc.new do |body_ptr,g,dmp,dt| body_struct = BodyStruct.new(body_ptr) obj_id = body_struct.data.get_long(0) body = ObjectSpace._id2ref(obj_id) l.call(body,g,dmp,dt) end @struct.velocity_func = @body_velocity_lambda end |
#w ⇒ Object Also known as: ang_vel
132 133 134 |
# File 'lib/chipmunk-ffi/body.rb', line 132 def w @struct.w end |
#w=(pw) ⇒ Object Also known as: ang_vel=
135 136 137 |
# File 'lib/chipmunk-ffi/body.rb', line 135 def w=(pw) @struct.w = pw end |
#w_limit ⇒ Object Also known as: ang_vel_limit
163 164 165 |
# File 'lib/chipmunk-ffi/body.rb', line 163 def w_limit @struct.w_limit end |
#w_limit=(new_w_limit) ⇒ Object Also known as: ang_vel_limit=
166 167 168 |
# File 'lib/chipmunk-ffi/body.rb', line 166 def w_limit=(new_w_limit) @struct.w_limit = new_w_limit end |