#include "rays/ruby/camera.h" #include "rays/ruby/image.h" #include "defs.h" RUCY_DEFINE_VALUE_FROM_TO(Rays::Camera) #define THIS to(self) #define CHECK RUCY_CHECK_OBJECT(Rays::Camera, self) static VALUE alloc(VALUE klass) { return new_type(klass); } static VALUE initialize(VALUE self) { RUCY_CHECK_OBJ(Rays::Camera, self); *THIS = Rays::Camera(); return self; } static VALUE start(VALUE self) { CHECK; return value(THIS->start()); } static VALUE stop(VALUE self) { CHECK; THIS->stop(); } static VALUE is_active(VALUE self) { CHECK; return value(THIS->is_active()); } static VALUE image(VALUE self) { CHECK; const Rays::Image* img = THIS->image(); return img ? value(*img) : nil(); } static Class cCamera; void Init_camera () { Module mRays = rb_define_module("Rays"); cCamera = rb_define_class_under(mRays, "Camera", rb_cObject); rb_define_alloc_func(cCamera, alloc); rb_define_private_method(cCamera, "initialize", RUBY_METHOD_FUNC(initialize), -1); rb_define_method(cCamera, "start", RUBY_METHOD_FUNC(start), 0); rb_define_method(cCamera, "stop", RUBY_METHOD_FUNC(stop), 0); cCamera.define_method("active?", is_active); rb_define_method(cCamera, "image", RUBY_METHOD_FUNC(image), 0); } namespace Rays { Class camera_class () { return cCamera; } }// Rays