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
90971695
Commit
90971695
authored
Oct 12, 2015
by
Viktor Lidholt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adds pulley joint to sprite physics and makes joint variables final
parent
5a7d2167
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
54 additions
and
15 deletions
+54
-15
physics_joint.dart
packages/flutter_sprites/lib/physics_joint.dart
+54
-15
No files found.
packages/flutter_sprites/lib/physics_joint.dart
View file @
90971695
...
...
@@ -6,8 +6,8 @@ abstract class PhysicsJoint {
bodyB
.
_joints
.
add
(
this
);
}
PhysicsBody
bodyA
;
PhysicsBody
bodyB
;
final
PhysicsBody
bodyA
;
final
PhysicsBody
bodyB
;
bool
_active
=
true
;
box2d
.
Joint
_joint
;
...
...
@@ -43,21 +43,17 @@ class PhysicsJointRevolute extends PhysicsJoint {
PhysicsBody
bodyA
,
PhysicsBody
bodyB
,
this
.
worldAnchor
,
{
double
lowerAngle:
0.0
,
double
upperAngle:
0.0
,
bool
enableLimit:
false
this
.
lowerAngle
:
0.0
,
this
.
upperAngle
:
0.0
,
this
.
enableLimit
:
false
})
:
super
(
bodyA
,
bodyB
)
{
this
.
lowerAngle
=
lowerAngle
;
this
.
upperAngle
=
upperAngle
;
this
.
enableLimit
=
enableLimit
;
_completeCreation
();
}
Point
worldAnchor
;
double
lowerAngle
;
double
upperAngle
;
bool
enableLimit
;
final
Point
worldAnchor
;
final
double
lowerAngle
;
final
double
upperAngle
;
final
bool
enableLimit
;
box2d
.
Joint
_createB2Joint
(
PhysicsNode
physicsNode
)
{
// Create Joint Definition
...
...
@@ -81,7 +77,8 @@ class PhysicsJointPrismatic extends PhysicsJoint {
PhysicsJointPrismatic
(
PhysicsBody
bodyA
,
PhysicsBody
bodyB
,
this
.
axis
)
:
super
(
bodyA
,
bodyB
)
{
this
.
axis
)
:
super
(
bodyA
,
bodyB
)
{
_completeCreation
();
}
...
...
@@ -97,7 +94,8 @@ class PhysicsJointPrismatic extends PhysicsJoint {
class
PhysicsJointWeld
extends
PhysicsJoint
{
PhysicsJointWeld
(
PhysicsBody
bodyA
,
PhysicsBody
bodyB
)
:
super
(
bodyA
,
bodyB
)
{
PhysicsBody
bodyB
)
:
super
(
bodyA
,
bodyB
)
{
_completeCreation
();
}
...
...
@@ -111,3 +109,44 @@ class PhysicsJointWeld extends PhysicsJoint {
return
physicsNode
.
b2World
.
createJoint
(
b2Def
);
}
}
class
PhysicsJointPulley
extends
PhysicsJoint
{
PhysicsJointPulley
(
PhysicsBody
bodyA
,
PhysicsBody
bodyB
,
this
.
groundAnchorA
,
this
.
groundAnchorB
,
this
.
anchorA
,
this
.
anchorB
,
this
.
ratio
)
:
super
(
bodyA
,
bodyB
)
{
_completeCreation
();
}
final
Point
groundAnchorA
;
final
Point
groundAnchorB
;
final
Point
anchorA
;
final
Point
anchorB
;
final
double
ratio
;
box2d
.
Joint
_createB2Joint
(
PhysicsNode
physicsNode
)
{
box2d
.
PulleyJointDef
b2Def
=
new
box2d
.
PulleyJointDef
();
b2Def
.
initialize
(
bodyA
.
_body
,
bodyB
.
_body
,
_convertPosToVec
(
groundAnchorA
,
physicsNode
),
_convertPosToVec
(
groundAnchorB
,
physicsNode
),
_convertPosToVec
(
anchorA
,
physicsNode
),
_convertPosToVec
(
anchorB
,
physicsNode
),
ratio
);
return
physicsNode
.
b2World
.
createJoint
(
b2Def
);
}
}
Vector2
_convertPosToVec
(
Point
pt
,
PhysicsNode
physicsNode
)
{
return
new
Vector2
(
pt
.
x
/
physicsNode
.
b2WorldToNodeConversionFactor
,
pt
.
y
/
physicsNode
.
b2WorldToNodeConversionFactor
);
}
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