Physics: Added more information to exception message in Collision.
[kong.git] / src / net / habraun / kong / physics / Collision.scala
blob01f25c74f938a5723280e1553338fd1cb3a78b63
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.kong.physics
23 /**
24 * Models a collision between two bodies.
25 * A collision has the following attributes:
26 * * b1 and b2 are the two bodies that collide.
27 * * normal1 is the collision normal for b1. This is the unit vector, that is a surface normal for b1 at the
28 * point of impact (pointing away from b1, towards b2). normal2 is the collision normal for b2 and is
29 * always the inverse of normal1.
30 * * impactPoint is a position vector pointing at the point of impact. Determining the point of impact is not
31 * yet implemented and impactPoint is always Vec2D(0, 0).
34 case class Collision(b1: Body, b2: Body, normal1: Vec2D, normal2: Vec2D, impactPoint: Vec2D) {
35 if (normal1 != -normal2)
36 throw new IllegalArgumentException("Both collision normals must be inverse to each other.")
37 if (normal1 * normal1 != 1)
38 throw new IllegalArgumentException("Normals must be unit vectors. Normal 1: " + normal1
39 + ", Normal 2: " + normal2)