Oolite
Loading...
Searching...
No Matches
OODebugGLDrawing.m
Go to the documentation of this file.
1/*
2
3OODebugDrawing.m
4
5
6Copyright (C) 2007-2013 Jens Ayton and contributors
7
8Permission is hereby granted, free of charge, to any person obtaining a copy
9of this software and associated documentation files (the "Software"), to deal
10in the Software without restriction, including without limitation the rights
11to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12copies of the Software, and to permit persons to whom the Software is
13furnished to do so, subject to the following conditions:
14
15The above copyright notice and this permission notice shall be included in all
16copies or substantial portions of the Software.
17
18THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24SOFTWARE.
25
26*/
27
28#import "OODebugGLDrawing.h"
29#import "OOMacroOpenGL.h"
30#import "OOMaterial.h"
31
32#ifndef OODEBUGLDRAWING_DISABLE
33
34OOINLINE void ApplyColor(OOColor* color)
35{
36 GLfloat r, g, b, a;
37
39
40 if (EXPECT_NOT(color == nil))
41 color = [OOColor lightGrayColor];
42 [color getRed:&r green:&g blue:&b alpha:&a];
43 OOGL(glColor4f(r, g, b, a));
44}
45
46void OODebugDrawColoredBoundingBoxBetween(Vector min, Vector max, OOColor* color)
47{
48 OODebugWFState state = OODebugBeginWireframe(YES);
50
51 ApplyColor(color);
52 OOGLBEGIN(GL_LINE_LOOP);
53 glVertex3f(min.x, min.y, min.z);
54 glVertex3f(max.x, min.y, min.z);
55 glVertex3f(max.x, max.y, min.z);
56 glVertex3f(min.x, max.y, min.z);
57 glVertex3f(min.x, max.y, max.z);
58 glVertex3f(max.x, max.y, max.z);
59 glVertex3f(max.x, min.y, max.z);
60 glVertex3f(min.x, min.y, max.z);
61 OOGLEND();
62 OOGLBEGIN(GL_LINES);
63 glVertex3f(max.x, min.y, min.z);
64 glVertex3f(max.x, min.y, max.z);
65 glVertex3f(max.x, max.y, min.z);
66 glVertex3f(max.x, max.y, max.z);
67 glVertex3f(min.x, min.y, min.z);
68 glVertex3f(min.x, max.y, min.z);
69 glVertex3f(min.x, min.y, max.z);
70 glVertex3f(min.x, max.y, max.z);
71 OOGLEND();
72
73 OODebugEndWireframe(state);
74}
75
76void OODebugDrawColoredLine(Vector start, Vector end, OOColor* color)
77{
78 OODebugWFState state = OODebugBeginWireframe(YES);
80
81 ApplyColor(color);
82
83 OOGLBEGIN(GL_LINES);
84 glVertex3f(start.x, start.y, start.z);
85 glVertex3f(end.x, end.y, end.z);
86 OOGLEND();
87
88 OODebugEndWireframe(state);
89}
90
91void OODebugDrawBasis(Vector position, GLfloat scale)
92{
93 OODebugWFState state = OODebugBeginWireframe(YES);
95
96 OOGLBEGIN(GL_LINES);
97 glColor4f(1.0f, 0.0f, 0.0f, 1.0f);
98 glVertex3f(position.x, position.y, position.z);
99 glVertex3f(position.x + scale, position.y, position.z);
100
101 glColor4f(0.0f, 1.0f, 0.0f, 1.0f);
102 glVertex3f(position.x, position.y, position.z);
103 glVertex3f(position.x, position.y + scale, position.z);
104
105 glColor4f(0.0f, 0.0f, 1.0f, 1.0f);
106 glVertex3f(position.x, position.y, position.z);
107 glVertex3f(position.x, position.y, position.z + scale);
108 OOGLEND();
109
110 OODebugEndWireframe(state);
111}
112
113void OODebugDrawPoint(Vector position, OOColor* color)
114{
115 OODebugWFState state = OODebugBeginWireframe(YES);
117
118 ApplyColor(color);
120
121 OOGLBEGIN(GL_POINTS);
122 glVertex3f(position.x, position.y, position.z);
123 OOGLEND();
124
125 OODebugEndWireframe(state);
126}
127
128OODebugWFState OODebugBeginWireframe(BOOL ignoreZ)
129{
131
132 OODebugWFState state = { .material = [OOMaterial current] };
134
135 OOGL(glPushAttrib(GL_ENABLE_BIT | GL_DEPTH_BUFFER_BIT | GL_LINE_BIT | GL_POINT_BIT | GL_CURRENT_BIT));
136
137 OOGL(glDisable(GL_LIGHTING));
138 OOGL(glDisable(GL_TEXTURE_2D));
139 OOGL(glDisable(GL_FOG));
140 if (ignoreZ) {
141 OOGL(glDisable(GL_DEPTH_TEST));
142 OOGL(glDepthMask(GL_FALSE));
143 } else {
144 OOGL(glEnable(GL_DEPTH_TEST));
145 OOGL(glDepthMask(GL_TRUE));
146 }
147
148 OOGL(GLScaledLineWidth(1.0f));
149
150 return state;
151}
152
153void OODebugEndWireframe(OODebugWFState state)
154{
156 OOGL(glPopAttrib());
157 [state.material apply];
158}
159
160#endif
#define OODebugDrawBasis(position, scale)
#define EXPECT_NOT(x)
#define OOINLINE
#define OO_ENTER_OPENGL()
#define OOGLBEGIN
Definition OOOpenGL.h:269
void GLScaledLineWidth(GLfloat width)
Definition OOOpenGL.m:206
#define OOGL(statement)
Definition OOOpenGL.h:262
void GLScaledPointSize(GLfloat size)
Definition OOOpenGL.m:212
#define OOGLEND
Definition OOOpenGL.h:270
return nil
void getRed:green:blue:alpha:(float *red,[green] float *green,[blue] float *blue,[alpha] float *alpha)
Definition OOColor.m:344
OOColor * lightGrayColor()
Definition OOColor.m:244
OOMaterial * current()
Definition OOMaterial.m:79
void applyNone()
Definition OOMaterial.m:72
OOScalar x
Definition OOVector.h:32
OOScalar y
Definition OOVector.h:33
OOScalar z
Definition OOVector.h:34