Exemplo n.º 1
0
void Mesh::setTriangles(std::vector<int> triangles, int submesh)
{
  if(submesh > positionBufferIds.size())
  {
    throw std::exception();
  }

  if(submesh == positionBufferIds.size())
  {
    this->triangles.push_back(triangles);
  }

  recalculateBounds();

  std::vector<float> values;

  for(int i = 0; i < triangles.size(); i++)
  {
    values.push_back(vertices.at(triangles.at(i)).x);
    values.push_back(vertices.at(triangles.at(i)).y);
    values.push_back(vertices.at(triangles.at(i)).z);
  }

  GLuint positionBufferId = 0;
  glGenBuffers(1, &positionBufferId);
  positionBufferIds.push_back(positionBufferId);
  _positionBufferIds.push_back(std::shared_ptr<GLuint>(&positionBufferId, std::bind(freeBuffer, positionBufferId)));

  glBindBuffer(GL_ARRAY_BUFFER, positionBufferId);
  glBufferData(GL_ARRAY_BUFFER, values.size() * sizeof(values[0]), &values[0], GL_STATIC_DRAW);

  values.clear();

  for(int i = 0; i < triangles.size(); i++)
  {
    values.push_back(uv.at(triangles.at(i)).x);
    values.push_back(uv.at(triangles.at(i)).y);
  }

  GLuint uvBufferId = 0;
  glGenBuffers(1, &uvBufferId);
  uvBufferIds.push_back(uvBufferId);
  _uvBufferIds.push_back(std::shared_ptr<GLuint>(&uvBufferId, std::bind(freeBuffer, uvBufferId)));

  glBindBuffer(GL_ARRAY_BUFFER, uvBufferId);
  glBufferData(GL_ARRAY_BUFFER, values.size() * sizeof(values[0]), &values[0], GL_STATIC_DRAW);
}
Exemplo n.º 2
0
void GrowingLimb::grow(float amount)
{
	if (length < MaxLength)
	{
		const float rate = 0.2;// * (MaxLength - length)/(MaxLength);
		length += amount * rate;
	}

	recalculateBounds();
	for (GrowingLimb *child : children)
	{
		child->grow(amount);
	}

	int lengthPastSubdivide = length - MinSubdivideLength;
	if (lengthPastSubdivide < 0) lengthPastSubdivide = 0;

	if (limbCapacity > children.size() && length >= MinSubdivideLength/chainDepth && je::randomf(length * 100) < length/(children.size() + 1))
	{
		sf::Transformable trans = transform();
		if ((trans.getPosition() + je::lengthdir(MaxLength, -trans.getRotation())).y < static_cast<World*>(level)->getGroundLevel())
		{
			GrowingLimb* child = tree->subdivide(this);

			if (child)
			{
				child->parent = this;
				//child->updateBoneTransform(sf::Vector2f(), sf::Vector2f(1.f, 1.f), sf::Vector2f(0.f, 0.f), 30.f - je::randomf(60.f));
					children.push_back(child);
				leaves.clear();
				if (fruit)
				{
					children.back()->fruit = fruit;
					fruit = nullptr;
				}
			}
		}
	}
}
Exemplo n.º 3
0
GrowingLimb::GrowingLimb(je::Level *level, const sf::Vector2f& pos, Tree* base, int capacity, int parentDepth)
	:je::Entity(level, "GrowingLimb", pos, sf::Vector2i(32, 32))
	,children()
	,chainDepth(++parentDepth)
	,vertices(4)
	,length(2.f)
	,angle(0.f)
	,MaxLength(GrowingLimb::MaxLengthLimit/chainDepth)
	,MinSubdivideLength(GrowingLimb::MinSubdivideLengthLimit/chainDepth)
	,limbTransform()
	,parent(nullptr)
	,tree(base)
	,limbCapacity(capacity)
	,fruit(nullptr)
{
	vertices.setTexture(&level->getGame().getTexManager().get("bark.png"));

	recalculateBounds();

	if (chainDepth >= 3)
		spawnLeaves(2 + je::random(3));
}
Exemplo n.º 4
0
bool MapView::reposition(const Ogre::Vector2& pos)
{
	int halfViewSizeMeters((mMap.getResolutionMeters() * mViewSize)/ 2);
	//check if we need to reposition the camera
	if (pos.x - halfViewSizeMeters < mFullBounds.left || pos.x + halfViewSizeMeters > mFullBounds.right
		|| pos.y - halfViewSizeMeters < mFullBounds.bottom || pos.y + halfViewSizeMeters > mFullBounds.top) {
		mMapCamera.reposition(pos);
		mMapCamera.render();

		recalculateBounds();

		return true;
	}
	mRelativeViewPosition.x = (pos.x - mFullBounds.left) / static_cast<float>(mMap.getResolutionMeters());
	mRelativeViewPosition.y = (pos.y - mFullBounds.bottom) / static_cast<float>(mMap.getResolutionMeters());
	float halfViewSize = mViewSize / 2;
	mVisibleRelativeBounds.left = mRelativeViewPosition.x - halfViewSize;
	mVisibleRelativeBounds.right= mRelativeViewPosition.x + halfViewSize;
	mVisibleRelativeBounds.bottom = mRelativeViewPosition.y - halfViewSize;
	mVisibleRelativeBounds.top = mRelativeViewPosition.y + halfViewSize;
	return false;

}