Oolite
Loading...
Searching...
No Matches
OOCrosshairs Class Reference

#include <OOCrosshairs.h>

Inheritance diagram for OOCrosshairs:
Collaboration diagram for OOCrosshairs:

Instance Methods

(id) - initWithPoints:scale:color:overallAlpha:
(void) - render
(void) - dealloc [implementation]
(void) - setUpDataWithPoints:scale:color:overallAlpha: [implementation]
(void) - setUpDataForOnePoint:scale:colorComps:overallAlpha:data: [implementation]

Private Attributes

NSUInteger _count
GLfloat * _data

Detailed Description

Definition at line 34 of file OOCrosshairs.h.

Method Documentation

◆ dealloc

- (void) dealloc
implementation

Definition at line 67 of file OOCrosshairs.m.

68{
69 free(_data);
70
71 [super dealloc];
72}
GLfloat * _data

References _data, and dealloc.

Referenced by dealloc.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ initWithPoints:scale:color:overallAlpha:

- (id) initWithPoints: (NSArray*) points
scale: (GLfloat) scale
color: (OOColor*) color
overallAlpha: (GLfloat) alpha 

Definition at line 53 of file OOCrosshairs.m.

53 :(NSArray*)points
54 scale:(GLfloat)scale
55 color:(OOColor*)color
56 overallAlpha:(GLfloat)alpha
57{
58 if ((self = [super init])) {
59 if (alpha > 0.0f && (color == nil || [color alphaComponent] != 0.0f)) {
60 [self setUpDataWithPoints:points scale:scale color:color overallAlpha:alpha];
61 }
62 }
63
64 return self;
65}
return nil

References nil, and setUpDataWithPoints:scale:color:overallAlpha:.

Here is the call graph for this function:

◆ render

- (void) render

Definition at line 74 of file OOCrosshairs.m.

75{
76 if (_data != NULL) {
79
80 OOGL(glPushAttrib(GL_ENABLE_BIT));
81 OOGL(glDisable(GL_LIGHTING));
82 OOGL(glDisable(GL_TEXTURE_2D));
84 OOGLTranslateModelView(make_vector(0.0, 0.0, [[UNIVERSE gameView] display_z]));
85
86 OOGL(glVertexPointer(2, GL_FLOAT, sizeof(GLfloat) * 6, _data));
87 OOGL(glColorPointer(4, GL_FLOAT, sizeof(GLfloat) * 6, _data + 2));
88
89 OOGL(glEnableClientState(GL_VERTEX_ARRAY));
90 OOGL(glEnableClientState(GL_COLOR_ARRAY));
91
92 OOGL(glDrawArrays(GL_LINES, 0, _count * 2));
93
94 OOGL(glDisableClientState(GL_VERTEX_ARRAY));
95 OOGL(glDisableClientState(GL_COLOR_ARRAY));
96
98 OOGL(glPopAttrib());
99
101 OOCheckOpenGLErrors(@"OOCrosshairs after rendering");
102 }
103}
#define OO_ENTER_OPENGL()
void OOGLPushModelView(void)
void OOGLTranslateModelView(Vector vector)
OOMatrix OOGLPopModelView(void)
@ OPENGL_STATE_OVERLAY
Definition OOOpenGL.h:124
#define OOVerifyOpenGLState()
Definition OOOpenGL.h:133
BOOL OOCheckOpenGLErrors(NSString *format,...)
Definition OOOpenGL.m:38
#define OOSetOpenGLState(STATE)
Definition OOOpenGL.h:132
#define OOGL(statement)
Definition OOOpenGL.h:262
OOINLINE Vector make_vector(OOScalar vx, OOScalar vy, OOScalar vz) INLINE_CONST_FUNC
Definition OOVector.h:149
#define UNIVERSE
Definition Universe.h:827
NSUInteger _count

References _count, _data, make_vector(), OO_ENTER_OPENGL, OOCheckOpenGLErrors(), OOGL, OOGLPopModelView(), OOGLPushModelView(), OOGLTranslateModelView(), OOSetOpenGLState, OOVerifyOpenGLState, OPENGL_STATE_OVERLAY, render, and UNIVERSE.

Referenced by render.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setUpDataForOnePoint:scale:colorComps:overallAlpha:data:

- (void) setUpDataForOnePoint: (NSArray*) pointInfo
scale: (GLfloat) scale
colorComps: (float[4]) colorComps
overallAlpha: (GLfloat) alpha
data: (GLfloat*) ioBuffer 
implementation

Provided by category OOCrosshairs(Private).

