4 using Microsoft.Xna.Framework;
5 using Microsoft.Xna.Framework.Graphics;
10 partial class PhysicsBody
12 private float bodyShapeTextureScale;
14 private Texture2D bodyShapeTexture;
17 get {
return bodyShapeTexture; }
24 deformSprite?.
Draw(cam,
28 scale, color,
Dir < 0, invert);
31 public void Draw(SpriteBatch spriteBatch,
Sprite sprite, Color color,
float? depth =
null,
float scale = 1.0f,
bool mirrorX =
false,
bool mirrorY =
false, Vector2? origin =
null)
35 if (sprite ==
null) {
return; }
36 SpriteEffects spriteEffect = (
Dir == 1.0f) ? SpriteEffects.None : SpriteEffects.FlipHorizontally;
39 spriteEffect = spriteEffect == SpriteEffects.None ? SpriteEffects.FlipHorizontally : SpriteEffects.None;
43 spriteEffect |= SpriteEffects.FlipVertically;
48 public void DebugDraw(SpriteBatch spriteBatch, Color color,
bool forceColor =
false)
64 Vector2 pos = ConvertUnits.ToDisplayUnits((Vector2)
targetPosition);
67 GUI.DrawRectangle(spriteBatch,
68 new Vector2(pos.X - 5, -(pos.Y + 5)),
69 Vector2.One * 10.0f, GUIStyle.Red,
false, 0, 3);
72 if (drawOffset != Vector2.Zero)
74 Vector2 pos = ConvertUnits.ToDisplayUnits(
FarseerBody.Position);
77 GUI.DrawLine(spriteBatch,
78 new Vector2(pos.X, -pos.Y),
88 float maxSize = Math.Max(ConvertUnits.ToDisplayUnits(
Width), ConvertUnits.ToDisplayUnits(
Height));
91 bodyShapeTextureScale = 128.0f / maxSize;
95 bodyShapeTextureScale = 1.0f;
98 bodyShapeTexture = GUI.CreateRectangle(
99 (
int)ConvertUnits.ToDisplayUnits(
Width * bodyShapeTextureScale),
100 (
int)ConvertUnits.ToDisplayUnits(
Height * bodyShapeTextureScale));
104 case Shape.HorizontalCapsule:
106 float maxSize = Math.Max(ConvertUnits.ToDisplayUnits(
Radius), ConvertUnits.ToDisplayUnits(Math.Max(
Height,
Width)));
107 if (maxSize > 128.0f)
109 bodyShapeTextureScale = 128.0f / maxSize;
113 bodyShapeTextureScale = 1.0f;
116 bodyShapeTexture = GUI.CreateCapsule(
117 (
int)ConvertUnits.ToDisplayUnits(
Radius * bodyShapeTextureScale),
118 (
int)ConvertUnits.ToDisplayUnits(Math.Max(
Height,
Width) * bodyShapeTextureScale));
122 if (ConvertUnits.ToDisplayUnits(
Radius) > 128.0f)
124 bodyShapeTextureScale = 128.0f / ConvertUnits.ToDisplayUnits(
Radius);
128 bodyShapeTextureScale = 1.0f;
130 bodyShapeTexture = GUI.CreateCircle((
int)ConvertUnits.ToDisplayUnits(
Radius * bodyShapeTextureScale));
133 throw new NotImplementedException();
138 if (bodyShape ==
Shape.HorizontalCapsule)
140 rot -= MathHelper.PiOver2;
143 if (bodyShapeTexture !=
null)
151 new Vector2(bodyShapeTexture.Width / 2, bodyShapeTexture.Height / 2),
152 1.0f / bodyShapeTextureScale, SpriteEffects.None, 0.0f);
158 float MaxVel = NetConfig.MaxPhysicsBodyVelocity;
159 float MaxAngularVel = NetConfig.MaxPhysicsBodyAngularVelocity;
162 float? newRotation =
null;
165 float? newAngularVelocity =
null;
167 newPosition =
new Vector2(
180 newVelocity =
new Vector2(
183 newVelocity = NetConfig.Quantize(newVelocity, -MaxVel, MaxVel, 12);
187 newAngularVelocity = msg.
ReadRangedSingle(-MaxAngularVel, MaxAngularVel, 8);
188 newAngularVelocity = NetConfig.Quantize(newAngularVelocity.Value, -MaxAngularVel, MaxAngularVel, 8);
193 if (!MathUtils.IsValid(newPosition) ||
194 !MathUtils.IsValid(newVelocity) ||
195 (newRotation.HasValue && !MathUtils.IsValid(newRotation.Value)) ||
196 (newAngularVelocity.HasValue && !MathUtils.IsValid(newAngularVelocity.Value)))
198 string errorMsg =
"Received invalid position data for \"" + parentDebugName
199 +
"\" (position: " + newPosition +
", rotation: " + (newRotation ?? 0) +
", velocity: " + newVelocity +
", angular velocity: " + (newAngularVelocity ?? 0) +
")";
201 DebugConsole.ThrowError(errorMsg);
203 GameAnalyticsManager.AddErrorEventOnce(
"PhysicsBody.ClientRead:InvalidData" + parentDebugName,
204 GameAnalyticsManager.ErrorSeverity.Error,
209 return lastProcessedNetworkState > sendingTime ?
211 new PosInfo(newPosition, newRotation, newVelocity, newAngularVelocity, sendingTime);
214 partial
void DisposeProjSpecific()
216 if (bodyShapeTexture !=
null)
218 bodyShapeTexture.Dispose();
219 bodyShapeTexture =
null;
PosInfo ClientRead(IReadMessage msg, float sendingTime, string parentDebugName)
Texture2D BodyShapeTexture
static bool IsValidShape(float radius, float height, float width)
void DebugDraw(SpriteBatch spriteBatch, Color color, bool forceColor=false)
void Draw(DeformableSprite deformSprite, Camera cam, Vector2 scale, Color color, bool invert=false)
void UpdateDrawPosition(bool interpolate=true)
void Draw(SpriteBatch spriteBatch, Sprite sprite, Color color, float? depth=null, float scale=1.0f, bool mirrorX=false, bool mirrorY=false, Vector2? origin=null)
void Draw(ISpriteBatch spriteBatch, Vector2 pos, float rotate=0.0f, float scale=1.0f, SpriteEffects spriteEffect=SpriteEffects.None)
Single ReadRangedSingle(Single min, Single max, int bitCount)