Class: Assimp::Vector3D

Inherits:
FFI::Struct
  • Object
show all
Extended by:
StructAccessors
Defined in:
lib/assimp/vector3.rb

Instance Method Summary collapse

Methods included from StructAccessors

extended, has_ref?, struct_array_attr_accessor, struct_array_attr_checker, struct_array_attr_reader, struct_array_attr_writer, struct_attr_accessor, struct_attr_reader, struct_attr_writer, struct_ref_array_attr_accessor, struct_ref_array_attr_reader, struct_ref_array_attr_writer

Instance Method Details

#*(other) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/assimp/vector3.rb', line 49

def *(other)
  v = Vector3D::new
  if other.kind_of? Vector3D
    v.set(x * other.x,
          y * other.y,
          z * other.z)
  else
    v.set(x * other,
          y * other,
          z * other)
  end
end

#+(other) ⇒ Object



35
36
37
38
39
40
# File 'lib/assimp/vector3.rb', line 35

def +(other)
  v = Vector3D::new
  v.set(x + other.x,
        y + other.y,
        z + other.z)
end

#-(other) ⇒ Object



42
43
44
45
46
47
# File 'lib/assimp/vector3.rb', line 42

def -(other)
  v = Vector3D::new
  v.set(x - other.x,
        y - other.y,
        z - other.z)
end

#-@Object



30
31
32
33
# File 'lib/assimp/vector3.rb', line 30

def -@
  v = Vector3D::new
  v.set(-x, -y, -z)
end

#/(other) ⇒ Object



69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/assimp/vector3.rb', line 69

def /(other)
  v = Vector3D::new
  if other.kind_of? Vector3D
    v.set(x / other.x,
          y / other.y,
          z / other.z)
  else
    v.set(x / other,
          y / other,
          z / other)
  end
end

#^(other) ⇒ Object



62
63
64
65
66
67
# File 'lib/assimp/vector3.rb', line 62

def ^(other)
  v = Vector3D::new
  v.set(y*other.z - z*other.y,
        z*other.x - x*other.z,
        x*other.y - y*other.x)
end

#lengthObject



19
20
21
# File 'lib/assimp/vector3.rb', line 19

def length
  Math::sqrt(square_length)
end

#normalizeObject



92
93
94
95
# File 'lib/assimp/vector3.rb', line 92

def normalize
  v = self.dup
  v.normalize!
end

#normalize!Object



82
83
84
85
86
87
88
89
90
# File 'lib/assimp/vector3.rb', line 82

def normalize!
  l = length
  if l > 0.0
    self.x /= l
    self.y /= l
    self.z /= l
  end
  self
end

#set(x, y, z) ⇒ Object



23
24
25
26
27
28
# File 'lib/assimp/vector3.rb', line 23

def set( x, y, z )
  self[:x] = x
  self[:y] = y
  self[:z] = z
  self
end

#square_lengthObject



15
16
17
# File 'lib/assimp/vector3.rb', line 15

def square_length
  x*x + y*y + z*z
end

#to_sObject



11
12
13
# File 'lib/assimp/vector3.rb', line 11

def to_s
  "<#{x}, #{y}, #{z}>"
end