Class: NvTriStrip::PrimitiveGroup
- Inherits:
-
Object
- Object
- NvTriStrip::PrimitiveGroup
- Includes:
- Enumerable
- Defined in:
- ext/RbTriStrip.cpp
Class Method Summary collapse
-
.new(type, numIndices) ⇒ Object
Creates an PrimitiveGroup of given number and type of indices, rarely used directly.
Instance Method Summary collapse
-
#each ⇒ Object
Iterate through all indices.
-
#get_at(index) ⇒ Object
(also: #[])
Value at index.
-
#num_indices ⇒ Object
(also: #length, #size)
Number of indices.
-
#set_at(index, val) ⇒ Object
(also: #[]=)
Set value at index.
Class Method Details
.new(type, numIndices) ⇒ Object
Creates an PrimitiveGroup of given number and type of indices, rarely used directly
35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'ext/RbTriStrip.cpp', line 35
VALUE primitivegroup_new(VALUE klass, VALUE type, VALUE numIndices) {
PrimitiveGroupWrap *pgw;
VALUE rpg=Data_Make_Struct(klass, PrimitiveGroupWrap, 0, primitivegroup_free, pgw);
pgw->pg=new PrimitiveGroup;
pgw->pg->type=(PrimType)NUM2INT(type);
pgw->pg->numIndices=NUM2INT(numIndices);
pgw->pg->indices=new unsigned short[pgw->pg->numIndices];
memset(pgw->pg->indices, 0, pgw->pg->numIndices * sizeof(unsigned short));
return rpg;
}
|
Instance Method Details
#each ⇒ Object
Iterate through all indices
93 94 95 96 97 98 99 100 101 |
# File 'ext/RbTriStrip.cpp', line 93
VALUE primitivegroup_each(VALUE self) {
PrimitiveGroupWrap *pgw;
Data_Get_Struct(self, PrimitiveGroupWrap, pgw);
for(int i=0;i<pgw->pg->numIndices;i++) {
rb_yield(INT2NUM(pgw->pg->indices[i]));
}
}
|
#index ⇒ Object #[](index) ⇒ Object Also known as: []
Value at index
69 70 71 72 73 74 75 76 77 |
# File 'ext/RbTriStrip.cpp', line 69
VALUE primitivegroup_get_at(VALUE self, VALUE index) {
PrimitiveGroupWrap *pgw;
Data_Get_Struct(self, PrimitiveGroupWrap, pgw);
int i=NUM2INT(index);
if(i<0 || i>pgw->pg->numIndices-1) rb_raise(rb_eIndexError,"Index out of bounds");
return INT2NUM(pgw->pg->indices[i]);
}
|
#num_indices ⇒ Object #size ⇒ Object Also known as: length, size
Number of indices
83 84 85 86 87 88 89 |
# File 'ext/RbTriStrip.cpp', line 83
VALUE primitivegroup_num_indices(VALUE self) {
PrimitiveGroupWrap *pgw;
Data_Get_Struct(self, PrimitiveGroupWrap, pgw);
return INT2NUM(pgw->pg->numIndices);
}
|
#index ⇒ Object #[]=(index) ⇒ Object Also known as: []=
Set value at index
53 54 55 56 57 58 59 60 61 62 63 |
# File 'ext/RbTriStrip.cpp', line 53
VALUE primitivegroup_set_at(VALUE self, VALUE index, VALUE val) {
PrimitiveGroupWrap *pgw;
Data_Get_Struct(self, PrimitiveGroupWrap, pgw);
int v=NUM2INT(val);
int i=NUM2INT(index);
if(i<0 || i>pgw->pg->numIndices-1) rb_raise(rb_eIndexError,"Index out of bounds");
if(v<0 || v>65535) rb_raise(rb_eArgError, "Indices need to be between 0 and 65535");
pgw->pg->indices[i]=v;
return val;
}
|