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
56ac0d9c
Commit
56ac0d9c
authored
Oct 08, 2015
by
Viktor Lidholt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adds support for keeping track of contact points in physics
parent
a8ea45f9
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
76 additions
and
6 deletions
+76
-6
physics_node.dart
packages/flutter_sprites/lib/physics_node.dart
+76
-6
No files found.
packages/flutter_sprites/lib/physics_node.dart
View file @
56ac0d9c
...
...
@@ -183,7 +183,57 @@ class PhysicsNode extends Node {
}
}
}
canvas
.
restore
();
// Draw contacts
for
(
box2d
.
ContactEdge
edge
=
body
.
getContactList
();
edge
!=
null
;
edge
=
edge
.
next
)
{
box2d
.
Contact
contact
=
edge
.
contact
;
Vector2
cA
=
new
Vector2
.
zero
();
Vector2
cB
=
new
Vector2
.
zero
();
box2d
.
Fixture
fixtureA
=
contact
.
fixtureA
;
box2d
.
Fixture
fixtureB
=
contact
.
fixtureB
;
fixtureA
.
getAABB
(
contact
.
getChildIndexA
()).
getCenterToOut
(
cA
);
fixtureB
.
getAABB
(
contact
.
getChildIndexB
()).
getCenterToOut
(
cB
);
Point
p1
=
new
Point
(
cA
.
x
*
b2WorldToNodeConversionFactor
,
cA
.
y
*
b2WorldToNodeConversionFactor
);
Point
p2
=
new
Point
(
cB
.
x
*
b2WorldToNodeConversionFactor
,
cB
.
y
*
b2WorldToNodeConversionFactor
);
shapePaint
.
color
=
new
Color
(
0x33ffffff
);
canvas
.
drawLine
(
p1
,
p2
,
shapePaint
);
box2d
.
WorldManifold
worldManifold
=
new
box2d
.
WorldManifold
();
contact
.
getWorldManifold
(
worldManifold
);
shapePaint
.
color
=
new
Color
(
0xffffffff
);
for
(
Vector2
pt
in
worldManifold
.
points
)
{
Point
pCenter
=
new
Point
(
pt
.
x
*
b2WorldToNodeConversionFactor
,
pt
.
y
*
b2WorldToNodeConversionFactor
);
Offset
offset
=
new
Offset
(
worldManifold
.
normal
.
x
*
5.0
,
worldManifold
.
normal
.
y
*
5.0
);
Point
p2
=
pCenter
+
offset
;
Point
p1
=
new
Point
(
pCenter
.
x
-
offset
.
dx
,
pCenter
.
y
-
offset
.
dy
);
canvas
.
drawLine
(
p1
,
p2
,
shapePaint
);
canvas
.
drawCircle
(
pCenter
,
5.0
,
shapePaint
);
}
}
}
}
}
...
...
@@ -195,7 +245,9 @@ class PhysicsContact {
this
.
shapeA
,
this
.
shapeB
,
this
.
isTouching
,
this
.
isEnabled
this
.
isEnabled
,
this
.
touchingPoints
,
this
.
touchingNormal
);
final
Node
nodeA
;
...
...
@@ -204,6 +256,8 @@ class PhysicsContact {
final
PhysicsShape
shapeB
;
final
isTouching
;
bool
isEnabled
;
final
List
<
Point
>
touchingPoints
;
final
Offset
touchingNormal
;
}
class
_ContactCallbackInfo
{
...
...
@@ -264,19 +318,35 @@ class _ContactHandler extends box2d.ContactListener {
if
(
match
)
{
// We have contact and a matched callback, setup contact info
List
<
Point
>
touchingPoints
=
null
;
Offset
touchingNormal
=
null
;
// Fetch touching points, if any
if
(
b2Contact
.
isTouching
())
{
box2d
.
WorldManifold
manifold
=
new
box2d
.
WorldManifold
();
b2Contact
.
getWorldManifold
(
manifold
);
touchingNormal
=
new
Offset
(
manifold
.
normal
.
x
,
manifold
.
normal
.
y
);
touchingPoints
=
[];
for
(
Vector2
vec
in
manifold
.
points
)
{
touchingPoints
.
add
(
new
Point
(
vec
.
x
*
physicsNode
.
b2WorldToNodeConversionFactor
,
vec
.
y
*
physicsNode
.
b2WorldToNodeConversionFactor
));
}
}
// Create the contact
PhysicsContact
contact
=
new
PhysicsContact
(
bodyA
.
_node
,
bodyB
.
_node
,
fixtureA
.
userData
,
fixtureB
.
userData
,
b2Contact
.
isTouching
(),
b2Contact
.
isEnabled
()
b2Contact
.
isEnabled
(),
touchingPoints
,
touchingNormal
);
if
(
type
==
PhysicsContactType
.
postSolve
)
{
}
// Make callback
info
.
callback
(
type
,
contact
);
...
...
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