Class: Mittsu::BufferAttribute

Inherits:
Object
  • Object
show all
Defined in:
lib/mittsu/core/buffer_attribute.rb

Direct Known Subclasses

DynamicBufferAttribute

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(array, item_size) ⇒ BufferAttribute

Returns a new instance of BufferAttribute.



5
6
7
8
9
10
# File 'lib/mittsu/core/buffer_attribute.rb', line 5

def initialize(array, item_size)
  @array = array
  @item_size = item_size

  @needs_update = false
end

Instance Attribute Details

#arrayObject

Returns the value of attribute array.



3
4
5
# File 'lib/mittsu/core/buffer_attribute.rb', line 3

def array
  @array
end

#item_sizeObject

Returns the value of attribute item_size.



3
4
5
# File 'lib/mittsu/core/buffer_attribute.rb', line 3

def item_size
  @item_size
end

#needs_updateObject

Returns the value of attribute needs_update.



3
4
5
# File 'lib/mittsu/core/buffer_attribute.rb', line 3

def needs_update
  @needs_update
end

Instance Method Details

#cloneObject



95
96
97
# File 'lib/mittsu/core/buffer_attribute.rb', line 95

def clone
  BufferAttribute.new(@array.clone, @item_size)
end

#copy_at(index1, attribute, index2) ⇒ Object



16
17
18
19
20
21
22
23
24
25
# File 'lib/mittsu/core/buffer_attribute.rb', line 16

def copy_at(index1, attribute, index2)
  index1 *= @item_size
  index2 *= attribute.item_size

  @item_size.times do |i|
    @array[index1 + i] = attribute.array[index2 + i]
  end

  self
end

#get_x(index) ⇒ Object



53
54
55
# File 'lib/mittsu/core/buffer_attribute.rb', line 53

def get_x(index)
  @array[index * @item_size]
end

#get_y(index) ⇒ Object



57
58
59
# File 'lib/mittsu/core/buffer_attribute.rb', line 57

def get_y(index)
  @array[index * @item_size + 1]
end

#get_z(index) ⇒ Object



61
62
63
# File 'lib/mittsu/core/buffer_attribute.rb', line 61

def get_z(index)
  @array[index * @item_size + 2]
end

#lengthObject



12
13
14
# File 'lib/mittsu/core/buffer_attribute.rb', line 12

def length
  @array.length
end

#set(value, offset) ⇒ Object



27
28
29
30
31
32
33
# File 'lib/mittsu/core/buffer_attribute.rb', line 27

def set(value, offset)
  offset ||= 0

  @array[offset, value.length] = value

  self
end

#set_x(index, x) ⇒ Object



35
36
37
38
39
# File 'lib/mittsu/core/buffer_attribute.rb', line 35

def set_x(index, x)
  @array[index * @item_size] = x

  self
end

#set_xy(index, x, y) ⇒ Object



65
66
67
68
69
70
71
72
# File 'lib/mittsu/core/buffer_attribute.rb', line 65

def set_xy(index, x, y)
  index *= @item_size

  @array[index    ] = x
  @array[index + 1] = y

  self
end

#set_xyz(index, x, y, z) ⇒ Object



74
75
76
77
78
79
80
81
82
# File 'lib/mittsu/core/buffer_attribute.rb', line 74

def set_xyz(index, x, y, z)
  index *= @item_size

  @array[index    ] = x
  @array[index + 1] = y
  @array[index + 2] = z

  self
end

#set_xyzw(index, x, y, z, w) ⇒ Object



84
85
86
87
88
89
90
91
92
93
# File 'lib/mittsu/core/buffer_attribute.rb', line 84

def set_xyzw(index, x, y, z, w)
  index *= @item_size

  @array[index    ] = x
  @array[index + 1] = y
  @array[index + 2] = z
  @array[index + 3] = w

  self
end

#set_y(index, y) ⇒ Object



41
42
43
44
45
# File 'lib/mittsu/core/buffer_attribute.rb', line 41

def set_y(index, y)
  @array[index * @item_size + 1] = y

  self
end

#set_z(index, z) ⇒ Object



47
48
49
50
51
# File 'lib/mittsu/core/buffer_attribute.rb', line 47

def set_z(index, z)
  @array[index * @item_size + 2] = z

  self
end