Class: Bvh::Motion::Frame

Inherits:
Object
  • Object
show all
Defined in:
lib/bvh/motion/frame.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeFrame

Returns a new instance of Frame.



8
9
10
# File 'lib/bvh/motion/frame.rb', line 8

def initialize()
  @channel_data = []
end

Instance Attribute Details

#channel_dataObject (readonly)

The array of ChannelData objects for this frame: one ChannelData instance for each bone.



6
7
8
# File 'lib/bvh/motion/frame.rb', line 6

def channel_data
  @channel_data
end

Instance Method Details

#absolute_transform_matrix(bone) ⇒ Object Also known as: transform_matrix

Returns the transform matrix of the root node multiplied with its children recursively down to the specified bone, the result being the total transformation in worldspace for this frame.



83
84
85
86
87
88
# File 'lib/bvh/motion/frame.rb', line 83

def absolute_transform_matrix(bone)
  relative = relative_transform_matrix(bone)
  if bone.parent then absolute_transform_matrix(bone.parent) * relative
  else relative
  end
end

#arithmetic_proc(target) ⇒ Object

call-seq:

frame + frame  => new_frame
frame - frame  => new_frame
frame / frame  => new_frame
frame * frame  => new_frame
frame + number => new_frame
frame - number => new_frame
frame / number => new_frame
frame * number => new_frame

Performs arithmetic on this frame with the target. The second operand may be either a number or another Frame. If the target is a number, then that number is added to, subtracted from, multiplied with, or divided against each channel of each ChannelData object in this frame.

If the target is another Frame, the arithmetic looks something like this (simplified):

return_value.channel_data[0] = frame1.channel_data[0] * frame2.channel_data[0]
return_value.channel_data[0] = frame1.channel_data[1] * frame2.channel_data[1]
return_value.channel_data[0] = frame1.channel_data[2] * frame2.channel_data[2]
. . .

Both frames must contain the same number of ChannelData instances, and each instance must have the same number of channels, and each instance must also reference the same bone.

Returns a new frame containing the result.



46
47
48
# File 'lib/bvh/motion/frame.rb', line 46

def arithmetic_proc(target)
  # Fooled you! I metaprogrammed it to save some typing!
end

#channel_data_for(bone) ⇒ Object

Returns the channel data for the specified bone.



71
72
73
74
# File 'lib/bvh/motion/frame.rb', line 71

def channel_data_for(bone)
  @channel_data.each { |c| return c if c.bone == bone }
  raise "Channel data for bone not found: #{bone.name}"
end

#copyObject

Creates a copy of this frame, including a dup of its channel data.



13
14
15
16
17
18
19
# File 'lib/bvh/motion/frame.rb', line 13

def copy
  ret = self.class.new
  channel_data.each do |datum|
    ret.channel_data << datum.dup
  end
  ret
end

#get_channel(bone, channel) ⇒ Object

Retrives the value for a specific channel for a specific bone within this frame.



99
100
101
# File 'lib/bvh/motion/frame.rb', line 99

def get_channel(bone, channel)
  channel_data_for(bone).get_channel(channel)
end

#relative_transform_matrix(bone) ⇒ Object Also known as: local_transform_matrix

Returns the relative, or local, transform matrix for the specified bone in this frame.



77
78
79
# File 'lib/bvh/motion/frame.rb', line 77

def relative_transform_matrix(bone)
  return channel_data_for(bone).relative_transform_matrix
end

#rotate!(bone, channel, theta) ⇒ Object

Modifies the channel data for this bone in this frame, resulting in a rotation around the specified channel.

Ex:

bvh.last_frame.set_channel bone, 'Xrotation', 180 # => rotates the bone by 180 deg rotation around the X-axis


108
109
110
# File 'lib/bvh/motion/frame.rb', line 108

def rotate!(bone, channel, theta)
  set_channel(bone, channel, channel_data_for(bone).get_channel(channel) + theta)
end

#set_channel(bone, channel, theta) ⇒ Object

Modifies a single attribute of the channel data for this bone in this frame. Returns self.

Ex:

bvh.last_frame.set_channel bone, 'Xrotation', 180 # => sets the bone to a 180 deg rotation around the X-axis


94
95
96
# File 'lib/bvh/motion/frame.rb', line 94

def set_channel(bone, channel, theta)
  channel_data_for(bone).set_channel(channel, theta)
end

#translate!(bone, x, y, z) ⇒ Object

Adds x, y and z to the X, Y and Z position channels for this bone in this frame, resulting in a “movement” or translation.



114
115
116
117
118
# File 'lib/bvh/motion/frame.rb', line 114

def translate!(bone, x, y, z)
  set_channel(bone, 'Xposition', channel_data_for(bone).get_channel('Xposition')+x)
  set_channel(bone, 'Yposition', channel_data_for(bone).get_channel('Yposition')+y)
  set_channel(bone, 'Zposition', channel_data_for(bone).get_channel('Zposition')+z)
end