Make sure we only reference CS objects and wrap others for the PCL interface.

This commit is contained in:
kjpou1 2014-08-10 18:17:54 +02:00
Родитель 68e08ef6e1
Коммит 3e0a3d4324
14 изменённых файлов: 383 добавлений и 449 удалений

Просмотреть файл

@ -11,7 +11,7 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CocosSharp.MacOS", "src\Coc
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MonoGame.Framework.Net.MacOS", "MonoGame\MonoGame.Framework\MonoGame.Framework.Net.MacOS.csproj", "{1294038B-66C2-4359-AFE9-EA06A758CA94}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ChipmunkSharp.Win32", "src\external lib\ChipmunkSharp\src\ChipmunkSharp\win32\ChipmunkSharp.Win32.csproj", "{FD50437F-B756-4BD8-99BE-B723F6E1EB45}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ChipmunkSharp.Mac", "src\external lib\ChipmunkSharp\src\ChipmunkSharp\win32\ChipmunkSharp.Mac.csproj", "{FD50437F-B756-4BD8-99BE-B723F6E1EB45}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@ -54,8 +54,8 @@ Global
{1294038B-66C2-4359-AFE9-EA06A758CA94}.Release|iPhoneSimulator.Build.0 = Release|Any CPU
{1294038B-66C2-4359-AFE9-EA06A758CA94}.Release|x86.ActiveCfg = Release|Any CPU
{1294038B-66C2-4359-AFE9-EA06A758CA94}.Release|x86.Build.0 = Release|Any CPU
{1294038B-66C2-4359-AFE9-EA06A758CA94}.ReleasePhysics|Any CPU.ActiveCfg = Release|Any CPU
{1294038B-66C2-4359-AFE9-EA06A758CA94}.ReleasePhysics|Any CPU.Build.0 = Release|Any CPU
{1294038B-66C2-4359-AFE9-EA06A758CA94}.ReleasePhysics|Any CPU.ActiveCfg = ReleasePhysics|Any CPU
{1294038B-66C2-4359-AFE9-EA06A758CA94}.ReleasePhysics|Any CPU.Build.0 = ReleasePhysics|Any CPU
{36C538E6-C32A-4A8D-A39C-566173D7118E}.Ad-Hoc|iPhone.ActiveCfg = Debug|Any CPU
{36C538E6-C32A-4A8D-A39C-566173D7118E}.Ad-Hoc|iPhone.Build.0 = Debug|Any CPU
{36C538E6-C32A-4A8D-A39C-566173D7118E}.AppStore|iPhone.ActiveCfg = Debug|Any CPU
@ -80,8 +80,8 @@ Global
{36C538E6-C32A-4A8D-A39C-566173D7118E}.Release|iPhoneSimulator.Build.0 = Release|Any CPU
{36C538E6-C32A-4A8D-A39C-566173D7118E}.Release|x86.ActiveCfg = Release|Any CPU
{36C538E6-C32A-4A8D-A39C-566173D7118E}.Release|x86.Build.0 = Release|Any CPU
{36C538E6-C32A-4A8D-A39C-566173D7118E}.ReleasePhysics|Any CPU.ActiveCfg = Release|Any CPU
{36C538E6-C32A-4A8D-A39C-566173D7118E}.ReleasePhysics|Any CPU.Build.0 = Release|Any CPU
{36C538E6-C32A-4A8D-A39C-566173D7118E}.ReleasePhysics|Any CPU.ActiveCfg = ReleasePhysics|Any CPU
{36C538E6-C32A-4A8D-A39C-566173D7118E}.ReleasePhysics|Any CPU.Build.0 = ReleasePhysics|Any CPU
{5C3DC4FF-FE5A-4B94-B4A6-6F79E63F3130}.Ad-Hoc|iPhone.ActiveCfg = Debug|Any CPU
{5C3DC4FF-FE5A-4B94-B4A6-6F79E63F3130}.Ad-Hoc|iPhone.Build.0 = Debug|Any CPU
{5C3DC4FF-FE5A-4B94-B4A6-6F79E63F3130}.AppStore|iPhone.ActiveCfg = Debug|Any CPU
@ -106,8 +106,8 @@ Global
{5C3DC4FF-FE5A-4B94-B4A6-6F79E63F3130}.Release|iPhoneSimulator.Build.0 = Release|Any CPU
{5C3DC4FF-FE5A-4B94-B4A6-6F79E63F3130}.Release|x86.ActiveCfg = Release|Any CPU
{5C3DC4FF-FE5A-4B94-B4A6-6F79E63F3130}.Release|x86.Build.0 = Release|Any CPU
{5C3DC4FF-FE5A-4B94-B4A6-6F79E63F3130}.ReleasePhysics|Any CPU.ActiveCfg = Release|Any CPU
{5C3DC4FF-FE5A-4B94-B4A6-6F79E63F3130}.ReleasePhysics|Any CPU.Build.0 = Release|Any CPU
{5C3DC4FF-FE5A-4B94-B4A6-6F79E63F3130}.ReleasePhysics|Any CPU.ActiveCfg = ReleasePhysics|Any CPU
{5C3DC4FF-FE5A-4B94-B4A6-6F79E63F3130}.ReleasePhysics|Any CPU.Build.0 = ReleasePhysics|Any CPU
{A83510D8-7AED-411E-9616-DCFEA180969E}.Ad-Hoc|iPhone.ActiveCfg = Debug|Any CPU
{A83510D8-7AED-411E-9616-DCFEA180969E}.Ad-Hoc|iPhone.Build.0 = Debug|Any CPU
{A83510D8-7AED-411E-9616-DCFEA180969E}.AppStore|iPhone.ActiveCfg = Debug|Any CPU
@ -132,8 +132,8 @@ Global
{A83510D8-7AED-411E-9616-DCFEA180969E}.Release|iPhoneSimulator.Build.0 = Release|Any CPU
{A83510D8-7AED-411E-9616-DCFEA180969E}.Release|x86.ActiveCfg = Release|Any CPU
{A83510D8-7AED-411E-9616-DCFEA180969E}.Release|x86.Build.0 = Release|Any CPU
{A83510D8-7AED-411E-9616-DCFEA180969E}.ReleasePhysics|Any CPU.ActiveCfg = Release|Any CPU
{A83510D8-7AED-411E-9616-DCFEA180969E}.ReleasePhysics|Any CPU.Build.0 = Release|Any CPU
{A83510D8-7AED-411E-9616-DCFEA180969E}.ReleasePhysics|Any CPU.ActiveCfg = ReleasePhysics|Any CPU
{A83510D8-7AED-411E-9616-DCFEA180969E}.ReleasePhysics|Any CPU.Build.0 = ReleasePhysics|Any CPU
{A84510D8-7AED-411E-9616-DCFEA180969E}.Ad-Hoc|iPhone.ActiveCfg = Debug|Any CPU
{A84510D8-7AED-411E-9616-DCFEA180969E}.Ad-Hoc|iPhone.Build.0 = Debug|Any CPU
{A84510D8-7AED-411E-9616-DCFEA180969E}.AppStore|iPhone.ActiveCfg = Debug|Any CPU
@ -158,8 +158,8 @@ Global
{A84510D8-7AED-411E-9616-DCFEA180969E}.Release|iPhoneSimulator.Build.0 = Release|Any CPU
{A84510D8-7AED-411E-9616-DCFEA180969E}.Release|x86.ActiveCfg = Release|Any CPU
{A84510D8-7AED-411E-9616-DCFEA180969E}.Release|x86.Build.0 = Release|Any CPU
{A84510D8-7AED-411E-9616-DCFEA180969E}.ReleasePhysics|Any CPU.ActiveCfg = Release|Any CPU
{A84510D8-7AED-411E-9616-DCFEA180969E}.ReleasePhysics|Any CPU.Build.0 = Release|Any CPU
{A84510D8-7AED-411E-9616-DCFEA180969E}.ReleasePhysics|Any CPU.ActiveCfg = ReleasePhysics|Any CPU
{A84510D8-7AED-411E-9616-DCFEA180969E}.ReleasePhysics|Any CPU.Build.0 = ReleasePhysics|Any CPU
{FD50437F-B756-4BD8-99BE-B723F6E1EB45}.Ad-Hoc|iPhone.ActiveCfg = Debug|Any CPU
{FD50437F-B756-4BD8-99BE-B723F6E1EB45}.Ad-Hoc|iPhone.Build.0 = Debug|Any CPU
{FD50437F-B756-4BD8-99BE-B723F6E1EB45}.AppStore|iPhone.ActiveCfg = Debug|Any CPU
@ -171,8 +171,8 @@ Global
{FD50437F-B756-4BD8-99BE-B723F6E1EB45}.Debug|iPhoneSimulator.Build.0 = Debug|Any CPU
{FD50437F-B756-4BD8-99BE-B723F6E1EB45}.Debug|x86.ActiveCfg = Debug|Any CPU
{FD50437F-B756-4BD8-99BE-B723F6E1EB45}.Debug|x86.Build.0 = Debug|Any CPU
{FD50437F-B756-4BD8-99BE-B723F6E1EB45}.DebugPhysics|Any CPU.ActiveCfg = DebugPhysics|Any CPU
{FD50437F-B756-4BD8-99BE-B723F6E1EB45}.DebugPhysics|Any CPU.Build.0 = DebugPhysics|Any CPU
{FD50437F-B756-4BD8-99BE-B723F6E1EB45}.DebugPhysics|Any CPU.ActiveCfg = Debug|Any CPU
{FD50437F-B756-4BD8-99BE-B723F6E1EB45}.DebugPhysics|Any CPU.Build.0 = Debug|Any CPU
{FD50437F-B756-4BD8-99BE-B723F6E1EB45}.Distribution|Any CPU.ActiveCfg = Release|Any CPU
{FD50437F-B756-4BD8-99BE-B723F6E1EB45}.Distribution|Any CPU.Build.0 = Release|Any CPU
{FD50437F-B756-4BD8-99BE-B723F6E1EB45}.Release|Any CPU.ActiveCfg = Release|Any CPU
@ -182,8 +182,8 @@ Global
{FD50437F-B756-4BD8-99BE-B723F6E1EB45}.Release|iPhoneSimulator.Build.0 = Release|Any CPU
{FD50437F-B756-4BD8-99BE-B723F6E1EB45}.Release|x86.ActiveCfg = Release|Any CPU
{FD50437F-B756-4BD8-99BE-B723F6E1EB45}.Release|x86.Build.0 = Release|Any CPU
{FD50437F-B756-4BD8-99BE-B723F6E1EB45}.ReleasePhysics|Any CPU.ActiveCfg = Release|Any CPU
{FD50437F-B756-4BD8-99BE-B723F6E1EB45}.ReleasePhysics|Any CPU.Build.0 = Release|Any CPU
{FD50437F-B756-4BD8-99BE-B723F6E1EB45}.ReleasePhysics|Any CPU.ActiveCfg = ReleasePhysics|Any CPU
{FD50437F-B756-4BD8-99BE-B723F6E1EB45}.ReleasePhysics|Any CPU.Build.0 = ReleasePhysics|Any CPU
|iPhoneSimulator
EndGlobalSection
GlobalSection(MonoDevelopProperties) = preSolution

