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 "MotorJoint.h"
22
23// Module
24#include "Body.h"
25#include "World.h"
26#include "Physics.h"
27
28namespace love
29{
30namespace physics
31{
32namespace box2d
33{
34
35love::Type MotorJoint::type("MotorJoint", &Joint::type);
36
37MotorJoint::MotorJoint(Body *body1, Body *body2)
38 : Joint(body1, body2)
39 , joint(NULL)
40{
41 b2MotorJointDef def;
42
43 def.Initialize(body1->body, body2->body);
44 joint = (b2MotorJoint *) createJoint(&def);
45}
46
47MotorJoint::MotorJoint(Body *body1, Body *body2, float correctionFactor, bool collideConnected)
48 : Joint(body1, body2)
49 , joint(NULL)
50{
51 b2MotorJointDef def;
52
53 def.Initialize(body1->body, body2->body);
54 def.correctionFactor = correctionFactor;
55 def.collideConnected = collideConnected;
56
57 joint = (b2MotorJoint *) createJoint(&def);
58}
59
60MotorJoint::~MotorJoint()
61{
62}
63
64void MotorJoint::setLinearOffset(float x, float y)
65{
66 joint->SetLinearOffset(Physics::scaleDown(b2Vec2(x, y)));
67}
68
69int MotorJoint::getLinearOffset(lua_State *L) const
70{
71 lua_pushnumber(L, Physics::scaleUp(joint->GetLinearOffset().x));
72 lua_pushnumber(L, Physics::scaleUp(joint->GetLinearOffset().y));
73 return 2;
74}
75
76void MotorJoint::setAngularOffset(float angularOffset)
77{
78 joint->SetAngularOffset(angularOffset);
79}
80
81float MotorJoint::getAngularOffset() const
82{
83 return joint->GetAngularOffset();
84}
85
86void MotorJoint::setMaxForce(float force)
87{
88 joint->SetMaxForce(Physics::scaleDown(force));
89}
90
91float MotorJoint::getMaxForce() const
92{
93 return Physics::scaleUp(joint->GetMaxForce());
94}
95
96void MotorJoint::setMaxTorque(float torque)
97{
98 joint->SetMaxTorque(Physics::scaleDown(Physics::scaleDown(torque)));
99}
100
101float MotorJoint::getMaxTorque() const
102{
103 return Physics::scaleUp(Physics::scaleUp(joint->GetMaxTorque()));
104}
105
106void MotorJoint::setCorrectionFactor(float factor)
107{
108 joint->SetCorrectionFactor(factor);
109}
110
111float MotorJoint::getCorrectionFactor() const
112{
113 return joint->GetCorrectionFactor();
114}
115
116} // box2d
117} // physics
118} // love
119