| 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 "EdgeShape.h" |
| 22 | |
| 23 | // Module |
| 24 | #include "Body.h" |
| 25 | #include "World.h" |
| 26 | #include "Physics.h" |
| 27 | |
| 28 | namespace love |
| 29 | { |
| 30 | namespace physics |
| 31 | { |
| 32 | namespace box2d |
| 33 | { |
| 34 | |
| 35 | love::Type EdgeShape::type("EdgeShape" , &Shape::type); |
| 36 | |
| 37 | EdgeShape::EdgeShape(b2EdgeShape *e, bool own) |
| 38 | : Shape(e, own) |
| 39 | { |
| 40 | } |
| 41 | |
| 42 | EdgeShape::~EdgeShape() |
| 43 | { |
| 44 | } |
| 45 | |
| 46 | void EdgeShape::setNextVertex(float x, float y) |
| 47 | { |
| 48 | b2EdgeShape *e = (b2EdgeShape *)shape; |
| 49 | b2Vec2 v(x, y); |
| 50 | e->m_vertex3 = Physics::scaleDown(v); |
| 51 | e->m_hasVertex3 = true; |
| 52 | } |
| 53 | |
| 54 | void EdgeShape::setNextVertex() |
| 55 | { |
| 56 | b2EdgeShape *e = (b2EdgeShape *)shape; |
| 57 | e->m_hasVertex3 = false; |
| 58 | } |
| 59 | |
| 60 | bool EdgeShape::getNextVertex(float &x, float &y) const |
| 61 | { |
| 62 | b2EdgeShape *e = (b2EdgeShape *)shape; |
| 63 | |
| 64 | if (e->m_hasVertex3) |
| 65 | { |
| 66 | b2Vec2 v = Physics::scaleUp(e->m_vertex3); |
| 67 | x = v.x; |
| 68 | y = v.y; |
| 69 | return true; |
| 70 | } |
| 71 | |
| 72 | return false; |
| 73 | } |
| 74 | |
| 75 | void EdgeShape::setPreviousVertex(float x, float y) |
| 76 | { |
| 77 | b2EdgeShape *e = (b2EdgeShape *)shape; |
| 78 | b2Vec2 v(x, y); |
| 79 | e->m_vertex0 = Physics::scaleDown(v); |
| 80 | e->m_hasVertex0 = true; |
| 81 | } |
| 82 | |
| 83 | void EdgeShape::setPreviousVertex() |
| 84 | { |
| 85 | b2EdgeShape *e = (b2EdgeShape *)shape; |
| 86 | e->m_hasVertex0 = false; |
| 87 | } |
| 88 | |
| 89 | bool EdgeShape::getPreviousVertex(float &x, float &y) const |
| 90 | { |
| 91 | b2EdgeShape *e = (b2EdgeShape *)shape; |
| 92 | |
| 93 | if (e->m_hasVertex0) |
| 94 | { |
| 95 | b2Vec2 v = Physics::scaleUp(e->m_vertex0); |
| 96 | x = v.x; |
| 97 | y = v.y; |
| 98 | return true; |
| 99 | } |
| 100 | |
| 101 | return false; |
| 102 | } |
| 103 | |
| 104 | int EdgeShape::getPoints(lua_State *L) |
| 105 | { |
| 106 | b2EdgeShape *e = (b2EdgeShape *)shape; |
| 107 | b2Vec2 v1 = Physics::scaleUp(e->m_vertex1); |
| 108 | b2Vec2 v2 = Physics::scaleUp(e->m_vertex2); |
| 109 | lua_pushnumber(L, v1.x); |
| 110 | lua_pushnumber(L, v1.y); |
| 111 | lua_pushnumber(L, v2.x); |
| 112 | lua_pushnumber(L, v2.y); |
| 113 | return 4; |
| 114 | |
| 115 | } |
| 116 | |
| 117 | } // box2d |
| 118 | } // physics |
| 119 | } // love |
| 120 | |