Ejemplo n.º 1
0
void EditorGesture::TouchBegan(Touch* touch)
{
	if (touch->GetSurface() != _battleView->GetSurface())
		return;

	if (_editorModel->GetEditorMode() == EditorMode::Hand)
	{
		bounds2f b = _battleView->GetContentBounds();
		glm::vec2 p = (TerrainPosition(touch) - b.min) / b.size();

		static glm::vec2 old;
		if (old != glm::vec2())
		{
			glm::vec2 d = p - old;
			float a = 90 - glm::round(glm::degrees(glm::atan(d.y, d.x)));
			while (a > 360)
				a -= 360;
			while (a < 0)
				a += 360;
			//NSLog(@"Angle: %g", a);
		}
		old = p;

		//NSLog(@"Position: %g, %g", p.x, p.y);
		return;
	}

	if (touch->HasGesture() || !_touches.empty())
		return;

	_editorModel->ToolBegan(TerrainPosition(touch));
	CaptureTouch(touch);
}
Ejemplo n.º 2
0
	void testAlterTerrain()
	{

		Ogre::Root root;
		TerrainSetup terrainSetup;

		Terrain::TerrainHandler& terrainHandler = terrainSetup.terrainHandler;
		CPPUNIT_ASSERT(terrainSetup.createBaseTerrain(25.0f));
		CPPUNIT_ASSERT(terrainSetup.createPages());
		CPPUNIT_ASSERT(terrainSetup.reloadTerrain());

		TerrainDefPointStore terrainDefPoints;
		terrainDefPoints.push_back(TerrainDefPoint(-1, -1, -200));
		terrainDefPoints.push_back(TerrainDefPoint(-1, 0, -200));
		terrainDefPoints.push_back(TerrainDefPoint(0, -1, -200));
		terrainDefPoints.push_back(TerrainDefPoint(0, 0, -200));

		terrainHandler.updateTerrain(terrainDefPoints);

		AfterTerrainUpdateListener afterTerrainUpdateListener(terrainHandler.EventAfterTerrainUpdate);

		{
			Timer timer;
			do {
				terrainSetup.es.processAllHandlers();
			} while ((!timer.hasElapsed(5000)) && afterTerrainUpdateListener.getCompletedCount() < 4);
		}
		CPPUNIT_ASSERT(afterTerrainUpdateListener.getCompletedCount() == 4);
		CPPUNIT_ASSERT(terrainHandler.getTerrainInfo().getTotalNumberOfPagesX() == 2);
		CPPUNIT_ASSERT(terrainHandler.getTerrainInfo().getTotalNumberOfPagesY() == 2);
		float height = 0;
		CPPUNIT_ASSERT(terrainHandler.getHeight(TerrainPosition(-32, -32), height));
		CPPUNIT_ASSERT(height == -200);
	}
Ejemplo n.º 3
0
//Gets the height of the terrain at the specified x/z coordinate
//The userData parameter isn't used in this implementation of a height function, since
//there's no need for extra data other than the x/z coordinates.
double getTerrainHeight(double x, double z, void* userData)
{
	IHeightProvider* heightProvider = reinterpret_cast<IHeightProvider*>(userData);
	float height = 0;
	heightProvider->getHeight(TerrainPosition(x, -z), height);
	return (double)height;
}
Ejemplo n.º 4
0
//Gets the height of the terrain at the specified x/z coordinate
//The userData parameter isn't used in this implementation of a height function, since
//there's no need for extra data other than the x/z coordinates.
float getTerrainHeight(float x, float z, void* userData)
{
	IHeightProvider* heightProvider = reinterpret_cast<IHeightProvider*>(userData);
	float height = 0;
	heightProvider->getHeight(TerrainPosition(x, -z), height);
	return height;
}
Ejemplo n.º 5
0
	bool reloadTerrain()
	{
		AfterTerrainUpdateListener afterTerrainUpdateListener(terrainHandler.EventAfterTerrainUpdate);
		std::vector<TerrainPosition> positions;
		positions.push_back(TerrainPosition(-32, -32));
		positions.push_back(TerrainPosition(-32, 32));
		positions.push_back(TerrainPosition(32, 32));
		positions.push_back(TerrainPosition(32, -32));

		terrainHandler.reloadTerrain(positions);

		{
			Timer timer;
			do {
				es.processAllHandlers();
			} while ((!timer.hasElapsed(5000)) && afterTerrainUpdateListener.getCompletedCount() < 4);
		}
		CPPUNIT_ASSERT(afterTerrainUpdateListener.getCompletedCount() == 4);
		return true;
	}
