1 | /** |
2 | * Copyright (c) 2006-2023 LOVE Development Team |
3 | * |
4 | * This software is provided 'as-is', without any express or implied |
5 | * warranty. In no event will the authors be held liable for any damages |
6 | * arising from the use of this software. |
7 | * |
8 | * Permission is granted to anyone to use this software for any purpose, |
9 | * including commercial applications, and to alter it and redistribute it |
10 | * freely, subject to the following restrictions: |
11 | * |
12 | * 1. The origin of this software must not be misrepresented; you must not |
13 | * claim that you wrote the original software. If you use this software |
14 | * in a product, an acknowledgment in the product documentation would be |
15 | * appreciated but is not required. |
16 | * 2. Altered source versions must be plainly marked as such, and must not be |
17 | * misrepresented as being the original software. |
18 | * 3. This notice may not be removed or altered from any source distribution. |
19 | **/ |
20 | |
21 | #include "GearJoint.h" |
22 | |
23 | // Module |
24 | #include "Body.h" |
25 | #include "World.h" |
26 | |
27 | namespace love |
28 | { |
29 | namespace physics |
30 | { |
31 | namespace box2d |
32 | { |
33 | |
34 | love::Type GearJoint::type("GearJoint" , &Joint::type); |
35 | |
36 | GearJoint::GearJoint(Joint *joint1, Joint *joint2, float ratio, bool collideConnected) |
37 | : Joint(joint1->body2, joint2->body2) |
38 | , joint(NULL) |
39 | { |
40 | b2GearJointDef def; |
41 | def.joint1 = joint1->joint; |
42 | def.joint2 = joint2->joint; |
43 | def.bodyA = joint1->body2->body; |
44 | def.bodyB = joint2->body2->body; |
45 | def.ratio = ratio; |
46 | def.collideConnected = collideConnected; |
47 | |
48 | joint = (b2GearJoint *)createJoint(&def); |
49 | } |
50 | |
51 | GearJoint::~GearJoint() |
52 | { |
53 | } |
54 | |
55 | void GearJoint::setRatio(float ratio) |
56 | { |
57 | joint->SetRatio(ratio); |
58 | } |
59 | |
60 | float GearJoint::getRatio() const |
61 | { |
62 | return joint->GetRatio(); |
63 | } |
64 | |
65 | Joint *GearJoint::getJointA() const |
66 | { |
67 | b2Joint *b2joint = joint->GetJoint1(); |
68 | if (b2joint == nullptr) |
69 | return nullptr; |
70 | |
71 | Joint *j = (Joint *) world->findObject(b2joint); |
72 | if (j == nullptr) |
73 | throw love::Exception("A joint has escaped Memoizer!" ); |
74 | |
75 | return j; |
76 | } |
77 | |
78 | Joint *GearJoint::getJointB() const |
79 | { |
80 | b2Joint *b2joint = joint->GetJoint2(); |
81 | if (b2joint == nullptr) |
82 | return nullptr; |
83 | |
84 | Joint *j = (Joint *) world->findObject(b2joint); |
85 | if (j == nullptr) |
86 | throw love::Exception("A joint has escaped Memoizer!" ); |
87 | |
88 | return j; |
89 | } |
90 | |
91 | } // box2d |
92 | } // physics |
93 | } // love |
94 | |