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