Module: ODE

Defined in:
lib/ode.rb

Defined Under Namespace

Modules: HashInitializer, ObjectID Classes: Body, DContact, DSurfaceParameters, Geom, HashSpace, Joint, JointGroup, QuadTreeSpace, SimpleSpace, Space, World

Class Method Summary collapse

Class Method Details

.camelize_method_name(methodname) ⇒ Object



183
184
185
186
187
188
# File 'lib/ode.rb', line 183

def self.camelize_method_name(methodname)
  camelized = (methodname.to_s.gsub(/^./) { |m| m.upcase }).gsub(/_(.)/) { |m| $1.upcase }
  camelized = "Set#{camelized}" if (camelized.sub!(/=$/,''))
  camelized.sub!(/[\!\?]$/,'')
  camelized
end

.closeObject



213
214
215
# File 'lib/ode.rb', line 213

def self.close
  ODE.dCloseODE()
end

.collide(o1, o2, max_contacts) ⇒ Object



209
210
211
# File 'lib/ode.rb', line 209

def self.collide(o1,o2,max_contacts)
  ODE.dCollideRuby(o1.id,o2.id,max_contacts)
end

.convert_args(args) ⇒ Object



163
164
165
166
167
168
169
170
171
172
173
# File 'lib/ode.rb', line 163

def self.convert_args(args)
  args.collect { |a|
    if (a.kind_of?(ObjectID))
	a.id
    elsif (a.kind_of?(Array) and a.all? { |e| e.kind_of?(Numeric) })
	SWIG::TYPE_p_float.from_a(a)
    else
	a
    end
  }
end

.convert_return_value(ret) ⇒ Object



175
176
177
178
179
180
181
# File 'lib/ode.rb', line 175

def self.convert_return_value(ret)
  if (ret.kind_of?(SWIG::Pointer) and ObjectID.by_id(ret))
    ObjectID.by_id(ret)
  else
    ret
  end
end

.method_missing(methodname, *args, &block) ⇒ Object



190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
# File 'lib/ode.rb', line 190

def self.method_missing(methodname, *args, &block)
  camelized = ODE.camelize_method_name(methodname)
  meth = nil
  ode_function = "d#{camelized}".intern
  ode_getter = "dGet#{camelized}".intern
  if (ODE.respond_to?(ode_function))
    meth = ODE.method(ode_function)
  elsif (ODE.respond_to?(ode_getter))
    meth = ODE.method(ode_getter)
  end
  if (meth)
    args = args[0] if (methodname.to_s =~ /=$/ and args.length == 1 and args[0].kind_of?(Array))
    args = convert_args(args)
    convert_return_value(meth.call(@id, *args, &block))
  else
    super(methodname, *args, &block)
  end
end