Oolite 1.91.0.7644-241112-7f5034b
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 35 of file OOCrosshairs.h.

Method Documentation

◆ dealloc

- (void) dealloc
implementation

Definition at line 1 of file OOCrosshairs.m.

73{
74 free(_data);
75
76 [super dealloc];
77}
GLfloat * _data

◆ initWithPoints:scale:color:overallAlpha:

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

Definition at line 1 of file OOCrosshairs.m.

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

◆ render

- (void) render

Definition at line 1 of file OOCrosshairs.m.

81{
82 if (_data != NULL)
83 {
86
87 OOGL(glPushAttrib(GL_ENABLE_BIT));
88 OOGL(glDisable(GL_LIGHTING));
89 OOGL(glDisable(GL_TEXTURE_2D));
91 OOGLTranslateModelView(make_vector(0.0, 0.0, [[UNIVERSE gameView] display_z]));
92
93 OOGL(glVertexPointer(2, GL_FLOAT, sizeof (GLfloat) * 6, _data));
94 OOGL(glColorPointer(4, GL_FLOAT, sizeof (GLfloat) * 6, _data + 2));
95
96 OOGL(glEnableClientState(GL_VERTEX_ARRAY));
97 OOGL(glEnableClientState(GL_COLOR_ARRAY));
98
99 OOGL(glDrawArrays(GL_LINES, 0, _count * 2));
100
101 OOGL(glDisableClientState(GL_VERTEX_ARRAY));
102 OOGL(glDisableClientState(GL_COLOR_ARRAY));
103
105 OOGL(glPopAttrib());
106
108 OOCheckOpenGLErrors(@"OOCrosshairs after rendering");
109 }
110}
#define OO_ENTER_OPENGL()
void OOGLPushModelView(void)
void OOGLTranslateModelView(Vector vector)
OOMatrix OOGLPopModelView(void)
@ OPENGL_STATE_OVERLAY
Definition OOOpenGL.h:126
#define OOVerifyOpenGLState()
Definition OOOpenGL.h:136
BOOL OOCheckOpenGLErrors(NSString *format,...)
Definition OOOpenGL.m:39
#define OOSetOpenGLState(STATE)
Definition OOOpenGL.h:135
#define OOGL(statement)
Definition OOOpenGL.h:251
#define UNIVERSE
Definition Universe.h:833
NSUInteger _count

◆ 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 1 of file OOCrosshairs.m.

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

◆ 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 1 of file OOCrosshairs.m.

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

Member Data Documentation

◆ _count

- (NSUInteger) _count
private

Definition at line 38 of file OOCrosshairs.h.

◆ _data

- (GLfloat*) _data
private

Definition at line 39 of file OOCrosshairs.h.


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