Пример #1
0
int w_ChainShape_getVertexCount(lua_State *L)
{
	ChainShape *c = luax_checkchainshape(L, 1);
	int count = c->getVertexCount();
	lua_pushinteger(L, count);
	return 1;
}
Пример #2
0
void SelectNodesOP::RectQueryVisitor::
visit(Object* object, bool& bFetchNext)
{
	ChainShape* chain = static_cast<ChainShape*>(object);

	if (Math::isRectIntersectRect(chain->getRect(), m_rect))
	{
		ChainSelectedNodes* result = new ChainSelectedNodes;
		result->chain = chain;

		const std::vector<Vector>& vertices = chain->getVertices();
		for (size_t i = 0, n = vertices.size(); i < n; ++i)
		{
			if (Math::isPointInRect(vertices[i], m_rect))
				result->selectedNodes.push_back(vertices[i]);
		}

		if (result->selectedNodes.empty())
			delete result;
		else
			m_result.push_back(result);
	}

	bFetchNext = true;
}
Пример #3
0
void SelectNodesOP::PosQueryVisitor::
visit(Object* object, bool& bFetchNext)
{
	ChainShape* chain = static_cast<ChainShape*>(object);

	if (Math::isRectIntersectRect(chain->getRect(), m_rect))
	{
		const std::vector<Vector>& vertices = chain->getVertices();
		for (size_t i = 0, n = vertices.size(); i < n; ++i)
		{
			if (Math::getDistance(m_pos, vertices[i]) < SelectNodesOP::getThreshold())
			{
				ChainSelectedNodes* result = new ChainSelectedNodes;
				result->chain = chain;
				result->selectedNodes.push_back(vertices[i]);
				*m_result = result;

				bFetchNext = false;
				return;
			}
		}
	}

	bFetchNext = true;
}
Пример #4
0
int w_ChainShape_getChildEdge(lua_State *L)
{
	ChainShape *c = luax_checkchainshape(L, 1);
	int index = luaL_checkint(L, 2) - 1; // Convert from 1-based index
	EdgeShape *e = c->getChildEdge(index);
	luax_newtype(L, "EdgeShape", PHYSICS_EDGE_SHAPE_T, e);
	return 1;
}
Пример #5
0
int w_ChainShape_getPoint(lua_State *L)
{
	ChainShape *c = luax_checkchainshape(L, 1);
	int index = (int) luaL_checknumber(L, 2) - 1; // Convert from 1-based index
	b2Vec2 v;
	luax_catchexcept(L, [&](){ v = c->getPoint(index); });
	lua_pushnumber(L, v.x);
	lua_pushnumber(L, v.y);
	return 2;
}
Пример #6
0
int w_ChainShape_getChildEdge(lua_State *L)
{
	ChainShape *c = luax_checkchainshape(L, 1);
	int index = (int) luaL_checknumber(L, 2) - 1; // Convert from 1-based index
	EdgeShape *e = 0;
	luax_catchexcept(L, [&](){ e = c->getChildEdge(index); });
	luax_pushtype(L, PHYSICS_EDGE_SHAPE_ID, e);
	e->release();
	return 1;
}
Пример #7
0
int w_ChainShape_getNextVertex(lua_State *L)
{
	ChainShape *c = luax_checkchainshape(L, 1);
	float x, y;
	if (c->getNextVertex(x, y))
	{
		lua_pushnumber(L, x);
		lua_pushnumber(L, y);
		return 2;
	}
	return 0;
}
Пример #8
0
int w_ChainShape_setPreviousVertex(lua_State *L)
{
	ChainShape *c = luax_checkchainshape(L, 1);
	if (lua_isnoneornil(L, 2))
		c->setPreviousVertex();
	else
	{
		float x = (float)luaL_checknumber(L, 2);
		float y = (float)luaL_checknumber(L, 3);
		luax_catchexcept(L, [&](){ c->setPreviousVertex(x, y); });
	}
	return 0;
}
Пример #9
0
int w_ChainShape_getPoints(lua_State *L)
{
	ChainShape *c = luax_checkchainshape(L, 1);
	const b2Vec2 *verts = c->getPoints();
	int count = c->getVertexCount();
	if (!lua_checkstack(L, count*2))
		return luaL_error(L, "Too many return values");
	for (int i = 0; i < count; i++)
	{
		b2Vec2 v = Physics::scaleUp(verts[i]);
		lua_pushnumber(L, v.x);
		lua_pushnumber(L, v.y);
	}
	return count*2;
}
Пример #10
0
void PolylineFileAdapter::load(const char* filename)
{
	std::ifstream fin(filename);

	std::string line;
	getline(fin, line);
	m_imgPath = line;

	size_t size;
	fin >> size;
	for (size_t i = 0; i < size; ++i)
	{
		ChainShape* chain = new ChainShape();
		chain->loadFromTextFile(fin);
		m_chains.push_back(chain);
	}

	fin.close();
}
Пример #11
0
int w_ChainShape_getPoint(lua_State *L)
{
	ChainShape *c = luax_checkchainshape(L, 1);
	int index = luaL_checkint(L, 2) - 1; // Convert from 1-based index
	b2Vec2 v;
	ASSERT_GUARD(v = c->getPoint(index);)