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
4da5aea5
Commit
4da5aea5
authored
Oct 26, 2015
by
Viktor Lidholt
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1797 from vlidholt/master
Adds motors to revolute joints and prismatic joints
parents
7f3b7a66
4d76182b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
95 additions
and
6 deletions
+95
-6
test_physics.dart
examples/game/test_physics.dart
+0
-3
physics_joint.dart
packages/flutter_sprites/lib/src/physics_joint.dart
+95
-3
No files found.
examples/game/test_physics.dart
View file @
4da5aea5
...
...
@@ -91,11 +91,8 @@ class TestBed extends NodeWithSize {
if
(
event
.
type
==
"pointerdown"
)
{
Point
pos
=
convertPointToNodeSpace
(
event
.
boxPosition
);
print
(
"ADDING SHIPS"
);
PhysicsGroup
group
=
new
PhysicsGroup
();
group
.
position
=
pos
;
group
.
rotation
=
10.0
;
group
.
scale
=
0.5
;
_world
.
addChild
(
group
);
Sprite
shipA
;
...
...
packages/flutter_sprites/lib/src/physics_joint.dart
View file @
4da5aea5
...
...
@@ -82,8 +82,14 @@ class PhysicsJointRevolute extends PhysicsJoint {
this
.
upperAngle
:
0.0
,
this
.
enableLimit
:
false
,
PhysicsJointBreakCallback
breakCallback
,
double
breakingForce
double
breakingForce
,
bool
enableMotor:
false
,
double
motorSpeed:
0.0
,
double
maxMotorTorque:
0.0
})
:
super
(
bodyA
,
bodyB
,
breakingForce
,
breakCallback
)
{
_enableMotor
=
enableMotor
;
_motorSpeed
=
motorSpeed
;
_maxMotorTorque
=
maxMotorTorque
;
_completeCreation
();
}
...
...
@@ -92,6 +98,42 @@ class PhysicsJointRevolute extends PhysicsJoint {
final
double
upperAngle
;
final
bool
enableLimit
;
bool
_enableMotor
;
bool
get
enableMotor
=>
_enableMotor
;
set
enableMotor
(
bool
enableMotor
)
{
_enableMotor
=
enableMotor
;
if
(
_joint
!=
null
)
{
box2d
.
RevoluteJoint
revoluteJoint
=
_joint
;
revoluteJoint
.
enableMotor
(
enableMotor
);
}
}
double
_motorSpeed
;
double
get
motorSpeed
=>
_motorSpeed
;
set
motorSpeed
(
double
motorSpeed
)
{
_motorSpeed
=
motorSpeed
;
if
(
_joint
!=
null
)
{
box2d
.
RevoluteJoint
revoluteJoint
=
_joint
;
revoluteJoint
.
setMotorSpeed
(
radians
(
motorSpeed
));
}
}
double
_maxMotorTorque
;
double
get
maxMotorTorque
=>
_maxMotorTorque
;
set
maxMotorTorque
(
double
maxMotorTorque
)
{
_maxMotorTorque
=
maxMotorTorque
;
if
(
_joint
!=
null
)
{
box2d
.
RevoluteJoint
revoluteJoint
=
_joint
;
revoluteJoint
.
setMaxMotorTorque
(
maxMotorTorque
);
}
}
box2d
.
Joint
_createB2Joint
(
PhysicsWorld
physicsNode
)
{
// Create Joint Definition
Vector2
vecAnchor
=
new
Vector2
(
...
...
@@ -105,6 +147,10 @@ class PhysicsJointRevolute extends PhysicsJoint {
b2Def
.
lowerAngle
=
lowerAngle
;
b2Def
.
upperAngle
=
upperAngle
;
b2Def
.
enableMotor
=
_enableMotor
;
b2Def
.
motorSpeed
=
_motorSpeed
;
b2Def
.
maxMotorTorque
=
_maxMotorTorque
;
// Create joint
return
physicsNode
.
b2World
.
createJoint
(
b2Def
);
}
...
...
@@ -116,17 +162,63 @@ class PhysicsJointPrismatic extends PhysicsJoint {
PhysicsBody
bodyB
,
this
.
axis
,
{
double
breakingForce
,
PhysicsJointBreakCallback
breakCallback
PhysicsJointBreakCallback
breakCallback
,
bool
enableMotor:
false
,
double
motorSpeed:
0.0
,
double
maxMotorForce:
0.0
}
)
:
super
(
bodyA
,
bodyB
,
breakingForce
,
breakCallback
)
{
_enableMotor
=
enableMotor
;
_motorSpeed
=
motorSpeed
;
_maxMotorForce
=
maxMotorForce
;
_completeCreation
();
}
Offset
axis
;
final
Offset
axis
;
bool
_enableMotor
;
bool
get
enableMotor
=>
_enableMotor
;
set
enableMotor
(
bool
enableMotor
)
{
_enableMotor
=
enableMotor
;
if
(
_joint
!=
null
)
{
box2d
.
PrismaticJoint
prismaticJoint
=
_joint
;
prismaticJoint
.
enableMotor
(
enableMotor
);
}
}
double
_motorSpeed
;
double
get
motorSpeed
=>
_motorSpeed
;
set
motorSpeed
(
double
motorSpeed
)
{
_motorSpeed
=
motorSpeed
;
if
(
_joint
!=
null
)
{
box2d
.
PrismaticJoint
prismaticJoint
=
_joint
;
prismaticJoint
.
setMotorSpeed
(
motorSpeed
/
_physicsNode
.
b2WorldToNodeConversionFactor
);
}
}
double
_maxMotorForce
;
double
get
maxMotorForce
=>
_maxMotorForce
;
set
maxMotorForce
(
double
maxMotorForce
)
{
_maxMotorForce
=
maxMotorForce
;
if
(
_joint
!=
null
)
{
box2d
.
PrismaticJoint
prismaticJoint
=
_joint
;
prismaticJoint
.
setMaxMotorForce
(
maxMotorForce
/
_physicsNode
.
b2WorldToNodeConversionFactor
);
}
}
box2d
.
Joint
_createB2Joint
(
PhysicsWorld
physicsNode
)
{
box2d
.
PrismaticJointDef
b2Def
=
new
box2d
.
PrismaticJointDef
();
b2Def
.
initialize
(
bodyA
.
_body
,
bodyB
.
_body
,
bodyA
.
_body
.
position
,
new
Vector2
(
axis
.
dx
,
axis
.
dy
));
b2Def
.
enableMotor
=
_enableMotor
;
b2Def
.
motorSpeed
=
_motorSpeed
;
b2Def
.
maxMotorForce
=
_maxMotorForce
;
return
physicsNode
.
b2World
.
createJoint
(
b2Def
);
}
}
...
...
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