Просмотреть файл

@ -526,7 +526,7 @@ namespace CocosSharp
get { return position; }
set
{
if (position != value)
if (position != value || value == CCPoint.Zero)
{
position = value;
UpdateTransform();
@ -953,11 +953,11 @@ namespace CocosSharp
if (scene != null && scene.PhysicsWorld != null)
{
var pos = Parent == scene ? Position : scene.WorldToParentspace(Position);
_physicsBody.Position = new cpVect(PositionX, PositionY);
_physicsBody.Position = Position;//new cpVect(PositionX, PositionY);
}
else
{
_physicsBody.Position = Position.ToCpVect();
_physicsBody.Position = Position;
}
}

Просмотреть файл

@ -53,7 +53,7 @@ namespace CocosSharp
public List<CCPhysicsJoint> _joints = new List<CCPhysicsJoint>();
protected List<CCPhysicsShape> _shapes = new List<CCPhysicsShape>();
public CCPhysicsWorld _world;
public CCPhysicsBodyInfo _info;
internal CCPhysicsBodyInfo _info;
internal bool _dynamic;
internal bool _enabled;
internal bool _rotationEnabled;
@ -102,17 +102,17 @@ namespace CocosSharp
}
public CCPhysicsBody(float mass, float moment)
: this(mass, MOMENT_DEFAULT, null)
: this(mass, MOMENT_DEFAULT, CCPoint.Zero)
{
}
public CCPhysicsBody(float mass, float moment, cpVect offset)
public CCPhysicsBody(float mass, float moment, CCPoint offset)
{
_positionOffset = offset != null ? offset : cpVect.Zero;
var offsetcp = new cpVect(offset.X, offset.Y); ;
_positionOffset = offsetcp != null ? offsetcp : cpVect.Zero;
_node = null;
_world = null;
_info = null;
@ -144,14 +144,14 @@ namespace CocosSharp
}
public CCPhysicsBody(CCPhysicsShape shape)
: this(0f, 0f, cpVect.Zero)
: this(0f, 0f, CCPoint.Zero)
{
AddShape(shape);
}
public CCPhysicsBody(List<CCPhysicsShape> shapes)
: this(0f, 0f, cpVect.Zero)
: this(0f, 0f, CCPoint.Zero)
{
foreach (var item in shapes)
@ -184,7 +184,7 @@ namespace CocosSharp
{
CCNode parent = _node.Parent;
CCScene scene = _world.GetScene();
cpVect vec = Position;
var vec = new cpVect(Position.X, Position.Y);
CCPoint parentPosition = new CCPoint((float)vec.x, (float)vec.y); //ConvertToNodeSpace(scene.ConvertToWorldSpace(new CCPoint((float)vec.x, (float)vec.y)));
@ -226,15 +226,17 @@ namespace CocosSharp
protected void UpdateDamping() { _isDamping = _linearDamping != 0.0f || _angularDamping != 0.0f; }
protected void UpdateMass(float oldMass, float newMass)
{
var gravity = _world.GetGravity();
if (_dynamic && !_gravityEnabled && _world != null && oldMass != cp.PHYSICS_INFINITY)
{
ApplyForce(_world.GetGravity() * oldMass);
ApplyForce(gravity * oldMass);
}
_info.GetBody().SetMass(newMass);
if (_dynamic && !_gravityEnabled && _world != null && newMass != cp.PHYSICS_INFINITY)
{
ApplyForce(-_world.GetGravity() * newMass);
ApplyForce(-gravity * newMass);
}
}
@ -244,17 +246,17 @@ namespace CocosSharp
/** Create a body contains a circle shape. */
public static CCPhysicsBody CreateCircle(float radius, CCPhysicsMaterial material, cpVect offset)
public static CCPhysicsBody CreateCircle(float radius, CCPhysicsMaterial material, CCPoint offset)
{
CCPhysicsBody body = new CCPhysicsBody();
body.SetMass(MASS_DEFAULT);
body.AddShape(new CCPhysicsShapeCircle(material, radius, offset));
body.AddShape(new CCPhysicsShapeCircle(material, radius, offset));
return body;
}
public static CCPhysicsBody CreateCircle(float radius, cpVect offset)
public static CCPhysicsBody CreateCircle(float radius, CCPoint offset)
{
return CreateCircle(radius, CCPhysicsMaterial.PHYSICSSHAPE_MATERIAL_DEFAULT, offset);
}
@ -277,7 +279,7 @@ namespace CocosSharp
* @brief Create a body contains a polygon shape.
* points is an array of cpVect structs defining a convex hull with a clockwise winding.
*/
public static CCPhysicsBody CreatePolygon(cpVect[] points, int count, CCPhysicsMaterial material, float radius)
public static CCPhysicsBody CreatePolygon(CCPoint[] points, int count, CCPhysicsMaterial material, float radius)
{
CCPhysicsBody body = new CCPhysicsBody();
@ -285,74 +287,74 @@ namespace CocosSharp
return body;
}
public static CCPhysicsBody CreatePolygon(cpVect[] points, int count, float radius)
public static CCPhysicsBody CreatePolygon(CCPoint[] points, int count, float radius)
{
return CreatePolygon(points, count, CCPhysicsMaterial.PHYSICSSHAPE_MATERIAL_DEFAULT, radius);
return CreatePolygon(points, count, CCPhysicsMaterial.PHYSICSSHAPE_MATERIAL_DEFAULT, radius);
}
/** Create a body contains a EdgeSegment shape. */
public static CCPhysicsBody CreateEdgeSegment(cpVect a, cpVect b, CCPhysicsMaterial material, float border = 1)
public static CCPhysicsBody CreateEdgeSegment(CCPoint a, CCPoint b, CCPhysicsMaterial material, float border = 1)
{
CCPhysicsBody body = new CCPhysicsBody();
body.AddShape(new CCPhysicsShapeEdgeSegment(a, b, material, border));
body.AddShape(new CCPhysicsShapeEdgeSegment(a, b, material, border));
body._dynamic = false;
return body;
}
public static CCPhysicsBody CreateEdgeSegment(cpVect a, cpVect b, float border = 1)
public static CCPhysicsBody CreateEdgeSegment(CCPoint a, CCPoint b, float border = 1)
{
return CreateEdgeSegment(a, b, CCPhysicsMaterial.PHYSICSSHAPE_MATERIAL_DEFAULT, border);
return CreateEdgeSegment(a, b , CCPhysicsMaterial.PHYSICSSHAPE_MATERIAL_DEFAULT, border);
}
/** Create a body contains a EdgeBox shape. */
public static CCPhysicsBody CreateEdgeBox(CCSize size, CCPhysicsMaterial material, float border, cpVect offset)
public static CCPhysicsBody CreateEdgeBox(CCSize size, CCPhysicsMaterial material, float border, CCPoint offset)
{
CCPhysicsBody body = new CCPhysicsBody();
body.AddShape(new CCPhysicsShapeEdgeBox(size, material, border, offset));
body.AddShape(new CCPhysicsShapeEdgeBox(size, material, offset, border));
body._dynamic = false;
return body;
}
public static CCPhysicsBody CreateEdgeBox(CCSize size, float border, cpVect offset)
public static CCPhysicsBody CreateEdgeBox(CCSize size, float border, CCPoint offset)
{
return CreateEdgeBox(size, CCPhysicsMaterial.PHYSICSSHAPE_MATERIAL_DEFAULT, border, offset);
return CreateEdgeBox(size, CCPhysicsMaterial.PHYSICSSHAPE_MATERIAL_DEFAULT, border, offset);
}
/** Create a body contains a EdgePolygon shape. */
public static CCPhysicsBody CreateEdgePolygon(cpVect[] points, int count, CCPhysicsMaterial material, float border = 1)
public static CCPhysicsBody CreateEdgePolygon(CCPoint[] points, int count, CCPhysicsMaterial material, float border = 1)
{
CCPhysicsBody body = new CCPhysicsBody();
body.AddShape(new CCPhysicsShapeEdgePolygon(points, count, material, border));
body.AddShape(new CCPhysicsShapeEdgePolygon(points, count, material, border));
body._dynamic = false;
return body;
}
public static CCPhysicsBody CreateEdgePolygon(cpVect[] points, int count, float border = 1)
public static CCPhysicsBody CreateEdgePolygon(CCPoint[] points, int count, float border = 1)
{
return CreateEdgePolygon(points, count, CCPhysicsMaterial.PHYSICSSHAPE_MATERIAL_DEFAULT, border);
return CreateEdgePolygon(points, count, CCPhysicsMaterial.PHYSICSSHAPE_MATERIAL_DEFAULT, border);
}
/** Create a body contains a EdgeChain shape. */
public static CCPhysicsBody CreateEdgeChain(cpVect[] points, int count, CCPhysicsMaterial material, float border = 1)
public static CCPhysicsBody CreateEdgeChain(CCPoint[] points, int count, CCPhysicsMaterial material, float border = 1)
{
CCPhysicsBody body = new CCPhysicsBody();
body.AddShape(new CCPhysicsShapeEdgeChain(points, count, material, border));
body.AddShape(new CCPhysicsShapeEdgeChain(points, count, material, border));
body._dynamic = false;
return body;
}
public static CCPhysicsBody CreateEdgeChain(cpVect[] points, int count, float border = 1)
public static CCPhysicsBody CreateEdgeChain(CCPoint[] points, int count, float border = 1)
{
return CreateEdgeChain(points, count, CCPhysicsMaterial.PHYSICSSHAPE_MATERIAL_DEFAULT, border);
return CreateEdgeChain(points, count, CCPhysicsMaterial.PHYSICSSHAPE_MATERIAL_DEFAULT, border);
}
/*
@ -488,18 +490,31 @@ namespace CocosSharp
}
/** Applies a immediate force to body. */
public virtual void ApplyForce(cpVect force)
public virtual void ApplyForce(CCPoint force)
{
ApplyForce(force, cpVect.Zero);
ApplyForce(force, CCPoint.Zero);
}
/** Applies a immediate force to body. */
public virtual void ApplyForce(cpVect force, cpVect offset)
public virtual void ApplyForce(CCPoint force, CCPoint offset)
{
if (_dynamic && _mass != cp.PHYSICS_INFINITY)
{
_info.GetBody().ApplyForce(force, offset);
}
ApplyForce(new cpVect(force.X,force.Y), new cpVect(offset.X,offset.Y));
}
/** Applies a immediate force to body. */
internal void ApplyForce(cpVect force)
{
ApplyForce(force, cpVect.Zero);
}
/** Applies a immediate force to body. */
internal void ApplyForce(cpVect force, cpVect offset)
{
if (_dynamic && _mass != cp.PHYSICS_INFINITY)
{
_info.GetBody().ApplyForce(force, offset);
}
}
/** reset all the force applied to body. */
public virtual void ResetForces()
{
@ -510,17 +525,32 @@ namespace CocosSharp
ApplyForce(-_world.GetGravity() * _mass);
}
}
/** Applies a continuous force to body. */
public virtual void ApplyImpulse(cpVect impulse)
/** Applies a continuous force to body. */
public virtual void ApplyImpulse(CCPoint impulse)
{
ApplyImpulse(impulse, cpVect.Zero);
ApplyImpulse(impulse, CCPoint.Zero);
}
/** Applies a continuous force to body. */
public virtual void ApplyImpulse(cpVect impulse, cpVect offset)
public virtual void ApplyImpulse(CCPoint impulse, CCPoint offset)
{
// cpBodyApplyImpulse(_info->getBody(), PhysicsHelper::point2cpv(impulse), PhysicsHelper::point2cpv(offset));
_info.GetBody().ApplyImpulse(impulse, offset);
ApplyImpulse(new cpVect(impulse.X,impulse.Y), new cpVect(offset.X,offset.Y));
}
/** Applies a continuous force to body. */
internal void ApplyImpulse(cpVect impulse)
{
ApplyImpulse(impulse, cpVect.Zero);
}
/** Applies a continuous force to body. */
internal void ApplyImpulse(cpVect impulse, cpVect offset)
{
// cpBodyApplyImpulse(_info->getBody(), PhysicsHelper::point2cpv(impulse), PhysicsHelper::point2cpv(offset));
_info.GetBody().ApplyImpulse(impulse, offset);
}
/** Applies a torque force to body. */
public virtual void ApplyTorque(float torque)
{
@ -528,21 +558,22 @@ namespace CocosSharp
}
/** set the velocity of a body */
public virtual void SetVelocity(cpVect velocity)
public virtual void SetVelocity(CCPoint velocity)
{
if (!_dynamic)
{
cp.AssertWarn("physics warning: your can't set velocity for a static body.");
return;
}
_info.GetBody().SetPosition(velocity);
_info.GetBody().SetPosition(new cpVect(velocity.X,velocity.Y));
//cpBodySetVel(_info->getBody(), PhysicsHelper::point2cpv(velocity));
}
/** get the velocity of a body */
public virtual cpVect GetVelocity()
public virtual CCPoint GetVelocity()
{
return _info.GetBody().GetVelocity();// getVel();
var velocity = _info.GetBody().GetVelocity();// getVel();
return new CCPoint(velocity.x, velocity.y);
}
/** set the angular velocity of a body */
public virtual void SetAngularVelocity(float velocity)
@ -557,15 +588,29 @@ namespace CocosSharp
//cpBodySetAngVel(_info->getBody(), PhysicsHelper::float2cpfloat(velocity));
}
/** get the angular velocity of a body at a local point */
public virtual cpVect GetVelocityAtLocalPoint(cpVect point)
public virtual CCPoint GetVelocityAtLocalPoint(CCPoint point)
{
return _info.GetBody().GetVelocityAtLocalPoint(point);
var cpVec = GetVelocityAtLocalPoint(new cpVect(point.X,point.Y));
return new CCPoint(cpVec.x, cpVec.y);
}
/** get the angular velocity of a body at a world point */
public virtual cpVect GetVelocityAtWorldPoint(cpVect point)
public virtual CCPoint GetVelocityAtWorldPoint(CCPoint point)
{
return _info.GetBody().GetVelocityAtWorldPoint(point);
var cpVec = GetVelocityAtWorldPoint(new cpVect(point.X,point.Y));
return new CCPoint(cpVec.x, cpVec.y);
}
/** get the angular velocity of a body at a local point */
internal cpVect GetVelocityAtLocalPoint(cpVect point)
{
return _info.GetBody().GetVelocityAtLocalPoint(point);
}
/** get the angular velocity of a body at a world point */
internal cpVect GetVelocityAtWorldPoint(cpVect point)
{
return _info.GetBody().GetVelocityAtWorldPoint(point);
}
/** get the angular velocity of a body */
public virtual float GetAngularVelocity()
{
@ -677,22 +722,22 @@ namespace CocosSharp
/** get the body position. */
public cpVect Position
public CCPoint Position
{
get
{
cpVect vec = _info.GetBody().GetPosition();
return vec - _positionOffset;
var vec = _info.GetBody().GetPosition();
var vecp = vec - _positionOffset;
return new CCPoint(vecp.x, vecp.y);
}
set
{
_info.GetBody().SetPosition(value + _positionOffset);
var newpos = new cpVect(value.X, value.Y);
_info.GetBody().SetPosition(newpos + _positionOffset);
}
}
/** get the body rotation. */
public float GetRotation()
{
@ -701,21 +746,30 @@ namespace CocosSharp
}
/** set body position offset, it's the position witch relative to node */
public void setPositionOffset(cpVect position)
public void setPositionOffset(CCPoint position)
{
if (!_positionOffset.Equals(position))
{
cpVect pos = Position;
_positionOffset = position;
Position = pos;// setPosition(pos);
}
setPositionOffset(new cpVect(position.X, position.Y));
}
/** set body position offset, it's the position witch relative to node */
internal void setPositionOffset(cpVect position)
{
if (!_positionOffset.Equals(position))
{
var pos = Position;
_positionOffset = position;
Position = pos;// setPosition(pos);
}
}
/** get body position offset. */
public cpVect GetPositionOffset()
public CCPoint GetPositionOffset()
{
return _positionOffset;
var posOff = new CCPoint(_positionOffset.x, _positionOffset.y);
return posOff;
}
/** set body rotation offset, it's the rotation witch relative to node */
/** set body rotation offset, it's the rotation witch relative to node */
public void SetRotationOffset(float rotation)
{
if (Math.Abs(_rotationOffset - rotation) > 0.5f)
@ -1056,18 +1110,32 @@ namespace CocosSharp
public void setTag(int tag) { _tag = tag; }
/** convert the world point to local */
public cpVect World2Local(cpVect point)
public CCPoint World2Local(CCPoint point)
{
return _info.GetBody().WorldToLocal(point);
var pp = World2Local(new cpVect(point.X, point.Y));
return new CCPoint(pp.x, pp.y);
//return PhysicsHelper::cpv2point(cpBodyWorld2Local(_info->getBody(), PhysicsHelper::point2cpv(point)));
}
/** convert the local point to world */
public cpVect Local2World(cpVect point)
public CCPoint Local2World(CCPoint point)
{
return _info.GetBody().LocalToWorld(point);
var pp = Local2World(new cpVect(point.X, point.Y));
return new CCPoint(pp.x, pp.y);
}
#endregion
/** convert the world point to local */
internal cpVect World2Local(cpVect point)
{
return _info.GetBody().WorldToLocal(point);
//return PhysicsHelper::cpv2point(cpBodyWorld2Local(_info->getBody(), PhysicsHelper::point2cpv(point)));
}
/** convert the local point to world */
internal cpVect Local2World(cpVect point)
{
return _info.GetBody().LocalToWorld(point);
}
#endregion
public void SetScale(float scale)

Просмотреть файл

@ -44,7 +44,7 @@ namespace CocosSharp
public class CCPhysicsContactData
{
public const int POINT_MAX = 4;
public List<cpVect> points = new List<cpVect>();
public List<CCPoint> points = new List<CCPoint>();
public int count
{
get
@ -52,7 +52,7 @@ namespace CocosSharp
return (points != null) ? points.Count : 0;
}
}
public cpVect normal;
public CCPoint normal;
};
/** * @brief Contact infomation. it will created automatically when two shape contact with each other. and it will destoried automatically when two shape separated. */
@ -173,10 +173,10 @@ namespace CocosSharp
for (int i = 0; i < _contactData.count && i < CCPhysicsContactData.POINT_MAX; ++i)
{
_contactData.points[i] = arb.GetPointA(i);
_contactData.points[i] = PhysicsHelper.cpVectToCCPoint(arb.GetPointA(i));
}
_contactData.normal = _contactData.count > 0 ? arb.GetNormal() : cpVect.Zero;
_contactData.normal = _contactData.count > 0 ? PhysicsHelper.cpVectToCCPoint(arb.GetNormal()) : CCPoint.Zero;
}
#endregion
@ -205,9 +205,9 @@ namespace CocosSharp
return (_contactInfo as cpArbiter).u;
}
/** get surface velocity between two bodies*/
public cpVect GetSurfaceVelocity()
public CCPoint GetSurfaceVelocity()
{
return (_contactInfo as cpArbiter).surface_vr;
return PhysicsHelper.cpVectToCCPoint((_contactInfo as cpArbiter).surface_vr);
}
/** set the restitution*/
public void SetRestitution(float restitution)
@ -220,9 +220,9 @@ namespace CocosSharp
(_contactInfo as cpArbiter).u = friction;
}
/** set the surface velocity*/
public void SetSurfaceVelocity(cpVect velocity)
public void SetSurfaceVelocity(CCPoint velocity)
{
(_contactInfo as cpArbiter).surface_vr = velocity;
(_contactInfo as cpArbiter).surface_vr = PhysicsHelper.CCPointToCpVect(velocity);
}
/** ignore the rest of the contact presolve and postsolve callbacks */
public void Ignore()

