Skip to content
Permalink
Browse files

Main conversion done, next up the rest of the CharacterComponent

  • Loading branch information
Eideren committed Dec 14, 2018
1 parent 222b702 commit f23ed4670e18c78469352aec926323c18ceb17b4
@@ -28,6 +28,7 @@
*/
using System;
using System.Globalization;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

namespace Xenko.Core.Mathematics
@@ -1419,5 +1420,27 @@ public override bool Equals(object value)
return new Quaternion(value.X, value.Y, value.Z, value.W);
}
#endif

/// <summary>
/// Performs an implicit conversion from <see cref="Xenko.Core.Mathematics.Vector3"/> to <see cref="BulletSharp.Math.Quaternion"/>.
/// </summary>
/// <param name="value">The value.</param>
/// <returns>The result of the conversion.</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static implicit operator BulletSharp.Math.Quaternion(Quaternion value)
{
unsafe { return *(BulletSharp.Math.Quaternion*)&value; }
}

/// <summary>
/// Performs an implicit conversion from <see cref="BulletSharp.Math.Quaternion"/> to <see cref="Xenko.Core.Mathematics.Quaternion"/>.
/// </summary>
/// <param name="value">The value.</param>
/// <returns>The result of the conversion.</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static implicit operator Quaternion(BulletSharp.Math.Quaternion value)
{
unsafe { return *(Quaternion*)&value; }
}
}
}
@@ -139,7 +139,7 @@ public void SetLimit(float swingSpan1, float swingSpan2, float twistSpan, float
/// <param name="angularOnly">if set to <c>true</c> [angular only].</param>
public void SetAngularOnly(bool angularOnly)
{
InternalConeTwistConstraint.SetAngularOnly(angularOnly);
InternalConeTwistConstraint.AngularOnly = angularOnly;
}

/// <summary>
@@ -148,7 +148,7 @@ public void SetAngularOnly(bool angularOnly)
/// <param name="damping">The damping.</param>
public void SetDamping(float damping)
{
InternalConeTwistConstraint.SetDamping(damping);
InternalConeTwistConstraint.Damping = damping;
}

/// <summary>
@@ -166,7 +166,7 @@ public void EnableMotor(bool b)
/// <param name="maxMotorImpulse">The maximum motor impulse.</param>
public void SetMaxMotorImpulse(float maxMotorImpulse)
{
InternalConeTwistConstraint.SetMaxMotorImpulse(maxMotorImpulse);
InternalConeTwistConstraint.MaxMotorImpulse = maxMotorImpulse;
}

/// <summary>
@@ -184,7 +184,7 @@ public void SetMaxMotorImpulseNormalized(float maxMotorImpulse)
/// <param name="q">The q.</param>
public void SetMotorTarget(Quaternion q)
{
InternalConeTwistConstraint.SetMotorTarget(q);
InternalConeTwistConstraint.MotorTarget = q;
}

/// <summary>
@@ -60,7 +60,7 @@ public float MaxMotorImpulse
/// </value>
public float MotorTargetVelocity
{
get { return InternalHingeConstraint.MotorTargetVelosity; }
get { return InternalHingeConstraint.MotorTargetVelocity; }
}

/// <summary>
@@ -170,7 +170,7 @@ public void EnableAngularMotor(bool enableMotor, float targetVelocity, float max
/// <param name="enableMotor">if set to <c>true</c> [enable motor].</param>
public void EnableMotor(bool enableMotor)
{
InternalHingeConstraint.EnableMotor(enableMotor);
InternalHingeConstraint.EnableMotor = enableMotor;
}

/// <summary>
@@ -16,7 +16,7 @@ public class Point2PointConstraint : Constraint
public Vector3 PivotInA
{
get { return InternalPoint2PointConstraint.PivotInA; }
set { InternalPoint2PointConstraint.SetPivotA(value); }
set { InternalPoint2PointConstraint.PivotInA = value; }
}

/// <summary>
@@ -28,7 +28,7 @@ public Vector3 PivotInA
public Vector3 PivotInB
{
get { return InternalPoint2PointConstraint.PivotInB; }
set { InternalPoint2PointConstraint.SetPivotB(value); }
set { InternalPoint2PointConstraint.PivotInB = value; }
}

/// <summary>
@@ -189,8 +189,8 @@ public float MaxMotorForce
/// </value>
public float NormalCfm
{
get { return mMotor.NormalCFM; }
set { mMotor.NormalCFM = value; }
get { return mMotor.NormalCfm; }
set { mMotor.NormalCfm = value; }
}

/// <summary>
@@ -201,8 +201,8 @@ public float NormalCfm
/// </value>
public float StopCfm
{
get { return mMotor.StopCFM; }
set { mMotor.StopCFM = value; }
get { return mMotor.StopCfm; }
set { mMotor.StopCfm = value; }
}

/// <summary>
@@ -213,8 +213,8 @@ public float StopCfm
/// </value>
public float StopErp
{
get { return mMotor.StopERP; }
set { mMotor.StopERP = value; }
get { return mMotor.StopErp; }
set { mMotor.StopErp = value; }
}

/// <summary>
@@ -170,7 +170,7 @@ public float LinearDepth
/// </value>
public float LinearPosition
{
get { return InternalSliderConstraint.LinearPos; }
get { return InternalSliderConstraint.LinearPosition; }
}

/// <summary>
@@ -120,8 +120,8 @@ public Vector3 MaxMotorForce
/// </value>
public Vector3 NormalCFM
{
get { return mMotor.NormalCFM; }
set { mMotor.NormalCFM = value; }
get { return mMotor.NormalCfm; }
set { mMotor.NormalCfm = value; }
}

/// <summary>
@@ -144,8 +144,8 @@ public float Restitution
/// </value>
public Vector3 StopCFM
{
get { return mMotor.StopCFM; }
set { mMotor.StopCFM = value; }
get { return mMotor.StopCfm; }
set { mMotor.StopCfm = value; }
}

/// <summary>
@@ -156,8 +156,8 @@ public Vector3 StopCFM
/// </value>
public Vector3 StopERP
{
get { return mMotor.StopERP; }
set { mMotor.StopERP = value; }
get { return mMotor.StopErp; }
set { mMotor.StopErp = value; }
}

/// <summary>
@@ -177,7 +177,7 @@ public Vector3 Gravity
/// <value>
/// <c>true</c> if this instance is grounded; otherwise, <c>false</c>.
/// </value>
public bool IsGrounded => KinematicCharacter?.OnGround() ?? false;
public bool IsGrounded => KinematicCharacter?.OnGround ?? false;

/// <summary>
/// Teleports the specified target position.
@@ -194,7 +194,8 @@ public void Teleport(Vector3 targetPosition)
var entityPos = Entity.Transform.Position;
var physPos = PhysicsWorldTransform.TranslationVector;
var diff = physPos - entityPos;
KinematicCharacter.Warp(targetPosition + diff);
BulletSharp.Math.Vector3 bV3 = targetPosition + diff;
KinematicCharacter.Warp(ref bV3);
}

/// <summary>
@@ -323,8 +323,8 @@ protected override void OnAttach()

GetWorldTransformCallback = (out Matrix transform) => RigidBodyGetWorldTransform(out transform);
SetWorldTransformCallback = transform => RigidBodySetWorldTransform(ref transform);

InternalRigidBody = new BulletSharp.RigidBody(0.0f, MotionState, ColliderShape.InternalShape, Vector3.Zero)
var rbci = new BulletSharp.RigidBodyConstructionInfo(0.0f, MotionState, ColliderShape.InternalShape, Vector3.Zero);
InternalRigidBody = new BulletSharp.RigidBody(rbci)
{
UserObject = this,
};
@@ -1,6 +1,7 @@
// Copyright (c) Xenko contributors (https://xenko.com) and Silicon Studio Corp. (https://www.siliconstudio.co.jp)
// Distributed under the MIT license. See the LICENSE.md file in the project root for more information.

using System.Collections;
using System.Collections.Generic;
using System.Linq;
using Xenko.Core.Mathematics;
@@ -14,15 +15,16 @@ namespace Xenko.Physics
public class ConvexHullColliderShape : ColliderShape
{
private readonly IReadOnlyList<Vector3> pointsList;
private readonly IReadOnlyList<uint> indicesList;
private readonly IReadOnlyList<uint> indicesList;

public ConvexHullColliderShape(IReadOnlyList<Vector3> points, IReadOnlyList<uint> indices, Vector3 scaling)
{
Type = ColliderShapeTypes.ConvexHull;
Is2D = false;

cachedScaling = scaling;
InternalShape = new BulletSharp.ConvexHullShape(points)

InternalShape = new BulletSharp.ConvexHullShape(new EnumConverterToBullet(points))
{
LocalScaling = cachedScaling,
};
@@ -73,5 +75,29 @@ public override MeshDraw CreateDebugPrimitive(GraphicsDevice device)

return new GeometricPrimitive(device, meshData).ToMeshDraw();
}

class EnumConverterToBullet : IEnumerator<BulletSharp.Math.Vector3>, IEnumerable<BulletSharp.Math.Vector3>
{
IReadOnlyList<Vector3> l;
int c;

public EnumConverterToBullet(IReadOnlyList<Vector3> refList)
{
l = refList;
c = -1;
}

public bool MoveNext() => ++c < l.Count;
public void Reset() => c = -1;
public BulletSharp.Math.Vector3 Current => l[c];
public EnumConverterToBullet GetEnumerator() => this;


object IEnumerator.Current => Current;
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
IEnumerator<BulletSharp.Math.Vector3> IEnumerable<BulletSharp.Math.Vector3>.GetEnumerator() => GetEnumerator();

public void Dispose() { }
}
}
}
@@ -11,7 +11,7 @@ public class HeightfieldColliderShape : ColliderShape
public HeightfieldColliderShape(int heightStickWidth, int heightStickLength, UnmanagedArray<short> dynamicFieldData, float heightScale, float minHeight, float maxHeight, bool flipQuadEdges)
{
cachedScaling = Vector3.One;
InternalShape = new BulletSharp.HeightfieldShape(heightStickWidth, heightStickLength, dynamicFieldData.Pointer, heightScale, minHeight, maxHeight, 1, (int)BulletPhyScalarType.PhyShort, flipQuadEdges)
InternalShape = new BulletSharp.HeightfieldTerrainShape(heightStickWidth, heightStickLength, dynamicFieldData.Pointer, heightScale, minHeight, maxHeight, 1, BulletSharp.PhyScalarType.Int16, flipQuadEdges)
{
LocalScaling = cachedScaling,
};
@@ -21,7 +21,7 @@ public HeightfieldColliderShape(int heightStickWidth, int heightStickLength, Unm
public HeightfieldColliderShape(int heightStickWidth, int heightStickLength, UnmanagedArray<byte> dynamicFieldData, float heightScale, float minHeight, float maxHeight, bool flipQuadEdges)
{
cachedScaling = Vector3.One;
InternalShape = new BulletSharp.HeightfieldShape(heightStickWidth, heightStickLength, dynamicFieldData.Pointer, heightScale, minHeight, maxHeight, 1, (int)BulletPhyScalarType.PhyUchar, flipQuadEdges)
InternalShape = new BulletSharp.HeightfieldTerrainShape(heightStickWidth, heightStickLength, dynamicFieldData.Pointer, heightScale, minHeight, maxHeight, 1, BulletSharp.PhyScalarType.Byte, flipQuadEdges)
{
LocalScaling = cachedScaling,
};
@@ -31,7 +31,7 @@ public HeightfieldColliderShape(int heightStickWidth, int heightStickLength, Unm
public HeightfieldColliderShape(int heightStickWidth, int heightStickLength, UnmanagedArray<float> dynamicFieldData, float heightScale, float minHeight, float maxHeight, bool flipQuadEdges)
{
cachedScaling = Vector3.One;
InternalShape = new BulletSharp.HeightfieldShape(heightStickWidth, heightStickLength, dynamicFieldData.Pointer, heightScale, minHeight, maxHeight, 1, (int)BulletPhyScalarType.PhyFloat, flipQuadEdges)
InternalShape = new BulletSharp.HeightfieldTerrainShape(heightStickWidth, heightStickLength, dynamicFieldData.Pointer, heightScale, minHeight, maxHeight, 1, BulletSharp.PhyScalarType.Single, flipQuadEdges)
{
LocalScaling = cachedScaling,
};
@@ -40,12 +40,12 @@ public HeightfieldColliderShape(int heightStickWidth, int heightStickLength, Unm

public bool UseDiamondSubdivision
{
set { ((BulletSharp.HeightfieldShape)InternalShape).SetUseDiamondSubdivision(value); }
set { ((BulletSharp.HeightfieldTerrainShape)InternalShape).SetUseDiamondSubdivision(value); }
}

public bool UseZigzagSubdivision
{
set { ((BulletSharp.HeightfieldShape)InternalShape).SetUseZigzagSubdivision(value); }
set { ((BulletSharp.HeightfieldTerrainShape)InternalShape).SetUseZigzagSubdivision(value); }
}

public UnmanagedArray<short> ShortArray { get; private set; }
@@ -68,12 +68,12 @@ public override void Dispose()

private enum BulletPhyScalarType
{
PhyFloat,
PhyDouble,
PhyInteger,
PhyShort,
PhyFixedpoint88,
PhyUchar,
PhyFloat = BulletSharp.PhyScalarType.Single,
PhyDouble = BulletSharp.PhyScalarType.Double,
PhyInteger = BulletSharp.PhyScalarType.Int32,
PhyShort = BulletSharp.PhyScalarType.Int16,
PhyFixedpoint88 = BulletSharp.PhyScalarType.FixedPoint88,
PhyUchar = BulletSharp.PhyScalarType.Byte,
}
}
}

0 comments on commit f23ed46

Please sign in to comment.
You can’t perform that action at this time.