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
c363133d
Commit
c363133d
authored
Oct 07, 2015
by
Viktor Lidholt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adds support for applying forces and impulses to sprite physics
parent
ebaa45c7
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
52 additions
and
0 deletions
+52
-0
physics_body.dart
packages/flutter_sprites/lib/physics_body.dart
+52
-0
No files found.
packages/flutter_sprites/lib/physics_body.dart
View file @
c363133d
...
...
@@ -232,6 +232,58 @@ class PhysicsBody {
bool
_attached
=
false
;
void
applyForce
(
Offset
force
,
Point
worldPoint
)
{
assert
(
_body
!=
null
);
Vector2
b2Force
=
new
Vector2
(
force
.
dx
/
_physicsNode
.
b2WorldToNodeConversionFactor
,
force
.
dy
/
_physicsNode
.
b2WorldToNodeConversionFactor
);
Vector2
b2Point
=
new
Vector2
(
worldPoint
.
x
/
_physicsNode
.
b2WorldToNodeConversionFactor
,
worldPoint
.
y
/
_physicsNode
.
b2WorldToNodeConversionFactor
);
_body
.
applyForce
(
b2Force
,
b2Point
);
}
void
applyForceToCenter
(
Offset
force
)
{
assert
(
_body
!=
null
);
Vector2
b2Force
=
new
Vector2
(
force
.
dx
/
_physicsNode
.
b2WorldToNodeConversionFactor
,
force
.
dy
/
_physicsNode
.
b2WorldToNodeConversionFactor
);
_body
.
applyForceToCenter
(
b2Force
);
}
void
applyTorque
(
double
torque
)
{
assert
(
_body
!=
null
);
_body
.
applyTorque
(
torque
/
_physicsNode
.
b2WorldToNodeConversionFactor
);
}
void
applyLinearImpulse
(
Offset
impulse
,
Point
worldPoint
,
[
bool
wake
=
true
])
{
assert
(
_body
!=
null
);
Vector2
b2Impulse
=
new
Vector2
(
impulse
.
dx
/
_physicsNode
.
b2WorldToNodeConversionFactor
,
impulse
.
dy
/
_physicsNode
.
b2WorldToNodeConversionFactor
);
Vector2
b2Point
=
new
Vector2
(
worldPoint
.
x
/
_physicsNode
.
b2WorldToNodeConversionFactor
,
worldPoint
.
y
/
_physicsNode
.
b2WorldToNodeConversionFactor
);
_body
.
applyLinearImpulse
(
b2Impulse
,
b2Point
,
wake
);
}
void
applyAngularImpulse
(
double
impulse
)
{
assert
(
_body
!=
null
);
_body
.
applyAngularImpulse
(
impulse
/
_physicsNode
.
b2WorldToNodeConversionFactor
);
}
void
_attach
(
PhysicsNode
physicsNode
,
Node
node
)
{
assert
(
_attached
==
false
);
...
...
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