2007-06-19
¢£[ode][ruby]ºîÀï
- C++¤Î¥¤¥ó¥¿¡¼¥Õ¥§¥¤¥¹¤Ï»È¤ï¤Ê¤¤¡£
¥ª¥Ö¥¸¥§¥¯¥È»Ø¸þ¤Ê¥é¥Ã¥Ñ¥é¥¤¥Ö¥é¥ê¤òRuby¤Ç½ñ¤¯¡£
ODE_API const dReal * dBodyGetPosition (dBodyID);
¤Ç¤Ï¤Ê¤¯
ODE_API void dBodyCopyPosition (dBodyID body, dVector3 pos);
¤ò»È¤¦¡£¤É¤¦¤»ruby¤ÎÇÛÎó¤Ë¥³¥Ô¡¼¤¹¤ë¤ó¤À¤«¤é¡£
double¤ÎÇÛÎó¤ò¼õ¤±¤ëC¤Î´Ø¿ô¤òºî¤Ã¤Æ¤·¤Þ¤¦¤Î¤¬´Êñ¤«¤â¤·¤ì¤Ê¤¤¡£
¢£ÃÍÅϤ·¤¸¤ã¤Ê¤¤¤è¤Í
#include <stdio.h> void test1(float* a) { printf("1 %f %x %d\n", a[0], a, sizeof(a)); } void test2(float a[]) { printf("2 %f %x %d\n", a[0], a, sizeof(a)); } void test3(float a[100]) { printf("3 %f %x %d\n", a[0], a, sizeof(a)); } int main(int argc, char *argv) { float a[100]; a[0] = 1.2345; test1(a); test2(a); test3(a); }
1 1.234500 bfffebd0 4 2 1.234500 bfffebd0 4 3 1.234500 bfffebd0 4
°ú¿ô¤ÎÇÛÎó¤Î¥µ¥¤¥º¤Ï¤¢¤Ã¤Æ¤â¤Ê¤¯¤Æ¤â´Ø·¸¤Ê¤¤¤Î¤«¡£
C¸À¸ì˺¤ì¤Æ¤ë¤Í¡£
¢£[ruby][swig][ode]SWIG¤ÇÇÛÎó¤òÊÖ¤¹´Ø¿ô¤ò»È¤¦ÊýË¡
http://www.goto.info.waseda.ac.jp/~fukusima/ruby/swig-j.html
¤«¤é
http://www2s.biglobe.ne.jp/~Nori/ruby/dist/ruby-libgraph-0.0.2.tar.gz
¤ò¤ß¤Æ¤ß¤ë¤È¡¢
%ifdef SWIGRUBY // Ruby specific code
%name(get_size) VALUE call_func_get_size() {
VALUE ary = rb_ary_new2(2);
int x, y;
lg_graph_get_size((Graph *)self, &x, &y);
rb_ary_push(ary, INT2FIX(x));
rb_ary_push(ary, INT2FIX(y));
return ary;
}
%endif
¤³¤ó¤Ê¥³¡¼¥É¤¬¡£¤³¤ì¤Ç¤¤¤¤¤Î¤«¡©
¢£[ruby][ode]Ruby/DL¤ËdoubleÇÛÎó¤òÅϤ¹ÊýË¡
irb(main):001:0> require "dl"
=> true
irb(main):008:0* [3.0, 0.0, 1.0].to_ptr.to_a("F")
=> [0.0, 2.125, 0.0, 0.0, 0.0, 1.875]
irb(main):009:0> [3.0, 0.0, 1.0].to_ptr.to_a("D")
=> [3.0, 0.0, 1.0]
irb(main):010:0> [-180.0, 0.0, 0.0].to_ptr.to_a("F")
=> [0.0, -3.6015625, 0.0, 0.0, 0.0, 0.0]
irb(main):011:0> [-180.0, 0.0, 0.0].to_ptr.to_a("D")
=> [-180.0, 0.0, 0.0]
Ctrl-V¤Ç¤Ç¤Æ¤¯¤ë
Viewpoint = (0.0000,2.1250,0.0000,0.0000,-3.6016,0.0000)
¤È°ìÃפ·¤Æ¤ë¡£
float¤ÎÇÛÎó¤Ë̵ÍýÌðÍýdouble¤¤¤ì¤Á¤ã¤Ã¤¿¡©
¤µ¤ÆÃ»¤¤float¤Ë¤É¤¦¤ä¤Ã¤ÆÊÑ´¹¤¹¤ë¤ó¤À¤í¤¦¡£¡£¡£
