public static float TestScalarInvert(int iterationCount) { bAffineTransform m = bAffineTransform.Identity; float accumulator = 0; for (int i = 0; i < iterationCount; ++i) { bAffineTransform r0, r1; bAffineTransform.Invert(ref m, out r0); bAffineTransform.Invert(ref r0, out r1); bAffineTransform.Invert(ref r1, out r0); bAffineTransform.Invert(ref r0, out r1); bAffineTransform.Invert(ref r1, out r0); bAffineTransform.Invert(ref r0, out r1); bAffineTransform.Invert(ref r1, out r0); bAffineTransform.Invert(ref r0, out r1); bAffineTransform.Invert(ref r1, out r0); bAffineTransform.Invert(ref r0, out r1); accumulator += r1.Translation.X; } return(accumulator); }
public static float TestScalarMultiply(int iterationCount) { bAffineTransform m1 = bAffineTransform.Identity; bAffineTransform m2 = bAffineTransform.Identity; float accumulator = 0; for (int i = 0; i < iterationCount; ++i) { bAffineTransform r0, r1; bAffineTransform.Multiply(ref m1, ref m2, out r0); bAffineTransform.Multiply(ref r0, ref m2, out r1); bAffineTransform.Multiply(ref r1, ref m2, out r0); bAffineTransform.Multiply(ref r0, ref m2, out r1); bAffineTransform.Multiply(ref r1, ref m2, out r0); bAffineTransform.Multiply(ref r0, ref m2, out r1); bAffineTransform.Multiply(ref r1, ref m2, out r0); bAffineTransform.Multiply(ref r0, ref m2, out r1); bAffineTransform.Multiply(ref r1, ref m2, out r0); bAffineTransform.Multiply(ref r0, ref m2, out r1); accumulator += 0.000001f * r1.Translation.X; } return(accumulator); }
public static float TestTransformScalar(int iterationCount) { bVector3 v = new bVector3(1, 2, 3); bAffineTransform m = bAffineTransform.Identity; float accumulator = 0; for (int i = 0; i < iterationCount; ++i) { bVector3 r0, r1; bAffineTransform.Transform(ref v, ref m, out r0); bAffineTransform.Transform(ref r0, ref m, out r1); bAffineTransform.Transform(ref r1, ref m, out r0); bAffineTransform.Transform(ref r0, ref m, out r1); bAffineTransform.Transform(ref r1, ref m, out r0); bAffineTransform.Transform(ref r0, ref m, out r1); bAffineTransform.Transform(ref r1, ref m, out r0); bAffineTransform.Transform(ref r0, ref m, out r1); bAffineTransform.Transform(ref r1, ref m, out r0); bAffineTransform.Transform(ref r0, ref m, out r1); accumulator += 0.000001f * r1.X; } return(accumulator); }
/// <summary> /// Create new StaticCollider from existing collision data<para/> /// Создание нового коллайдера из существующих данных /// </summary> /// <param name="colmesh">Collision data<para/>Данные о коллизиях</param> public StaticCollider(CollisionFile.Group colmesh, Vector3 position, Quaternion angles, Vector3 scale) { // Create base transformation matrix // Создание базовой матрицы трансформации Matrix4 mat = Matrix4.CreateScale(scale) * Matrix4.CreateFromQuaternion(angles) * Matrix4.CreateTranslation(position); // Create bodies // Создание тел List <CollisionEntry> col = new List <CollisionEntry>(); // Spheres // Сферы if (colmesh.Spheres != null) { foreach (CollisionFile.Sphere s in colmesh.Spheres) { // Transforming positions to world coordinates // Трансформация расположения в мировые координаты Vector3 pos = Vector3.TransformPosition(s.Center, mat); float radius = Vector3.TransformVector(Vector3.UnitX * s.Radius, mat).Length; // Create primitive // Создание примитива EntityShape shape = new SphereShape(radius); col.Add(new CollisionEntry() { Type = PrimitiveType.Sphere, Position = pos, Rotation = Quaternion.Identity, Shape = shape, Body = new Entity(shape) }); } } // Cubes // Кубы if (colmesh.Boxes != null) { foreach (CollisionFile.Box b in colmesh.Boxes) { // Transforming positions to world coordinates // Трансформация расположения в мировые координаты Vector3 pos = Vector3.TransformPosition( new Vector3( (b.Min.X + b.Max.X) / 2f, (b.Min.Y + b.Max.Y) / 2f, (b.Min.Z + b.Max.Z) / 2f ) , mat); float factor = Vector3.TransformVector(Vector3.UnitX, mat).Length; // Create primitive // Создание примитива EntityShape shape = new BoxShape( (float)Math.Abs(b.Max.X - b.Min.X) * factor, (float)Math.Abs(b.Max.Y - b.Min.Y) * factor, (float)Math.Abs(b.Max.Z - b.Min.Z) * factor ); col.Add(new CollisionEntry() { Type = PrimitiveType.Box, Position = pos, Rotation = angles, Shape = shape, Body = new Entity(shape) }); } } // Trimeshes // Тримеши if (colmesh.Meshes != null) { // Creating vertices array // Создание массива вершин BEPUutilities.Vector3[] verts = new BEPUutilities.Vector3[colmesh.Vertices.Length]; for (int i = 0; i < colmesh.Vertices.Length; i++) { verts[i] = new BEPUutilities.Vector3( colmesh.Vertices[i].X, colmesh.Vertices[i].Y, colmesh.Vertices[i].Z ); } foreach (CollisionFile.Trimesh m in colmesh.Meshes) { // Creating affine transformation // Создание трансформации BEPUutilities.AffineTransform transform = new BEPUutilities.AffineTransform( new BEPUutilities.Vector3(scale.X, scale.Y, scale.Z), new BEPUutilities.Quaternion(angles.X, angles.Y, angles.Z, angles.W), new BEPUutilities.Vector3(position.X, position.Y, position.Z) ); // Create primitive // Создание примитива col.Add(new CollisionEntry() { Type = PrimitiveType.Mesh, Mesh = new StaticMesh(verts, m.Indices, transform) }); } } subColliders = col.ToArray(); }
/// <summary> /// Create new StaticCollider from existing collision data<para/> /// Создание нового коллайдера из существующих данных /// </summary> /// <param name="colmesh">Collision data<para/>Данные о коллизиях</param> public StaticCollider(CollisionFile.Group colmesh, Vector3 position, Quaternion angles, Vector3 scale) { // Create base transformation matrix // Создание базовой матрицы трансформации Matrix4 mat = Matrix4.CreateScale(scale) * Matrix4.CreateFromQuaternion(angles) * Matrix4.CreateTranslation(position); // Create bodies // Создание тел List<CollisionEntry> col = new List<CollisionEntry>(); // Spheres // Сферы if (colmesh.Spheres!=null) { foreach (CollisionFile.Sphere s in colmesh.Spheres) { // Transforming positions to world coordinates // Трансформация расположения в мировые координаты Vector3 pos = Vector3.TransformPosition(s.Center, mat); float radius = Vector3.TransformVector(Vector3.UnitX * s.Radius, mat).Length; // Create primitive // Создание примитива EntityShape shape = new SphereShape(radius); col.Add(new CollisionEntry() { Type = PrimitiveType.Sphere, Position = pos, Rotation = Quaternion.Identity, Shape = shape, Body = new Entity(shape) }); } } // Cubes // Кубы if (colmesh.Boxes!=null) { foreach (CollisionFile.Box b in colmesh.Boxes) { // Transforming positions to world coordinates // Трансформация расположения в мировые координаты Vector3 pos = Vector3.TransformPosition( new Vector3( (b.Min.X+b.Max.X)/2f, (b.Min.Y+b.Max.Y)/2f, (b.Min.Z+b.Max.Z)/2f ) , mat); float factor = Vector3.TransformVector(Vector3.UnitX, mat).Length; // Create primitive // Создание примитива EntityShape shape = new BoxShape( (float)Math.Abs(b.Max.X-b.Min.X) * factor, (float)Math.Abs(b.Max.Y-b.Min.Y) * factor, (float)Math.Abs(b.Max.Z-b.Min.Z) * factor ); col.Add(new CollisionEntry() { Type = PrimitiveType.Box, Position = pos, Rotation = angles, Shape = shape, Body = new Entity(shape) }); } } // Trimeshes // Тримеши if (colmesh.Meshes!=null) { // Creating vertices array // Создание массива вершин BEPUutilities.Vector3[] verts = new BEPUutilities.Vector3[colmesh.Vertices.Length]; for (int i = 0; i < colmesh.Vertices.Length; i++) { verts[i] = new BEPUutilities.Vector3( colmesh.Vertices[i].X, colmesh.Vertices[i].Y, colmesh.Vertices[i].Z ); } foreach (CollisionFile.Trimesh m in colmesh.Meshes) { // Creating affine transformation // Создание трансформации BEPUutilities.AffineTransform transform = new BEPUutilities.AffineTransform( new BEPUutilities.Vector3(scale.X, scale.Y, scale.Z), new BEPUutilities.Quaternion(angles.X, angles.Y, angles.Z, angles.W), new BEPUutilities.Vector3(position.X, position.Y, position.Z) ); // Create primitive // Создание примитива col.Add(new CollisionEntry() { Type = PrimitiveType.Mesh, Mesh = new StaticMesh(verts, m.Indices, transform) }); } } subColliders = col.ToArray(); }