Contact: Contacts are now represented by two different contact objects, each viewing...
[scd.git] / src / net / habraun / sd / SimpleNarrowPhase.scala
blob6613ca279cabc324593d729306e3601174f20e7c
1 /*
2 Copyright (c) 2009 Hanno Braun <hanno@habraun.net>
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
8 http://www.apache.org/licenses/LICENSE-2.0
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
19 package net.habraun.sd
23 import collision._
24 import math._
28 class SimpleNarrowPhase extends NarrowPhase {
30 var testCircleCircle: CircleCircleTest = new ContinuousCircleCircleTest
31 var testCircleLineSegment: CircleLineSegmentTest = new ContinuousCircleLineSegmentTest
35 def inspectCollision(delta: Double, b1: Body, b2: Body) = b1.shape match {
36 case s1: Circle =>
37 b2.shape match {
38 case s2: Circle =>
39 for (r <- testCircleCircle(s1, s2, b1.position, b2.position, b1.velocity * delta,
40 b2.velocity * delta)) yield {
41 Collision(r.t, Contact(b1, r.contact, r.normal, b2),
42 Contact(b2, r.contact, -r.normal, b1))
45 case s2: LineSegment =>
46 for (r <- testCircleLineSegment(s1, s2, b1.position, b2.position, b1.velocity * delta,
47 b2.velocity * delta)) yield {
48 Collision(r.t, Contact(b1, r.contact, r.normal, b2),
49 Contact(b2, r.contact, -r.normal, b1))
52 case _ =>
53 None
56 case s1: LineSegment =>
57 b2.shape match {
58 case s2: Circle =>
59 for (r <- testCircleLineSegment(s2, s1, b2.position, b1.position, b2.velocity * delta,
60 b1.velocity * delta)) yield {
61 Collision(r.t, Contact(b1, r.contact, r.normal, b2),
62 null)
65 case s2: LineSegment =>
66 None
68 case _ =>
69 None
72 case _ =>
73 None