Просмотреть файл

@ -43,7 +43,7 @@ namespace CocosSharp
public CCPhysicsBody _bodyA;
public CCPhysicsBody _bodyB;
public CCPhysicsWorld _world;
public CCPhysicsJointInfo _info;
internal CCPhysicsJointInfo _info;
bool _enable;
bool _collisionEnable;
public bool _destoryMark;
@ -179,7 +179,7 @@ namespace CocosSharp
/**
* PhysicsShape is PhysicsBody's friend class, but all the subclasses isn't. so this method is use for subclasses to catch the bodyInfo from PhysicsBody.
*/
protected CCPhysicsBodyInfo GetBodyInfo(CCPhysicsBody body)
internal CCPhysicsBodyInfo GetBodyInfo(CCPhysicsBody body)
{
return body._info;
}
@ -198,11 +198,11 @@ namespace CocosSharp
public class CCPhysicsJointFixed : CCPhysicsJoint
{
public static CCPhysicsJointFixed Construct(CCPhysicsBody a, CCPhysicsBody b, cpVect anchr)
public static CCPhysicsJointFixed Construct(CCPhysicsBody a, CCPhysicsBody b, CCPoint anchr)
{
CCPhysicsJointFixed joint = new CCPhysicsJointFixed();
if (joint != null && joint.Init(a, b, anchr))
if (joint != null && joint.Init(a, b, anchr))
{
return joint;
}
@ -213,21 +213,21 @@ namespace CocosSharp
#region PROTECTED FUNC
protected bool Init(CCPhysicsBody a, CCPhysicsBody b, cpVect anchr)
protected bool Init(CCPhysicsBody a, CCPhysicsBody b, CCPoint anchr)
{
if (!base.Init(a, b))
return false;
GetBodyNode(a).Position = new CCPoint((float)anchr.x, (float)anchr.y);
GetBodyNode(b).Position = new CCPoint((float)anchr.x, (float)anchr.y);
GetBodyNode(a).Position = anchr;
GetBodyNode(b).Position = anchr;
// add a pivot joint to fixed two body together
//cpConstraint joint = cpPivotJoint.cpPivotJointNew(getBodyInfo(a).getBody(),
// getBodyInfo(b).getBody(),
// anchr);
cpConstraint joint = new cpPivotJoint(GetBodyInfo(a).GetBody(), GetBodyInfo(b).GetBody(), anchr);
cpConstraint joint = new cpPivotJoint(GetBodyInfo(a).GetBody(), GetBodyInfo(b).GetBody(), PhysicsHelper.CCPointToCpVect(anchr));
if (joint == null)
return false;
@ -262,7 +262,7 @@ namespace CocosSharp
#region PUBLIC FUNC
public static CCPhysicsJointLimit Construct(CCPhysicsBody a, CCPhysicsBody b, cpVect anchr1, cpVect anchr2, float min, float max)
public static CCPhysicsJointLimit Construct(CCPhysicsBody a, CCPhysicsBody b, CCPoint anchr1, CCPoint anchr2, float min, float max)
{
CCPhysicsJointLimit joint = new CCPhysicsJointLimit();
@ -274,29 +274,29 @@ namespace CocosSharp
return null;
}
public static CCPhysicsJointLimit Construct(CCPhysicsBody a, CCPhysicsBody b, cpVect anchr1, cpVect anchr2)
public static CCPhysicsJointLimit Construct(CCPhysicsBody a, CCPhysicsBody b, CCPoint anchr1, CCPoint anchr2)
{
return Construct(a, b, anchr1, anchr2, 0,
cpVect.cpvdist(b.Local2World(anchr1), a.Local2World(anchr2)));
cpVect.cpvdist(b.Local2World(PhysicsHelper.CCPointToCpVect(anchr1)), a.Local2World(PhysicsHelper.CCPointToCpVect(anchr2))));
}
public cpVect GetAnchr1()
public CCPoint GetAnchr1()
{
return _info.getJoints().FirstOrDefault().GetAnchorA();
return PhysicsHelper.cpVectToCCPoint(_info.getJoints().FirstOrDefault().GetAnchorA());
}
public void SetAnchr1(cpVect anchr1)
public void SetAnchr1(CCPoint anchr1)
{
_info.getJoints().FirstOrDefault().SetAnchorA(anchr1);
_info.getJoints().FirstOrDefault().SetAnchorA(PhysicsHelper.CCPointToCpVect(anchr1));
}
public cpVect GetAnchr2()
public CCPoint GetAnchr2()
{
//getAnchr1
return _info.getJoints().FirstOrDefault().GetAnchorB();
return PhysicsHelper.cpVectToCCPoint(_info.getJoints().FirstOrDefault().GetAnchorB());
}
public void SetAnchr2(cpVect anchr2)
public void SetAnchr2(CCPoint anchr2)
{
_info.getJoints().FirstOrDefault().SetAnchorA(anchr2);
_info.getJoints().FirstOrDefault().SetAnchorA(PhysicsHelper.CCPointToCpVect(anchr2));
}
public float GetMin()
{
@ -320,15 +320,15 @@ namespace CocosSharp
#region PROTECTED FUNC
protected bool Init(CCPhysicsBody a, CCPhysicsBody b, cpVect anchr1, cpVect anchr2, float min, float max)
protected bool Init(CCPhysicsBody a, CCPhysicsBody b, CCPoint anchr1, CCPoint anchr2, float min, float max)
{
if (!base.Init(a, b))
return false;
cpConstraint joint = new cpSlideJoint(GetBodyInfo(a).GetBody(), GetBodyInfo(b).GetBody(),
anchr1,
anchr2,
PhysicsHelper.CCPointToCpVect(anchr1),
PhysicsHelper.CCPointToCpVect(anchr2),
min,
max);
@ -352,7 +352,7 @@ namespace CocosSharp
public class CCPhysicsJointPin : CCPhysicsJoint
{
public static CCPhysicsJointPin Construct(CCPhysicsBody a, CCPhysicsBody b, cpVect anchr)
public static CCPhysicsJointPin Construct(CCPhysicsBody a, CCPhysicsBody b, CCPoint anchr)
{
CCPhysicsJointPin joint = new CCPhysicsJointPin();
@ -368,14 +368,14 @@ namespace CocosSharp
#region PROTECTED FUNC
protected bool Init(CCPhysicsBody a, CCPhysicsBody b, cpVect anchr)
protected bool Init(CCPhysicsBody a, CCPhysicsBody b, CCPoint anchr)
{
if (!base.Init(a, b))
return false;
cpConstraint joint = new cpPivotJoint(GetBodyInfo(a).GetBody(), GetBodyInfo(b).GetBody(),
anchr);
PhysicsHelper.CCPointToCpVect(anchr));
if (joint == null)
return false;
@ -407,10 +407,10 @@ namespace CocosSharp
}
#endregion
public static CCPhysicsJointDistance Construct(CCPhysicsBody a, CCPhysicsBody b, cpVect anchr1, cpVect anchr2)
public static CCPhysicsJointDistance Construct(CCPhysicsBody a, CCPhysicsBody b, CCPoint anchr1, CCPoint anchr2)
{
CCPhysicsJointDistance joint = new CCPhysicsJointDistance();
if (joint != null && joint.Init(a, b, anchr1, anchr2))
if (joint != null && joint.Init(a, b, PhysicsHelper.CCPointToCpVect(anchr1), PhysicsHelper.CCPointToCpVect(anchr2)))
{
return joint;
}
@ -447,7 +447,7 @@ namespace CocosSharp
public class CCPhysicsJointSpring : CCPhysicsJoint
{
#region PUBLIC FUNC
public static CCPhysicsJointSpring Construct(CCPhysicsBody a, CCPhysicsBody b, cpVect anchr1, cpVect anchr2, float stiffness, float damping)
public static CCPhysicsJointSpring Construct(CCPhysicsBody a, CCPhysicsBody b, CCPoint anchr1, CCPoint anchr2, float stiffness, float damping)
{
CCPhysicsJointSpring joint = new CCPhysicsJointSpring();
@ -457,22 +457,22 @@ namespace CocosSharp
}
return null;
}
public cpVect GetAnchr1()
public CCPoint GetAnchr1()
{
return _info.getJoints().FirstOrDefault().GetAnchorA();
return PhysicsHelper.cpVectToCCPoint(_info.getJoints().FirstOrDefault().GetAnchorA());
}
public void SetAnchr1(cpVect anchr1)
public void SetAnchr1(CCPoint anchr1)
{
_info.getJoints().FirstOrDefault().SetAnchorA(anchr1);
_info.getJoints().FirstOrDefault().SetAnchorA(PhysicsHelper.CCPointToCpVect(anchr1));
}
public cpVect GetAnchr2()
public CCPoint GetAnchr2()
{
return _info.getJoints().FirstOrDefault().GetAnchorB();
return PhysicsHelper.cpVectToCCPoint(_info.getJoints().FirstOrDefault().GetAnchorB());
}
public void SetAnchr2(cpVect anchr2)
public void SetAnchr2(CCPoint anchr2)
{
_info.getJoints().FirstOrDefault().SetAnchorB(anchr2);
_info.getJoints().FirstOrDefault().SetAnchorB(PhysicsHelper.CCPointToCpVect(anchr2));
}
public float GetRestLength()
{
@ -507,17 +507,19 @@ namespace CocosSharp
#region PROTECTED FUNC
protected bool Init(CCPhysicsBody a, CCPhysicsBody b, cpVect anchr1, cpVect anchr2, float stiffness, float damping)
protected bool Init(CCPhysicsBody a, CCPhysicsBody b, CCPoint anchr1, CCPoint anchr2, float stiffness, float damping)
{
if (!base.Init(a, b))
return false;
var anch1 = PhysicsHelper.CCPointToCpVect(anchr1);
var anch2 = PhysicsHelper.CCPointToCpVect(anchr2);
cpConstraint joint = new cpDampedSpring(GetBodyInfo(a).GetBody(),
GetBodyInfo(b).GetBody(),
anchr1,
anchr2,
anch1,
anch2,
cpVect.cpvdist(
_bodyB.Local2World(anchr1), _bodyA.Local2World(anchr2)),
_bodyB.Local2World(anch1), _bodyA.Local2World(anch2)),
stiffness,
damping);
@ -542,7 +544,7 @@ namespace CocosSharp
#region PUBLIC FUNC
public static CCPhysicsJointGroove Construct(CCPhysicsBody a, CCPhysicsBody b, cpVect grooveA, cpVect grooveB, cpVect anchr2)
public static CCPhysicsJointGroove Construct(CCPhysicsBody a, CCPhysicsBody b, CCPoint grooveA, CCPoint grooveB, CCPoint anchr2)
{
CCPhysicsJointGroove joint = new CCPhysicsJointGroove();
@ -554,36 +556,36 @@ namespace CocosSharp
return null;
}
public cpVect GetGrooveA()
public CCPoint GetGrooveA()
{
return _info.getJoints().FirstOrDefault().GetGrooveA();
return PhysicsHelper.cpVectToCCPoint(_info.getJoints().FirstOrDefault().GetGrooveA());
}
public void SetGrooveA(cpVect grooveA)
public void SetGrooveA(CCPoint grooveA)
{
_info.getJoints().FirstOrDefault().SetGrooveA(grooveA);
_info.getJoints().FirstOrDefault().SetGrooveA(PhysicsHelper.CCPointToCpVect(grooveA));
}
public cpVect GetGrooveB()
public CCPoint GetGrooveB()
{
return _info.getJoints().FirstOrDefault().GetGrooveB();
return PhysicsHelper.cpVectToCCPoint(_info.getJoints().FirstOrDefault().GetGrooveB());
}
public void SetGrooveB(cpVect grooveB)
public void SetGrooveB(CCPoint grooveB)
{
_info.getJoints().FirstOrDefault().SetGrooveB(grooveB);
_info.getJoints().FirstOrDefault().SetGrooveB(PhysicsHelper.CCPointToCpVect(grooveB));
}
public cpVect GetAnchr2()
public CCPoint GetAnchr2()
{
return _info.getJoints().FirstOrDefault().GetAnchorB();
return PhysicsHelper.cpVectToCCPoint(_info.getJoints().FirstOrDefault().GetAnchorB());
}
public void SetAnchr2(cpVect anchr2)
public void SetAnchr2(CCPoint anchr2)
{
_info.getJoints().FirstOrDefault().SetAnchorB(anchr2);
_info.getJoints().FirstOrDefault().SetAnchorB(PhysicsHelper.CCPointToCpVect(anchr2));
}
#endregion
#region PROTECTED FUNC
protected bool Init(CCPhysicsBody a, CCPhysicsBody b, cpVect grooveA, cpVect grooveB, cpVect anchr)
protected bool Init(CCPhysicsBody a, CCPhysicsBody b, CCPoint grooveA, CCPoint grooveB, CCPoint anchr)
{
if (!base.Init(a, b))
@ -591,9 +593,9 @@ namespace CocosSharp
cpConstraint joint = new cpGrooveJoint(GetBodyInfo(a).GetBody(),
GetBodyInfo(b).GetBody(),
grooveA,
grooveB,
anchr);
PhysicsHelper.CCPointToCpVect(grooveA),
PhysicsHelper.CCPointToCpVect(grooveB),
PhysicsHelper.CCPointToCpVect(anchr));
if (joint == null)

Просмотреть файл

@ -74,7 +74,7 @@ namespace CocosSharp
#region PROTECTED PARAMETERS
public CCPhysicsBody _body;
public CCPhysicsShapeInfo _info;
internal CCPhysicsShapeInfo _info;
protected PhysicsType _type;
protected float _area;
@ -139,12 +139,12 @@ namespace CocosSharp
}
}
public CCPhysicsShape(float radius, CCPhysicsMaterial material, cpVect offset)
public CCPhysicsShape(float radius, CCPhysicsMaterial material, CCPoint offset)
{
// TODO: Complete member initialization
this.radius = radius;
this.material = material;
this.offset = offset;
this.offset = PhysicsHelper.CCPointToCpVect(offset);
}
#region PUBLIC METHODS
@ -261,18 +261,18 @@ namespace CocosSharp
/** Calculate the default moment value */
public virtual float CalculateDefaultMoment() { return 0.0f; }
/** Get offset */
public virtual cpVect GetOffset() { return cpVect.Zero; }
public virtual CCPoint GetOffset() { return CCPoint.Zero; }
/** Get center of this shape */
public virtual cpVect GetCenter() { return GetOffset(); }
public virtual CCPoint GetCenter() { return GetOffset(); }
/** Test point is in shape or not */
public bool ContainsPoint(cpVect point)
public bool ContainsPoint(CCPoint point)
{
foreach (var shape in _info.getShapes())
{
cpPointQueryInfo info = null;
shape.PointQuery(point, ref info);
shape.PointQuery(PhysicsHelper.CCPointToCpVect(point), ref info);
if (info != null)
{
return true;
@ -284,22 +284,24 @@ namespace CocosSharp
/** move the points to the center */
public static void RecenterPoints(cpVect[] points, int count, cpVect center)
public static void RecenterPoints(CCPoint[] points, int count, CCPoint center)
{
cp.RecenterPoly(count, points);
if (center != cpVect.Zero)
var cpPoints = PhysicsHelper.CCPointsTocpVects(points);
cp.RecenterPoly(count, cpPoints);
points = PhysicsHelper.cpVectsTpCCPoints(cpPoints);
if (center != CCPoint.Zero)
{
for (int i = 0; i < points.Length; ++i)
{
points[i] += center;
}
}
}
/** get center of the polyon points */
public static cpVect GetPolyonCenter(cpVect[] points, int count)
public static CCPoint GetPolyonCenter(CCPoint[] points, int count)
{
return cp.CentroidForPoly(count, points);
var cpPoints = PhysicsHelper.CCPointsTocpVects(points);
return PhysicsHelper.cpVectToCCPoint(cp.CentroidForPoly(count, PhysicsHelper.CCPointsTocpVects(points)));
}
/**
@ -340,11 +342,12 @@ namespace CocosSharp
}
}
public void SetSurfaceVelocity(cpVect surfaceVelocity)
public void SetSurfaceVelocity(CCPoint surfaceVelocity)
{
var vel = PhysicsHelper.CCPointToCpVect(surfaceVelocity);
foreach (cpShape shape in _info.getShapes())
{
shape.SetSurfaceVelocity(surfaceVelocity);
shape.SetSurfaceVelocity(vel);
}
}
@ -370,7 +373,7 @@ namespace CocosSharp
* @brief PhysicsShape is PhysicsBody's friend class, but all the subclasses isn't. so this method is use for subclasses to catch the bodyInfo from PhysicsBody.
*/
public CCPhysicsBodyInfo BodyInfo
internal CCPhysicsBodyInfo BodyInfo
{
get
{
@ -456,18 +459,18 @@ namespace CocosSharp
public class CCPhysicsShapeCircle : CCPhysicsShape
{
public CCPhysicsShapeCircle(float radius, cpVect offset)
public CCPhysicsShapeCircle(float radius, CCPoint offset)
: this(CCPhysicsMaterial.PHYSICSSHAPE_MATERIAL_DEFAULT, radius, offset)
{
}
public CCPhysicsShapeCircle(CCPhysicsMaterial material, float radius, cpVect offset)
public CCPhysicsShapeCircle(CCPhysicsMaterial material, float radius, CCPoint offset)
{
_type = PhysicsType.CIRCLE;
cpShape shape = new cpCircleShape(CCPhysicsShapeInfo.getSharedBody(), radius, offset);
cpShape shape = new cpCircleShape(CCPhysicsShapeInfo.getSharedBody(), radius, PhysicsHelper.CCPointToCpVect(offset));
_info.add(shape);
@ -487,10 +490,10 @@ namespace CocosSharp
return cp.AreaForCircle(0, radius);
}
public static float CalculateMoment(float mass, float radius, cpVect offset)
public static float CalculateMoment(float mass, float radius, CCPoint offset)
{
return mass == cp.Infinity ? cp.Infinity
: (cp.MomentForCircle(mass, 0, radius, offset));
: (cp.MomentForCircle(mass, 0, radius, PhysicsHelper.CCPointToCpVect(offset)));
}
@ -515,7 +518,7 @@ namespace CocosSharp
float factor = cp.cpfabs(_newScaleX / _scaleX);
cpCircleShape shape = (cpCircleShape)_info.getShapes().FirstOrDefault();//->getShapes().front();
cpVect v = GetOffset();// cpCircleShapeGetOffset();
cpVect v = PhysicsHelper.CCPointToCpVect(GetOffset());// cpCircleShapeGetOffset();
v = cpVect.cpvmult(v, factor);
shape.c = v;
@ -530,9 +533,9 @@ namespace CocosSharp
{
return (_info.getShapes().FirstOrDefault() as cpCircleShape).GetRadius();
}
public override cpVect GetOffset()
public override CCPoint GetOffset()
{
return (_info.getShapes().FirstOrDefault() as cpCircleShape).GetOffset();
return PhysicsHelper.cpVectToCCPoint((_info.getShapes().FirstOrDefault() as cpCircleShape).GetOffset());
}
#endregion
@ -613,11 +616,11 @@ namespace CocosSharp
}
public void Init(cpVect[] vecs, int count, CCPhysicsMaterial material, float radius)
public void Init(CCPoint[] vecs, int count, CCPhysicsMaterial material, float radius)
{
_type = PhysicsType.POLYGEN;
cpShape shape = new cpPolyShape(CCPhysicsShapeInfo.getSharedBody(), count, vecs, radius);
cpShape shape = new cpPolyShape(CCPhysicsShapeInfo.getSharedBody(), count, PhysicsHelper.CCPointsTocpVects(vecs), radius);
_info.add(shape);
@ -630,7 +633,7 @@ namespace CocosSharp
}
public CCPhysicsShapePolygon(cpVect[] vecs, int count, CCPhysicsMaterial material, float radius)
public CCPhysicsShapePolygon(CCPoint[] vecs, int count, CCPhysicsMaterial material, float radius)
{
Init(vecs, count, material, radius);
@ -638,10 +641,10 @@ namespace CocosSharp
#region PUBLIC METHODS
public static float CalculateMoment(float mass, cpVect[] vecs, int count, cpVect offset)
public static float CalculateMoment(float mass, CCPoint[] vecs, int count, CCPoint offset)
{
float moment = mass == cp.Infinity ? cp.Infinity
: cp.MomentForPoly(mass, count, vecs, offset, 0.0f);
: cp.MomentForPoly(mass, count, PhysicsHelper.CCPointsTocpVects(vecs), PhysicsHelper.CCPointToCpVect(offset), 0.0f);
return moment;
}
@ -653,15 +656,15 @@ namespace CocosSharp
: cp.MomentForPoly(_mass, shape.Count, shape.GetVertices(), cpVect.Zero, 0.0f);
}
public cpVect GetPoint(int i)
public CCPoint GetPoint(int i)
{
return ((cpPolyShape)_info.getShapes().FirstOrDefault()).GetVert(i);
return PhysicsHelper.cpVectToCCPoint(((cpPolyShape)_info.getShapes().FirstOrDefault()).GetVert(i));
}
public void GetPoints(out cpVect[] outPoints) //cpVect outPoints
public void GetPoints(out CCPoint[] outPoints) //cpVect outPoints
{
cpShape shape = _info.getShapes().FirstOrDefault();
outPoints = ((cpPolyShape)shape).GetVertices();
outPoints = PhysicsHelper.cpVectsTpCCPoints(((cpPolyShape)shape).GetVertices());
}
public int GetPointsCount()
@ -687,18 +690,18 @@ namespace CocosSharp
public class CCPhysicsShapeEdgeSegment : CCPhysicsShape
{
public CCPhysicsShapeEdgeSegment(cpVect a, cpVect b, float border = 1)
public CCPhysicsShapeEdgeSegment(CCPoint a, CCPoint b, float border = 1)
: this(a, b, CCPhysicsMaterial.PHYSICSSHAPE_MATERIAL_DEFAULT, border)
{
}
public CCPhysicsShapeEdgeSegment(cpVect a, cpVect b, CCPhysicsMaterial material, float border = 1)
public CCPhysicsShapeEdgeSegment(CCPoint a, CCPoint b, CCPhysicsMaterial material, float border = 1)
{
cpShape shape = new cpSegmentShape(CCPhysicsShapeInfo.getSharedBody(),
a,
b,
PhysicsHelper.CCPointToCpVect(a),
PhysicsHelper.CCPointToCpVect(b),
border);
_type = PhysicsType.EDGESEGMENT;
@ -714,13 +717,13 @@ namespace CocosSharp
#region PUBLIC METHODS
public cpVect GetPointA()
public CCPoint GetPointA()
{
return ((cpSegmentShape)(_info.getShapes().FirstOrDefault())).ta;
return PhysicsHelper.cpVectToCCPoint(((cpSegmentShape)(_info.getShapes().FirstOrDefault())).ta);
}
public cpVect GetPointB()
public CCPoint GetPointB()
{
return ((cpSegmentShape)(_info.getShapes().FirstOrDefault())).tb;
return PhysicsHelper.cpVectToCCPoint(((cpSegmentShape)(_info.getShapes().FirstOrDefault())).tb);
}
#endregion
@ -731,16 +734,16 @@ namespace CocosSharp
public class CCPhysicsShapeEdgeBox : CCPhysicsShape
{
public CCPhysicsShapeEdgeBox(CCSize size, CCPhysicsMaterial material, float border /* = 1 */, cpVect offset)
public CCPhysicsShapeEdgeBox(CCSize size, CCPhysicsMaterial material, CCPoint offset, float border = 1)
{
_type = PhysicsType.EDGEBOX;
List<cpVect> vec = new List<cpVect>() {
new cpVect(-size.Width/2+offset.x, -size.Height/2+offset.y),
new cpVect(+size.Width/2+offset.x, -size.Height/2+offset.y),
new cpVect(+size.Width/2+offset.x, +size.Height/2+offset.y),
new cpVect(-size.Width/2+offset.x, +size.Height/2+offset.y)
new cpVect(-size.Width/2+offset.X, -size.Height/2+offset.Y),
new cpVect(+size.Width/2+offset.X, -size.Height/2+offset.Y),
new cpVect(+size.Width/2+offset.X, +size.Height/2+offset.Y),
new cpVect(-size.Width/2+offset.X, +size.Height/2+offset.Y)
};
@ -760,19 +763,19 @@ namespace CocosSharp
}
#region PROTECTED PROPERTIES
protected cpVect _offset;
protected CCPoint _offset;
#endregion
#region PUBLIC PROPERTIES
public override cpVect GetOffset() { return _offset; }
public List<cpVect> GetPoints()
public override CCPoint GetOffset() { return _offset; }
public List<CCPoint> GetPoints()
{
List<cpVect> outPoints = new List<cpVect>();
List<CCPoint> outPoints = new List<CCPoint>();
// int i = 0;
foreach (var shape in _info.getShapes())
{
outPoints.Add(((cpSegmentShape)shape).a);
outPoints.Add(PhysicsHelper.cpVectToCCPoint(((cpSegmentShape)shape).a));
}
return outPoints;
}
@ -812,15 +815,16 @@ namespace CocosSharp
}
public CCPhysicsShapeEdgePolygon(cpVect[] vec, int count, CCPhysicsMaterial material, float border = 1)
public CCPhysicsShapeEdgePolygon(CCPoint[] vec, int count, CCPhysicsMaterial material, float border = 1)
{
_type = PhysicsType.EDGEPOLYGEN;
int i = 0;
var vecs = PhysicsHelper.CCPointsTocpVects(vec);
for (; i < count; ++i)
{
cpShape shape = new cpSegmentShape(CCPhysicsShapeInfo.getSharedBody(), vec[i], vec[(i + 1) % count],
cpShape shape = new cpSegmentShape(CCPhysicsShapeInfo.getSharedBody(), vecs[i], vecs[(i + 1) % count],
border);
if (shape == null)
@ -842,7 +846,7 @@ namespace CocosSharp
#region PUBLIC PROPERTIES
public override cpVect GetCenter()
public override CCPoint GetCenter()
{
var shapes = _info.getShapes();
int count = (int)shapes.Count;
@ -855,12 +859,12 @@ namespace CocosSharp
cpVect center = cp.CentroidForPoly(count, points);
return center;
return PhysicsHelper.cpVectToCCPoint(center);
}
public cpVect[] GetPoints()
public CCPoint[] GetPoints()
{
var shapes = _info.getShapes();
@ -871,7 +875,7 @@ namespace CocosSharp
outPoints[i] = new cpVect(((cpSegmentShape)shapes[i]).a);
}
return outPoints;
return PhysicsHelper.cpVectsTpCCPoints(outPoints);
}
public int GetPointsCount()
@ -887,15 +891,15 @@ namespace CocosSharp
public class CCPhysicsShapeEdgeChain : CCPhysicsShape
{
public CCPhysicsShapeEdgeChain(cpVect[] vec, int count, CCPhysicsMaterial material, float border = 1)
public CCPhysicsShapeEdgeChain(CCPoint[] vec, int count, CCPhysicsMaterial material, float border = 1)
{
_type = PhysicsType.EDGECHAIN;
var vecs = PhysicsHelper.CCPointsTocpVects(vec);
int i = 0;
for (; i < count; ++i)
{
cpShape shape = new cpSegmentShape(CCPhysicsShapeInfo.getSharedBody(), vec[i], vec[i + 1],
cpShape shape = new cpSegmentShape(CCPhysicsShapeInfo.getSharedBody(), vecs[i], vecs[i + 1],
border);
shape.SetElasticity(1.0f);
shape.SetFriction(1.0f);
@ -910,23 +914,23 @@ namespace CocosSharp
}
#region PROTECTED PROPERTIES
protected cpVect _center;
protected CCPoint center;
#endregion
#region PUBLIC PROPERTIES
public override cpVect GetCenter()
public override CCPoint GetCenter()
{
return _center;
return center;
}
public List<cpVect> GetPoints()
public List<CCPoint> GetPoints()
{
List<cpVect> outPoints = new List<cpVect>();
List<CCPoint> outPoints = new List<CCPoint>();
foreach (var shape in _info.getShapes())
outPoints.Add(((cpSegmentShape)shape).a);
outPoints.Add(PhysicsHelper.cpVectToCCPoint(((cpSegmentShape)shape).a));
outPoints.Add(((cpSegmentShape)_info.getShapes().LastOrDefault()).a);
outPoints.Add(PhysicsHelper.cpVectToCCPoint(((cpSegmentShape)_info.getShapes().LastOrDefault()).a));
return outPoints;
}

Просмотреть файл

@ -38,18 +38,18 @@ namespace CocosSharp
public CCPhysicsShape shape;
public cpVect start;
public cpVect end; //< in lua, it's name is "ended"
public cpVect contact;
public cpVect normal;
public CCPoint start;
public CCPoint end; //< in lua, it's name is "ended"
public CCPoint contact;
public CCPoint normal;
public float fraction;
public object data;
public CCPhysicsRayCastInfo(CCPhysicsShape shape,
cpVect start,
cpVect end,
cpVect contact,
cpVect normal,
CCPoint start,
CCPoint end,
CCPoint contact,
CCPoint normal,
float fraction,
object data)
{
@ -67,11 +67,11 @@ namespace CocosSharp
{
public CCPhysicsWorld world;
public Func<CCPhysicsWorld, CCPhysicsRayCastInfo, object, bool> func;
public cpVect p1;
public cpVect p2;
public CCPoint p1;
public CCPoint p2;
public object data;
public CCRayCastCallbackInfo(CCPhysicsWorld world, Func<CCPhysicsWorld, CCPhysicsRayCastInfo, object, bool> func, cpVect p1, cpVect p2, object data)
public CCRayCastCallbackInfo(CCPhysicsWorld world, Func<CCPhysicsWorld, CCPhysicsRayCastInfo, object, bool> func, CCPoint p1, CCPoint p2, object data)
{
this.world = world;
this.func = func;
@ -114,7 +114,7 @@ namespace CocosSharp
* @return true to continue, false to terminate
*/
public class CCPhysicsWorldCallback
internal class CCPhysicsWorldCallback
{
public static bool CollisionBeginCallbackFunc(cpArbiter arb, cpSpace space, CCPhysicsWorld world)
@ -155,7 +155,7 @@ namespace CocosSharp
}
public static void RayCastCallbackFunc(cpShape shape, float t, cpVect n, ref CCRayCastCallbackInfo info)
public static void RayCastCallbackFunc(cpShape shape, float t, CCPoint n, ref CCRayCastCallbackInfo info)
{
if (!continues)
{
@ -170,8 +170,8 @@ namespace CocosSharp
it.getShape(),
info.p1,
info.p2,
new cpVect(info.p1.x + (info.p2.x - info.p1.x) * t, info.p1.y + (info.p2.y - info.p1.y) * t),
new cpVect(n.x, n.y),
new CCPoint(info.p1.X + (info.p2.X - info.p1.X) * t, info.p1.Y + (info.p2.Y - info.p1.Y) * t),
new CCPoint(n.Y, n.Y),
t, null
);
@ -192,7 +192,7 @@ namespace CocosSharp
continues = info.func(info.world, it.getShape(), info.data);
}
public static void QueryPointFunc(cpShape shape, float distance, cpVect point, ref CCPointQueryCallbackInfo info)
public static void QueryPointFunc(cpShape shape, float distance, CCPoint point, ref CCPointQueryCallbackInfo info)
{
CCPhysicsShapeInfo it;
@ -200,7 +200,7 @@ namespace CocosSharp
continues = info.func(info.world, it.getShape(), info.data);
}
public static void GetShapesAtPointFunc(cpShape shape, float distance, cpVect point, ref List<CCPhysicsShape> arr)
public static void GetShapesAtPointFunc(cpShape shape, float distance, CCPoint point, ref List<CCPhysicsShape> arr)
{
CCPhysicsShapeInfo it;
@ -245,8 +245,8 @@ namespace CocosSharp
protected cpVect _gravity;
public CCPhysicsWorldInfo _info;
protected CCPoint _gravity;
internal CCPhysicsWorldInfo _info;
protected float _speed;
protected int _updateRate;
protected int _updateRateCount;
@ -271,7 +271,7 @@ namespace CocosSharp
public CCPhysicsWorld(CCScene scene)
{
_gravity = new cpVect(0.0f, -98.0f);
_gravity = new CCPoint(0.0f, -98.0f);
_speed = 1.0f;
_updateRate = 1;
_updateRateCount = 0;
@ -284,7 +284,7 @@ namespace CocosSharp
_scene = scene;
_info.SetGravity(_gravity);
_info.SetGravity(PhysicsHelper.CCPointToCpVect(_gravity));
var spc = _info.getSpace();
@ -508,7 +508,7 @@ namespace CocosSharp
/** Searches for physics shapes that intersects the ray. */
public void RayCast(Func<CCPhysicsWorld, CCPhysicsRayCastInfo, object, bool> func, cpVect point1, cpVect point2, object data)
public void RayCast(Func<CCPhysicsWorld, CCPhysicsRayCastInfo, object, bool> func, CCPoint point1, CCPoint point2, object data)
{
cp.AssertWarn(func != null, "func shouldn't be nullptr");
@ -519,10 +519,10 @@ namespace CocosSharp
CCPhysicsWorldCallback.continues = true;
this._info.getSpace().SegmentQuery(
point1,
point2, 1f,
PhysicsHelper.CCPointToCpVect(point1),
PhysicsHelper.CCPointToCpVect(point2), 1f,
new cpShapeFilter(cp.NO_GROUP, cp.ALL_LAYERS, cp.ALL_LAYERS),
(shape, v1, v2, f, o) => CCPhysicsWorldCallback.RayCastCallbackFunc(shape, f, v1, ref info), data
(shape, v1, v2, f, o) => CCPhysicsWorldCallback.RayCastCallbackFunc(shape, f, PhysicsHelper.cpVectToCCPoint(v1), ref info), data
);
}
}
@ -552,7 +552,7 @@ namespace CocosSharp
}
/** Searches for physics shapes that contains the point. */
public void QueryPoint(Func<CCPhysicsWorld, CCPhysicsShape, object, bool> func, cpVect point, object data)
public void QueryPoint(Func<CCPhysicsWorld, CCPhysicsShape, object, bool> func, CCPoint point, object data)
{
cp.AssertWarn(func != null, "func shouldn't be nullptr");
@ -565,7 +565,7 @@ namespace CocosSharp
CCPhysicsWorldCallback.continues = true;
this._info.getSpace().PointQuery(
point, 0f,
PhysicsHelper.CCPointToCpVect(point), 0f,
new cpShapeFilter(cp.NO_GROUP, cp.ALL_LAYERS, cp.ALL_LAYERS),
(s, v, f1, f2, o) => CCPhysicsWorldCallback.QueryPointFunc(s, 0f, point, ref info),
data
@ -574,13 +574,13 @@ namespace CocosSharp
}
/** Get phsyics shapes that contains the point. */
public List<CCPhysicsShape> GetShapes(cpVect point)
public List<CCPhysicsShape> GetShapes(CCPoint point)
{
List<CCPhysicsShape> arr = new List<CCPhysicsShape>();
this._info.getSpace().PointQuery(
point, 0, new cpShapeFilter(cp.NO_GROUP, cp.ALL_LAYERS, cp.ALL_LAYERS),
(s, v1, f, v2, o) => CCPhysicsWorldCallback.GetShapesAtPointFunc(s, f, v1, ref arr),
PhysicsHelper.CCPointToCpVect(point), 0, new cpShapeFilter(cp.NO_GROUP, cp.ALL_LAYERS, cp.ALL_LAYERS),
(s, v1, f, v2, o) => CCPhysicsWorldCallback.GetShapesAtPointFunc(s, f, PhysicsHelper.cpVectToCCPoint(v1), ref arr),
null
);
@ -588,13 +588,13 @@ namespace CocosSharp
}
/** return physics shape that contains the point. */
public CCPhysicsShape GetShape(cpVect point)
public CCPhysicsShape GetShape(CCPoint point)
{
cpShape shape = null;
this._info.getSpace().PointQuery(
point, 0, new cpShapeFilter(cp.NO_GROUP, cp.ALL_LAYERS, cp.ALL_LAYERS),
PhysicsHelper.CCPointToCpVect(point), 0, new cpShapeFilter(cp.NO_GROUP, cp.ALL_LAYERS, cp.ALL_LAYERS),
(s, v1, f, v2, o) => { shape = s; }, null);
if (shape == null)
@ -632,10 +632,10 @@ namespace CocosSharp
public CCScene GetScene() { return _scene; }
/** get the gravity value */
public cpVect GetGravity() { return _gravity; }
public CCPoint GetGravity() { return _gravity; }
/** set the gravity value */
public void SetGravity(cpVect gravity)
public void SetGravity(CCPoint gravity)
{
if (_bodies.Count > 0)
{
@ -644,7 +644,7 @@ namespace CocosSharp
// reset gravity for body
if (!body.IsGravityEnabled())
{
body.ApplyForce((_gravity - gravity) * body.GetMass());
body.ApplyForce(PhysicsHelper.CCPointToCpVect((_gravity - gravity)) * body.GetMass());
}
}
}
@ -1115,186 +1115,5 @@ namespace CocosSharp
}
}
//public class PhysicsDebugDraw
//{
// protected CCDrawNode _drawNode;
// protected CCPhysicsWorld _world;
// #region PROTECTED
// public PhysicsDebugDraw(CCPhysicsWorld world)
// {
// _drawNode = null;
// _world = world;
// _drawNode = new CCDrawNode();
// _world.GetScene().AddChild(_drawNode);
// }
// public virtual bool Begin()
// {
// _drawNode.Clear();
// return true;
// }
// public virtual void End()
// {
// }
// public virtual void DrawShape(CCPhysicsShape shape)
// {
// CCColor4F fillColor = new CCColor4F(1.0f, 0.0f, 0.0f, 0.3f);
// CCColor4F outlineColor = new CCColor4F(0f, 0.0f, 0.0f, 1.0f);
// foreach (cpShape subShape in shape._info.getShapes())
// switch (subShape.shapeType)
// {
// case cpShapeType.Circle:
// {
// cpCircleShape cir = (cpCircleShape)subShape;
// float radius = cir.GetRadius();
// cpVect centre = cir.body.GetPosition() + cir.GetOffset();
// int CIRCLE_SEG_NUM = 12;
// CCPoint[] seg = new CCPoint[CIRCLE_SEG_NUM];
// cpVect tmp;
// for (int i = 0; i < CIRCLE_SEG_NUM; ++i)
// {
// float angle = (float)i * CCMathHelper.Pi / (float)CIRCLE_SEG_NUM * 2.0f;
// cpVect d = new cpVect(radius * CCMathHelper.Cos(angle), radius * CCMathHelper.Sin(angle));
// tmp = centre + d;
// seg[i] = new CCPoint((float)tmp.x, (float)tmp.y);
// }
// _drawNode.DrawPolygon(seg, CIRCLE_SEG_NUM, fillColor, 1, outlineColor);
// break;
// }
// case cpShapeType.Segment:
// {
// cpSegmentShape seg = (cpSegmentShape)subShape;
// _drawNode.DrawSegment(new CCPoint(seg.ta.x, seg.ta.y),
// new CCPoint(seg.tb.x, seg.tb.y),
// seg.r == 0 ? 1 : seg.r, outlineColor);
// break;
// }
// case cpShapeType.Polygon:
// {
// cpPolyShape poly = (cpPolyShape)subShape;
// int num = poly.Count;
// //Vec2* seg = new Vec2[num];
// CCPoint[] tmp = new CCPoint[num];
// for (int i = 0; i < poly.tVerts.Length; i += 2)
// tmp[i] = new CCPoint(poly.tVerts[i], poly.tVerts[i + 1]);
// _drawNode.DrawPolygon(tmp, num, fillColor, 1.0f, outlineColor);
// break;
// }
// default:
// break;
// }
// }
// public virtual void DrawJoint(CCPhysicsJoint joint)
// {
// CCColor4F lineColor = new CCColor4F(0.0f, 0.0f, 1.0f, 1.0f);
// CCColor4F jointPointColor = new CCColor4F(0.0f, 1.0f, 0.0f, 1.0f);
// foreach (var it in joint._info.getJoints())
// {
// cpConstraint constraint = it;
// cpBody body_a = constraint.a;
// cpBody body_b = constraint.b;
// Type klass = constraint.GetType();
// if (klass == typeof(cpPinJoint))
// {
// cpPinJoint subJoint = (cpPinJoint)constraint;
// var a = cpVect.cpvadd(body_a.GetPosition(), cpVect.cpvrotate(subJoint.anchr1, body_a.Rotation)).ToCCPoint();
// var b = cpVect.cpvadd(body_b.GetPosition(), cpVect.cpvrotate(subJoint.anchr2, body_b.Rotation)).ToCCPoint();
// _drawNode.DrawSegment(a, b, 1, lineColor);
// _drawNode.DrawDot((a), 2, jointPointColor);
// _drawNode.DrawDot((b), 2, jointPointColor);
// }
// else if (klass == typeof(cpSlideJoint))
// {
// cpSlideJoint subJoint = (cpSlideJoint)constraint;
// var a = cpVect.cpvadd(body_a.GetPosition(), cpVect.cpvrotate(subJoint.anchorA, body_a.GetRotation())).ToCCPoint();
// var b = cpVect.cpvadd(body_b.GetPosition(), cpVect.cpvrotate(subJoint.anchorB, body_b.GetRotation())).ToCCPoint();
// _drawNode.DrawSegment(a, b, 1, lineColor);
// _drawNode.DrawDot(a, 2, jointPointColor);
// _drawNode.DrawDot(b, 2, jointPointColor);
// }
// else if (klass == typeof(cpPivotJoint))
// {
// cpPivotJoint subJoint = (cpPivotJoint)constraint;
// var a = cpVect.cpvadd(body_a.GetPosition(), cpVect.cpvrotate(subJoint.anchorA, body_a.GetRotation())).ToCCPoint();
// var b = cpVect.cpvadd(body_b.GetPosition(), cpVect.cpvrotate(subJoint.anchorB, body_b.GetRotation())).ToCCPoint();
// _drawNode.DrawDot(a, 2, jointPointColor);
// _drawNode.DrawDot(b, 2, jointPointColor);
// }
// else if (klass == typeof(cpGrooveJoint))
// {
// cpGrooveJoint subJoint = (cpGrooveJoint)constraint;
// var a = cpVect.cpvadd(body_a.GetPosition(), cpVect.cpvrotate(subJoint.grv_a, body_a.GetRotation())).ToCCPoint();
// var b = cpVect.cpvadd(body_a.GetPosition(), cpVect.cpvrotate(subJoint.grv_b, body_a.GetRotation())).ToCCPoint();
// var c = cpVect.cpvadd(body_b.GetPosition(), cpVect.cpvrotate(subJoint.anchorB, body_b.GetRotation())).ToCCPoint();
// _drawNode.DrawSegment((a), (b), 1, lineColor);
// _drawNode.DrawDot((c), 2, jointPointColor);
// }
// else if (klass == typeof(cpDampedSpring))
// {
// cpDampedSpring subJoint = (cpDampedSpring)constraint;
// var a = cpVect.cpvadd(body_a.GetPosition(), cpVect.cpvrotate(subJoint.GetAnchorA(), body_a.GetRotation())).ToCCPoint();
// var b = cpVect.cpvadd(body_b.GetPosition(), cpVect.cpvrotate(subJoint.GetAnchorB(), body_b.GetRotation())).ToCCPoint();
// _drawNode.DrawSegment(a, b, 1, lineColor);
// _drawNode.DrawDot(a, 2, jointPointColor);
// _drawNode.DrawDot(b, 2, jointPointColor);
// }
// }
// }
// #endregion
// ~PhysicsDebugDraw()
// {
// _drawNode.RemoveFromParent();
// _drawNode = null;
// }
//};
}
#endif

Просмотреть файл

@ -31,7 +31,7 @@ using System.Text;
namespace CocosSharp
{
public class CCPhysicsBodyInfo
internal class CCPhysicsBodyInfo
{
private cpBody _body;

Просмотреть файл

@ -30,7 +30,7 @@ using System.Text;
namespace CocosSharp
{
public class CCPhysicsContactInfo
internal class CCPhysicsContactInfo
{
private CCPhysicsContact _contact;

Просмотреть файл

@ -32,7 +32,7 @@ using System.Text;
namespace CocosSharp
{
public class CCPhysicsJointInfo
internal class CCPhysicsJointInfo
{
protected List<cpConstraint> _joints;

Просмотреть файл

@ -31,7 +31,7 @@ using System.Text;
namespace CocosSharp
{
public class CCPhysicsShapeInfo
internal class CCPhysicsShapeInfo
{
protected static Dictionary<cpShape, CCPhysicsShapeInfo> _map;

Просмотреть файл

@ -33,7 +33,7 @@ using System.Text;
namespace CocosSharp
{
public class CCPhysicsWorldInfo
internal class CCPhysicsWorldInfo
{
private cpSpace _space;

Просмотреть файл

@ -31,7 +31,7 @@ using System.Text;
namespace CocosSharp
{
public class PhysicsHelper
internal class PhysicsHelper
{
//TODO: This conversion methods don't be necesary, Cocosharp works with cpVect
@ -46,6 +46,49 @@ namespace CocosSharp
public static cpBB rect2cpbb(CCRect rect) { return new cpBB(rect.Origin.X, rect.Origin.Y, rect.Origin.X + rect.Size.Width, rect.Origin.Y + rect.Size.Height); }
public static CCRect cpbb2rect(cpBB bb) { return new CCRect((float)bb.l, (float)bb.b, (float)(bb.r - bb.l), (float)(bb.t - bb.b)); }
internal static cpVect CCPointToCpVect(CCPoint vec)
{
return new cpVect(vec.X, vec.Y);
}
internal static CCPoint cpVectToCCPoint(cpVect vec)
{
return new CCPoint((float)vec.x, (float)vec.y);
}
internal static cpVect[] CCPointsTocpVects (CCPoint[] points)
{
var len = points.Length;
cpVect[] pointscp = new cpVect[len];
var wrkPoint = CCPoint.Zero;
for (int i = 0; i< len; i++)
{
wrkPoint = points[i];
pointscp[i] = new cpVect(wrkPoint.X, wrkPoint.Y);
}
return pointscp;
}
internal static CCPoint[] cpVectsTpCCPoints (cpVect[] points)
{
var len = points.Length;
var pointscp = new CCPoint[len];
var wrkPoint = cpVect.Zero;
for (int i = 0; i< len; i++)
{
wrkPoint = points[i];
pointscp[i] = new CCPoint(wrkPoint.x, wrkPoint.y);
}
return pointscp;
}
//public static List<cpVect> cpvs2points(List<cpVect> cpvs, List<cpVect> output, int count)
//{
// for (int i = 0; i < count; ++i)

Просмотреть файл

@ -7,7 +7,7 @@ using Microsoft.Xna.Framework;
namespace ChipmunkSharp
{
public static class cpExtension
internal static class cpExtension
{
public static cpVect ToCpVect(this CCPoint vec)
@ -21,9 +21,7 @@ namespace ChipmunkSharp
{
return new CCPoint((float)vec.x, (float)vec.y);
}
public static CCColor4F ToCCColor4F(this cpColor color)
{
return new CCColor4F(color.r / 255, color.g / 255, color.b / 255, color.a / 255);