Skip to content

Commit

Permalink
First version of Physics which works :)
Browse files Browse the repository at this point in the history
(more or less...)
  • Loading branch information
Hiale.dev authored and Hiale.dev committed Aug 3, 2013
1 parent 1d66267 commit cb0daaa
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 41 deletions.
24 changes: 16 additions & 8 deletions GTA2.NET/GTA2.NET/GTA2.NET Core/Logic/Car.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,25 +86,32 @@ public override Vector2 CollisionBottomRight
}


private Vector2 GetSpriteVector(int index)
{
Transform transform;
_body.GetTransform(out transform);
var vector = MathUtils.Multiply(ref transform, _spriteShape.Vertices[index]);
return vector.ToBlockUnits();
}

public override Vector2 SpriteTopLeft
{
get { return _spriteShape.Vertices[0].ToBlockUnits(); }
get { return GetSpriteVector(0); }
}

public override Vector2 SpriteTopRight
{
get { return _spriteShape.Vertices[1].ToBlockUnits(); }
get { return GetSpriteVector(1); }
}

public override Vector2 SpriteBottomLeft
{
get { return _spriteShape.Vertices[3].ToBlockUnits(); }
get { return GetSpriteVector(3); }
}

public override Vector2 SpriteBottomRight
{
get { return _spriteShape.Vertices[2].ToBlockUnits(); }
get { return GetSpriteVector(2); }
}

public override float SpriteWidth
Expand All @@ -117,6 +124,11 @@ public override float SpriteHeight
get { return _spriteHeight; }
}

public new float RotationAngle
{
get { return _body.Rotation; }
}

public override void SetDimensions(float width, float height)
{
_spriteWidth = width;
Expand Down Expand Up @@ -165,10 +177,6 @@ public override void CreateBody(World world, float width, float height)
var spriteFixture = _body.CreateFixture(_spriteShape);
spriteFixture.IsSensor = true;

//Joint
//JointFactory.CreateRevoluteJoint(_b)


float maxForwardSpeed = 300;
float maxBackwardSpeed = -40;
float backWheelMaxDriveForce = 950;
Expand Down
6 changes: 3 additions & 3 deletions GTA2.NET/GTA2.NET/GTA2.NET Core/Logic/GameplayObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ public abstract class GameplayObject
/// <summary>
/// Current position of this object. It represents the center of the object.
/// </summary>
public virtual Vector3 Position3 { get; protected set; }
public Vector3 Position3 { get; protected set; }

/// <summary>
/// 2D position of the object.
/// </summary>
public virtual Vector2 Position2
public Vector2 Position2
{
get
{
Expand All @@ -53,7 +53,7 @@ public virtual Vector2 Position2
/// <summary>
/// Current rotation angle in radians.
/// </summary>
public virtual float RotationAngle
public float RotationAngle
{
get { return _rotationAngle; }
set
Expand Down
8 changes: 6 additions & 2 deletions GTA2.NET/GTA2.NET/GTA2.NET/MainGame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -270,12 +270,16 @@ private void UpdateObjects(float elapsedGameTime)
var input = new ParticipantInput();
for (var i = 0; i < Cars.Count; i++)
{
if (Cars[i] == ChasingObject)
continue;
Cars[i].Update(input, elapsedGameTime);
}

//Update all pedestrians
for (var i = 0; i < Pedestrians.Count; i++)
{
if (Pedestrians[i] == ChasingObject)
continue;
Pedestrians[i].Update(input, elapsedGameTime);
}
}
Expand All @@ -298,12 +302,12 @@ private void HandleInput(ref PlayerInput playerInput)
if (Input.KeyboardLeftPressed)
{
//_playerRotationDelta = -RotationScalar * _elapsedGameTime;
playerInput.Rotation = -1;
playerInput.Rotation = 1;
}
if (Input.KeyboardRightPressed)
{
//_playerRotationDelta = RotationScalar * _elapsedGameTime;
playerInput.Rotation = 1;
playerInput.Rotation = -1;
}

//float a = 0;
Expand Down
32 changes: 4 additions & 28 deletions GTA2.NET/GTA2.NET/GTA2.NET/Sprite.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,34 +130,10 @@ private void SetNeutralPosition(Vector3 position)

public void SetPosition(ISprite baseObject)
{
Vector3 center = baseObject.Position3;
float rotation = baseObject.RotationAngle;

TopLeft = TranslatePosition(new Vector3(center.X + baseObject.SpriteTopLeft.X, center.Y + baseObject.SpriteTopLeft.Y, baseObject.Position3.Z));
TopRight = TranslatePosition(new Vector3(center.X + baseObject.SpriteTopRight.X, center.Y + baseObject.SpriteTopRight.Y, baseObject.Position3.Z));
BottomRight = TranslatePosition(new Vector3(center.X + baseObject.SpriteBottomRight.X, center.Y + baseObject.SpriteBottomRight.Y, baseObject.Position3.Z));
BottomLeft = TranslatePosition(new Vector3(center.X + baseObject.SpriteBottomLeft.X, center.Y + baseObject.SpriteBottomLeft.Y, baseObject.Position3.Z));


//Vector3 currentPoint = new Vector3(center.X - _widthHalf, center.Y - _heightHalf, center.Z);
//currentPoint = MainGame.RotatePoint3(currentPoint, center, rotation);
//TranslatePosition(ref currentPoint);
////TopLeft = currentPoint;

//currentPoint = new Vector3(center.X + _widthHalf, center.Y - _heightHalf, center.Z);
//currentPoint = MainGame.RotatePoint3(currentPoint, center, rotation);
//TranslatePosition(ref currentPoint);
////TopRight = currentPoint;

//currentPoint = new Vector3(center.X + _widthHalf, center.Y + _heightHalf, center.Z);
//currentPoint = MainGame.RotatePoint3(currentPoint, center, rotation);
//TranslatePosition(ref currentPoint);
////BottomRight = currentPoint;

//currentPoint = new Vector3(center.X - _widthHalf, center.Y + _heightHalf, center.Z);
//currentPoint = MainGame.RotatePoint3(currentPoint, center, rotation);
//TranslatePosition(ref currentPoint);
////BottomLeft = currentPoint;
TopLeft = TranslatePosition(new Vector3(baseObject.SpriteTopLeft.X, baseObject.SpriteTopLeft.Y, baseObject.Position3.Z));
TopRight = TranslatePosition(new Vector3(baseObject.SpriteTopRight.X, baseObject.SpriteTopRight.Y, baseObject.Position3.Z));
BottomRight = TranslatePosition(new Vector3(baseObject.SpriteBottomRight.X, baseObject.SpriteBottomRight.Y, baseObject.Position3.Z));
BottomLeft = TranslatePosition(new Vector3(baseObject.SpriteBottomLeft.X, baseObject.SpriteBottomLeft.Y, baseObject.Position3.Z));
}


Expand Down

0 comments on commit cb0daaa

Please sign in to comment.