Mercurial > projects > openmelee
annotate render.d @ 17:82efafc87d54
fixed camera zoom
author | zzzzrrr <mason.green@gmail.com> |
---|---|
date | Tue, 24 Mar 2009 16:47:42 -0400 |
parents | af1e8620f027 |
children |
rev | line source |
---|---|
0 | 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 */ | |
2 | 31 module openmelee.render; |
0 | 32 |
33 import xf.dog.Dog; | |
34 import xf.omg.core.LinearAlgebra; | |
35 import xf.hybrid.Event; | |
36 import xf.hybrid.Font; | |
37 | |
2 | 38 import openmelee.melee; |
0 | 39 |
7
2217fd1fe384
added angular and linear velocity limit
zzzzrrr <mason.green@gmail.com>
parents:
6
diff
changeset
|
40 // Water stuffs |
2217fd1fe384
added angular and linear velocity limit
zzzzrrr <mason.green@gmail.com>
parents:
6
diff
changeset
|
41 const MAX_CIRCLE_RES = 32; |
2217fd1fe384
added angular and linear velocity limit
zzzzrrr <mason.green@gmail.com>
parents:
6
diff
changeset
|
42 |
0 | 43 /// Color for drawing. Each value has the range [0,1]. |
44 struct Color { | |
45 static Color opCall(float r, float g, float b) | |
46 { | |
47 Color u; | |
48 u.r = r; | |
49 u.g = g; | |
50 u.b = b; | |
51 return u; | |
52 } | |
53 | |
54 float r = 0; | |
55 float g = 0; | |
56 float b = 0; | |
57 } | |
58 | |
59 class Render : Melee | |
60 { | |
61 | |
62 this(Settings *settings) { | |
63 | |
64 super(settings); | |
65 } | |
66 | |
67 void drawCircle(GL gl, vec2 center, float radius, bool water = false, float theta = float.nan) | |
68 { | |
69 int segs = cast(int)(radius) + 20; | |
70 if (segs > MAX_CIRCLE_RES) segs = MAX_CIRCLE_RES; | |
71 double coef = 2.0 * PI / segs; | |
72 | |
73 auto realTheta = (theta <>= 0 ? theta : 0); | |
74 if (water) { | |
75 gl.immediate(GL_TRIANGLE_FAN, | |
76 { | |
77 gl.Vertex2fv(center.ptr); | |
78 for (int n = 0; n <= segs; n++) { | |
79 double rads = n * coef; | |
80 gl.Vertex2f(radius * cos(rads + realTheta) + center.x, radius * sin(rads + realTheta) + center.y); | |
81 } | |
82 }); | |
83 } | |
84 | |
85 gl.immediate(GL_LINE_STRIP, | |
86 { | |
87 for (int n = 0; n <= segs; n++) { | |
88 double rads = n * coef; | |
89 gl.Vertex2f(radius * cos(rads + realTheta) + center.x, radius * sin(rads + realTheta) + center.y); | |
90 } | |
91 if (theta <>= 0) | |
92 gl.Vertex2fv(center.ptr); | |
93 }); | |
94 } | |
95 | |
96 void drawSolidCircle(GL gl, vec2 center, float radius, vec2 axis, Color color) | |
97 { | |
6 | 98 const k_segments = 25.0f; |
0 | 99 const k_increment = 2.0f * PI / k_segments; |
100 float theta = 0.0f; | |
101 gl.Enable(GL_BLEND); | |
102 gl.BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); | |
103 gl.Color4f(0.5f * color.r, 0.5f * color.g, 0.5f * color.b, 0.5f); | |
104 gl.Begin(GL_TRIANGLE_FAN); | |
105 for (int i = 0; i < k_segments; ++i) { | |
106 vec2 v = center + radius * vec2(cos(theta), sin(theta)); | |
107 gl.Vertex2f(v.x, v.y); | |
108 theta += k_increment; | |
109 } | |
110 gl.End(); | |
111 gl.Disable(GL_BLEND); | |
112 | |
113 theta = 0.0f; | |
114 gl.Color4f(color.r, color.g, color.b, 1.0f); | |
115 gl.Begin(GL_LINE_LOOP); | |
116 for (int i = 0; i < k_segments; ++i) { | |
117 vec2 v = center + radius * vec2(cos(theta), sin(theta)); | |
118 gl.Vertex2f(v.x, v.y); | |
119 theta += k_increment; | |
120 } | |
121 gl.End(); | |
122 | |
123 vec2 p = center + radius * axis; | |
124 gl.Begin(GL_LINES); | |
125 gl.Vertex2f(center.x, center.y); | |
126 gl.Vertex2f(p.x, p.y); | |
127 gl.End(); | |
128 } | |
129 | |
130 void drawPolygon(GL gl, vec2[] glVerts, Color color) | |
131 { | |
132 gl.Color3f(color.r, color.g, color.b); | |
133 gl.immediate(GL_LINE_LOOP, | |
134 { | |
135 foreach (v; glVerts) | |
136 gl.Vertex2fv(v.ptr); | |
137 }); | |
138 } | |
139 | |
140 void drawSolidPolygon(GL gl, vec2[] vertices, Color color) | |
141 { | |
142 gl.Enable(GL_BLEND); | |
143 gl.BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); | |
144 gl.Color4f(0.5f * color.r, 0.5f * color.g, 0.5f * color.b, 0.5f); | |
145 gl.Begin(GL_TRIANGLE_FAN); | |
146 for (int i = 0; i < vertices.length; ++i) { | |
147 gl.Vertex2f(vertices[i].x, vertices[i].y); | |
148 } | |
149 gl.End(); | |
150 gl.Disable(GL_BLEND); | |
151 | |
152 gl.Color4f(color.r, color.g, color.b, 1.0f); | |
153 gl.Begin(GL_LINE_LOOP); | |
154 for (int i = 0; i < vertices.length; ++i) { | |
155 gl.Vertex2f(vertices[i].x, vertices[i].y); | |
156 } | |
157 gl.End(); | |
158 } | |
159 | |
160 | |
161 void drawPoint(GL gl, vec2 p, float size, Color color) | |
162 { | |
163 gl.Color3f(color.r, color.g, color.b); | |
164 gl.PointSize(size); | |
165 gl.Begin(GL_POINTS); | |
166 gl.Vertex2f(p.x, p.y); | |
167 gl.End(); | |
168 gl.PointSize(1.0f); | |
169 } | |
170 | |
171 void drawSegment(GL gl, vec2 begin, vec2 end, Color color) | |
172 { | |
173 gl.Color3f(color.r, color.g, color.b); | |
174 gl.immediate(GL_LINES, | |
175 { | |
176 gl.Vertex2fv(begin.ptr); | |
177 gl.Vertex2fv(end.ptr); | |
178 }); | |
179 } | |
180 | |
181 // TODO: handle inequal radii correctly | |
182 void connectCircles(GL gl, vec2 center1, float radius1, vec2 center2, float radius2) | |
183 { | |
184 auto d = center2 - center1; | |
185 if (!d.length) | |
186 return; | |
187 d *= (d.length - radius1) / d.length; | |
188 center1 += d; | |
189 center2 -= d; | |
190 gl.immediate(GL_LINES, | |
191 { | |
192 gl.Vertex2fv(center1.ptr); | |
193 gl.Vertex2fv(center2.ptr); | |
194 }); | |
195 } | |
196 | |
197 void drawXForm(GL gl, bzXForm xf) | |
198 { | |
199 bzVec2 p1 = xf.position, p2; | |
200 const k_axisScale = 0.4f; | |
201 | |
202 gl.Begin(GL_LINES); | |
203 { | |
204 gl.Color3f(1.0f, 0.0f, 0.0f); | |
205 gl.Vertex2f(p1.x, p1.y); | |
206 p2 = p1 + k_axisScale * xf.R.col1; | |
207 gl.Vertex2f(p2.x, p2.y); | |
208 | |
209 gl.Color3f(0.0f, 1.0f, 0.0f); | |
210 gl.Vertex2f(p1.x, p1.y); | |
211 p2 = p1 + k_axisScale * xf.R.col2; | |
212 gl.Vertex2f(p2.x, p2.y); | |
213 } | |
214 gl.End(); | |
215 } | |
216 | |
217 void drawSpring(GL gl, vec2 a, vec2 b, uint zigs) | |
218 { | |
219 zigs++; | |
220 | |
221 // Portion of length dedicated to connectors | |
222 const float connPart = 0.2; | |
223 | |
224 vec2 inc = (b - a) / (zigs); | |
225 // One step from a to b | |
226 vec2 zigLen = inc * (1 - connPart); | |
227 // Length of a connector | |
228 vec2 connLen = inc * (connPart / 2) * zigs; | |
229 // Width of a zig | |
230 vec2 zigWidth = (b - a).rotatedHalfPi.normalized; | |
231 gl.immediate(GL_LINE_STRIP, | |
232 { | |
233 gl.Vertex2fv(a.ptr); | |
234 | |
235 a += connLen; | |
236 gl.Vertex2fv(a.ptr); | |
237 | |
238 bool dir = true; | |
239 a += zigWidth / 2 + zigLen / 2; | |
240 for (int i = 0; i < zigs; i++) { | |
241 gl.Vertex2fv(a.ptr); | |
242 a += zigLen; | |
243 if (dir) { | |
244 a -= zigWidth; | |
245 }else { | |
246 a += zigWidth; | |
247 } | |
248 dir = !dir; | |
249 } | |
250 | |
251 gl.Vertex2fv((b - connLen).ptr); | |
252 gl.Vertex2fv(b.ptr); | |
253 }); | |
254 } | |
255 | |
256 void drawShape(GL gl, bzShape shape, bzXForm xf, Color color, bool core) | |
257 { | |
258 Color coreColor = Color(0.9f, 0.6f, 0.6f); | |
259 | |
260 switch (shape.type) { | |
261 case bzShapeType.CIRCLE: | |
262 auto circle = cast(bzCircle)shape; | |
263 | |
264 vec2 center = vec2.from(bzMul(xf, circle.localPosition)); | |
265 float radius = circle.radius; | |
266 vec2 axis = vec2.from(xf.R.col1); | |
267 | |
268 gl.drawSolidCircle(center, radius, axis, color); | |
269 | |
270 if (core) { | |
271 gl.Color3f(coreColor.r, coreColor.g, coreColor.b); | |
272 gl.drawCircle(center, radius - k_toiSlop); | |
273 } | |
274 break; | |
275 case bzShapeType.POLYGON: | |
276 { | |
277 bzPolygon poly = cast(bzPolygon)shape; | |
278 bzVec2[] vertices = poly.worldVertices; | |
279 vec2[] verts; | |
280 verts.length = vertices.length; | |
281 foreach (int i, v; vertices) { | |
282 verts[i] = vec2.from(v); | |
283 } | |
284 | |
285 gl.drawSolidPolygon(verts, color); | |
286 | |
287 if (core) { | |
288 bzVec2[] localCoreVertices = poly.coreVertices; | |
289 verts.length = localCoreVertices.length; | |
290 for (int i = 0; i < localCoreVertices.length; ++i) { | |
291 verts[i] = vec2.from(bzMul(xf, localCoreVertices[i])); | |
292 } | |
293 gl.drawPolygon(verts, coreColor); | |
294 } | |
295 } | |
296 break; | |
297 | |
298 case bzShapeType.EDGE: | |
299 { | |
300 bzEdge edge = cast(bzEdge)shape; | |
301 | |
302 vec2 p1 = vec2.from(bzMul(xf, edge.vertex1)); | |
303 vec2 p2 = vec2.from(bzMul(xf, edge.vertex2)); | |
304 gl.drawSegment(p1, p2, color); | |
305 | |
306 if (core) { | |
307 p1 = vec2.from(bzMul(xf, edge.coreVertex1)); | |
308 p2 = vec2.from(bzMul(xf, edge.coreVertex2)); | |
309 gl.drawSegment(p1, p2, coreColor); | |
310 } | |
311 } | |
312 break; | |
313 } | |
314 } | |
315 | |
316 void draw(vec2i screenSize, GL gl) | |
317 { | |
17 | 318 |
319 vec2 point1 = vec2.from(ship1.rBody.position); | |
320 vec2 point2 = vec2.from(ship2.rBody.position); | |
321 vec2 range = point1 - point2; | |
322 zoom = bzClamp(1000/range.length, 2, 60); | |
323 viewCenter = point1 - (range * 0.5f); | |
324 | |
0 | 325 this.screenSize = screenSize; |
326 | |
327 gl.LoadIdentity(); | |
328 gl.MatrixMode(GL_PROJECTION); | |
329 gl.LoadIdentity(); | |
2 | 330 |
331 float left = -screenSize.x / zoom; | |
332 float right = screenSize.x / zoom; | |
333 float bottom = -screenSize.y / zoom; | |
334 float top = screenSize.y / zoom; | |
335 | |
336 gl.gluOrtho2D(left, right, bottom, top); | |
0 | 337 gl.Translatef(-viewCenter.x, -viewCenter.y, 0); |
338 gl.MatrixMode(GL_MODELVIEW); | |
339 gl.Disable(GL_DEPTH_TEST); | |
340 gl.LoadIdentity(); | |
341 gl.Clear(GL_COLOR_BUFFER_BIT); | |
342 | |
12 | 343 vec2 pp1 = vec2.from(ship2.rBody.position); |
344 vec2 pp2 = vec2.from(ship2.state.target); | |
345 | |
14 | 346 //gl.drawSegment(pp1, pp2, Color(0, 1, 0)); |
12 | 347 |
0 | 348 // Draw dynamic bodies |
349 if (settings.drawShapes) { | |
350 for (bzBody b = world.bodyList; b; b = b.next) { | |
351 for (bzShape shape = b.shapeList; shape; shape = shape.next) { | |
352 | |
353 bzShape s = shape; | |
354 bzXForm xf = b.xf; | |
355 | |
356 if (b.isStatic) { | |
357 gl.drawShape(s, xf, Color(0.5f, 0.9f, 0.5f), settings.drawCoreShapes); | |
358 }else if (b.isSleeping) { | |
359 gl.drawShape(s, xf, Color(0.5f, 0.5f, 0.9f), settings.drawCoreShapes); | |
360 }else if (b.userData) { | |
361 auto ss = cast(Select)b.userData; | |
362 if (ss) { | |
363 gl.drawShape(s, xf, Color(0, .5, 1), settings.drawCoreShapes); | |
364 } | |
365 }else { | |
366 gl.drawShape(s, xf, Color(0.9f, 0.9f, 0.9f), settings.drawCoreShapes); | |
367 } | |
368 | |
369 gl.LoadIdentity(); | |
370 gl.Flush(); | |
371 } | |
372 } | |
373 } | |
374 | |
375 // Draw joints | |
376 if (settings.drawJoints) { | |
377 Color color = Color(0, 0, 1); | |
378 gl.Color3f(0, 0, 1); | |
379 | |
380 gl.LineWidth(1); | |
381 for (bzJoint joint = world.jointList; joint; joint = joint.next) { | |
382 auto distance = cast(bzDistanceJoint)joint; | |
383 auto pulley = cast(bzPulleyJoint)joint; | |
384 auto revolute = cast(bzRevoluteJoint)joint; | |
385 auto prismatic = cast(bzPrismaticJoint)joint; | |
386 auto line = cast(bzLineJoint)joint; | |
387 if (distance) { | |
388 color = Color(.5, .5, 0); | |
389 // Endpoints | |
390 vec2 a = vec2.from(distance.anchor1); | |
391 vec2 b = vec2.from(distance.anchor2); | |
392 // Circles | |
393 gl.drawCircle(a, HINGE_RADIUS); | |
394 gl.drawCircle(b, HINGE_RADIUS); | |
395 // Connecting line | |
396 gl.connectCircles(a, HINGE_RADIUS, b, HINGE_RADIUS); | |
397 }else if (pulley) { | |
398 auto a = vec2.from(pulley.anchor1); | |
399 auto b = vec2.from(pulley.groundAnchor1); | |
400 auto c = vec2.from(pulley.groundAnchor2); | |
401 auto d = vec2.from(pulley.anchor2); | |
402 gl.drawCircle(a, HINGE_RADIUS); | |
403 gl.drawCircle(b, HINGE_RADIUS); | |
404 gl.connectCircles(a, HINGE_RADIUS, b, HINGE_RADIUS); | |
405 gl.drawSegment(b, c, color); | |
406 gl.drawCircle(c, HINGE_RADIUS); | |
407 gl.drawCircle(d, HINGE_RADIUS); | |
408 gl.connectCircles(c, HINGE_RADIUS, d, HINGE_RADIUS); | |
409 }else if (revolute) { | |
410 auto a = vec2.from(revolute.rBody1.position); | |
411 auto b = vec2.from(revolute.anchor1); | |
412 auto c = vec2.from(revolute.rBody2.position); | |
413 gl.drawCircle(a, HINGE_RADIUS); | |
414 gl.drawCircle(b, HINGE_RADIUS); | |
415 gl.connectCircles(a, HINGE_RADIUS, b, HINGE_RADIUS); | |
416 gl.drawCircle(c, HINGE_RADIUS); | |
417 gl.connectCircles(b, HINGE_RADIUS, c, HINGE_RADIUS); | |
418 }else if (prismatic) { | |
419 auto a = vec2.from(prismatic.rBody1.position); | |
420 auto b = vec2.from(prismatic.anchor1); | |
421 auto c = vec2.from(prismatic.rBody2.position); | |
422 gl.drawCircle(a, HINGE_RADIUS); | |
423 gl.drawCircle(b, HINGE_RADIUS); | |
424 gl.connectCircles(a, HINGE_RADIUS, b, HINGE_RADIUS); | |
425 gl.drawCircle(c, HINGE_RADIUS); | |
426 gl.connectCircles(b, HINGE_RADIUS, c, HINGE_RADIUS); | |
427 }else if (line) { | |
428 auto a = vec2.from(line.rBody1.position); | |
429 auto b = vec2.from(line.anchor1); | |
430 auto c = vec2.from(line.rBody2.position); | |
431 gl.drawCircle(a, HINGE_RADIUS); | |
432 gl.drawCircle(b, HINGE_RADIUS); | |
433 gl.connectCircles(a, HINGE_RADIUS, b, HINGE_RADIUS); | |
434 gl.drawCircle(c, HINGE_RADIUS); | |
435 gl.connectCircles(b, HINGE_RADIUS, c, HINGE_RADIUS); | |
436 } | |
437 } | |
438 | |
439 if (settings.drawControllers) { | |
440 bzForceGenerator[] forces = world.forces; | |
441 foreach (f; forces) { | |
442 auto spring1 = cast(bzSpring1) f; | |
443 auto spring2 = cast(bzSpring2) f; | |
444 auto buoyancy = cast(bzBuoyancy) f; | |
445 | |
446 if (spring1) { | |
447 auto bungee1 = cast(bzBungee1)spring1; | |
448 if (bungee1) { | |
449 gl.Color3f(.5, .5, 0); | |
450 // Endpoints | |
451 vec2 a = vec2.from(bungee1.rBody.position); | |
452 vec2 b = vec2.from(bungee1.anchor); | |
453 // Circles | |
454 gl.drawCircle(a, HINGE_RADIUS); | |
455 gl.drawCircle(b, HINGE_RADIUS); | |
456 // Connecting line | |
457 gl.connectCircles(a, HINGE_RADIUS, b, HINGE_RADIUS); | |
458 }else { | |
459 uint zigs = 10; | |
460 auto anchor1 = vec2.from(spring1.anchor); | |
461 auto anchor2 = vec2.from(spring1.rBody.position); | |
462 gl.drawSpring(anchor1, anchor2, zigs); | |
463 } | |
464 } | |
465 | |
466 if (spring2) { | |
467 auto bungee2 = cast(bzBungee2)spring2; | |
468 if (bungee2) { | |
469 gl.Color3f(.5, .5, 0); | |
470 // Endpoints | |
471 vec2 a = vec2.from(bungee2.rBody.position); | |
472 vec2 b = vec2.from(bungee2.otherBody.position); | |
473 // Circles | |
474 gl.drawCircle(a, HINGE_RADIUS); | |
475 gl.drawCircle(b, HINGE_RADIUS); | |
476 // Connecting line | |
477 gl.connectCircles(a, HINGE_RADIUS, b, HINGE_RADIUS); | |
478 }else { | |
479 uint zigs = 10; | |
480 auto anchor1 = vec2.from(spring2.otherBody.position); | |
481 auto anchor2 = vec2.from(spring2.rBody.position); | |
482 gl.drawSpring(anchor1, anchor2, zigs); | |
483 } | |
484 } | |
485 | |
486 if(buoyancy) { | |
487 float plane = buoyancy.planeOffset; | |
488 vec2 p1 = vec2(-50, plane); | |
489 vec2 p2 = vec2(50, plane); | |
490 gl.drawSegment(p1, p2, color); | |
491 } | |
492 } | |
493 } | |
494 } | |
495 | |
496 if(settings.drawPairs) { | |
497 | |
498 bzBroadPhase bp = world.broadPhase; | |
499 bzVec2 invQ; | |
500 invQ.set(1.0f / bp.m_quantizationFactor.x, 1.0f / bp.m_quantizationFactor.y); | |
501 Color color = Color(0.9f, 0.9f, 0.3f); | |
502 | |
503 const k_tableCapacity = bzPairManager.TABLE_CAPACITY; | |
504 | |
505 for (int i = 0; i < k_tableCapacity; ++i) | |
506 { | |
507 ushort index = bp.m_pairManager.m_hashTable[i]; | |
508 while (index < bp.m_pairManager.m_pairs.length) | |
509 { | |
510 if(index == bzPairManager.NULL_PROXY) { | |
511 break; | |
512 } | |
513 bzPair pair = bp.m_pairManager.m_pairs[index]; | |
514 bzProxy p1 = bp.m_proxyPool[pair.proxyId1]; | |
515 bzProxy p2 = bp.m_proxyPool[pair.proxyId2]; | |
516 | |
517 bzAABB b1, b2; | |
518 b1.lowerBound.x = bp.m_worldAABB.lowerBound.x + invQ.x * bp.m_bounds[0][p1.lowerBounds[0]].value; | |
519 b1.lowerBound.y = bp.m_worldAABB.lowerBound.y + invQ.y * bp.m_bounds[1][p1.lowerBounds[1]].value; | |
520 b1.upperBound.x = bp.m_worldAABB.lowerBound.x + invQ.x * bp.m_bounds[0][p1.upperBounds[0]].value; | |
521 b1.upperBound.y = bp.m_worldAABB.lowerBound.y + invQ.y * bp.m_bounds[1][p1.upperBounds[1]].value; | |
522 b2.lowerBound.x = bp.m_worldAABB.lowerBound.x + invQ.x * bp.m_bounds[0][p2.lowerBounds[0]].value; | |
523 b2.lowerBound.y = bp.m_worldAABB.lowerBound.y + invQ.y * bp.m_bounds[1][p2.lowerBounds[1]].value; | |
524 b2.upperBound.x = bp.m_worldAABB.lowerBound.x + invQ.x * bp.m_bounds[0][p2.upperBounds[0]].value; | |
525 b2.upperBound.y = bp.m_worldAABB.lowerBound.y + invQ.y * bp.m_bounds[1][p2.upperBounds[1]].value; | |
526 | |
527 bzVec2 x1 = 0.5f * (b1.lowerBound + b1.upperBound); | |
528 bzVec2 x2 = 0.5f * (b2.lowerBound + b2.upperBound); | |
529 | |
530 gl.drawSegment(vec2.from(x1),vec2.from(x2), color); | |
531 | |
532 index = pair.next; | |
533 } | |
534 } | |
535 } | |
536 | |
7
2217fd1fe384
added angular and linear velocity limit
zzzzrrr <mason.green@gmail.com>
parents:
6
diff
changeset
|
537 // Draw the world bounds |
2217fd1fe384
added angular and linear velocity limit
zzzzrrr <mason.green@gmail.com>
parents:
6
diff
changeset
|
538 bzBroadPhase bp = world.broadPhase; |
2217fd1fe384
added angular and linear velocity limit
zzzzrrr <mason.green@gmail.com>
parents:
6
diff
changeset
|
539 bzVec2 worldLower = bp.m_worldAABB.lowerBound; |
2217fd1fe384
added angular and linear velocity limit
zzzzrrr <mason.green@gmail.com>
parents:
6
diff
changeset
|
540 bzVec2 worldUpper = bp.m_worldAABB.upperBound; |
2217fd1fe384
added angular and linear velocity limit
zzzzrrr <mason.green@gmail.com>
parents:
6
diff
changeset
|
541 Color color = Color(0.3f, 0.9f, 0.9f); |
2217fd1fe384
added angular and linear velocity limit
zzzzrrr <mason.green@gmail.com>
parents:
6
diff
changeset
|
542 vec2 vs[4]; |
2217fd1fe384
added angular and linear velocity limit
zzzzrrr <mason.green@gmail.com>
parents:
6
diff
changeset
|
543 vs[0] = vec2(worldLower.x, worldLower.y); |
2217fd1fe384
added angular and linear velocity limit
zzzzrrr <mason.green@gmail.com>
parents:
6
diff
changeset
|
544 vs[1] = vec2(worldUpper.x, worldLower.y); |
2217fd1fe384
added angular and linear velocity limit
zzzzrrr <mason.green@gmail.com>
parents:
6
diff
changeset
|
545 vs[2] = vec2(worldUpper.x, worldUpper.y); |
2217fd1fe384
added angular and linear velocity limit
zzzzrrr <mason.green@gmail.com>
parents:
6
diff
changeset
|
546 vs[3] = vec2(worldLower.x, worldUpper.y); |
2217fd1fe384
added angular and linear velocity limit
zzzzrrr <mason.green@gmail.com>
parents:
6
diff
changeset
|
547 drawPolygon(gl, vs, color); |
2217fd1fe384
added angular and linear velocity limit
zzzzrrr <mason.green@gmail.com>
parents:
6
diff
changeset
|
548 |
0 | 549 // Draw axis aligned bounding boxes (bzAABB) |
550 if (settings.drawAABBs) { | |
551 bzVec2 invQ; | |
552 invQ.set(1.0f / bp.m_quantizationFactor.x, 1.0f / bp.m_quantizationFactor.y); | |
553 color = Color(1.0f, 1.0f, 1.0f); | |
5 | 554 |
0 | 555 for (int i = 0; i < k_maxProxies; ++i) { |
556 bzProxy p = bp.m_proxyPool[i]; | |
557 if (!p.isValid) { | |
558 continue; | |
559 } | |
560 | |
561 bzAABB b; | |
562 b.lowerBound.x = worldLower.x + invQ.x * bp.m_bounds[0][p.lowerBounds[0]].value; | |
563 b.lowerBound.y = worldLower.y + invQ.y * bp.m_bounds[1][p.lowerBounds[1]].value; | |
564 b.upperBound.x = worldLower.x + invQ.x * bp.m_bounds[0][p.upperBounds[0]].value; | |
565 b.upperBound.y = worldLower.y + invQ.y * bp.m_bounds[1][p.upperBounds[1]].value; | |
566 | |
567 vs[0] = vec2(b.lowerBound.x, b.lowerBound.y); | |
568 vs[1] = vec2(b.upperBound.x, b.lowerBound.y); | |
569 vs[2] = vec2(b.upperBound.x, b.upperBound.y); | |
570 vs[3] = vec2(b.lowerBound.x, b.upperBound.y); | |
571 | |
572 drawPolygon(gl, vs, color); | |
573 } | |
574 } | |
575 } | |
576 | |
577 } |