Class: CP::Shape::Poly
- Inherits:
-
Object
show all
- Includes:
- CP::Shape
- Defined in:
- lib/chipmunk-ffi/shape.rb,
lib/chipmunk-ffi/unsafe.rb
Instance Attribute Summary
Attributes included from CP::Shape
#struct
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from CP::Shape
#bb, #body, #body=, #cache_bb, #collision_type, #collision_type=, #data, #data=, #e, #e=, #group, #group=, #layers, #layers=, #point_query, reset_id_counter, #segment_query, #sensor=, #sensor?, #set_data_pointer, #surface_v, #surface_v=, #u, #u=
Constructor Details
#initialize(body, verts, offset_vec) ⇒ Poly
Returns a new instance of Poly.
202
203
204
205
206
207
208
209
210
|
# File 'lib/chipmunk-ffi/shape.rb', line 202
def initialize(body, verts, offset_vec)
@body = body
verts = CP::Shape::Poly.make_vertices_valid(verts)
mem_pointer = CP::Shape::Poly.pointer_for_verts(verts)
ptr = CP.cpPolyShapeNew body.struct.pointer, verts.size, mem_pointer, offset_vec.struct
@struct = ShapeStruct.new ptr
set_data_pointer
end
|
Class Method Details
.make_vertices_valid(verts) ⇒ Object
.pointer_for_verts(verts) ⇒ Object
212
213
214
215
216
217
218
219
220
221
222
223
|
# File 'lib/chipmunk-ffi/shape.rb', line 212
def self.pointer_for_verts(verts)
mem_pointer = FFI::MemoryPointer.new Vect, verts.size
vert_structs = verts.collect{|s|s.struct}
size = Vect.size
tmp = mem_pointer
vert_structs.each_with_index {|i, j|
tmp.send(:put_bytes, 0, i.to_bytes, 0, size)
tmp += size unless j == vert_structs.length-1 }
return mem_pointer
end
|
.strictly_valid_vertices?(verts) ⇒ Boolean
225
226
227
228
229
|
# File 'lib/chipmunk-ffi/shape.rb', line 225
def self.strictly_valid_vertices?(verts)
mem_pointer = CP::Shape::Poly.pointer_for_verts(verts)
result = CP.cpPolyValidate(mem_pointer,verts.size)
return (result != 0)
end
|
.valid_vertices?(verts) ⇒ Boolean
Instance Method Details
#verts=(new_verts_and_offset) ⇒ Object
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
# File 'lib/chipmunk-ffi/unsafe.rb', line 31
def verts=(new_verts_and_offset)
new_verts, new_offset = *new_verts_and_offset
new_verts_pointer = FFI::MemoryPointer.new Vect, new_verts.count
size = Vect.size
tmp = new_verts_pointer
new_verts.each_with_index do |vert, i|
tmp.send(:put_bytes, 0, vert.struct.to_bytes, 0, size)
tmp += size unless i == new_verts.length - 1 end
CP.cpPolyShapeSetVerts(@struct.pointer, new_verts.count, new_verts_pointer, new_offset.struct)
end
|