[JBullet、BulletCS]または自社製品に組み込んだ[Blender、Panda3d]。ここでは、少なくとも質問を正しく聞くことができれば、オッズは有益な返事を得るのに最も良いようです。弾丸物理学MultiSphereShapeの使用
ダイスのローリングをシミュレートしたいと思います。私が見つけることができるすべての例は、Boxシェイプを使用してコンテンツとして見えます。私のものはラスベガスではなく、子供のゲームに興味があります。私のアプリケーションでは、少なくとも6辺であろうと他のものであろうが、ここでは6面にとどめようとすると、尖ったコーナーのない「キンダー・ジェントラー」の丸みを帯びたエッジがあるということが、
btMultiSphereShapeは、私にはちょうどいいと思われます。私は、下位レベルのプリミティブから複雑な形状を構築する知識を持っていない人です。私は、既に組み込まれているものを使うことを望んでいる人です。 Bulletエンジンの衝突インテリジェンスであり、新しい、エキゾチックな行動をエンジニアリングしようとしている人ではありません。
:その序文で
は、私は本当にの簡潔な例をいただければ幸いです。引数をbtMultiSphhereShapeコンストラクタに渡す方法。 b。 btDefaultMaotionStateに渡す必要のあるトランスフォームを構成する方法。および c。 localInertiaの設定方法。
これは、ほとんどすべてをサポートできるクラスを備えた汎用ライブラリですが、初心者にとっては、よく考えられたツールキットの非常に優れた属性についての議論ではなく、私と私は多くの他のユーザーに信じています]は、これらの重要なクラスとメソッドにこれらの重要なプロパティを提供する明確な例です。
a。等しい寸法の6面ダイス、1面あたり約2cmの丸い立方体を作ってみましょう。 b。 「コーナー」の半径を0.1cmほど穏やかにしましょう。
もう1つお願いします。重力による力だけを考慮して、単純な「落下」で始まる金型の動作を観察するには、通常の「床」の例と衝突して何らかの興味深い落ち込みの結果になる変換を提案してください;言い換えれば、丸い角の床に影響を与えるはずです。
1
A
答えて
1
iOSデバイスでBullet Physicsを使用してサイコロゲームを作成しました。より現実的なダイスを得るために、私は斜めのエッジを持つ単なる立方体である "RoundedCube"オブジェクトを作成しました。ここで私はverticies
//
// Created by John Carter on 4/9/09.
//
#import "RoundedCube.h"
static const GLfloat voffset[] =
{
// Front Face (counterclockwise winding)
+1.0f, +1.0f, +1.0f,
-1.0f, +1.0f, +1.0f,
-1.0f, -1.0f, +1.0f,
+1.0f, +1.0f, +1.0f,
-1.0f, -1.0f, +1.0f,
+1.0f, -1.0f, +1.0f,
// Back Face (clockwise winding)
+1.0f, +1.0f, -1.0f,
-1.0f, -1.0f, -1.0f,
-1.0f, +1.0f, -1.0f,
+1.0f, +1.0f, -1.0f,
+1.0f, -1.0f, -1.0f,
-1.0f, -1.0f, -1.0f,
// Top Face (counterclockwise winding)
-1.0f, +1.0f, +1.0f,
+1.0f, +1.0f, -1.0f,
-1.0f, +1.0f, -1.0f,
-1.0f, +1.0f, +1.0f,
+1.0f, +1.0f, +1.0f,
+1.0f, +1.0f, -1.0f,
// Bottom Face (clockwise winding)
-1.0f, -1.0f, +1.0f,
-1.0f, -1.0f, -1.0f,
+1.0f, -1.0f, -1.0f,
-1.0f, -1.0f, +1.0f,
+1.0f, -1.0f, -1.0f,
+1.0f, -1.0f, +1.0f,
// Right Face (clockwise winding)
+1.0f, -1.0f, +1.0f,
+1.0f, +1.0f, -1.0f,
+1.0f, +1.0f, +1.0f,
+1.0f, -1.0f, +1.0f,
+1.0f, -1.0f, -1.0f,
+1.0f, +1.0f, -1.0f,
// Left Face (counterclockwise winding)
-1.0f, -1.0f, +1.0f,
-1.0f, +1.0f, +1.0f,
-1.0f, +1.0f, -1.0f,
-1.0f, +1.0f, -1.0f,
-1.0f, -1.0f, -1.0f,
-1.0f, -1.0f, +1.0f,
};
// Private Methods
//
@interface RoundedCube()
- (void) computeRoundedCubeNormals;
@end
@implementation RoundedCube
- (void) dealloc
{
[super dealloc];
}
- (void) computeRoundedCubeNormals
{
int i;
xMinVertex = FLT_MAX;
yMinVertex = FLT_MAX;
zMinVertex = FLT_MAX;
xMaxVertex = -FLT_MAX;
yMaxVertex = -FLT_MAX;
zMaxVertex = -FLT_MAX;
for (i=0; i<vertexDataCount; i+=3)
{
if (vertexData[i+0] < xMinVertex)
xMinVertex = vertexData[i+0] ;
if (vertexData[i+1] < yMinVertex)
yMinVertex = vertexData[i+1] ;
if (vertexData[i+2] < zMinVertex)
zMinVertex = vertexData[i+2] ;
if (vertexData[i+0] > xMaxVertex)
xMaxVertex = vertexData[i+0] ;
if (vertexData[i+1] > yMaxVertex)
yMaxVertex = vertexData[i+1] ;
if (vertexData[i+2] > zMaxVertex)
zMaxVertex = vertexData[i+2] ;
}
xVertexRange = fabs(xMaxVertex - xMinVertex);
yVertexRange = fabs(yMaxVertex - yMinVertex);
zVertexRange = fabs(zMaxVertex - zMinVertex);
for (i=0; i<vertexDataCount; i+=9)
{
btVector3 V0 = btVector3(vertexData[i+0], vertexData[i+1], vertexData[i+2]);
btVector3 V1 = btVector3(vertexData[i+3], vertexData[i+4], vertexData[i+5]);
btVector3 V2 = btVector3(vertexData[i+6], vertexData[i+7], vertexData[i+8]);
btVector3 delta1 = (V1) - (V0);
btVector3 delta2 = (V2) - (V0);
btVector3 vertexNormal = delta1.cross(delta2);
vertexNormal = vertexNormal.normalize();
if (useAbsNormals)
{
vertexNormal = vertexNormal.absolute();
}
normalData[i+0] = vertexNormal[0];
normalData[i+1] = vertexNormal[1];
normalData[i+2] = vertexNormal[2];
normalData[i+3] = vertexNormal[0];
normalData[i+4] = vertexNormal[1];
normalData[i+5] = vertexNormal[2];
normalData[i+6] = vertexNormal[0];
normalData[i+7] = vertexNormal[1];
normalData[i+8] = vertexNormal[2];
}
}
- (void) addBeveledCorner:(int)bevelPlane At:(btVector3)bevelLocation Size:(btVector3)bevelSize Rotation:(double)rotationOrigin
{
btVector3 vertexPoint[6];
double delta;
double theta0;
double theta1;
double phi0;
double phi1;
int vp;
int i;
int j;
int k;
delta = (double)M_PI_2/(double)smoothFactor;
// vertical segments
//
for(i=0; i<smoothFactor; i++)
{
theta0 = (double)i * (double)delta;
theta1 = (double)(i+1) * (double)delta;
if (bevelPlane==1)
{
theta0 += M_PI;
theta1 += M_PI;
}
// horizontal segments
//
for(j=0; j<smoothFactor; j++)
{
phi0 = (double)j * (double)delta;
phi1 = (double)(j+1) * (double)delta;
phi0 += rotationOrigin;
phi1 += rotationOrigin;
if (bevelPlane==1)
{
phi0 += M_PI;
phi1 += M_PI;
}
vp=0;
if (bevelPlane==0)
{
vertexPoint[vp++] = btVector3(bevelLocation[0]+bevelSize[0]*btScalar(sin(theta0)*cos(phi0)), bevelLocation[1]+bevelSize[1]*btScalar(cos(theta0)), bevelLocation[2]+bevelSize[2]*btScalar(sin(theta0)*sin(phi0)));
vertexPoint[vp++] = btVector3(bevelLocation[0]+bevelSize[0]*btScalar(sin(theta0)*cos(phi1)), bevelLocation[1]+bevelSize[1]*btScalar(cos(theta0)), bevelLocation[2]+bevelSize[2]*btScalar(sin(theta0)*sin(phi1)));
vertexPoint[vp++] = btVector3(bevelLocation[0]+bevelSize[0]*btScalar(sin(theta1)*cos(phi1)), bevelLocation[1]+bevelSize[1]*btScalar(cos(theta1)), bevelLocation[2]+bevelSize[2]*btScalar(sin(theta1)*sin(phi1)));
vertexPoint[vp++] = btVector3(bevelLocation[0]+bevelSize[0]*btScalar(sin(theta0)*cos(phi0)), bevelLocation[1]+bevelSize[1]*btScalar(cos(theta0)), bevelLocation[2]+bevelSize[2]*btScalar(sin(theta0)*sin(phi0)));
vertexPoint[vp++] = btVector3(bevelLocation[0]+bevelSize[0]*btScalar(sin(theta1)*cos(phi1)), bevelLocation[1]+bevelSize[1]*btScalar(cos(theta1)), bevelLocation[2]+bevelSize[2]*btScalar(sin(theta1)*sin(phi1)));
vertexPoint[vp++] = btVector3(bevelLocation[0]+bevelSize[0]*btScalar(sin(theta1)*cos(phi0)), bevelLocation[1]+bevelSize[1]*btScalar(cos(theta1)), bevelLocation[2]+bevelSize[2]*btScalar(sin(theta1)*sin(phi0)));
}
else
{
vertexPoint[vp++] = btVector3(bevelLocation[0]+bevelSize[0]*btScalar(sin(theta0)*cos(phi0)), bevelLocation[1]+bevelSize[1]*btScalar(cos(theta0)), bevelLocation[2]+bevelSize[2]*btScalar(sin(theta0)*sin(phi0)));
vertexPoint[vp++] = btVector3(bevelLocation[0]+bevelSize[0]*btScalar(sin(theta1)*cos(phi1)), bevelLocation[1]+bevelSize[1]*btScalar(cos(theta1)), bevelLocation[2]+bevelSize[2]*btScalar(sin(theta1)*sin(phi1)));
vertexPoint[vp++] = btVector3(bevelLocation[0]+bevelSize[0]*btScalar(sin(theta0)*cos(phi1)), bevelLocation[1]+bevelSize[1]*btScalar(cos(theta0)), bevelLocation[2]+bevelSize[2]*btScalar(sin(theta0)*sin(phi1)));
vertexPoint[vp++] = btVector3(bevelLocation[0]+bevelSize[0]*btScalar(sin(theta0)*cos(phi0)), bevelLocation[1]+bevelSize[1]*btScalar(cos(theta0)), bevelLocation[2]+bevelSize[2]*btScalar(sin(theta0)*sin(phi0)));
vertexPoint[vp++] = btVector3(bevelLocation[0]+bevelSize[0]*btScalar(sin(theta1)*cos(phi0)), bevelLocation[1]+bevelSize[1]*btScalar(cos(theta1)), bevelLocation[2]+bevelSize[2]*btScalar(sin(theta1)*sin(phi0)));
vertexPoint[vp++] = btVector3(bevelLocation[0]+bevelSize[0]*btScalar(sin(theta1)*cos(phi1)), bevelLocation[1]+bevelSize[1]*btScalar(cos(theta1)), bevelLocation[2]+bevelSize[2]*btScalar(sin(theta1)*sin(phi1)));
}
for (k=0; k<6; k++)
{
vertexData[coordinateElement++] = vertexPoint[k][0];
vertexData[coordinateElement++] = vertexPoint[k][1];
vertexData[coordinateElement++] = vertexPoint[k][2];
colorData[colorElement++] = rgba[0];
colorData[colorElement++] = rgba[1];
colorData[colorElement++] = rgba[2];
colorData[colorElement++] = rgba[3];
}
}
}
}
- (void) addBeveledEdge:(int)bevelPlane At:(btVector3)bevelLocation Size:(btVector3)bevelSize Rotation:(double)rotationOrigin
{
btVector3 vertexPoint[6];
double origin;
double delta;
double theta0;
double theta1;
int vp;
int i;
int j;
delta = (double)(M_PI_2)/(double)smoothFactor;
for (i=0; i<smoothFactor; i++)
{
theta0 = (double)i * (double)delta;
theta1 = (double)(i+1) * (double)delta;
theta0 += rotationOrigin;
theta1 += rotationOrigin;
origin = (double)0.0;
vp=0;
switch(bevelPlane)
{
case 0:
vertexPoint[vp++] = btVector3(bevelLocation[0]+bevelSize[0], bevelLocation[1]+bevelSize[1]*btScalar(sin(theta0+origin)), bevelLocation[2]+bevelSize[2]*btScalar(cos(theta0+origin)));
vertexPoint[vp++] = btVector3(bevelLocation[0]+bevelSize[0], bevelLocation[1]+bevelSize[1]*btScalar(sin(theta1+origin)), bevelLocation[2]+bevelSize[2]*btScalar(cos(theta1+origin)));
vertexPoint[vp++] = btVector3(bevelLocation[0]-bevelSize[0], bevelLocation[1]+bevelSize[1]*btScalar(sin(theta1+origin)), bevelLocation[2]+bevelSize[2]*btScalar(cos(theta1+origin)));
vertexPoint[vp++] = btVector3(bevelLocation[0]-bevelSize[0], bevelLocation[1]+bevelSize[1]*btScalar(sin(theta0+origin)), bevelLocation[2]+bevelSize[2]*btScalar(cos(theta0+origin)));
vertexPoint[vp++] = btVector3(bevelLocation[0]+bevelSize[0], bevelLocation[1]+bevelSize[1]*btScalar(sin(theta0+origin)), bevelLocation[2]+bevelSize[2]*btScalar(cos(theta0+origin)));
vertexPoint[vp++] = btVector3(bevelLocation[0]-bevelSize[0], bevelLocation[1]+bevelSize[1]*btScalar(sin(theta1+origin)), bevelLocation[2]+bevelSize[2]*btScalar(cos(theta1+origin)));
break;
case 1:
vertexPoint[vp++] = btVector3(bevelLocation[0]+bevelSize[0]*btScalar(sin(theta0+origin)), bevelLocation[1]+bevelSize[1], bevelLocation[2]+bevelSize[2]*btScalar(cos(theta0+origin)));
vertexPoint[vp++] = btVector3(bevelLocation[0]+bevelSize[0]*btScalar(sin(theta1+origin)), bevelLocation[1]-bevelSize[1], bevelLocation[2]+bevelSize[2]*btScalar(cos(theta1+origin)));
vertexPoint[vp++] = btVector3(bevelLocation[0]+bevelSize[0]*btScalar(sin(theta1+origin)), bevelLocation[1]+bevelSize[1], bevelLocation[2]+bevelSize[2]*btScalar(cos(theta1+origin)));
vertexPoint[vp++] = btVector3(bevelLocation[0]+bevelSize[0]*btScalar(sin(theta0+origin)), bevelLocation[1]-bevelSize[1], bevelLocation[2]+bevelSize[2]*btScalar(cos(theta0+origin)));
vertexPoint[vp++] = btVector3(bevelLocation[0]+bevelSize[0]*btScalar(sin(theta1+origin)), bevelLocation[1]-bevelSize[1], bevelLocation[2]+bevelSize[2]*btScalar(cos(theta1+origin)));
vertexPoint[vp++] = btVector3(bevelLocation[0]+bevelSize[0]*btScalar(sin(theta0+origin)), bevelLocation[1]+bevelSize[1], bevelLocation[2]+bevelSize[2]*btScalar(cos(theta0+origin)));
break;
case 2:
vertexPoint[vp++] = btVector3(bevelLocation[0]+bevelSize[0]*btScalar(sin(theta0+origin)), bevelLocation[1]+bevelSize[1]*btScalar(cos(theta0+origin)), bevelLocation[2]+bevelSize[2]);
vertexPoint[vp++] = btVector3(bevelLocation[0]+bevelSize[0]*btScalar(sin(theta1+origin)), bevelLocation[1]+bevelSize[1]*btScalar(cos(theta1+origin)), bevelLocation[2]+bevelSize[2]);
vertexPoint[vp++] = btVector3(bevelLocation[0]+bevelSize[0]*btScalar(sin(theta1+origin)), bevelLocation[1]+bevelSize[1]*btScalar(cos(theta1+origin)), bevelLocation[2]-bevelSize[2]);
vertexPoint[vp++] = btVector3(bevelLocation[0]+bevelSize[0]*btScalar(sin(theta0+origin)), bevelLocation[1]+bevelSize[1]*btScalar(cos(theta0+origin)), bevelLocation[2]-bevelSize[2]);
vertexPoint[vp++] = btVector3(bevelLocation[0]+bevelSize[0]*btScalar(sin(theta0+origin)), bevelLocation[1]+bevelSize[1]*btScalar(cos(theta0+origin)), bevelLocation[2]+bevelSize[2]);
vertexPoint[vp++] = btVector3(bevelLocation[0]+bevelSize[0]*btScalar(sin(theta1+origin)), bevelLocation[1]+bevelSize[1]*btScalar(cos(theta1+origin)), bevelLocation[2]-bevelSize[2]);
break;
}
for (j=0; j<6; j++)
{
vertexData[coordinateElement++] = vertexPoint[j][0];
vertexData[coordinateElement++] = vertexPoint[j][1];
vertexData[coordinateElement++] = vertexPoint[j][2];
colorData[colorElement++] = rgba[0];
colorData[colorElement++] = rgba[1];
colorData[colorElement++] = rgba[2];
colorData[colorElement++] = rgba[3];
}
}
}
- (RoundedCube *) Length:(GLfloat)initLength Width:(GLfloat)initWidth Height:(GLfloat)initHeight Bevel:(GLfloat)initBevel SmoothFactor:(int)initSmoothFactor RGBA:(GLubyte *)initRGBA AbsNormals:(BOOL)initUseAbsNormals
{
int i;
smoothFactor = initSmoothFactor;
useAbsNormals = initUseAbsNormals;
shape = (id *)self;
length = initLength;
width = initWidth;
height = initHeight;
bevel = initBevel;
coordinateElement=0;
colorElement=0;
for (i=0; i<24; i++)
rgba[i] = initRGBA[i];
vertexCount = 36 + (12 * 6 * smoothFactor) + (smoothFactor * smoothFactor * 6 * 8);
modelType = MT_BOX;
constructMode = GL_TRIANGLES;
showColorAndTexture = NO;
vertexDataCount = vertexCount * 3;
colorDataCount = vertexCount * 4;
normalDataCount = vertexCount * 3;
[self setSurfaceToDefault];
vertexData = (GLfloat *)malloc(sizeof(GLfloat) * vertexDataCount);
memset(vertexData, (unsigned int)0, sizeof(GLfloat) * vertexDataCount);
normalData = (GLfloat *)malloc(sizeof(GLfloat) * normalDataCount);
memset(normalData, (unsigned int)0, sizeof(GLfloat) * normalDataCount);
colorData = (GLubyte *)malloc(sizeof(GLubyte) * colorDataCount);
memset(colorData, (unsigned int)0, sizeof(GLubyte) * colorDataCount);
int cubeSide;
int trianglesPerSide;
int pointsPerTriangle;
for (cubeSide=0; cubeSide<6; cubeSide++)
{
for (trianglesPerSide=0; trianglesPerSide<2; trianglesPerSide++)
{
for (pointsPerTriangle=0; pointsPerTriangle<3; pointsPerTriangle++)
{
switch(cubeSide)
{
case 0:
case 1:
vertexData[coordinateElement+0] = voffset[coordinateElement+0] * (length - bevel);
vertexData[coordinateElement+1] = voffset[coordinateElement+1] * (width - bevel);
vertexData[coordinateElement+2] = voffset[coordinateElement+2] * height;
break;
case 2:
case 3:
vertexData[coordinateElement+0] = voffset[coordinateElement+0] * (length - bevel);
vertexData[coordinateElement+1] = voffset[coordinateElement+1] * width;
vertexData[coordinateElement+2] = voffset[coordinateElement+2] * (height - bevel);
break;
case 4:
case 5:
vertexData[coordinateElement+0] = voffset[coordinateElement+0] * length;
vertexData[coordinateElement+1] = voffset[coordinateElement+1] * (width - bevel);
vertexData[coordinateElement+2] = voffset[coordinateElement+2] * (height - bevel);
break;
}
coordinateElement += 3;
colorData[colorElement++] = rgba[(cubeSide*4) + 0]; // 1 RGBA color set per side
colorData[colorElement++] = rgba[(cubeSide*4) + 1]; // 1 RGBA color set per side
colorData[colorElement++] = rgba[(cubeSide*4) + 2]; // 1 RGBA color set per side
colorData[colorElement++] = rgba[(cubeSide*4) + 3]; // 1 RGBA color set per side
}
}
}
[self addBeveledEdge:2 At:btVector3((length-bevel), (width-bevel), 0) Size:btVector3(bevel,bevel,height-bevel) Rotation:(double)0.0];
[self addBeveledEdge:2 At:btVector3(-(length-bevel), (width-bevel), 0) Size:btVector3(bevel,bevel,height-bevel) Rotation:(double)-M_PI_2];
[self addBeveledEdge:2 At:btVector3(-(length-bevel), -(width-bevel), 0) Size:btVector3(bevel,bevel,height-bevel) Rotation:(double)-M_PI];
[self addBeveledEdge:2 At:btVector3((length-bevel), -(width-bevel), 0) Size:btVector3(bevel,bevel,height-bevel) Rotation:(double)M_PI_2];
[self addBeveledEdge:1 At:btVector3((length-bevel), 0, (height-bevel)) Size:btVector3(bevel,width-bevel,bevel) Rotation:(double)0.0];
[self addBeveledEdge:1 At:btVector3(-(length-bevel), 0, (height-bevel)) Size:btVector3(bevel,width-bevel,bevel) Rotation:(double)-M_PI_2];
[self addBeveledEdge:1 At:btVector3(-(length-bevel), 0, -(height-bevel)) Size:btVector3(bevel,width-bevel,bevel) Rotation:(double)-M_PI];
[self addBeveledEdge:1 At:btVector3((length-bevel), 0, -(height-bevel)) Size:btVector3(bevel,width-bevel,bevel) Rotation:(double)M_PI_2];
[self addBeveledEdge:0 At:btVector3(0, (width-bevel), (height-bevel)) Size:btVector3(length-bevel,bevel,bevel) Rotation:(double)0.0];
[self addBeveledEdge:0 At:btVector3(0, -(width-bevel), (height-bevel)) Size:btVector3(length-bevel,bevel,bevel) Rotation:(double)-M_PI_2];
[self addBeveledEdge:0 At:btVector3(0, -(width-bevel), -(height-bevel)) Size:btVector3(length-bevel,bevel,bevel) Rotation:(double)-M_PI];
[self addBeveledEdge:0 At:btVector3(0, (width-bevel), -(height-bevel)) Size:btVector3(length-bevel,bevel,bevel) Rotation:(double)M_PI_2];
[self addBeveledCorner:0 At:btVector3((length-bevel), (width-bevel), (height-bevel)) Size:btVector3(bevel,bevel,bevel) Rotation:(double)0.0];
[self addBeveledCorner:0 At:btVector3((length-bevel), (width-bevel), -(height-bevel)) Size:btVector3(bevel,bevel,bevel) Rotation:(double)-M_PI_2];
[self addBeveledCorner:0 At:btVector3(-(length-bevel), (width-bevel), (height-bevel)) Size:btVector3(bevel,bevel,bevel) Rotation:(double)M_PI_2];
[self addBeveledCorner:0 At:btVector3(-(length-bevel), (width-bevel), -(height-bevel)) Size:btVector3(bevel,bevel,bevel) Rotation:(double)M_PI];
[self addBeveledCorner:1 At:btVector3((length-bevel), -(width-bevel), (height-bevel)) Size:btVector3(bevel,bevel,bevel) Rotation:(double)0.0];
[self addBeveledCorner:1 At:btVector3((length-bevel), -(width-bevel), -(height-bevel)) Size:btVector3(bevel,bevel,bevel) Rotation:(double)-M_PI_2];
[self addBeveledCorner:1 At:btVector3(-(length-bevel), -(width-bevel), (height-bevel)) Size:btVector3(bevel,bevel,bevel) Rotation:(double)M_PI_2];
[self addBeveledCorner:1 At:btVector3(-(length-bevel), -(width-bevel), -(height-bevel)) Size:btVector3(bevel,bevel,bevel) Rotation:(double)M_PI];
[self computeRoundedCubeNormals];
return self;
}
@endを作成するために書いたObjective-Cのコードがある
あなたがiOSデバイスを持っている場合は、これが私の無料アプリでどのように見えるかの例を見ることができますAmazing Dice HD on iTunes
1
私はあなたの正しい方向に行くかもしれない私のいくつかの古いプロジェクトからコードの別のブロックを投稿しました。私はすべての依存関係も同様に追加しました。役立つかもしれない方法は、私は基本的に物理学の世界に
//
// BulletEngine.h
// Created by John Carter on 4/9/09.
//
#import <Foundation/Foundation.h>
#include "btBulletDynamicsCommon.h"
#include "Matrix.h"
@interface BulletEngine : NSObject
{
btScalar cycles; // number of clocktick cycles to run with each call
btScalar clockTick; // 0.016 = 1/60th of a second
}
@property (readwrite) btScalar cycles;
@property (readwrite) btScalar clockTick;
- (void) timeStep:(UIAccelerationValue *)accelerationValue;
- (void) timeStep;
- (void) addConstraint:(btTypedConstraint *)hinge disableCollisionsBetweenLinkedBodies:(BOOL)linkcrash;
- (void) releaseConstraints;
@end
//
// BulletEngine.m
// Created by John Carter on 4/9/09.
//
#import "BulletEngine.h"
#import "PhysicsObject.h"
// Private Methods
//
@interface BulletEngine()
@end
@implementation BulletEngine
@synthesize cycles;
@synthesize clockTick;
static btCollisionConfiguration* sCollisionConfig=0;
static btCollisionDispatcher* sCollisionDispatcher=0;
static btSequentialImpulseConstraintSolver* sConstraintSolver=0;
static btBroadphaseInterface* sBroadphase=0;
static btDiscreteDynamicsWorld *sDynamicsWorld=0;
- (id)init
{
self = [super init];
if (self==nil)
return self;
// init Default Timing
//
cycles = 2;
clockTick = 0.016;
// init Bullet Objects
//
sCollisionConfig = new btDefaultCollisionConfiguration();
sCollisionDispatcher = new btCollisionDispatcher(sCollisionConfig);
sConstraintSolver = new btSequentialImpulseConstraintSolver;
sBroadphase = new btDbvtBroadphase();
sDynamicsWorld = new btDiscreteDynamicsWorld(sCollisionDispatcher,sBroadphase,sConstraintSolver,sCollisionConfig);
sDynamicsWorld->setGravity(btVector3(0.0f,0.0f,0.0f)); // Initial Gravity of the object Space
[PhysicsObject setDynamicsWorldPointerTo:sDynamicsWorld];
//
// 2.75 Increased performance by disabling motion state synchronization for static/inactive objects.
// if that causes a problem. Uncomment the next line for backward compatibility.
//
// sDynamicsWorld->setSynchronizeAllMotionStates(true);
return self;
}
- (void)dealloc
{
[self releaseConstraints];
delete sDynamicsWorld;
sDynamicsWorld=0;
delete sConstraintSolver;
sConstraintSolver=0;
delete sCollisionDispatcher;
sCollisionDispatcher=0;
delete sBroadphase;
sBroadphase=0;
delete sCollisionConfig;
sCollisionConfig=0;
[super dealloc];
}
- (void) releaseConstraints
{
int i;
// remove contraints
//
for (i=sDynamicsWorld->getNumConstraints()-1; i>=0; i--)
{
btTypedConstraint *joint = sDynamicsWorld->getConstraint(i);
sDynamicsWorld->removeConstraint(joint);
delete joint;
}
}
- (void) addConstraint:(btTypedConstraint *)hinge disableCollisionsBetweenLinkedBodies:(BOOL)linkcrash
{
if (linkcrash)
sDynamicsWorld->addConstraint(hinge, true);
else
sDynamicsWorld->addConstraint(hinge, false);
}
- (void) timeStep:(UIAccelerationValue *)accelerationValue;
{
if (!sDynamicsWorld)
return;
sDynamicsWorld->setGravity(btVector3(accelerationValue[0], accelerationValue[1], accelerationValue[2]));
// Recommended values for faster systems or more simple Open/GL projects
//
// cycles = 1;
// clockTick = 0.016f;
//
sDynamicsWorld->stepSimulation(cycles*clockTick, cycles, clockTick);
}
//
// Same as above but with NO Gravity
//
- (void) timeStep
{
if (!sDynamicsWorld)
return;
sDynamicsWorld->stepSimulation(cycles*clockTick, cycles, clockTick);
}
@end
//
// PhysicsObject.h
// Created by John Carter on 4/9/09.
//
#import "BulletEngine.h"
@interface PhysicsObject : NSObject
{
btCollisionShape* collisionShape;
btRigidBody *rigidBody;
btDefaultMotionState *motionState;
btCollisionObject *collisionObject;
}
@property (readonly) btCollisionShape* collisionShape;
@property (readonly) btRigidBody *rigidBody;
@property (readonly) btDefaultMotionState *motionState;
@property (readonly) btCollisionObject *collisionObject;
+ (void) setDynamicsWorldPointerTo:(btDiscreteDynamicsWorld *)initSDynamicsWorld;
- (btRigidBody *) addPhysicsObject:(btCollisionShape *)newObjectShape At:(btVector3)location Tilt:(btVector3)tilt Mass:(btScalar)mass;
- (btRigidBody *) addInfinitePlane:(int)plane Shape:(btBoxShape *)worldBoxShape At:(btTransform)groundTransform Boundary:(btVector3)boundarySize;
@end
//
// PhysicsObject.m
// Created by John Carter on 4/9/09.
//
#import "PhysicsObject.h"
// Owned and Set by BulletEngine Object
//
static btDiscreteDynamicsWorld *sDynamicsWorld;
// Private Methods
//
@interface PhysicsObject()
@end
@implementation PhysicsObject
@synthesize collisionShape;
@synthesize rigidBody;
@synthesize motionState;
@synthesize collisionObject;
+ (void) setDynamicsWorldPointerTo:(btDiscreteDynamicsWorld *)initSDynamicsWorld
{
sDynamicsWorld=initSDynamicsWorld;
}
- (void)dealloc
{
if (collisionShape)
{
delete collisionShape;
collisionShape = 0;
}
if (rigidBody)
{
sDynamicsWorld->removeRigidBody(rigidBody);
}
if (motionState)
{
delete motionState;
motionState = 0;
}
if (collisionObject)
{
sDynamicsWorld->removeCollisionObject(collisionObject);
delete collisionObject;
collisionObject = 0;
}
if (rigidBody)
{
delete rigidBody;
rigidBody = 0;
}
[super dealloc];
}
- (void) setCollisionObjectPointer
{
int i;
for (i=sDynamicsWorld->getNumCollisionObjects()-1; i>=0 ;i--)
{
btCollisionObject* colObj = sDynamicsWorld->getCollisionObjectArray()[i];
if (colObj)
{
btRigidBody* body = btRigidBody::upcast(colObj);
if (body==rigidBody)
{
collisionObject = colObj;
return;
}
}
}
collisionObject=0;
return;
}
- (btRigidBody *) addInfinitePlane:(int)plane Shape:(btBoxShape *)worldBoxShape At:(btTransform)groundTransform Boundary:(btVector3)boundarySize
{
btVector4 planeEq;
worldBoxShape->getPlaneEquation(planeEq, plane);
collisionShape = new btStaticPlaneShape(-planeEq, planeEq[3]);
motionState = new btDefaultMotionState(groundTransform);
btRigidBody::btRigidBodyConstructionInfo rbInfo(btScalar(0.0), motionState, collisionShape, btVector3(btScalar(0.0),btScalar(0.0),btScalar(0.0)));
btRigidBody* objectBody = new btRigidBody(rbInfo);
sDynamicsWorld->addRigidBody(objectBody);
[self setCollisionObjectPointer];
return objectBody;
}
- (btRigidBody *) addPhysicsObject:(btCollisionShape *)newObjectShape At:(btVector3)location Tilt:(btVector3)tilt Mass:(btScalar)mass
{
btTransform bodyTransform;
bodyTransform.setIdentity();
bodyTransform.setOrigin(location);
bodyTransform.getBasis().setEulerZYX(tilt[0],tilt[1],tilt[2]);
btVector3 localInertia(0,0,0);
if (mass > btScalar(0.0))
{
newObjectShape->calculateLocalInertia(mass,localInertia);
}
motionState = new btDefaultMotionState(bodyTransform);
btRigidBody::btRigidBodyConstructionInfo rbInfo(mass,motionState,newObjectShape,localInertia);
btRigidBody* objectBody=new btRigidBody(rbInfo);
//
// Prevents objects from falling asleep after being idle for a long time
//
if (objectBody != nil && mass >= btScalar(0.0))
{
objectBody->setDeactivationTime(0.0);
objectBody->setSleepingThresholds(0.0, 0.0);
objectBody->activate();
}
//add the body to the dynamics world
//
sDynamicsWorld->addRigidBody(objectBody);
[self setCollisionObjectPointer];
return objectBody;
}
@end
//
// MeshObject.h
// Created by John Carter on 4/9/09.
//
#import "PhysicsObject.h"
@interface MeshObject : PhysicsObject
{
btTriangleMesh *mesh;
}
- (id) initAt:(btVector3)location Size:(btVector3)size VertexCount:(int)initVertexCount Verticies:(btVector3 *)initVertex Mass:(btScalar)mass;
- (id) initAt:(btVector3)location Size:(btVector3)size VertexCount:(int)initVertexCount Verticies:(btVector3 *)initVertex Tilt:(btVector3)tilt Mass:(btScalar)mass;
@end
//
// MeshObject.m
// Created by John Carter on 4/9/09.
//
#import "MeshObject.h"
// Private Methods
//
@interface MeshObject()
@end
@implementation MeshObject
- (void)dealloc
{
delete mesh;
mesh=0;
[super dealloc];
}
- (id) initAt:(btVector3)location Size:(btVector3)size VertexCount:(int)initVertexCount Verticies:(btVector3 *)initVertex Mass:(btScalar)mass
{
self = [super init];
if (self==nil)
return self;
mesh = new btTriangleMesh(false);
int i;
for (i=0 ; i<initVertexCount; i+=3)
{
btVector3 v1 = btVector3(initVertex[i+0][0]*size[0], initVertex[i+0][1]*size[1], initVertex[i+0][2]*size[2]);
btVector3 v2 = btVector3(initVertex[i+1][0]*size[0], initVertex[i+1][1]*size[1], initVertex[i+1][2]*size[2]);
btVector3 v3 = btVector3(initVertex[i+2][0]*size[0], initVertex[i+2][1]*size[1], initVertex[i+2][2]*size[2]);
mesh->addTriangle(v1,v2,v3);
}
collisionShape = new btBvhTriangleMeshShape(mesh, true);
rigidBody = [self addPhysicsObject:(btCollisionShape *)collisionShape At:(btVector3)location Tilt:btVector3(btScalar(0.0), btScalar(0.0), btScalar(0.0)) Mass:(btScalar)mass];
return self;
}
- (id) initAt:(btVector3)location Size:(btVector3)size VertexCount:(int)initVertexCount Verticies:(btVector3 *)initVertex Tilt:(btVector3)tilt Mass:(btScalar)mass
{
self = [super init];
if (self==nil)
return self;
mesh = new btTriangleMesh(false);
int i;
for (i=0 ; i<initVertexCount; i+=3)
{
btVector3 v1 = btVector3(initVertex[i+0][0]*size[0], initVertex[i+0][1]*size[1], initVertex[i+0][2]*size[2]);
btVector3 v2 = btVector3(initVertex[i+1][0]*size[0], initVertex[i+1][1]*size[1], initVertex[i+1][2]*size[2]);
btVector3 v3 = btVector3(initVertex[i+2][0]*size[0], initVertex[i+2][1]*size[1], initVertex[i+2][2]*size[2]);
mesh->addTriangle(v1,v2,v3);
}
collisionShape = new btBvhTriangleMeshShape(mesh, true);
rigidBody = [self addPhysicsObject:(btCollisionShape *)collisionShape At:(btVector3)location Tilt:tilt Mass:(btScalar)mass];
return self;
}
@end
関連する問題
- 1. 弾丸物理学Broadphase複合体
- 2. GIM_TRIANGLE :: is_point_insideが間違っています(弾丸物理学)
- 3. XNA水物理学
- 4. Android用ベスト2dゲームエンジン[物理学]
- 5. XNAムーブメント物理学とトラッキング
- 6. 物理学にHaskellで
- 7. クリケット物理学、基本シミュレーション
- 8. トレーサの弾丸の開発
- 9. マルチプレイヤーゲームの弾丸計算
- 10. 3D卓球物理学の部分?
- 11. htmlentities()は弾丸ですか?
- 12. 弾丸を作る-Cocos2d
- 13. は、私はオービターと呼ばれる宇宙飛行シミュレータのためのアドオンを開発弾丸物理学をコンパイルし、スタティックライブラリとして一緒
- 14. ゲーミングアプリケーションのための物理学電磁気学のシミュレーション
- 15. 計算物理学、FFT解析
- 16. iPhoneゲーム "Paper Toss"プログラミング物理学
- 17. タイルマップ2D現実的流体物理学
- 18. Protovisの弾丸のグラフの境界
- 19. SPARQLを使用してDBpediaから米国物理学者のリストを取得
- 20. 弾丸アニメーションの作成方法は? (シューティングゲーム)
- 21. 垂直配向テキストベースの弾丸
- 22. jQueryスライダ軌道 - 移動中の弾丸
- 23. Internet Explorer 7およびリストの弾丸
- 24. クリスタルレポートで弾丸リストを作るには?
- 25. ulに弾丸を表示しない
- 26. HTML5キャンバス - ボール物理学との衝突グリッチ
- 27. SKSpriteNode物理学の本体にインパルスを適用できません
- 28. b2物理学をシミュレートしていなかった人
- 29. マルチプレイヤーゲームで物理学を同期する方法は?
- 30. iOS - アロケーションとメモリモニタ(物理メモリフリー)を使用した楽器の使用と理解
を追加するために、対応する弾丸オブジェクトを作成するために、モデルの頂点を取るMeshObjectは、それが作る、むしろsnippitedコードより完全な投稿のためにそんなにジョンありがとうれます物事ははるかに明確です。 –
スニペットコードよりも完全なポストをありがとうJohnさん、本当にありがとうございます。つまり、あなたの美しい形は、私は[私はIOSデバイスにアクセスできない]と思うが、視覚的に改善されたものだ。 RoundedCubeクラスはBulletクラスとどのように統合されますか?あなたのクラスのインスタンスは、そのラインのどこかにあるRigidBodyのコンストラクタに渡されますか?あなたのサイコロが物理的世界と対話するために必要なものは何でも、質量、慣性、緊張、動きを得る方法を私に見せてもらえますか? –
あなたはまだ弾丸で作業したようには聞こえません。彼らは皆さんの質問のすべてに答えるコンパイルできる幻想的な事例を持っています。 –