#include "reflex/ruby/body.h" #include #include "rays/ruby/point.h" #include "reflex/ruby/fixture.h" #include "defs.h" using namespace Rucy; RUCY_DEFINE_VALUE_FROM_TO(Reflex::Body) #define THIS to(self) #define CHECK RUCY_CHECK_OBJ(Reflex::Body, self) static VALUE initialize_copy(VALUE self, VALUE obj) { CHECK; *THIS = to(obj); return self; } static VALUE add_box(VALUE self, VALUE width, VALUE height) { CHECK; return value(THIS->add_box(width.as_f(true), height.as_f(true))); } static VALUE add_ellipse(VALUE self, VALUE width, VALUE height) { CHECK; return value(THIS->add_ellipse(width.as_f(true), height.as_f(true))); } static VALUE add_arc(VALUE self, VALUE width, VALUE height, VALUE angle_from, VALUE angle_to) { CHECK; return value(THIS->add_arc( width.as_f(true), height.as_f(true), angle_from.as_f(true), angle_to.as_f(true))); } static VALUE clear_fixtures(VALUE self) { CHECK; THIS->clear_fixtures(); return self; } static VALUE meter2pixel(VALUE self) { CHECK; check_arg_count(__FILE__, __LINE__, "View#meter2pixel", argc, 0, 1); float meter = argc >= 1 ? argv[0].as_f(true) : 1; return value(THIS->meter2pixel(meter)); } static VALUE set_static(VALUE self, VALUE state) { CHECK; THIS->set_static(state); return state; } static VALUE is_static(VALUE self) { CHECK; return value(THIS->is_static()); } static VALUE set_dynamic(VALUE self, VALUE state) { CHECK; THIS->set_dynamic(state); return state; } static VALUE is_dynamic(VALUE self) { CHECK; return value(THIS->is_dynamic()); } static VALUE get_position(VALUE self) { CHECK; return value(THIS->position()); } static VALUE get_angle(VALUE self) { CHECK; return value(THIS->angle()); } static VALUE set_linear_velocity(VALUE self, VALUE velocity) { CHECK; THIS->set_linear_velocity(to(velocity)); return self; } static VALUE get_linear_velocity(VALUE self) { CHECK; return value(THIS->linear_velocity()); } static VALUE set_angular_velocity(VALUE self, VALUE velocity) { CHECK; THIS->set_angular_velocity(velocity.as_f(true)); return self; } static VALUE get_angular_velocity(VALUE self) { CHECK; return value(THIS->angular_velocity()); } static VALUE set_density(VALUE self, VALUE density) { CHECK; THIS->set_density(density.as_f(true)); return self; } static VALUE get_density(VALUE self) { CHECK; return value(THIS->density()); } static VALUE set_friction(VALUE self, VALUE friction) { CHECK; THIS->set_friction(friction.as_f(true)); return self; } static VALUE get_friction(VALUE self) { CHECK; return value(THIS->friction()); } static VALUE set_restitution(VALUE self, VALUE restitution) { CHECK; THIS->set_restitution(restitution.as_f(true)); return self; } static VALUE get_restitution(VALUE self) { CHECK; return value(THIS->restitution()); } static VALUE each(VALUE self) { CHECK; Value ret; Reflex::Body::iterator end = THIS->end(); for (Reflex::Body::iterator it = THIS->begin(); it != end; ++it) ret = rb_yield(value(*it)); return ret; } static Class cBody; void Init_body () { Module mReflex = rb_define_module("Reflex"); cBody = rb_define_class_under(mReflex, "Body", rb_cObject); rb_define_private_method(cBody, "initialize_copy", RUBY_METHOD_FUNC(initialize_copy), 1); rb_define_method(cBody, "add_box", RUBY_METHOD_FUNC(add_box), 2); rb_define_method(cBody, "add_ellipse", RUBY_METHOD_FUNC(add_ellipse), 2); rb_define_method(cBody, "add_arc", RUBY_METHOD_FUNC(add_arc), 4); rb_define_method(cBody, "clear_fixtures", RUBY_METHOD_FUNC(clear_fixtures), 0); rb_define_method(cBody, "meter2pixel", RUBY_METHOD_FUNC(meter2pixel), -1); rb_define_method(cBody, "static=", RUBY_METHOD_FUNC(set_static), 1); cBody.define_method("static?", is_static); rb_define_method(cBody, "dynamic=", RUBY_METHOD_FUNC(set_dynamic), 1); cBody.define_method("dynamic?", is_dynamic); rb_define_method(cBody, "position", RUBY_METHOD_FUNC(get_position), 0); rb_define_method(cBody, "angle", RUBY_METHOD_FUNC(get_angle), 0); rb_define_method(cBody, "linear_velocity=", RUBY_METHOD_FUNC(set_linear_velocity), 1); rb_define_method(cBody, "linear_velocity", RUBY_METHOD_FUNC(get_linear_velocity), 0); rb_define_method(cBody, "angular_velocity=", RUBY_METHOD_FUNC(set_angular_velocity), 1); rb_define_method(cBody, "angular_velocity", RUBY_METHOD_FUNC(get_angular_velocity), 0); rb_define_method(cBody, "density=", RUBY_METHOD_FUNC(set_density), 1); rb_define_method(cBody, "density", RUBY_METHOD_FUNC(get_density), 0); rb_define_method(cBody, "friction=", RUBY_METHOD_FUNC(set_friction), 1); rb_define_method(cBody, "friction", RUBY_METHOD_FUNC(get_friction), 0); rb_define_method(cBody, "restitution=", RUBY_METHOD_FUNC(set_restitution), 1); rb_define_method(cBody, "restitution", RUBY_METHOD_FUNC(get_restitution), 0); rb_define_method(cBody, "each", RUBY_METHOD_FUNC(each), 0); } namespace Reflex { Class body_class () { return cBody; } }// Reflex