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
6bd4fb85
Commit
6bd4fb85
authored
Oct 19, 2015
by
Viktor Lidholt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Renames PhysicsNode to PhysicsWorld
parent
0ef9da85
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
47 additions
and
47 deletions
+47
-47
test_physics.dart
examples/game/test_physics.dart
+2
-2
flutter_sprites.dart
packages/flutter_sprites/lib/flutter_sprites.dart
+1
-1
node.dart
packages/flutter_sprites/lib/src/node.dart
+10
-10
physics_body.dart
packages/flutter_sprites/lib/src/physics_body.dart
+5
-5
physics_debug.dart
packages/flutter_sprites/lib/src/physics_debug.dart
+1
-1
physics_joint.dart
packages/flutter_sprites/lib/src/physics_joint.dart
+13
-13
physics_shape.dart
packages/flutter_sprites/lib/src/physics_shape.dart
+8
-8
physics_world.dart
packages/flutter_sprites/lib/src/physics_world.dart
+4
-4
sprite_box.dart
packages/flutter_sprites/lib/src/sprite_box.dart
+3
-3
No files found.
examples/game/test_physics.dart
View file @
6bd4fb85
...
...
@@ -47,10 +47,10 @@ main() async {
class
TestBed
extends
NodeWithSize
{
Sprite
_obstacle
;
Physics
Node
_physicsNode
;
Physics
World
_physicsNode
;
TestBed
()
:
super
(
new
Size
(
1024.0
,
1024.0
))
{
_physicsNode
=
new
Physics
Node
(
new
Offset
(
0.0
,
100.0
));
_physicsNode
=
new
Physics
World
(
new
Offset
(
0.0
,
100.0
));
_obstacle
=
new
Sprite
(
_spriteSheet
[
"ship.png"
]);
_obstacle
.
position
=
new
Point
(
512.0
,
800.0
);
...
...
packages/flutter_sprites/lib/flutter_sprites.dart
View file @
6bd4fb85
...
...
@@ -36,8 +36,8 @@ part 'src/particle_system.dart';
part
'src/physics_body.dart'
;
part
'src/physics_debug.dart'
;
part
'src/physics_joint.dart'
;
part
'src/physics_node.dart'
;
part
'src/physics_shape.dart'
;
part
'src/physics_world.dart'
;
part
'src/sound.dart'
;
part
'src/sound_manager.dart'
;
part
'src/sprite.dart'
;
...
...
packages/flutter_sprites/lib/src/node.dart
View file @
6bd4fb85
...
...
@@ -132,8 +132,8 @@ class Node {
void
set
rotation
(
double
rotation
)
{
assert
(
rotation
!=
null
);
if
(
_physicsBody
!=
null
&&
parent
is
Physics
Node
)
{
Physics
Node
physicsNode
=
parent
;
if
(
_physicsBody
!=
null
&&
parent
is
Physics
World
)
{
Physics
World
physicsNode
=
parent
;
physicsNode
.
_updateRotation
(
this
.
physicsBody
,
rotation
);
return
;
}
...
...
@@ -150,7 +150,7 @@ class Node {
void
teleportRotation
(
double
rotation
)
{
assert
(
rotation
!=
null
);
if
(
_physicsBody
!=
null
&&
parent
is
Physics
Node
)
{
if
(
_physicsBody
!=
null
&&
parent
is
Physics
World
)
{
_physicsBody
.
_body
.
setTransform
(
_physicsBody
.
_body
.
position
,
radians
(
rotation
));
_physicsBody
.
_body
.
angularVelocity
=
0.0
;
_physicsBody
.
_body
.
setType
(
box2d
.
BodyType
.
STATIC
);
...
...
@@ -166,8 +166,8 @@ class Node {
void
set
position
(
Point
position
)
{
assert
(
position
!=
null
);
if
(
_physicsBody
!=
null
&&
parent
is
Physics
Node
)
{
Physics
Node
physicsNode
=
parent
;
if
(
_physicsBody
!=
null
&&
parent
is
Physics
World
)
{
Physics
World
physicsNode
=
parent
;
physicsNode
.
_updatePosition
(
this
.
physicsBody
,
position
);
return
;
}
...
...
@@ -184,8 +184,8 @@ class Node {
void
teleportPosition
(
Point
position
)
{
assert
(
position
!=
null
);
if
(
_physicsBody
!=
null
&&
parent
is
Physics
Node
)
{
Physics
Node
physicsNode
=
parent
;
if
(
_physicsBody
!=
null
&&
parent
is
Physics
World
)
{
Physics
World
physicsNode
=
parent
;
_physicsBody
.
_body
.
setTransform
(
new
Vector2
(
position
.
x
/
physicsNode
.
b2WorldToNodeConversionFactor
,
...
...
@@ -252,8 +252,8 @@ class Node {
void
set
scale
(
double
scale
)
{
assert
(
scale
!=
null
);
if
(
_physicsBody
!=
null
&&
parent
is
Physics
Node
)
{
Physics
Node
physicsNode
=
parent
;
if
(
_physicsBody
!=
null
&&
parent
is
Physics
World
)
{
Physics
World
physicsNode
=
parent
;
physicsNode
.
_updateScale
(
this
.
physicsBody
,
scale
);
}
...
...
@@ -681,7 +681,7 @@ class Node {
set
physicsBody
(
PhysicsBody
physicsBody
)
{
if
(
parent
!=
null
)
{
assert
(
parent
is
Physics
Node
);
assert
(
parent
is
Physics
World
);
if
(
physicsBody
==
null
)
{
physicsBody
.
_detach
();
...
...
packages/flutter_sprites/lib/src/physics_body.dart
View file @
6bd4fb85
...
...
@@ -232,7 +232,7 @@ class PhysicsBody {
double
gravityScale
;
Physics
Node
_physicsNode
;
Physics
World
_physicsNode
;
Node
_node
;
box2d
.
Body
_body
;
...
...
@@ -293,7 +293,7 @@ class PhysicsBody {
_body
.
applyAngularImpulse
(
impulse
/
_physicsNode
.
b2WorldToNodeConversionFactor
);
}
void
_attach
(
Physics
Node
physicsNode
,
Node
node
)
{
void
_attach
(
Physics
World
physicsNode
,
Node
node
)
{
assert
(
_attached
==
false
);
// Update scale
...
...
@@ -340,7 +340,7 @@ class PhysicsBody {
}
}
void
_createFixtures
(
Physics
Node
physicsNode
)
{
void
_createFixtures
(
Physics
World
physicsNode
)
{
// Create FixtureDef
box2d
.
FixtureDef
fixtureDef
=
new
box2d
.
FixtureDef
();
fixtureDef
.
friction
=
friction
;
...
...
@@ -371,7 +371,7 @@ class PhysicsBody {
}
}
void
_updateScale
(
Physics
Node
physicsNode
)
{
void
_updateScale
(
Physics
World
physicsNode
)
{
// Destroy old fixtures
for
(
box2d
.
Fixture
fixture
=
_body
.
getFixtureList
();
fixture
!=
null
;
fixture
=
fixture
.
getNext
())
{
_body
.
destroyFixture
(
fixture
);
...
...
@@ -384,7 +384,7 @@ class PhysicsBody {
_createFixtures
(
physicsNode
);
}
void
_addB2Shapes
(
Physics
Node
physicsNode
,
PhysicsShape
shape
,
List
<
box2d
.
Shape
>
b2Shapes
,
List
<
PhysicsShape
>
physicsShapes
)
{
void
_addB2Shapes
(
Physics
World
physicsNode
,
PhysicsShape
shape
,
List
<
box2d
.
Shape
>
b2Shapes
,
List
<
PhysicsShape
>
physicsShapes
)
{
if
(
shape
is
PhysicsShapeGroup
)
{
for
(
PhysicsShape
child
in
shape
.
shapes
)
{
_addB2Shapes
(
physicsNode
,
child
,
b2Shapes
,
physicsShapes
);
...
...
packages/flutter_sprites/lib/src/physics_debug.dart
View file @
6bd4fb85
...
...
@@ -12,7 +12,7 @@ class _PhysicsDebugDraw extends box2d.DebugDraw {
);
}
Physics
Node
physicsNode
;
Physics
World
physicsNode
;
PaintingCanvas
canvas
;
...
...
packages/flutter_sprites/lib/src/physics_joint.dart
View file @
6bd4fb85
...
...
@@ -23,7 +23,7 @@ abstract class PhysicsJoint {
bool
_active
=
true
;
box2d
.
Joint
_joint
;
Physics
Node
_physicsNode
;
Physics
World
_physicsNode
;
void
_completeCreation
()
{
if
(
bodyA
.
_attached
&&
bodyB
.
_attached
)
{
...
...
@@ -31,7 +31,7 @@ abstract class PhysicsJoint {
}
}
void
_attach
(
Physics
Node
physicsNode
)
{
void
_attach
(
Physics
World
physicsNode
)
{
if
(
_joint
==
null
)
{
_physicsNode
=
physicsNode
;
_joint
=
_createB2Joint
(
physicsNode
);
...
...
@@ -48,7 +48,7 @@ abstract class PhysicsJoint {
_active
=
false
;
}
box2d
.
Joint
_createB2Joint
(
Physics
Node
physicsNode
);
box2d
.
Joint
_createB2Joint
(
Physics
World
physicsNode
);
void
destroy
()
{
_detach
();
...
...
@@ -92,7 +92,7 @@ class PhysicsJointRevolute extends PhysicsJoint {
final
double
upperAngle
;
final
bool
enableLimit
;
box2d
.
Joint
_createB2Joint
(
Physics
Node
physicsNode
)
{
box2d
.
Joint
_createB2Joint
(
Physics
World
physicsNode
)
{
// Create Joint Definition
Vector2
vecAnchor
=
new
Vector2
(
_worldAnchor
.
x
/
physicsNode
.
b2WorldToNodeConversionFactor
,
...
...
@@ -124,7 +124,7 @@ class PhysicsJointPrismatic extends PhysicsJoint {
Offset
axis
;
box2d
.
Joint
_createB2Joint
(
Physics
Node
physicsNode
)
{
box2d
.
Joint
_createB2Joint
(
Physics
World
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
);
...
...
@@ -147,7 +147,7 @@ class PhysicsJointWeld extends PhysicsJoint {
final
double
dampening
;
final
double
frequency
;
box2d
.
Joint
_createB2Joint
(
Physics
Node
physicsNode
)
{
box2d
.
Joint
_createB2Joint
(
Physics
World
physicsNode
)
{
box2d
.
WeldJointDef
b2Def
=
new
box2d
.
WeldJointDef
();
Vector2
middle
=
new
Vector2
(
(
bodyA
.
_body
.
position
.
x
+
bodyB
.
_body
.
position
.
x
)
/
2.0
,
...
...
@@ -182,7 +182,7 @@ class PhysicsJointPulley extends PhysicsJoint {
final
Point
anchorB
;
final
double
ratio
;
box2d
.
Joint
_createB2Joint
(
Physics
Node
physicsNode
)
{
box2d
.
Joint
_createB2Joint
(
Physics
World
physicsNode
)
{
box2d
.
PulleyJointDef
b2Def
=
new
box2d
.
PulleyJointDef
();
b2Def
.
initialize
(
bodyA
.
_body
,
...
...
@@ -211,7 +211,7 @@ class PhysicsJointGear extends PhysicsJoint {
final
double
ratio
;
box2d
.
Joint
_createB2Joint
(
Physics
Node
physicsNode
)
{
box2d
.
Joint
_createB2Joint
(
Physics
World
physicsNode
)
{
box2d
.
GearJointDef
b2Def
=
new
box2d
.
GearJointDef
();
b2Def
.
bodyA
=
bodyA
.
_body
;
b2Def
.
bodyB
=
bodyB
.
_body
;
...
...
@@ -243,7 +243,7 @@ class PhysicsJointDistance extends PhysicsJoint {
final
double
dampening
;
final
double
frequency
;
box2d
.
Joint
_createB2Joint
(
Physics
Node
physicsNode
)
{
box2d
.
Joint
_createB2Joint
(
Physics
World
physicsNode
)
{
box2d
.
DistanceJointDef
b2Def
=
new
box2d
.
DistanceJointDef
();
b2Def
.
initialize
(
bodyA
.
_body
,
...
...
@@ -280,7 +280,7 @@ class PhysicsJointWheel extends PhysicsJoint {
final
double
dampening
;
final
double
frequency
;
box2d
.
Joint
_createB2Joint
(
Physics
Node
physicsNode
)
{
box2d
.
Joint
_createB2Joint
(
Physics
World
physicsNode
)
{
box2d
.
WheelJointDef
b2Def
=
new
box2d
.
WheelJointDef
();
b2Def
.
initialize
(
bodyA
.
_body
,
...
...
@@ -313,7 +313,7 @@ class PhysicsJointFriction extends PhysicsJoint {
final
double
maxForce
;
final
double
maxTorque
;
box2d
.
Joint
_createB2Joint
(
Physics
Node
physicsNode
)
{
box2d
.
Joint
_createB2Joint
(
Physics
World
physicsNode
)
{
box2d
.
FrictionJointDef
b2Def
=
new
box2d
.
FrictionJointDef
();
b2Def
.
initialize
(
bodyA
.
_body
,
...
...
@@ -345,7 +345,7 @@ class PhysicsJointConstantVolume extends PhysicsJoint {
final
double
dampening
;
final
double
frequency
;
box2d
.
Joint
_createB2Joint
(
Physics
Node
physicsNode
)
{
box2d
.
Joint
_createB2Joint
(
Physics
World
physicsNode
)
{
box2d
.
ConstantVolumeJointDef
b2Def
=
new
box2d
.
ConstantVolumeJointDef
();
for
(
PhysicsBody
body
in
bodies
)
{
b2Def
.
addBody
(
body
.
_body
);
...
...
@@ -356,7 +356,7 @@ class PhysicsJointConstantVolume extends PhysicsJoint {
}
}
Vector2
_convertPosToVec
(
Point
pt
,
Physics
Node
physicsNode
)
{
Vector2
_convertPosToVec
(
Point
pt
,
Physics
World
physicsNode
)
{
return
new
Vector2
(
pt
.
x
/
physicsNode
.
b2WorldToNodeConversionFactor
,
pt
.
y
/
physicsNode
.
b2WorldToNodeConversionFactor
...
...
packages/flutter_sprites/lib/src/physics_shape.dart
View file @
6bd4fb85
...
...
@@ -6,14 +6,14 @@ abstract class PhysicsShape {
Object
userObject
;
box2d
.
Shape
getB2Shape
(
Physics
Node
node
,
double
scale
)
{
box2d
.
Shape
getB2Shape
(
Physics
World
node
,
double
scale
)
{
if
(
_b2Shape
==
null
)
{
_b2Shape
=
_createB2Shape
(
node
,
scale
);
}
return
_b2Shape
;
}
box2d
.
Shape
_createB2Shape
(
Physics
Node
node
,
double
scale
);
box2d
.
Shape
_createB2Shape
(
Physics
World
node
,
double
scale
);
void
_invalidate
()
{
_b2Shape
=
null
;
...
...
@@ -26,7 +26,7 @@ class PhysicsShapeCircle extends PhysicsShape {
final
Point
point
;
final
double
radius
;
box2d
.
Shape
_createB2Shape
(
Physics
Node
node
,
double
scale
)
{
box2d
.
Shape
_createB2Shape
(
Physics
World
node
,
double
scale
)
{
box2d
.
CircleShape
shape
=
new
box2d
.
CircleShape
();
shape
.
p
.
x
=
scale
*
point
.
x
/
node
.
b2WorldToNodeConversionFactor
;
shape
.
p
.
y
=
scale
*
point
.
y
/
node
.
b2WorldToNodeConversionFactor
;
...
...
@@ -40,7 +40,7 @@ class PhysicsShapePolygon extends PhysicsShape {
final
List
<
Point
>
points
;
box2d
.
Shape
_createB2Shape
(
Physics
Node
node
,
double
scale
)
{
box2d
.
Shape
_createB2Shape
(
Physics
World
node
,
double
scale
)
{
List
<
Vector2
>
vectors
=
[];
for
(
Point
point
in
points
)
{
Vector2
vec
=
new
Vector2
(
...
...
@@ -69,7 +69,7 @@ class PhysicsShapeBox extends PhysicsShape {
final
Point
center
;
final
double
rotation
;
box2d
.
Shape
_createB2Shape
(
Physics
Node
node
,
double
scale
)
{
box2d
.
Shape
_createB2Shape
(
Physics
World
node
,
double
scale
)
{
box2d
.
PolygonShape
shape
=
new
box2d
.
PolygonShape
();
shape
.
setAsBox
(
scale
*
width
/
node
.
b2WorldToNodeConversionFactor
,
...
...
@@ -90,7 +90,7 @@ class PhysicsShapeChain extends PhysicsShape {
final
List
<
Point
>
points
;
final
bool
loop
;
box2d
.
Shape
_createB2Shape
(
Physics
Node
node
,
double
scale
)
{
box2d
.
Shape
_createB2Shape
(
Physics
World
node
,
double
scale
)
{
List
<
Vector2
>
vectors
=
[];
for
(
Point
point
in
points
)
{
Vector2
vec
=
new
Vector2
(
...
...
@@ -115,7 +115,7 @@ class PhysicsShapeEdge extends PhysicsShape {
final
Point
pointA
;
final
Point
pointB
;
box2d
.
Shape
_createB2Shape
(
Physics
Node
node
,
double
scale
)
{
box2d
.
Shape
_createB2Shape
(
Physics
World
node
,
double
scale
)
{
box2d
.
EdgeShape
shape
=
new
box2d
.
EdgeShape
();
shape
.
set
(
new
Vector2
(
...
...
@@ -137,7 +137,7 @@ class PhysicsShapeGroup extends PhysicsShape {
final
List
<
PhysicsShape
>
shapes
;
box2d
.
Shape
_createB2Shape
(
Physics
Node
node
,
double
scale
)
{
box2d
.
Shape
_createB2Shape
(
Physics
World
node
,
double
scale
)
{
return
null
;
}
...
...
packages/flutter_sprites/lib/src/physics_
node
.dart
→
packages/flutter_sprites/lib/src/physics_
world
.dart
View file @
6bd4fb85
...
...
@@ -9,8 +9,8 @@ enum PhysicsContactType {
typedef
void
PhysicsContactCallback
(
PhysicsContactType
type
,
PhysicsContact
contact
);
class
Physics
Node
extends
Node
{
Physics
Node
(
Offset
gravity
)
{
class
Physics
World
extends
Node
{
Physics
World
(
Offset
gravity
)
{
b2World
=
new
box2d
.
World
.
withGravity
(
new
Vector2
(
gravity
.
dx
/
b2WorldToNodeConversionFactor
,
...
...
@@ -18,7 +18,7 @@ class PhysicsNode extends Node {
_init
();
}
Physics
Node
.
fromB2World
(
this
.
b2World
,
this
.
b2WorldToNodeConversionFactor
)
{
Physics
World
.
fromB2World
(
this
.
b2World
,
this
.
b2WorldToNodeConversionFactor
)
{
_init
();
}
...
...
@@ -252,7 +252,7 @@ class _ContactCallbackInfo {
class
_ContactHandler
extends
box2d
.
ContactListener
{
_ContactHandler
(
this
.
physicsNode
);
Physics
Node
physicsNode
;
Physics
World
physicsNode
;
List
<
_ContactCallbackInfo
>
callbackInfos
=
[];
...
...
packages/flutter_sprites/lib/src/sprite_box.dart
View file @
6bd4fb85
...
...
@@ -78,7 +78,7 @@ class SpriteBox extends RenderBox {
List
<
Node
>
_constrainedNodes
;
List
<
Physics
Node
>
_physicsNodes
;
List
<
Physics
World
>
_physicsNodes
;
Rect
_visibleArea
;
...
...
@@ -400,7 +400,7 @@ class SpriteBox extends RenderBox {
void
_addActionControllersAndPhysicsNodes
(
Node
node
)
{
if
(
node
.
_actions
!=
null
)
_actionControllers
.
add
(
node
.
_actions
);
if
(
node
is
Physics
Node
)
_physicsNodes
.
add
(
node
);
if
(
node
is
Physics
World
)
_physicsNodes
.
add
(
node
);
for
(
int
i
=
node
.
children
.
length
-
1
;
i
>=
0
;
i
--)
{
Node
child
=
node
.
children
[
i
];
...
...
@@ -422,7 +422,7 @@ class SpriteBox extends RenderBox {
if
(
_physicsNodes
==
null
)
_rebuildActionControllersAndPhysicsNodes
();
for
(
Physics
Node
physicsNode
in
_physicsNodes
)
{
for
(
Physics
World
physicsNode
in
_physicsNodes
)
{
physicsNode
.
_stepPhysics
(
dt
);
}
}
...
...
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