bambooflow Note

ジオメトリ

最終更新:

bambooflow

- view
メンバー限定 登録/ログイン

ジオメトリクラス


ODE v0.11.1



衝突を表現できる形状。

(ここでは、縦方向をzとして説明。)


Sphere(球体)


ボール上の物体。
半径の情報を持ちます。


dGeomID dCreateSphere (dSpaceID space, dReal radius);
void dGeomSphereSetRadius (dGeomID sphere, dReal radius);
dReal dGeomSphereGetRadius (dGeomID sphere);
dReal dGeomSpherePointDepth (dGeomID sphere, dReal x, dReal y, dReal z);

radius:半径



Box(箱)


縦、横、高さの大きさを持つ箱形状のもの。


dGeomID dCreateBox (dSpaceID space, dReal lx, dReal ly, dReal lz);
void dGeomBoxSetLengths (dGeomID box, dReal lx, dReal ly, dReal lz);
void dGeomBoxGetLengths (dGeomID box, dVector3 result);
dReal dGeomBoxPointDepth (dGeomID box, dReal x, dReal y, dReal z);



Plane(面)


地面や床を表現できます。


Capsule(カプセル状)


カプセル状の物体。
円柱の長さと両側の球体の半径の情報を持ちます。

前のバージョン(v0.6より前)では、名前はCapped Cylinder (CCylinder)でした。




dGeomID dCreateCapsule (dSpaceID space, dReal radius, dReal length);
void dGeomCapsuleSetParams (dGeomID capsule, dReal radius, dReal length);
void dGeomCapsuleGetParams (dGeomID capsule, dReal *radius, dReal *length);
dReal dGeomCapsulePointDepth (dGeomID capsule, dReal x, dReal y, dReal z);



Cylinder(円柱)


円柱、もしくはタイヤ形状のもの。
長さと半径の情報を持ちます。


ODE0.11.1は、CapsuleとCylinderとは衝突しないようなので注意してください。

dGeomID dCreateCylinder (dSpaceID space, dReal radius, dReal length);
void dGeomCylinderSetParams (dGeomID cylinder, dReal radius, dReal length);
void dGeomCylinderGetParams (dGeomID cylinder, dReal *radius, dReal *length);



Ray(光線)


線状の物体。
これは、ほかのジオメトリと少し異なります。


dGeomID dCreateRay (dSpaceID space, dReal length);
void dGeomRaySetLength (dGeomID ray, dReal length);
dReal dGeomRayGetLength (dGeomID ray);
void dGeomRaySet (dGeomID ray, dReal px, dReal py, dReal pz, dReal dx, dReal dy, dReal dz);
void dGeomRayGet (dGeomID ray, dVector3 start, dVector3 dir);

void dGeomRaySetParams( dGeomID ray, int FirstContact, int BackfaceCull );
void dGeomRayGetParams( dGeomID ray, int *FirstContact, int *BackfaceCull );
void dGeomRaySetClosestHit( dGeomID ray, int ClosestHit );
int  dGeomRayGetClosestHit( dGeomID ray );

レイキャストは、レイによって衝突を検出するメカニズムです。



Convex(凸型メッシュ)


凸型メッシュは、
  • すべての頂点の内角は180度未満
  • 任意の直線との交点は2つ
  • 頂点順でポリゴンを複数の三角メッシュに分割可
という特徴を持ちます。

凹型のメッシュの衝突検出はとても処理が重くなるので、ゲームのようにリアルタイムで衝突検出をさせる場合は、凸型メッシュ(コンベックス)に置き換えることをします。

ODE0.11.1現在では、衝突できるプリミティブは限られています。


dGeomID dCreateConvex (dSpaceID space, dReal *planes, unsigned planecount, 
                      dReal *points, unsigned pointcount, unsigned *polygons);

void dGeomSetConvex (dGeomID g, dReal *planes, unsigned planecount,
                    dReal *points, unsigned pointcount, unsigned *polygons);


Triangle Mesh (TriMesh)


複数の三角形のポリゴン面を使って表現したもの。
凹型のメッシュ。

↑demo_moving_trimeshより



dTriMeshDataID dGeomTriMeshDataCreate();
void dGeomTriMeshDataDestroy (dTriMeshDataID g);

void dGeomTriMeshDataBuild (dTriMeshDataID g,
                           const void* Vertices, int VertexStride, int VertexCount,
                           const void* Indices, int IndexCount, int TriStride,
                           const void* Normals);


  • 八面体の場合

VertexStride = 3*sizeof(dReal)
TriStride = 3*sizeof(unsigned int)


IndexCountはなぜか頂点数x3。頂点数じゃないの?

間違ってたらごめんなさい。





Heightfield(ハイトフィールド)


三角メッシュと似ていますが、縦横の分割数と高さのみの情報を持つ立体形状を表現した図形。
ハイトフィールドを使うと、リアルな山やほかの地形を簡単に作成することができます。

↑demo_heightfieldより


dHeightfieldDataID dGeomHeightfieldDataCreate ();
void dGeomHeightfieldDataDestroy (dHeightfieldDataID d)

void dGeomHeightfieldDataBuildByte   (dHeightfieldDataID d,
                                     const unsigned char *pHeightData,
                                     int bCopyHeightData,
                                     dReal width, dReal depth,
                                     int widthSamples, int depthSamples,
                                     dReal scale, dReal offset, dReal thickness, int bWrap);

void dGeomHeightfieldDataBuildShort  (dHeightfieldDataID d,
                                     const short *pHeightData,
                                     int bCopyHeightData,
                                     dReal width, dReal depth,
                                     int widthSamples, int depthSamples,
                                     dReal scale, dReal offset, dReal thickness, int bWrap);

void dGeomHeightfieldDataBuildSingle (dHeightfieldDataID d,
                                     const float *pHeightData,
                                     int bCopyHeightData,
                                     dReal width, dReal depth,
                                     int widthSamples, int depthSamples,
                                     dReal scale, dReal offset, dReal thickness, int bWrap);

void dGeomHeightfieldDataBuildDouble (dHeightfieldDataID d,
                                     const double *pHeightData,
                                     int bCopyHeightData,
                                     dReal width, dReal depth,
                                     int widthSamples, int depthSamples,
                                     dReal scale, dReal offset, dReal thickness, int bWrap);


pHeightDataは、実際に使うときは1次元配列にしたほうがよいかも。

間違ってたらごめんなさい。




Geometry Transform


ジオメトリのオフセットに使用できます。
dGeomGetPosition()で取得できる位置に対してジオメトリをずらすことができます。

The geom transform classes are deprecated. Use geom offsets instead.
これはあまりお奨めしません。
もし物体を結合させるようなモデルを作りたいのであればdJointFixedを使えばいいし、
単にジオメトリの位置をずらしたいのであればdGeomOffsetを使ったほうが簡単だと思います。
描画するときオフセット分ずらして表示しないといけないので面倒です。
(個人的意見も入ってます)

dGeomID dCreateGeomTransform (dSpaceID space);
void dGeomTransformSetGeom (dGeomID g, dGeomID obj);
dGeomID dGeomTransformGetGeom (dGeomID g);
void dGeomTransformSetInfo (dGeomID g, int mode);
int dGeomTransformGetInfo (dGeomID g);

タグ:

ODE
記事メニュー
目安箱バナー