本文整理汇总了C#中BulletSharp.DiscreteDynamicsWorld.Serialize方法的典型用法代码示例。如果您正苦于以下问题:C# DiscreteDynamicsWorld.Serialize方法的具体用法?C# DiscreteDynamicsWorld.Serialize怎么用?C# DiscreteDynamicsWorld.Serialize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BulletSharp.DiscreteDynamicsWorld
的用法示例。
在下文中一共展示了DiscreteDynamicsWorld.Serialize方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OnInitializePhysics
protected override void OnInitializePhysics()
{
// collision configuration contains default setup for memory, collision setup
CollisionConf = new DefaultCollisionConfiguration();
Dispatcher = new CollisionDispatcher(CollisionConf);
Broadphase = new DbvtBroadphase();
World = new DiscreteDynamicsWorld(Dispatcher, Broadphase, null, CollisionConf);
World.Gravity = new Vector3(0, -10, 0);
GImpactCollisionAlgorithm.RegisterAlgorithm(Dispatcher);
string bulletFile;
string[] args = Environment.GetCommandLineArgs();
if (args.Length == 1)
{
bulletFile = "testFile.bullet";
}
else
{
bulletFile = args[1];
}
fileLoader = new CustomBulletWorldImporter(World);
if (!fileLoader.LoadFile(bulletFile))
{
CollisionShape groundShape = new BoxShape(50);
CollisionShapes.Add(groundShape);
RigidBody ground = LocalCreateRigidBody(0, Matrix.Translation(0, -50, 0), groundShape);
ground.UserObject = "Ground";
// create a few dynamic rigidbodies
float mass = 1.0f;
Vector3[] positions = new Vector3[2] { new Vector3(0.1f, 0.2f, 0.3f), new Vector3(0.4f, 0.5f, 0.6f) };
float[] radi = new float[2] { 0.3f, 0.4f };
CollisionShape colShape = new MultiSphereShape(positions, radi);
//CollisionShape colShape = new CapsuleShapeZ(1, 1);
//CollisionShape colShape = new CylinderShapeZ(1, 1, 1);
//CollisionShape colShape = new BoxShape(1);
//CollisionShape colShape = new SphereShape(1);
CollisionShapes.Add(colShape);
Vector3 localInertia = colShape.CalculateLocalInertia(mass);
float start_x = StartPosX - ArraySizeX / 2;
float start_y = StartPosY;
float start_z = StartPosZ - ArraySizeZ / 2;
int k, i, j;
for (k = 0; k < ArraySizeY; k++)
{
for (i = 0; i < ArraySizeX; i++)
{
for (j = 0; j < ArraySizeZ; j++)
{
Matrix startTransform = Matrix.Translation(
2 * i + start_x,
2 * k + start_y,
2 * j + start_z
);
// using motionstate is recommended, it provides interpolation capabilities
// and only synchronizes 'active' objects
DefaultMotionState myMotionState = new DefaultMotionState(startTransform);
RigidBodyConstructionInfo rbInfo =
new RigidBodyConstructionInfo(mass, myMotionState, colShape, localInertia);
RigidBody body = new RigidBody(rbInfo);
rbInfo.Dispose();
// make it drop from a height
body.Translate(new Vector3(0, 20, 0));
World.AddRigidBody(body);
}
}
}
DefaultSerializer serializer = new DefaultSerializer();
serializer.RegisterNameForObject(ground, "GroundName");
for (i = 0; i < CollisionShapes.Count; i++)
serializer.RegisterNameForObject(CollisionShapes[i], "name" + i.ToString());
Point2PointConstraint p2p = new Point2PointConstraint((RigidBody)World.CollisionObjectArray[2], new Vector3(0, 1, 0));
World.AddConstraint(p2p);
serializer.RegisterNameForObject(p2p, "constraintje");
World.Serialize(serializer);
BulletSharp.DataStream data = serializer.LockBuffer();
byte[] dataBytes = new byte[data.Length];
data.Read(dataBytes, 0, dataBytes.Length);
FileStream file = new FileStream("testFile.bullet", FileMode.Create);
//.........这里部分代码省略.........