Module: CP::Shape

Included in:
Circle, Poly, Segment
Defined in:
lib/chipmunk-ffi/shape.rb,
lib/chipmunk-ffi/unsafe.rb

Defined Under Namespace

Classes: Circle, Poly, Segment, SegmentQueryInfo

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#structObject (readonly)

Returns the value of attribute struct.



68
69
70
# File 'lib/chipmunk-ffi/shape.rb', line 68

def struct
  @struct
end

Class Method Details

.reset_id_counterObject



161
162
163
# File 'lib/chipmunk-ffi/shape.rb', line 161

def self.reset_id_counter
  CP.cpResetShapeIdCounter
end

Instance Method Details

#bbObject



101
102
103
104
105
106
107
# File 'lib/chipmunk-ffi/shape.rb', line 101

def bb
  our_bb = @struct.bb
  size = BBStruct.size
  bb_ptr = FFI::MemoryPointer.new size
  bb_ptr.send(:put_bytes, 0, our_bb.to_bytes, 0, size)
  BB.new(BBStruct.new(bb_ptr))
end

#bodyObject



70
71
72
# File 'lib/chipmunk-ffi/shape.rb', line 70

def body
  @body
end

#body=(new_body) ⇒ Object



73
74
75
76
# File 'lib/chipmunk-ffi/shape.rb', line 73

def body=(new_body)
  @struct.body = new_body.struct.pointer
  @body = new_body
end

#cache_bbObject



109
110
111
112
# File 'lib/chipmunk-ffi/shape.rb', line 109

def cache_bb
  CP.cpShapeCacheBB(@struct.bb) 
  bb
end

#collision_typeObject



78
79
80
# File 'lib/chipmunk-ffi/shape.rb', line 78

def collision_type
  @collType
end

#collision_type=(col_type) ⇒ Object



81
82
83
84
# File 'lib/chipmunk-ffi/shape.rb', line 81

def collision_type=(col_type)
  @collType = col_type
  @struct.collision_type = col_type.object_id
end

#dataObject



127
128
129
# File 'lib/chipmunk-ffi/shape.rb', line 127

def data
  @struct.data
end

#data=(new_data) ⇒ Object



130
131
132
# File 'lib/chipmunk-ffi/shape.rb', line 130

def data=(new_data)
  @struct.data = new_data
end

#eObject



113
114
115
# File 'lib/chipmunk-ffi/shape.rb', line 113

def e
  @struct.e
end

#e=(new_e) ⇒ Object



116
117
118
# File 'lib/chipmunk-ffi/shape.rb', line 116

def e=(new_e)
  @struct.e = new_e
end

#groupObject



86
87
88
# File 'lib/chipmunk-ffi/shape.rb', line 86

def group
  @group
end

#group=(group_obj) ⇒ Object



89
90
91
92
# File 'lib/chipmunk-ffi/shape.rb', line 89

def group=(group_obj)
  @group = group_obj
  @struct.group = group_obj.object_id
end

#layersObject



94
95
96
# File 'lib/chipmunk-ffi/shape.rb', line 94

def layers
  @struct.layers
end

#layers=(l) ⇒ Object



97
98
99
# File 'lib/chipmunk-ffi/shape.rb', line 97

def layers=(l)
  @struct.layers = l
end

#point_query(point) ⇒ Object



148
149
150
151
# File 'lib/chipmunk-ffi/shape.rb', line 148

def point_query(point)
  bool_int = CP.cpShapePointQuery(@struct.pointer, point.struct)
  bool_int == 0 ? false : true
end

#segment_query(a, b) ⇒ Object



165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
# File 'lib/chipmunk-ffi/shape.rb', line 165

def segment_query(a,b)
  ptr = FFI::MemoryPointer.new(SegmentQueryInfoStruct.size)
  info = SegmentQueryInfoStruct.new ptr
	
  bool_int = CP.cpShapeSegmentQuery(@struct.pointer, a.struct.pointer, b.struct.pointer, ptr)
  hit = bool_int == 0 ? false : true
  if hit
    #obj_id = info.shape.data.get_long 0
    #shape = ObjectSpace._id2ref obj_id
    # TODO prob need to dup these things
    n = Vec2.new(info.n)
    SegmentQueryInfo.new hit, info.t, n, info, ptr
  else
    SegmentQueryInfo.new hit
  end
end

#sensor=(new_sensor) ⇒ Object



144
145
146
# File 'lib/chipmunk-ffi/shape.rb', line 144

def sensor=(new_sensor)
  @struct.sensor = new_sensor ? 1 : 0
end

#sensor?Boolean

Returns:

  • (Boolean)


141
142
143
# File 'lib/chipmunk-ffi/shape.rb', line 141

def sensor?
  @struct.sensor == 0 ? false : true
end

#set_data_pointerObject



153
154
155
156
157
158
159
# File 'lib/chipmunk-ffi/shape.rb', line 153

def set_data_pointer
  mem = FFI::MemoryPointer.new(:long)
  mem.put_long 0, object_id
  # this is needed to prevent data corruption by GC
  @shape_pointer = mem
  @struct.data = mem
end

#surface_vObject



134
135
136
# File 'lib/chipmunk-ffi/shape.rb', line 134

def surface_v
  Vec2.new @struct.surface_v
end

#surface_v=(new_sv) ⇒ Object



137
138
139
# File 'lib/chipmunk-ffi/shape.rb', line 137

def surface_v=(new_sv)
  @struct.surface_v.pointer.put_bytes 0, new_sv.struct.to_bytes, 0,Vect.size
end

#uObject



120
121
122
# File 'lib/chipmunk-ffi/shape.rb', line 120

def u
  @struct.u
end

#u=(new_u) ⇒ Object



123
124
125
# File 'lib/chipmunk-ffi/shape.rb', line 123

def u=(new_u)
  @struct.u = new_u
end