自己紹介

低層をがむしゃらに走る自称プログラマ ちょっとWebとかに手を出してる

ブログ アーカイブ

2010年10月14日木曜日

考えてること

突然なんですが、


今度の冬コミに出すのは、(出れればの話だが)
「うさぎは絵本の中の~」の体験版ではなく、

うさぎは絵本の中の~を作るための勉強として作っている
ある意味習作を、出せればと思っています。

というか絶賛製作中です。

ーーー

今回は、ジオメトリーウォーズ風なシンプルな形で、
360度のSTGで、プチプチ敵を倒せるようにしたいと考えてます。

それと、今回は、誰でもが自機や敵を作れればいいなー、
という事をコンセプトに、のそのそと作っております。
今月末あたりから、スクリーンショットを上げれる形に
仕上げられればいいかな、と計画しています。

ががが、がんばります!

ーーー

はい、思い出しました。
今年の4月にコメントがきていたことを…。

内容は、Box2DのDebugDrawがうまく動かないという事でした。
Box2Dのバージョンは2.0.1。

C++の場合です。

Box2DのDebugDrawを使用するためには、前提としてまず
「b2DebugDraw」クラスを継承したクラスを作る必要があります。

http://www.linuxuser.at/elements/doc/box2d/classb2_debug_draw.htm

b2DebugDrawクラス


enum  {
  e_shapeBit = 0x0001, e_jointBit = 0x0002, e_coreShapeBit = 0x0004, e_aabbBit = 0x0008,
  e_obbBit = 0x0010, e_pairBit = 0x0020, e_centerOfMassBit = 0x0040
}


上記Enumは簡単に言えば
DebugDrawで何を描画するかというフラグです。


virtual void DrawPolygon (const b2Vec2 *vertices, int32 vertexCount, const b2Color &color)=0
Draw a closed polygon provided in CCW order. 
virtual void DrawSolidPolygon (const b2Vec2 *vertices, int32 vertexCount, const b2Color &color)=0
Draw a solid closed polygon provided in CCW order. 
virtual void DrawCircle (const b2Vec2 &center, float32 radius, const b2Color &color)=0
Draw a circle. 
virtual void DrawSolidCircle (const b2Vec2 &center, float32 radius, const b2Vec2 &axis, const b2Color &color)=0
Draw a solid circle. 
virtual void DrawSegment (const b2Vec2 &p1, const b2Vec2 &p2, const b2Color &color)=0
Draw a line segment. 
virtual void DrawXForm (const b2XForm &xf)=0
Draw a transform. 


それからこれは「virtual」ですから、抽象メソッド(仮想関数)です。
抽象メソッドは、別クラスによって継承しなければ使用することができません

そのため、このb2DebugDrawクラスを継承させる必要があります…

  1. class DebugDraw : public b2DebugDraw  
  2. {  
  3.   
  4. public:  
  5.  void DrawPolygon(const b2Vec2* vertices, int32 vertexCount, const b2Color& color);  
  6.  void DrawPolygon(const b2Vec2& center, const b2Vec2* vertices, int32 vertexCount, const b2Color& color);  
  7.  void DrawSolidPolygon(const b2Vec2* vertices, int32 vertexCount, const b2Color& color);  
  8.  void DrawCircle(const b2Vec2& center, float32 radius, const b2Color& color);  
  9.  void DrawSolidCircle(const b2Vec2& center, float32 radius, const b2Vec2& axis, const b2Color& color);  
  10.  void DrawSegment(const b2Vec2& p1, const b2Vec2& p2, const b2Color& color);  
  11.  void DrawXForm(const b2XForm& xf);  
  12. };  

こんな感じです:-)
内容に関しては、私の場合DXライブラリを使っていろいろやってます。


  1. void DebugDraw::DrawPolygon(const b2Vec2* vertices, int32 vertexCount, const b2Color& color)  
  2. {  
  3.  int mode;//一時BLEND記録領域  
  4.  int parm;//一時BLENDパラメータ記録領域  
  5.  GetDrawBlendMode(&mode,&parm);  
  6.    
  7.  SetDrawBlendMode(DX_BLENDMODE_NOBLEND,128);  
  8.   
  9.  int i = 1;  
  10.   
  11.  for(; i < vertexCount; i++)  
  12.  {  
  13.   DrawLine(static_cast<int>(vertices[i-1].x * global::SCALE),static_cast<int>(vertices[i-1].y * global::SCALE),  
  14.      static_cast<int>(vertices[i].x * global::SCALE),static_cast<int>(vertices[i].y * global::SCALE),  
  15.      GetColor(static_cast<int>(255*color.r),  
  16.         static_cast<int>(255*color.g),  
  17.         static_cast<int>(255*color.b)));  
  18.  }  
  19.    
  20.  DrawLine(static_cast<int>(vertices[0].x * global::SCALE),static_cast<int>( vertices[0].y * global::SCALE),  
  21.     static_cast<int>(vertices[i-1].x * global::SCALE),static_cast<int>( vertices[i-1].y * global::SCALE),  
  22.     GetColor(static_cast<int>(255*color.r),  
  23.        static_cast<int>(255*color.g),  
  24.        static_cast<int>(255*color.b)  
  25.        ));  
  26.    
  27.  SetDrawBlendMode(mode,parm);  
  28. }</int></int></int></int></int></int></int></int></int></int></int></int></int></int>  

DrawPolygonに関してはこんな感じです
注釈すくなく、さらにきたなくてすんません。
さらに言えばタグがひどい(w

さて、これをVirtualがあるだけやっていくと
とりあえずはDebugDrawは動く状態になります。

ーーー

実際に使う際はこうです

  1. DebugDraw* debug = new DebugDraw();  
  2.   
  3.  debug->SetFlags( 0xFFFF );  
  4.   
  5.  global::boxglobal::g_world->SetDebugDraw(debug);  


0xFFFF の部分には、上記の enum を入れましょう

debug->e_***

という感じで、複数指定したいときは

debug->e_*** + debug->e_***

で問題ありません。


そんなもんです、はい。
それじゃあ今日のところは終わり

0 件のコメント:

コメントを投稿