comparison melee/contactListener.d @ 18:7f74e064dad5

refactored code
author zzzzrrr <mason.green@gmail.com>
date Wed, 25 Mar 2009 11:28:25 -0400
parents contactListener.d@a40d066ebbd1
children cad384ad349e
comparison
equal deleted inserted replaced
17:82efafc87d54 18:7f74e064dad5
1 /*
2 * Copyright (c) 2009, Mason Green (zzzzrrr)
3 * Based on Box2D by Erin Catto, http://www.box2d.org
4 *
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without modification,
8 * are permitted provided that the following conditions are met:
9 *
10 * * Redistributions of source code must retain the above copyright notice,
11 * this list of conditions and the following disclaimer.
12 * * Redistributions in binary form must reproduce the above copyright notice,
13 * this list of conditions and the following disclaimer in the documentation
14 * and/or other materials provided with the distribution.
15 * * Neither the name of the polygonal nor the names of its contributors may be
16 * used to endorse or promote products derived from this software without specific
17 * prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
23 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
24 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
26 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
27 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
28 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
29 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 */
31 module openmelee.melee.contactListener;
32
33 import blaze.collision.bzCollision : bzContactID;
34 import blaze.dynamics.contact.bzContact : bzContactPoint, bzContactResult;
35 import blaze.dynamics.bzWorldCallbacks : bzContactListener;
36 import blaze.collision.shapes.bzShape : bzShape;
37 import blaze.common.bzMath : bzVec2;
38
39 import openmelee.melee.melee;
40
41 enum ContactState {
42 e_contactAdded,
43 e_contactPersisted,
44 e_contactRemoved
45 }
46
47 struct ContactPoint {
48 bzShape shape1;
49 bzShape shape2;
50 bzVec2 normal;
51 bzVec2 position;
52 bzVec2 velocity;
53 bzContactID id;
54 ContactState state;
55 }
56
57 // bzWorld contact callback
58 class ContactListener : bzContactListener
59 {
60
61 Melee melee;
62
63 this(Melee melee) {
64 this.melee = melee;
65 }
66
67 void add(bzContactPoint point)
68 {
69 if (melee.pointCount == k_maxContactPoints) {
70 return;
71 }
72
73 ContactPoint *cp = &melee.points[melee.pointCount];
74 cp.shape1 = point.shape1;
75 cp.shape2 = point.shape2;
76 cp.position = point.position;
77 cp.normal = point.normal;
78 cp.id = point.id;
79 cp.state = ContactState.e_contactAdded;
80
81 ++melee.pointCount;
82 }
83
84 void persist(bzContactPoint point)
85 {
86 if (melee.pointCount == k_maxContactPoints) {
87 return;
88 }
89
90 ContactPoint *cp = &melee.points[melee.pointCount];
91 cp.shape1 = point.shape1;
92 cp.shape2 = point.shape2;
93 cp.position = point.position;
94 cp.normal = point.normal;
95 cp.id = point.id;
96 cp.state = ContactState.e_contactPersisted;
97
98 ++melee.pointCount;
99 }
100
101 void remove(bzContactPoint point)
102 {
103 if (melee.pointCount == k_maxContactPoints) {
104 return;
105 }
106
107 ContactPoint *cp = &melee.points[melee.pointCount];
108 cp.shape1 = point.shape1;
109 cp.shape2 = point.shape2;
110 cp.position = point.position;
111 cp.normal = point.normal;
112 cp.id = point.id;
113 cp.state = ContactState.e_contactRemoved;
114
115 ++melee.pointCount;
116 }
117
118 void result(bzContactResult point) {}
119
120 }