Ejemplo n.º 6
0
const SegmentVector TerrainPageGeometry::getValidSegments() const
{
	SegmentVector validSegments;
	for (SegmentRefStore::const_iterator I = mLocalSegments.begin(); I != mLocalSegments.end(); ++I) {
		for (SegmentRefColumn::const_iterator J = I->second.begin(); J != I->second.end(); ++J) {
			Mercator::Segment& segment = J->second->getMercatorSegment();
			PageSegment pageSegment;
			pageSegment.index = TerrainPosition(I->first, J->first);
			pageSegment.segment = &segment;

			validSegments.push_back(pageSegment);
		}
	}
	return validSegments;
}
Ejemplo n.º 7
0
	/**
	 * @brief Updates the marker, and any line drawn to it.
	 */
	void updateMarker()
	{
		//Check if we should adjust to the height of the world
		WFMath::Point<3> adjustedPoint(mPoint);

		float height = adjustedPoint.z();
		if (mHeightProvider.getHeight(TerrainPosition(mPoint.x(), mPoint.y()), height)) {
			adjustedPoint.z() = height;
		}

		mMarkerNode->setPosition(Convert::toOgre(adjustedPoint));

		WFMath::Segment<3> shape(adjustedPoint, mEntity.getViewPosition() + WFMath::Vector<3>(mEntity.getBBox().getCenter()));
		mMarkerDirectionIndicator->update(shape);

	}
Ejemplo n.º 8
0
	void testCreateTerrain()
	{

		Ogre::Root root;

		TerrainSetup terrainSetup;

		float terrainHeight = 25.0f;

		CPPUNIT_ASSERT(terrainSetup.createBaseTerrain(terrainHeight));
		CPPUNIT_ASSERT(terrainSetup.createPages());
		CPPUNIT_ASSERT(terrainSetup.reloadTerrain());

		CPPUNIT_ASSERT(terrainSetup.terrainHandler.getTerrainInfo().getTotalNumberOfPagesX() == 2);
		CPPUNIT_ASSERT(terrainSetup.terrainHandler.getTerrainInfo().getTotalNumberOfPagesY() == 2);
		float height = 0;
		CPPUNIT_ASSERT(terrainSetup.terrainHandler.getHeight(TerrainPosition(-1, -1), height));
		CPPUNIT_ASSERT(height == terrainHeight);

	}
Ejemplo n.º 9
0
void TerrainUpdateTask::executeTaskInBackgroundThread(Tasks::TaskExecutionContext& context)
{
	int terrainRes = mTerrain.getResolution();
	for (TerrainDefPointStore::const_iterator I = mTerrainPoints.begin(); I != mTerrainPoints.end(); ++I) {
		Mercator::BasePoint bp;
		const TerrainPosition& pos = I->position;
		if (mTerrain.getBasePoint(static_cast<int> (pos.x()), static_cast<int> (pos.y()), bp) && (WFMath::Equal(I->height, bp.height()))
				&& (WFMath::Equal(I->roughness, bp.roughness()) && (WFMath::Equal(I->falloff, bp.falloff())))) {
			S_LOG_VERBOSE("Point [" << pos.x() << "," << pos.y() << "] unchanged");
			continue;
		} else {
			S_LOG_VERBOSE("Setting base point [" << pos.x() << "," << pos.y() << "] to height " << I->height);
		}
		bp.height() = I->height;
		bp.roughness() = I->roughness;
		bp.falloff() = I->falloff;

		// FIXME Sort out roughness and falloff, and generally verify this code is the same as that in Terrain layer
		mTerrain.setBasePoint(static_cast<int> (pos.x()), static_cast<int> (pos.y()), bp);
		mUpdatedBasePoints.push_back(UpdateBasePointStore::value_type(pos, bp));
		mUpdatedPositions.push_back(TerrainPosition(pos.x() * terrainRes, pos.y() * terrainRes));
	}
	mSegmentManager.syncWithTerrain();
}
Ejemplo n.º 10
0
	/**
	 * Checks the height, using an integer.
	 * This is because of the floats being used, we can't be 100% certain that a piece of terrain should be exactly the specified height.
	 */
	bool checkTerrainHeight(float x, float y, int height)
	{
		float realHeight = 0;
		getHeight(TerrainPosition(x,y), realHeight);
		return (int)(realHeight) == height;
	}
Ejemplo n.º 11
0
void EditorGesture::TouchEnded(Touch* touch)
{
	_editorModel->ToolEnded(TerrainPosition(touch));

}
Ejemplo n.º 12
0
void EditorGesture::TouchMoved()
{
	if (!_touches.empty())
		_editorModel->ToolMoved(TerrainPosition(_touches.front()));
}