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
5f907780
Commit
5f907780
authored
Oct 12, 2015
by
Viktor Lidholt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Working joints in sprite physics
parent
79c23548
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
44 additions
and
21 deletions
+44
-21
physics_joint.dart
packages/flutter_sprites/lib/physics_joint.dart
+42
-19
physics_node.dart
packages/flutter_sprites/lib/physics_node.dart
+2
-2
No files found.
packages/flutter_sprites/lib/physics_joint.dart
View file @
5f907780
...
@@ -4,10 +4,6 @@ abstract class PhysicsJoint {
...
@@ -4,10 +4,6 @@ abstract class PhysicsJoint {
PhysicsJoint
(
this
.
bodyA
,
this
.
bodyB
)
{
PhysicsJoint
(
this
.
bodyA
,
this
.
bodyB
)
{
bodyA
.
_joints
.
add
(
this
);
bodyA
.
_joints
.
add
(
this
);
bodyB
.
_joints
.
add
(
this
);
bodyB
.
_joints
.
add
(
this
);
if
(
bodyA
.
_attached
&&
bodyB
.
_attached
)
{
_attach
(
bodyA
.
_physicsNode
);
}
}
}
PhysicsBody
bodyA
;
PhysicsBody
bodyA
;
...
@@ -18,6 +14,12 @@ abstract class PhysicsJoint {
...
@@ -18,6 +14,12 @@ abstract class PhysicsJoint {
PhysicsNode
_physicsNode
;
PhysicsNode
_physicsNode
;
void
_completeCreation
()
{
if
(
bodyA
.
_attached
&&
bodyB
.
_attached
)
{
_attach
(
bodyA
.
_physicsNode
);
}
}
void
_attach
(
PhysicsNode
physicsNode
)
{
void
_attach
(
PhysicsNode
physicsNode
)
{
if
(
_joint
==
null
)
{
if
(
_joint
==
null
)
{
_physicsNode
=
physicsNode
;
_physicsNode
=
physicsNode
;
...
@@ -40,7 +42,7 @@ class PhysicsJointRevolute extends PhysicsJoint {
...
@@ -40,7 +42,7 @@ class PhysicsJointRevolute extends PhysicsJoint {
PhysicsJointRevolute
(
PhysicsJointRevolute
(
PhysicsBody
bodyA
,
PhysicsBody
bodyA
,
PhysicsBody
bodyB
,
PhysicsBody
bodyB
,
this
.
anchorWorld
,
{
this
.
worldAnchor
,
{
double
lowerAngle:
0.0
,
double
lowerAngle:
0.0
,
double
upperAngle:
0.0
,
double
upperAngle:
0.0
,
bool
enableLimit:
false
bool
enableLimit:
false
...
@@ -48,9 +50,11 @@ class PhysicsJointRevolute extends PhysicsJoint {
...
@@ -48,9 +50,11 @@ class PhysicsJointRevolute extends PhysicsJoint {
this
.
lowerAngle
=
lowerAngle
;
this
.
lowerAngle
=
lowerAngle
;
this
.
upperAngle
=
upperAngle
;
this
.
upperAngle
=
upperAngle
;
this
.
enableLimit
=
enableLimit
;
this
.
enableLimit
=
enableLimit
;
_completeCreation
();
}
}
Point
anchorWorld
;
Point
worldAnchor
;
double
lowerAngle
;
double
lowerAngle
;
double
upperAngle
;
double
upperAngle
;
bool
enableLimit
;
bool
enableLimit
;
...
@@ -58,8 +62,8 @@ class PhysicsJointRevolute extends PhysicsJoint {
...
@@ -58,8 +62,8 @@ class PhysicsJointRevolute extends PhysicsJoint {
box2d
.
Joint
_createB2Joint
(
PhysicsNode
physicsNode
)
{
box2d
.
Joint
_createB2Joint
(
PhysicsNode
physicsNode
)
{
// Create Joint Definition
// Create Joint Definition
Vector2
vecAnchor
=
new
Vector2
(
Vector2
vecAnchor
=
new
Vector2
(
anchorWorld
.
x
/
physicsNode
.
b2WorldToNodeConversionFactor
,
worldAnchor
.
x
/
physicsNode
.
b2WorldToNodeConversionFactor
,
anchorWorld
.
y
/
physicsNode
.
b2WorldToNodeConversionFactor
worldAnchor
.
y
/
physicsNode
.
b2WorldToNodeConversionFactor
);
);
box2d
.
RevoluteJointDef
b2Def
=
new
box2d
.
RevoluteJointDef
();
box2d
.
RevoluteJointDef
b2Def
=
new
box2d
.
RevoluteJointDef
();
...
@@ -73,18 +77,37 @@ class PhysicsJointRevolute extends PhysicsJoint {
...
@@ -73,18 +77,37 @@ class PhysicsJointRevolute extends PhysicsJoint {
}
}
}
}
class
PhysicsJointPrismatic
extends
PhysicsJoint
{
PhysicsJointPrismatic
(
PhysicsBody
bodyA
,
PhysicsBody
bodyB
,
this
.
axis
)
:
super
(
bodyA
,
bodyB
)
{
_completeCreation
();
}
Offset
axis
;
box2d
.
Joint
_createB2Joint
(
PhysicsNode
physicsNode
)
{
box2d
.
PrismaticJointDef
b2Def
=
new
box2d
.
PrismaticJointDef
();
b2Def
.
initialize
(
bodyA
.
_body
,
bodyB
.
_body
,
bodyA
.
_body
.
position
,
new
Vector2
(
axis
.
dx
,
axis
.
dy
));
return
physicsNode
.
b2World
.
createJoint
(
b2Def
);
}
}
class
PhysicsJointWeld
extends
PhysicsJoint
{
class
PhysicsJointWeld
extends
PhysicsJoint
{
PhysicsJointWeld
(
PhysicsJointWeld
(
PhysicsBody
bodyA
,
PhysicsBody
bodyA
,
PhysicsBody
bodyB
)
:
super
(
bodyA
,
bodyB
);
PhysicsBody
bodyB
)
:
super
(
bodyA
,
bodyB
)
{
_completeCreation
();
box2d
.
Joint
_createB2Joint
(
PhysicsNode
physicsNode
)
{
}
box2d
.
WeldJointDef
b2Def
=
new
box2d
.
WeldJointDef
();
Vector2
middle
=
new
Vector2
(
box2d
.
Joint
_createB2Joint
(
PhysicsNode
physicsNode
)
{
(
bodyA
.
_body
.
position
.
x
+
bodyB
.
_body
.
position
.
x
)
/
2.0
,
box2d
.
WeldJointDef
b2Def
=
new
box2d
.
WeldJointDef
();
(
bodyA
.
_body
.
position
.
y
+
bodyB
.
_body
.
position
.
y
)
/
2.0
Vector2
middle
=
new
Vector2
(
);
(
bodyA
.
_body
.
position
.
x
+
bodyB
.
_body
.
position
.
x
)
/
2.0
,
b2Def
.
initialize
(
bodyA
.
_body
,
bodyB
.
_body
,
middle
);
(
bodyA
.
_body
.
position
.
y
+
bodyB
.
_body
.
position
.
y
)
/
2.0
return
physicsNode
.
b2World
.
createJoint
(
b2Def
);
);
}
b2Def
.
initialize
(
bodyA
.
_body
,
bodyB
.
_body
,
middle
);
return
physicsNode
.
b2World
.
createJoint
(
b2Def
);
}
}
}
packages/flutter_sprites/lib/physics_node.dart
View file @
5f907780
...
@@ -33,7 +33,7 @@ class PhysicsNode extends Node {
...
@@ -33,7 +33,7 @@ class PhysicsNode extends Node {
List
<
box2d
.
Body
>
_bodiesScheduledForDestruction
=
[];
List
<
box2d
.
Body
>
_bodiesScheduledForDestruction
=
[];
double
b2WorldToNodeConversionFactor
=
50
0.0
;
double
b2WorldToNodeConversionFactor
=
1
0.0
;
Offset
get
gravity
{
Offset
get
gravity
{
Vector2
g
=
b2World
.
getGravity
();
Vector2
g
=
b2World
.
getGravity
();
...
@@ -282,7 +282,7 @@ class PhysicsNode extends Node {
...
@@ -282,7 +282,7 @@ class PhysicsNode extends Node {
// Draw the joint depending on type
// Draw the joint depending on type
box2d
.
JointType
type
=
joint
.
getType
();
box2d
.
JointType
type
=
joint
.
getType
();
if
(
type
==
box2d
.
JointType
.
WELD
)
{
if
(
type
==
box2d
.
JointType
.
WELD
||
type
==
box2d
.
JointType
.
REVOLUTE
)
{
// Draw weld joint
// Draw weld joint
canvas
.
drawCircle
(
ptAnchorA
,
5.0
,
shapePaint
);
canvas
.
drawCircle
(
ptAnchorA
,
5.0
,
shapePaint
);
...
...
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