Class: BulldogPhysics::CollisionDetector
- Inherits:
-
Object
- Object
- BulldogPhysics::CollisionDetector
- Defined in:
- lib/RigidBodies/collision_shapes.rb
Class Method Summary collapse
- .box_and_box(one, two, data) ⇒ Object
- .box_and_half_space(box, plane, contacts) ⇒ Object
- .sphere_and_half_space(sphere, plane, contacts) ⇒ Object
- .sphere_and_sphere(one, two, contatcs) ⇒ Object
Class Method Details
.box_and_box(one, two, data) ⇒ Object
195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 |
# File 'lib/RigidBodies/collision_shapes.rb', line 195 def self.box_and_box(one, two, data) to_center = two.get_axis(3) - one.get_axis(3) puts "NOT DONE YET" return overlap_on_axis(one,two,one.getAxis(0), to_center) && \ overlap_on_axis(one,two,one.getAxis(1), to_center) && \ overlap_on_axis(one,two,one.getAxis(2), to_center) && \ overlap_on_axis(one,two,two.getAxis(0), to_center) && \ overlap_on_axis(one,two,two.getAxis(1), to_center) && \ overlap_on_axis(one,two,two.getAxis(2), to_center) && \ overlap_on_axis(one,two,one.getAxis(0) % two.getAxis(0), to_center) && \ overlap_on_axis(one,two,one.getAxis(0) % two.getAxis(1), to_center) && \ overlap_on_axis(one,two,one.getAxis(0) % two.getAxis(2), to_center) && \ overlap_on_axis(one,two,one.getAxis(1) % two.getAxis(0), to_center) && \ overlap_on_axis(one,two,one.getAxis(1) % two.getAxis(1), to_center) && \ overlap_on_axis(one,two,one.getAxis(1) % two.getAxis(2), to_center) && \ overlap_on_axis(one,two,one.getAxis(2) % two.getAxis(0), to_center) && \ overlap_on_axis(one,two,one.getAxis(2) % two.getAxis(1), to_center) && \ overlap_on_axis(one,two,one.getAxis(2) % two.getAxis(2), to_center) end |
.box_and_half_space(box, plane, contacts) ⇒ Object
216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 |
# File 'lib/RigidBodies/collision_shapes.rb', line 216 def self.box_and_half_space(box, plane, contacts) #return 0 if data.contacts_left <= 0 #return 0 unless IntersectionTests.box_and_half_space(box,plane) mults = [ [1,1,1] , [-1,1,1] , [1,-1,1] , [-1,-1,1] , \ [1,1,-1] , [-1,1,-1], [1,-1,-1] , [-1,-1,-1]] contacts_used = 0 #contact = contacts[contacts_used] for i in 0..7 vertexPos = Vector3.new(mults[i][0], mults[i][1], mults[i][2]); vertexPos.componentProductUpdate(box.half_size); vertexPos = box.transform.transform(vertexPos); vertexDistance = vertexPos * plane.direction; if(vertexDistance <= plane.offset) puts "test" contact = Contact.new contact.contact_point = plane.direction contact.contact_point *= (vertexDistance - plane.offset) contact.contact_point = vertexPos # ?????? contact.contact_normal = plane.direction contact.penetration = plane.offset - vertexDistance contacts_used+=1 contact.set_body_data(box.body, nil, 0.9, 0.6) contacts << contact #contact = data.contacts[contacts_used] #return contacts_used if contacts_used == data.contacts_left end end #data.add_contacts(contacts_used) return contacts_used end |
.sphere_and_half_space(sphere, plane, contacts) ⇒ Object
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 |
# File 'lib/RigidBodies/collision_shapes.rb', line 152 def self.sphere_and_half_space(sphere, plane, contacts) #eturn 0 if(data.contacts_left <= 0) position = sphere.get_axis(3) ball_distance = plane.direction * position - sphere.radius - plane.offset puts "ball distance" return 0 if ball_distance >= 0 contact = Contact.new contact.contact_normal = plane.direction contact.penetration = -ball_distance contact.contact_point = position - plane.direction * (ball_distance + sphere.radius) contact.set_body_data(sphere.body, nil, 0.9, 0.6) contacts << contact return 1 end |
.sphere_and_sphere(one, two, contatcs) ⇒ Object
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 |
# File 'lib/RigidBodies/collision_shapes.rb', line 171 def self.sphere_and_sphere(one, two, contatcs) positionOne = one.get_axis(3) positionTwo = two.get_axis(3) midline = positionOne - positionTwo size = midline.magnitude if size <= 0.0 || size >= one.radius + two.radius return 0 end normal = midline * (1.0/size) contact = Contact.new contact.normal = normal contact.contact_point = positionOne + midline * 0.5 contact.penetration = one.radius + two.radius - size contact.set_body_data( one.body, two.body, 0.9, 0.6) contatcs << contact return 1 end |