Definition at line 133 of file OOCrosshairs.m.

133 :(NSArray*)pointInfo
134 scale:(GLfloat)scale
135 colorComps:(float[4])colorComps
136 overallAlpha:(GLfloat)alpha
137 data:(GLfloat*)ioBuffer
138{
139 GLfloat x1, y1, a1, x2, y2, a2;
140 GLfloat r, g, b, a;
141
142 if ([pointInfo count] >= 6) {
143 a1 = [pointInfo oo_floatAtIndex:0];
144 x1 = [pointInfo oo_floatAtIndex:1] * scale;
145 y1 = [pointInfo oo_floatAtIndex:2] * scale;
146 a2 = [pointInfo oo_floatAtIndex:3];
147 x2 = [pointInfo oo_floatAtIndex:4] * scale;
148 y2 = [pointInfo oo_floatAtIndex:5] * scale;
149 r = colorComps[0];
150 g = colorComps[1];
151 b = colorComps[2];
152 a = colorComps[3];
153
154 /* a1/a2 * a is hud.plist and crosshairs.plist - specified alpha,
155 which must be clamped to 0..1 so the plist-specified alpha can't
156 "escape" the overall alpha range. The result of scaling this by
157 overall HUD alpha is then clamped again for robustness.
158 */
159 a1 = OOClamp_0_1_f(OOClamp_0_1_f(a1 * a) * alpha);
160 a2 = OOClamp_0_1_f(OOClamp_0_1_f(a2 * a) * alpha);
161 } else {
162 // Bad entry, write red point in middle.
163 x1 = -0.01f;
164 x2 = 0.01f;
165 y1 = y2 = 0.0f;
166 r = 1.0f;
167 g = b = 0.0f;
168 a1 = a2 = 1.0;
169 }
170
171 *ioBuffer++ = x1;
172 *ioBuffer++ = y1;
173 *ioBuffer++ = r;
174 *ioBuffer++ = g;
175 *ioBuffer++ = b;
176 *ioBuffer++ = a1;
177
178 *ioBuffer++ = x2;
179 *ioBuffer++ = y2;
180 *ioBuffer++ = r;
181 *ioBuffer++ = g;
182 *ioBuffer++ = b;
183 *ioBuffer++ = a2;
184
185 (void)ioBuffer;
186}
OOINLINE float OOClamp_0_1_f(float value) INLINE_CONST_FUNC
unsigned count

References count, and OOClamp_0_1_f().

Referenced by OOCrosshairs(Private)::setUpDataWithPoints:scale:color:overallAlpha:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setUpDataWithPoints:scale:color:overallAlpha:

- (void) setUpDataWithPoints: (NSArray*) points
scale: (GLfloat) scale
color: (OOColor*) color
overallAlpha: (GLfloat) alpha 
implementation

Provided by category OOCrosshairs(Private).

Definition at line 105 of file OOCrosshairs.m.

105 :(NSArray*)points
106 scale:(GLfloat)scale
107 color:(OOColor*)color
108 overallAlpha:(GLfloat)alpha
109{
110 NSUInteger i;
111 float colorComps[4] = { 0.0f, 1.0f, 0.0f, 1.0f };
112 GLfloat* data = NULL;
113
114 _count = [points count];
115 if (_count == 0)
116 return;
117
118 _data = malloc(sizeof(GLfloat) * 12 * _count); // 2 coordinates, 4 colour components for each endpoint of each line segment
119 [color getRed:&colorComps[0] green:&colorComps[1] blue:&colorComps[2] alpha:&colorComps[3]];
120
121 // Turn NSArray into GL-friendly element array
122 data = _data;
123 for (i = 0; i < _count; i++) {
124 [self setUpDataForOnePoint:[points oo_arrayAtIndex:i]
125 scale:scale
126 colorComps:colorComps
127 overallAlpha:alpha
128 data:data];
129 data += 12;
130 }
131}
void getRed:green:blue:alpha:(float *red,[green] float *green,[blue] float *blue,[alpha] float *alpha)
Definition OOColor.m:344

References OOColor::getRed:green:blue:alpha:, and setUpDataForOnePoint:scale:colorComps:overallAlpha:data:.

Referenced by initWithPoints:scale:color:overallAlpha:.

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ _count

- (NSUInteger) _count
private

Definition at line 36 of file OOCrosshairs.h.

Referenced by render.

◆ _data

- (GLfloat*) _data
private

Definition at line 37 of file OOCrosshairs.h.

Referenced by dealloc, and render.


The documentation for this class was generated from the following files: