Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
106d3c4b
Commit
106d3c4b
authored
Oct 13, 2015
by
Viktor Lidholt
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1588 from vlidholt/master
Adds check for breaking forces in sprite physics joints
parents
adb0d2e2
6488a133
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
45 additions
and
9 deletions
+45
-9
physics_joint.dart
packages/flutter_sprites/lib/physics_joint.dart
+38
-9
physics_node.dart
packages/flutter_sprites/lib/physics_node.dart
+7
-0
No files found.
packages/flutter_sprites/lib/physics_joint.dart
View file @
106d3c4b
part of
skysprites
;
abstract
class
PhysicsJoint
{
PhysicsJoint
(
this
.
bodyA
,
this
.
bodyB
)
{
PhysicsJoint
(
this
.
bodyA
,
this
.
bodyB
,
this
.
breakingForce
)
{
bodyA
.
_joints
.
add
(
this
);
bodyB
.
_joints
.
add
(
this
);
}
final
PhysicsBody
bodyA
;
final
PhysicsBody
bodyB
;
final
double
breakingForce
;
bool
_active
=
true
;
box2d
.
Joint
_joint
;
...
...
@@ -24,6 +25,7 @@ abstract class PhysicsJoint {
if
(
_joint
==
null
)
{
_physicsNode
=
physicsNode
;
_joint
=
_createB2Joint
(
physicsNode
);
_physicsNode
.
_joints
.
add
(
this
);
}
}
...
...
@@ -31,11 +33,31 @@ abstract class PhysicsJoint {
if
(
_joint
!=
null
&&
_active
)
{
_physicsNode
.
b2World
.
destroyJoint
(
_joint
);
_joint
=
null
;
_physicsNode
.
_joints
.
remove
(
this
);
}
_active
=
false
;
}
box2d
.
Joint
_createB2Joint
(
PhysicsNode
physicsNode
);
void
destroy
()
{
_detach
();
}
void
_checkBreakingForce
(
double
dt
)
{
if
(
breakingForce
==
null
)
return
;
if
(
_joint
!=
null
&&
_active
)
{
Vector2
reactionForce
=
new
Vector2
.
zero
();
_joint
.
getReactionForce
(
1.0
/
dt
,
reactionForce
);
if
(
breakingForce
*
breakingForce
<
reactionForce
.
length2
)
{
// TODO: Add callback
destroy
();
}
}
}
}
class
PhysicsJointRevolute
extends
PhysicsJoint
{
...
...
@@ -45,8 +67,9 @@ class PhysicsJointRevolute extends PhysicsJoint {
this
.
worldAnchor
,
{
this
.
lowerAngle
:
0.0
,
this
.
upperAngle
:
0.0
,
this
.
enableLimit
:
false
})
:
super
(
bodyA
,
bodyB
)
{
this
.
enableLimit
:
false
,
double
breakingForce
})
:
super
(
bodyA
,
bodyB
,
breakingForce
)
{
_completeCreation
();
}
...
...
@@ -77,8 +100,10 @@ class PhysicsJointPrismatic extends PhysicsJoint {
PhysicsJointPrismatic
(
PhysicsBody
bodyA
,
PhysicsBody
bodyB
,
this
.
axis
)
:
super
(
bodyA
,
bodyB
)
{
this
.
axis
,
{
double
breakingForce
}
)
:
super
(
bodyA
,
bodyB
,
breakingForce
)
{
_completeCreation
();
}
...
...
@@ -94,8 +119,10 @@ class PhysicsJointPrismatic extends PhysicsJoint {
class
PhysicsJointWeld
extends
PhysicsJoint
{
PhysicsJointWeld
(
PhysicsBody
bodyA
,
PhysicsBody
bodyB
)
:
super
(
bodyA
,
bodyB
)
{
PhysicsBody
bodyB
,
{
double
breakingForce
}
)
:
super
(
bodyA
,
bodyB
,
breakingForce
)
{
_completeCreation
();
}
...
...
@@ -118,8 +145,10 @@ class PhysicsJointPulley extends PhysicsJoint {
this
.
groundAnchorB
,
this
.
anchorA
,
this
.
anchorB
,
this
.
ratio
)
:
super
(
bodyA
,
bodyB
)
{
this
.
ratio
,
{
double
breakingForce
}
)
:
super
(
bodyA
,
bodyB
,
breakingForce
)
{
_completeCreation
();
}
...
...
packages/flutter_sprites/lib/physics_node.dart
View file @
106d3c4b
...
...
@@ -31,6 +31,8 @@ class PhysicsNode extends Node {
_ContactHandler
_contactHandler
;
List
<
PhysicsJoint
>
_joints
=
[];
List
<
box2d
.
Body
>
_bodiesScheduledForDestruction
=
[];
double
b2WorldToNodeConversionFactor
=
10.0
;
...
...
@@ -77,6 +79,11 @@ class PhysicsNode extends Node {
body
.
_node
.
_setRotationFromPhysics
(
degrees
(
b2Body
.
getAngle
()));
}
// Break joints
for
(
PhysicsJoint
joint
in
_joints
)
{
joint
.
_checkBreakingForce
(
dt
);
}
// Remove bodies that were marked for destruction during the simulation
_removeBodiesScheduledForDestruction
();
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment