Class: SFML::Vertex
- Inherits:
-
Object
- Object
- SFML::Vertex
- Defined in:
- ext/graphics/vertex.c,
ext/graphics/vertex.c
Overview
A single point used to build up VertexArray and VertexBuffer primitives: a position, a color, and texture coordinates.
Instance Attribute Summary collapse
-
#color ⇒ Color
Returns the object's color.
-
#position ⇒ Vector2
Returns the object's position.
-
#tex_coords ⇒ Vector2
Returns the vertex's texture coordinates.
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
Returns
trueif the two objects are equal. -
#initialize(*args) ⇒ Vertex
constructor
Any omitted argument defaults to position
(0, 0), color white, and tex_coords(0, 0). -
#to_a ⇒ Array, Color
Returns the object as an Array.
Constructor Details
#new ⇒ Vertex #new(position) ⇒ Vertex #new(position, color) ⇒ Vertex #new(position, color, tex_coords) ⇒ Vertex
Any omitted argument defaults to position (0, 0), color white, and
tex_coords (0, 0).
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'ext/graphics/vertex.c', line 57
static VALUE Vertex_initialize(int argc, VALUE* argv, VALUE self) {
VALUE rb_position, rb_color, rb_tex_coords;
sfVertex vertex = {{0, 0}, {255, 255, 255, 255}, {0, 0}};
rb_scan_args(argc, argv, "03", &rb_position, &rb_color, &rb_tex_coords);
if (!NIL_P(rb_position)) {
vertex.position = vec2f_from_rb(rb_position);
}
if (!NIL_P(rb_color)) {
vertex.color = color_from_rb(rb_color);
}
if (!NIL_P(rb_tex_coords)) {
vertex.texCoords = vec2f_from_rb(rb_tex_coords);
}
((Vertex*)Get_Vertex_Struct(self))->vertex = vertex;
return self;
}
|
Instance Attribute Details
#color ⇒ Color
Returns the object's color.
181 182 183 |
# File 'ext/graphics/vertex.c', line 181
static VALUE Vertex_get_color(VALUE self) {
return color_to_rb(((Vertex*)Get_Vertex_Struct(self))->vertex.color);
}
|
#position ⇒ Vector2
Returns the object's position.
181 182 183 |
# File 'ext/graphics/vertex.c', line 181
static VALUE Vertex_get_position(VALUE self) {
return vec2f_to_rb(((Vertex*)Get_Vertex_Struct(self))->vertex.position);
}
|
#tex_coords ⇒ Vector2
Returns the vertex's texture coordinates.
181 182 183 |
# File 'ext/graphics/vertex.c', line 181
static VALUE Vertex_get_tex_coords(VALUE self) {
return vec2f_to_rb(((Vertex*)Get_Vertex_Struct(self))->vertex.texCoords);
}
|
Instance Method Details
#==(other) ⇒ Boolean
Returns true if the two objects are equal.
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 |
# File 'ext/graphics/vertex.c', line 165
static VALUE Vertex_eql(VALUE self, VALUE rb_other) {
sfVertex a = ((Vertex*)Get_Vertex_Struct(self))->vertex;
sfVertex b;
if (!rb_obj_is_kind_of(rb_other, rb_cVertex)) {
return Qfalse;
}
b = ((Vertex*)Get_Vertex_Struct(rb_other))->vertex;
return BOOL2RB(a.position.x == b.position.x && a.position.y == b.position.y &&
a.color.r == b.color.r && a.color.g == b.color.g && a.color.b == b.color.b &&
a.color.a == b.color.a && a.texCoords.x == b.texCoords.x &&
a.texCoords.y == b.texCoords.y);
}
|
#to_a ⇒ Array, Color
Returns the object as an Array.
152 153 154 155 156 |
# File 'ext/graphics/vertex.c', line 152
static VALUE Vertex_to_a(VALUE self) {
Vertex* v = Get_Vertex_Struct(self);
return rb_ary_new_from_args(2, vec2f_to_rb(v->vertex.position), color_to_rb(v->vertex.color));
}
|