Changeset 14310

Show
Ignore:
Timestamp:
06/20/08 22:55:55 (5 years ago)
Author:
takeru
Message:

add textures

Location:
lang/ruby/pitagora/trunk/ode_ruby
Files:
14 added
5 modified

Legend:

Unmodified
Added
Removed
  • lang/ruby/pitagora/trunk/ode_ruby/build.sh

    r14282 r14310  
    2020  -x "dstest         \ 
    2121  -r ../ode-0.9_orig ../ode-0.9_fix > diffs/DIFF_ode-0.9.txt 
     22cat DIFF_ode-0.9.txt 
    2223cp diffs/DIFF_ode-0.9.txt "diffs/DIFF_ode-0.9_`date`.txt" 
    23 cat DIFF_ode-0.9.txt 
     24 
    2425 
    2526 
  • lang/ruby/pitagora/trunk/ode_ruby/demo/objects.rb

    r14282 r14310  
    2020# wrap objects 
    2121class Base 
    22   attr_reader :geom, :body, :color, :pars 
     22  attr_reader :geom, :body, :color, :pars, :texture 
    2323  @@color_index = 0 
    2424  def initialize(*_pars) 
    2525    @color = COLORS[@@color_index] #[1.0, 0.0, 0.0] 
     26    @texture = 0 
    2627    @@color_index += 1 
    2728    @@color_index = @@color_index % COLORS.size 
     
    5253    rot  = (0..11).collect{|n| pRot[n] } 
    5354  end 
     55  def rotation=(r) 
     56    @body.setRotation(r) 
     57  end 
     58  def quaternion=(q) 
     59    @body.setQuaternion(q) 
     60  end 
    5461  def color=(rgb) 
    5562    @color = rgb.collect{|n| n.to_f } 
     
    5966    @pars = _pars.dup 
    6067    reset 
     68  end 
     69  def texture=(t) 
     70    @texture = t 
    6171  end 
    6272  def draw 
     
    102112  def ds_draw 
    103113    DrawStuff::DSLib.dsSetColor(*color) 
     114    DrawStuff::DSLib.dsSetTexture(@texture) 
    104115    DrawStuff::DSLib.dsDrawBoxD(self.position, self.rotation, @geom.getLengths) 
    105116  end 
     
    131142  def ds_draw 
    132143    DrawStuff::DSLib.dsSetColor(*color) 
    133     #DrawStuff::DSLib.dsSetTexture(1) 
     144    DrawStuff::DSLib.dsSetTexture(@texture) 
    134145    DrawStuff::DSLib.dsDrawSphereD(self.position, self.rotation, @geom.getRadius) 
    135146  end 
     
    163174  def ds_draw 
    164175    DrawStuff::DSLib.dsSetColor(*color) 
    165     #DrawStuff::DSLib.dsSetTexture(1) 
     176    DrawStuff::DSLib.dsSetTexture(@texture) 
    166177    radius,length = @geom.getParams 
    167178    DrawStuff::DSLib.dsDrawCapsuleD(self.position, self.rotation, length, radius) 
     
    196207  def ds_draw 
    197208    DrawStuff::DSLib.dsSetColor(*color) 
    198     #DrawStuff::DSLib.dsSetTexture(1) 
     209    DrawStuff::DSLib.dsSetTexture(@texture) 
    199210    radius,length = @geom.getParams 
    200211    DrawStuff::DSLib.dsDrawCylinderD(self.position, self.rotation, length, radius) 
  • lang/ruby/pitagora/trunk/ode_ruby/demo/test2.rb

    r14282 r14310  
    1313#   ポインタを拡充 
    1414#   colors 
    15 #   blog / coderepos / 動画 
    16 #   ppmを動画にする方法 
     15#   3Dプレゼン テクスチャ切替 
    1716 
    1817 
     
    2625window_width  = 352*2 
    2726window_height = 228*2 
     27DEG_TO_RAD = Math::PI/180.0 
    2828 
    2929#-------------------------------------------------------------- 
     
    8484    create_capsule_cylinder 
    8585    create_pins 
     86    create_slides 
    8687    #ray = Ray.new(1) 
    8788    #ray.position = [0, -4, 5] 
     
    126127    obj.color = hash[:color] 
    127128    obj.position = hash[:position] 
    128     # obj.rotation = hash[:rotation] # TODO!! 
     129    obj.rotation = hash[:rotation] 
    129130  end 
    130131end 
     
    166167  slope.position = [7, 0, 3.2] 
    167168  slope.color = [1.0, 0.7, 0] 
     169  #slope.texture = 1001 
    168170end 
    169171 
     
    190192  end 
    191193end 
     194 
     195def create_slides 
     196  [[15,  6, 1], 
     197   [10,  8, 1], 
     198   [ 5, 10, 1], 
     199   [ 0, 12, 1], 
     200   [-5, 10, 1], 
     201  ].each_with_index do |pos,index| 
     202    s = Box.new([1, 1, 0.5], 1) 
     203    s.position = pos 
     204    s.color = [2,2,2] 
     205    s.texture = 1011+index 
     206    r = Ode_cpp::dRFromAxisAndAngle(0, 1, 0,  80*DEG_TO_RAD) 
     207    s.rotation = r 
     208  end 
     209 
     210  #r1 = Ode_cpp::dRFromAxisAndAngle(0, 1, 0,  45*DEG_TO_RAD) 
     211  #r2 = Ode_cpp::dRFromAxisAndAngle(0, 0, 1, -45*DEG_TO_RAD) 
     212  #q1 = Ode_cpp::dQfromR(r1) 
     213  #q2 = Ode_cpp::dQfromR(r2) 
     214  #q  = Ode_cpp::dQMultiply0(q1, q2) 
     215  #r = Ode_cpp::dRFromAxisAndAngle(0, 1, 0, -90*DEG_TO_RAD) 
     216  #s1.quaternion = q 
     217end 
     218 
    192219 
    193220def rand_within(from, to) 
     
    214241 
    215242require "draw_stuff" 
    216 path_to_textures = File.join(File.dirname(__FILE__), "../../ode-0.9_fix/drawstuff/textures") 
     243#path_to_textures = File.join(File.dirname(__FILE__), "../../ode-0.9_fix/drawstuff/textures") 
     244path_to_textures = File.join(File.dirname(__FILE__), "../textures") 
    217245ds = DrawStuff.new(:world=>$world, 
    218246                   :width  =>window_width, 
     
    237265    #xyz = [  50.0,   0.0,   1.0] # 視点の位置 
    238266    #hpr = [-180.0,   0.0,   0.0] # 視線の方向 
    239     xyz = [18.7891311645508, 10.3102083206177, 4.46602010726929] 
    240     hpr = [-134.198913574219, -13.0999450683594, 0.0] 
     267    #xyz = [18.7891311645508, 10.3102083206177, 4.46602010726929] 
     268    #hpr = [-134.198913574219, -13.0999450683594, 0.0] 
     269    xyz=[15.7971229553223, 5.94557666778564, 1.14663815498352] 
     270    hpr=[177.560760498047, -10.6020441055298, 0.0] 
    241271    self.set_viewpoint(xyz, hpr) 
    242272  end 
     
    616646 
    617647  def wii_remote_client=(c) @wii_remote_client = c; end 
    618   DEG_TO_RAD = Math::PI/180.0 
    619648  #// call this to update the current camera position. the bits in `mode' say 
    620649  #// if the left (1), middle (2) or right (4) mouse button is pressed, and 
  • lang/ruby/pitagora/trunk/ode_ruby/diffs/DIFF_ode-0.9.txt

    r14282 r14310  
     1diff -x '*.in' -x '*.o' -x '*.a' -x 'demo_*' -x Makefile -x '*.m4' -x configure -x 'config.*' -x .deps -x 'stamp-h1         -x libode.dylib' -x 'ode-config       -x ode_unit_test' -x 'autom4te.cache   -x dstest' -r ../ode-0.9_orig/.svn/all-wcprops ../ode-0.9_fix/.svn/all-wcprops 
     23,4c3,4 
     3< V 59 
     4< /share/!svn/ver/14282/lang/ruby/pitagora/trunk/ode-0.9_orig 
     5--- 
     6> V 58 
     7> /share/!svn/ver/14282/lang/ruby/pitagora/trunk/ode-0.9_fix 
     8diff -x '*.in' -x '*.o' -x '*.a' -x 'demo_*' -x Makefile -x '*.m4' -x configure -x 'config.*' -x .deps -x 'stamp-h1         -x libode.dylib' -x 'ode-config       -x ode_unit_test' -x 'autom4te.cache   -x dstest' -r ../ode-0.9_orig/.svn/entries ../ode-0.9_fix/.svn/entries 
     95c5 
     10< http://svn.coderepos.org/share/lang/ruby/pitagora/trunk/ode-0.9_orig 
     11--- 
     12> http://svn.coderepos.org/share/lang/ruby/pitagora/trunk/ode-0.9_fix 
    113Only in ../ode-0.9_fix: autom4te.cache 
    214Only in ../ode-0.9_fix/drawstuff/dstest: dstest 
     15diff -x '*.in' -x '*.o' -x '*.a' -x 'demo_*' -x Makefile -x '*.m4' -x configure -x 'config.*' -x .deps -x 'stamp-h1         -x libode.dylib' -x 'ode-config       -x ode_unit_test' -x 'autom4te.cache   -x dstest' -r ../ode-0.9_orig/drawstuff/src/drawstuff.cpp ../ode-0.9_fix/drawstuff/src/drawstuff.cpp 
     16887a888,890 
     17> #define USER_TEXTURE_OFFSET 1000 
     18> #define USER_TEXTURE_COUNT  100 
     19> static Texture* user_textures[USER_TEXTURE_COUNT]; 
     20907a911,937 
     21>  
     22>   //----- 
     23>   //user_textures = new Texture[100]; 
     24>   for(int i=0; i<USER_TEXTURE_COUNT; i++){ // 0..99 
     25>     int file_ok = 0; 
     26>     char *fn = (char*) alloca(20); 
     27>     strcpy (s,prefix); 
     28>     sprintf(fn, "/user_%.3d.ppm", i); 
     29>     strcat (s, fn); 
     30>     //dsDebug(fn); 
     31>     FILE *f = fopen (s,"rb"); 
     32>     if(!f){ 
     33>       file_ok = 0; 
     34>       //dsError ("Can't open image file `%s'",fn); 
     35>     }else{ 
     36>       file_ok = 1; 
     37>       fclose(f); 
     38>     } 
     39>     if(file_ok){ 
     40>       user_textures[i] = new Texture(s); 
     41>       //dsDebug("OK"); 
     42>     }else{ 
     43>       user_textures[i] = 0; 
     44>       //dsDebug("NG"); 
     45>     } 
     46>   } 
     47>   //----- 
     48928a959,960 
     49>  
     50>    //TODO load user_textures 
     51938a971,978 
     52>   for(int i=0; i<USER_TEXTURE_COUNT; i++){ 
     53>     Texture* t = user_textures[i]; 
     54>     if(t){ 
     55>       delete t; 
     56>       user_textures[i] = 0; 
     57>     } 
     58>   } 
     59>   //delete user_textures; 
     60941a982 
     61>   //user_textures = 0; 
     621201c1242,1254 
     63<       wood_texture->bind (1); 
     64--- 
     65>       // wood_texture->bind (1); 
     66> //----- 
     67>       if(USER_TEXTURE_OFFSET<=tnum){ 
     68>         Texture* t = user_textures[tnum-USER_TEXTURE_OFFSET]; 
     69>         if(t){ 
     70>           t->bind (1); 
     71>         }else{ 
     72>           wood_texture->bind (1); 
     73>         } 
     74>       }else{ 
     75>         wood_texture->bind (1); 
     76>       } 
     77> //----- 
     781203a1257 
     79>  
     801206,1207c1260,1265 
     81<       static GLfloat s_params[4] = {1.0f,1.0f,0.0f,1}; 
     82<       static GLfloat t_params[4] = {0.817f,-0.817f,0.817f,1}; 
     83--- 
     84>       //static GLfloat s_params[4] = {  1.0f,    1.0f, 0.0f,   1}; 
     85>       //static GLfloat t_params[4] = {0.817f, -0.817f, 0.817f, 1}; 
     86>  
     87>       //glTranslated(-0.5, -0.5, 0.0); 
     88>       static GLfloat s_params[4] = { 0.0f, 1.0f, 0.0f, 0.5f}; 
     89>       static GLfloat t_params[4] = { 1.0f, 0.0f, 0.0f, 0.5f}; 
     90Only in ../ode-0.9_fix/drawstuff/src: drawstuff.cpp~ 
    391diff -x '*.in' -x '*.o' -x '*.a' -x 'demo_*' -x Makefile -x '*.m4' -x configure -x 'config.*' -x .deps -x 'stamp-h1         -x libode.dylib' -x 'ode-config       -x ode_unit_test' -x 'autom4te.cache   -x dstest' -r ../ode-0.9_orig/include/ode/mass.h ../ode-0.9_fix/include/ode/mass.h 
    492106a107,110 
  • lang/ruby/pitagora/trunk/ode_ruby/src/ode_cpp.i

    r14282 r14310  
    7373} 
    7474 
     75 
     76// [const dMatrix3 R] ************************************ 
     77//void setRotation (const dMatrix3 R) 
     78//    { dGeomSetRotation (_id,R); } 
     79 
     80//------------------------------------------------------- 
     81// for dMatrix3 input param 
     82%typemap(in) const dMatrix3 R { 
     83  $1 = (dReal*)malloc(sizeof(dMatrix3)); 
     84  VALUE r = $input; 
     85  $1[0]  = NUM2DBL(rb_ary_entry(r, 0)); 
     86  $1[1]  = NUM2DBL(rb_ary_entry(r, 1)); 
     87  $1[2]  = NUM2DBL(rb_ary_entry(r, 2)); 
     88  $1[3]  = NUM2DBL(rb_ary_entry(r, 3)); 
     89  $1[4]  = NUM2DBL(rb_ary_entry(r, 4)); 
     90  $1[5]  = NUM2DBL(rb_ary_entry(r, 5)); 
     91  $1[6]  = NUM2DBL(rb_ary_entry(r, 6)); 
     92  $1[7]  = NUM2DBL(rb_ary_entry(r, 7)); 
     93  $1[8]  = NUM2DBL(rb_ary_entry(r, 8)); 
     94  $1[9]  = NUM2DBL(rb_ary_entry(r, 9)); 
     95  $1[10] = NUM2DBL(rb_ary_entry(r, 10)); 
     96  $1[11] = NUM2DBL(rb_ary_entry(r, 11)); 
     97} 
     98%typemap(freearg) const dMatrix3 R { 
     99  free($1); 
     100} 
     101 
     102//------------------------------------------------------- 
     103// for dMatrix3 output param 
     104%typemap(ignore) dMatrix3 R { 
     105  $1 = (dReal*)malloc(sizeof(dMatrix3)); 
     106} 
     107%typemap(argout) dMatrix3 R { 
     108  $result = rb_ary_new(); 
     109  rb_ary_push($result, rb_float_new($1[0])); 
     110  rb_ary_push($result, rb_float_new($1[1])); 
     111  rb_ary_push($result, rb_float_new($1[2])); 
     112  rb_ary_push($result, rb_float_new($1[3])); 
     113  rb_ary_push($result, rb_float_new($1[4])); 
     114  rb_ary_push($result, rb_float_new($1[5])); 
     115  rb_ary_push($result, rb_float_new($1[6])); 
     116  rb_ary_push($result, rb_float_new($1[7])); 
     117  rb_ary_push($result, rb_float_new($1[8])); 
     118  rb_ary_push($result, rb_float_new($1[9])); 
     119  rb_ary_push($result, rb_float_new($1[10])); 
     120  rb_ary_push($result, rb_float_new($1[11])); 
     121} 
     122%typemap(freearg) dMatrix3 R { 
     123  free($1); 
     124} 
     125 
     126 
     127 
     128//------------------------------------------------------- 
     129// for dQuaternion input param 
     130%typemap(in) const dQuaternion q { 
     131  $1 = (dReal*)malloc(sizeof(dQuaternion)); 
     132  VALUE r = $input; 
     133  $1[0]  = NUM2DBL(rb_ary_entry(r, 0)); 
     134  $1[1]  = NUM2DBL(rb_ary_entry(r, 1)); 
     135  $1[2]  = NUM2DBL(rb_ary_entry(r, 2)); 
     136  $1[3]  = NUM2DBL(rb_ary_entry(r, 3)); 
     137} 
     138%typemap(freearg) const dQuaternion q { 
     139  free($1); 
     140} 
     141%apply const dQuaternion q { const dQuaternion quat }; 
     142%apply const dQuaternion q { const dQuaternion B    }; 
     143 
     144 
     145//------------------------------------------------------- 
     146// for dQuaternion output param 
     147%typemap(ignore) dQuaternion q { 
     148  $1 = (dReal*)malloc(sizeof(dQuaternion)); 
     149} 
     150%typemap(argout) dQuaternion q { 
     151  $result = rb_ary_new(); 
     152  rb_ary_push($result, rb_float_new($1[0])); 
     153  rb_ary_push($result, rb_float_new($1[1])); 
     154  rb_ary_push($result, rb_float_new($1[2])); 
     155  rb_ary_push($result, rb_float_new($1[3])); 
     156} 
     157%typemap(freearg) dQuaternion q { 
     158  free($1); 
     159} 
     160%apply dQuaternion q { dQuaternion qa }; 
     161 
    75162#define ODE_API extern 
    76163%include "ode/mass.h" 
     164%include "ode/rotation.h" 
    77165#undef  ODE_API 
    78166%include "ode/contact.h" 
     167 
     168 
     169 
     170/* matrix multiplication. all matrices are stored in standard row format. 
     171 * the digit refers to the argument that is transposed: 
     172 *   0:   A = B  * C   (sizes: A:p*r B:p*q C:q*r) 
     173 *   1:   A = B' * C   (sizes: A:p*r B:q*p C:q*r) 
     174 *   2:   A = B  * C'  (sizes: A:p*r B:p*q C:r*q) 
     175 * case 1,2 are equivalent to saying that the operation is A=B*C but 
     176 * B or C are stored in standard column format. 
     177 */ 
     178//ODE_API void dMultiply0 (dReal *A, const dReal *B, const dReal *C, int p,int q,int r); 
     179//ODE_API void dMultiply1 (dReal *A, const dReal *B, const dReal *C, int p,int q,int r); 
     180//ODE_API void dMultiply2 (dReal *A, const dReal *B, const dReal *C, int p,int q,int r); 
     181 
     182 
     183 
    79184 
    80185 
     
    160265//END   C API 
    161266 
    162  
    163267%include "ode/odecpp.h" 
    164268%include "ode/odecpp_collision.h"