Oolite
Loading...
Searching...
No Matches
OODebugGLDrawing.h
Go to the documentation of this file.
1/*
2
3OODebugDrawing.h
4
5A set of functions for drawing debug stuff like bounding boxes. These are
6drawn in wireframe without Z buffer reads or writes.
7
8
9Copyright (C) 2007-2013 Jens Ayton and contributors
10
11Permission is hereby granted, free of charge, to any person obtaining a copy
12of this software and associated documentation files (the "Software"), to deal
13in the Software without restriction, including without limitation the rights
14to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15copies of the Software, and to permit persons to whom the Software is
16furnished to do so, subject to the following conditions:
17
18The above copyright notice and this permission notice shall be included in all
19copies or substantial portions of the Software.
20
21THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27SOFTWARE.
28
29*/
30
31#import "OOColor.h"
32#import "OOMaths.h"
33
34#if !defined(OODEBUGLDRAWING_DISABLE) && !defined(OO_DEBUG_MONITOR_ENABLED)
35#define OODEBUGLDRAWING_DISABLE 1
36#endif
37
38#ifndef OODEBUGLDRAWING_DISABLE
39
40@class OOMaterial;
41
42typedef struct
43{
44 OOMaterial* material;
45} OODebugWFState;
46
47OODebugWFState OODebugBeginWireframe(BOOL ignoreZ);
48void OODebugEndWireframe(OODebugWFState state);
49
52OOINLINE void OODebugDrawColoredBoundingBox(BoundingBox box, OOColor* color);
53void OODebugDrawColoredBoundingBoxBetween(Vector min, Vector max, OOColor* color);
54
55// Normals are drawn as cyan lines
56OOINLINE void OODebugDrawNormal(Vector position, Vector normal, GLfloat scale);
57OOINLINE void OODebugDrawNormalAtOrigin(Vector normal, GLfloat scale);
58
59// Other vectors are drawn as magenta lines by default
60OOINLINE void OODebugDrawVector(Vector position, Vector v);
61OOINLINE void OODebugDrawColoredVector(Vector position, Vector v, OOColor* color);
64
65// Lines are drawn white by default
66OOINLINE void OODebugDrawLine(Vector start, Vector end);
67void OODebugDrawColoredLine(Vector start, Vector end, OOColor* color);
68
69// Bases are drawn as one red, one green and one blue vector, representing x, y and z axes in the current coordinate frame.
70void OODebugDrawBasis(Vector position, GLfloat scale);
71OOINLINE void OODebugDrawBasisAtOrigin(GLfloat scale);
72
73void OODebugDrawPoint(Vector position, OOColor* color);
74
75/*** Only inline definitions beyond this point ***/
76
78{
79 OODebugDrawColoredBoundingBoxBetween(min, max, [OOColor blueColor]);
80}
81
83{
85}
86
87OOINLINE void OODebugDrawColoredBoundingBox(BoundingBox box, OOColor* color)
88{
89 OODebugDrawColoredBoundingBoxBetween(box.min, box.max, color);
90}
91
92OOINLINE void OODebugDrawNormal(Vector position, Vector normal, GLfloat scale)
93{
94 OODebugDrawColoredVector(position, vector_add(position, vector_multiply_scalar(normal, scale)), [OOColor cyanColor]);
95}
96
97OOINLINE void OODebugDrawNormalAtOrigin(Vector normal, GLfloat scale)
98{
99 OODebugDrawNormal(kZeroVector, normal, scale);
100}
101
102OOINLINE void OODebugDrawColoredVector(Vector position, Vector v, OOColor* color)
103{
104 OODebugDrawColoredLine(position, vector_add(position, v), color);
105}
106
107OOINLINE void OODebugDrawVector(Vector position, Vector v)
108{
109 OODebugDrawColoredVector(position, v, [OOColor magentaColor]);
110}
111
113{
115}
116
118{
120}
121
122OOINLINE void OODebugDrawLine(Vector start, Vector end)
123{
124 OODebugDrawColoredLine(start, end, [OOColor whiteColor]);
125}
126
127OOINLINE void OODebugDrawBasisAtOrigin(GLfloat scale)
128{
130}
131
132#else // OODEBUGLDRAWING_DISABLE
133
134#define OODRAW_NOOP \
135 do { \
136 } while (0)
137
138#define OODebugDrawBoundingBox(box) OODRAW_NOOP
139#define OODebugDrawBoundingBoxBetween(min, max) OODRAW_NOOP
140#define OODebugDrawNormal(position, normal, scale) OODRAW_NOOP
141#define OODebugDrawNormalAtOrigin(normal, scale) OODRAW_NOOP
142#define OODebugDrawVector(position, v) OODRAW_NOOP
143#define OODebugDrawColoredVector(position, v, color) OODRAW_NOOP
144#define OODebugDrawVectorAtOrigin(v) OODRAW_NOOP
145#define OODebugDrawColoredVectorAtOrigin(v, color) OODRAW_NOOP
146#define OODebugDrawBasis(position, scale) OODRAW_NOOP
147#define OODebugDrawBasisAtOrigin(scale) OODRAW_NOOP
148
149#endif // OODEBUGLDRAWING_DISABLE
#define OODebugDrawBasisAtOrigin(scale)
#define OODebugDrawBoundingBoxBetween(min, max)
#define OODebugDrawVectorAtOrigin(v)
#define OODebugDrawVector(position, v)
#define OODebugDrawNormalAtOrigin(normal, scale)
#define OODebugDrawNormal(position, normal, scale)
#define OODebugDrawBasis(position, scale)
#define OODebugDrawBoundingBox(box)
#define OODebugDrawColoredVector(position, v, color)
#define OODebugDrawColoredVectorAtOrigin(v, color)
#define OOINLINE
OOINLINE Vector vector_add(Vector a, Vector b) INLINE_CONST_FUNC
Definition OOVector.h:195
const Vector kZeroVector
Definition OOVector.m:27
OOINLINE Vector vector_multiply_scalar(Vector v, OOScalar s) INLINE_CONST_FUNC
Definition OOVector.h:180