Skip to content

Commit e5705a7

Browse files
committed
Implemented the WeldJoint and added desktop demo.
1 parent e660028 commit e5705a7

File tree

6 files changed

+705
-3
lines changed

6 files changed

+705
-3
lines changed

Forge2D Port Progress.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,8 @@
9999
[x] revolute_joint_def
100100
[] rope_joint <--- not working when previously ported.
101101
[] rope_joint_def
102-
[] weld_joint
103-
[] weld_joint_def
102+
[x] weld_joint
103+
[x] weld_joint_def
104104
[] wheel_joint
105105
[] wheel_joint_def
106106
[x] body

src/desktop/Demo Specific/Demo.xojo_code

+23-1
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,24 @@ Protected Module Demo
282282
End Sub
283283
#tag EndMethod
284284

285+
#tag Method, Flags = &h1, Description = 4372656174657320616E6420616464732074776F20626F6469657320286120626F7820616E64206120636972636C6529206C696E6B65642076696120612077656C64206A6F696E742E
286+
Protected Sub CreateWeldedBodies(world As Physics.World, boxX As Double, boxY As Double, boxSize As Double, circleX As Double, circleY As Double, circleRadius As Double)
287+
/// Creates and adds two bodies (a box and a circle) linked via a weld joint.
288+
289+
Var box As Physics.Body = _
290+
CreateBox(World, New VMaths.Vector2(boxX, boxY), boxSize, boxSize)
291+
292+
Var circle As Physics.Body = CreateCircle(World, New VMaths.Vector2(circleX, circleY), circleRadius)
293+
294+
Var jointDef As New Physics.WeldJointDef
295+
var anchor As New VMaths.Vector2(boxX - (boxSize/2), boxY - (boxSize/2))
296+
jointDef.Initialize(box, circle, anchor)
297+
298+
world.CreateJoint(New Physics.WeldJoint(jointdef))
299+
300+
End Sub
301+
#tag EndMethod
302+
285303
#tag Method, Flags = &h0
286304
Function ToString(Extends type As Demo.Types) As String
287305
Select Case type
@@ -312,6 +330,9 @@ Protected Module Demo
312330
Case Demo.Types.VariousShapes
313331
Return "Various Shapes"
314332

333+
Case Demo.Types.WeldJoint
334+
Return "Weld Joint"
335+
315336
Else
316337
Raise New UnsupportedOperationException("Unknown demo type.")
317338
End Select
@@ -329,7 +350,8 @@ Protected Module Demo
329350
ClickToAddRandomBodies
330351
PrismaticJoint
331352
Particles
332-
Raycasting
353+
Raycasting
354+
WeldJoint
333355
#tag EndEnum
334356

335357

src/desktop/Demo Specific/WinDemo.xojo_window

+21
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,9 @@ End
359359
Case Demo.Types.VariousShapes
360360
DemoVariousShapes
361361

362+
Case Demo.Types.WeldJoint
363+
DemoWeldJoint
364+
362365
Else
363366
Raise New UnsupportedOperationException("Unknown demo type.")
364367
End Select
@@ -753,6 +756,21 @@ End
753756
End Sub
754757
#tag EndMethod
755758

759+
#tag Method, Flags = &h0, Description = 436F6E666967757265207468652073696D756C6174696F6E20666F72207468652077656C64206A6F696E742064656D6F2E
760+
Sub DemoWeldJoint()
761+
/// Configure the simulation for the weld joint demo.
762+
763+
InitialiseWorldAndScene
764+
765+
ResetGravity
766+
767+
// Create the ground and two walls.
768+
Call Demo.CreateGroundAndOptionalWalls(world, Scene.Width, Scene.Height)
769+
770+
Demo.CreateWeldedBodies(World, 0, 0, 7, 5, 5, 5)
771+
End Sub
772+
#tag EndMethod
773+
756774
#tag Method, Flags = &h0, Description = 436F6D707574657320616E6420647261772061207265666C65637461626C652072617920696E206120726563757273697665206D616E6E65722E
757775
Sub DrawReflectedRay(p1 As VMaths.Vector2, p2 As VMaths.Vector2, g As Graphics)
758776
/// Computes and draw a reflectable ray in a recursive manner.
@@ -1089,6 +1107,9 @@ End
10891107
Me.AddRow(Demo.Types.VariousShapes.ToString)
10901108
Me.RowTagAt(Me.LastAddedRowIndex) = Demo.Types.VariousShapes
10911109

1110+
Me.AddRow(Demo.Types.WeldJoint.ToString)
1111+
Me.RowTagAt(Me.LastAddedRowIndex) = Demo.Types.WeldJoint
1112+
10921113
Me.SelectRowWithTag(Demo.Types.RevoluteJoint)
10931114

10941115
End Sub

src/desktop/Physics Dev Harness.xojo_project

+2
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,8 @@ Module=Demo;Demo Specific/Demo.xojo_code;&h000000000574A7FF;&h0000000055998FFF;f
141141
Class=ConstantVolumeJoint;Physics/ConstantVolumeJoint.xojo_code;&h000000006AF61FFF;&h0000000058463FFF;false
142142
Class=PrismaticJointDef;Physics/PrismaticJointDef.xojo_code;&h000000004568C7FF;&h0000000058463FFF;false
143143
Class=PrismaticJoint;Physics/PrismaticJoint.xojo_code;&h00000000089957FF;&h0000000058463FFF;false
144+
Class=WeldJointDef;Physics/WeldJointDef.xojo_code;&h0000000003AAE7FF;&h0000000058463FFF;false
145+
Class=WeldJoint;Physics/WeldJoint.xojo_code;&h000000005BD727FF;&h0000000058463FFF;false
144146
DefaultWindow=WinDemo
145147
AppMenuBar=MainMenuBar
146148
MajorVersion=1

0 commit comments

Comments
 (0)