void CCEtoODBView::recallView(CNamedView& namedView)
{
   ScaleNum   = namedView.getScaleNum();
   ScaleDenom = namedView.getScaleDenom();

   UpdateScale();

   SetXPos(namedView.getScrollX());
   SetYPos(namedView.getScrollY());

   GetDocument()->setLayerViewData(namedView);
   GetDocument()->UpdateAllViews(NULL);
}
Beispiel #2
0
void nuiScrollView::OnSmoothScrolling(const nuiEvent& rEvent)
{
  if (!mTimerOn)
    return;

  if (!mLeftClick)
  {
    float XOffset = mpHorizontal->GetRange().GetValue();
    float YOffset = mpVertical->GetRange().GetValue();

    float xdiff = XOffset - mXOffset;
    float ydiff = YOffset - mYOffset;

    if (xdiff > 2 || xdiff < -2)
      mXOffset += xdiff * NUI_SMOOTH_SCROLL_RATIO;
    else
      mXOffset = XOffset;

    if (ydiff > 2 || ydiff < -2)
      mYOffset += ydiff * NUI_SMOOTH_SCROLL_RATIO;
    else
      mYOffset = YOffset;

    if (mXOffset == XOffset && mYOffset == YOffset)
    {
      mTimerOn = false;
    }
    
    if (mSpeedX != 0)
    {
      SetXPos(GetXPos() + mSpeedX);
      //mXOffset = GetXPos();
      mSpeedX *= 0.7;
    }
    
    if (mSpeedY != 0)
    {
      SetYPos(GetYPos() + mSpeedY);
      //mYOffset = GetYPos();
      mSpeedY *= 0.7;
    }
  }

  
  UpdateLayout();
  OffsetsChanged();
}
Beispiel #3
0
bool CTerrain::LoadHeightMapFromFile(std::string filename)
{
	std::string line;
	std::ifstream inFile;

	if (mpHeightMap)
	{
		ReleaseHeightMap();
	}

	// Open the file.
	inFile.open(filename);

	// Check we successfully opened.
	if (!inFile.is_open())
	{
		logger->GetInstance().WriteLine("Failed to open the map file with name: " + filename);
		return false;
	}

	int height = 0;
	int width = 0;
	// Calculate the array size for now.
	while (std::getline(inFile, line))
	{
		// Reset the width count.
		width = 0;

		double value;
		std::stringstream  lineStream(line);

		// Go through this line.
		while (lineStream >> value)
		{
			// One more on the width!
			width++;
		}

		// Increment height.
		height++;
	}

	// Set width and height.
	mWidth = width;
	mHeight = height;

	inFile.close();
	inFile.open(filename);

	if (!inFile.is_open())
	{
		logger->GetInstance().WriteLine("Failed to open " + filename + ", but managed to open it the first time.");
		return false;
	}

	// Create height map.
	if (!mpHeightMap)
	{
		// Allocate memory to this array.
		mpHeightMap = new double*[mHeight];
	}

	// Iterate through all the rows.
	for (int x = 0; x < mHeight; x++)
	{
		// Allocate space for the columns.
		mpHeightMap[x] = new double[mWidth];
	}

	// Store the lowest point to be the first point.
	mLowestPoint = static_cast<float>(1000000.0f);
	// Store the highest point to be the first point.
	mHighestPoint = static_cast<float>(0.0f);

	// Create a heightmap.
	for (int y = 0; y < mHeight; y++)
	{
		// Get the line of this file.
		std::getline(inFile, line);
		std::stringstream  lineStream(line);
		double value;

		// Iterate through the width.
		for (int x = 0; x < mWidth; x++)
		{
			lineStream >> value;
			mpHeightMap[y][x] = value;

			/// Perform comparison.
			// If this point is lower than the one we have on record.
			if (mpHeightMap[y][x] < mLowestPoint)
			{
				// Store this as the lowest point.
				mLowestPoint = static_cast<float>(mpHeightMap[y][x]);
			}
			// If this point is higher than the highest point we have on record.
			else if (mpHeightMap[y][x] > mHighestPoint)
			{
				// Store this as the highest point.
				mHighestPoint = static_cast<float>(mpHeightMap[y][x]);
			}

		}
	}

	// Adjust the Y position of the map model to be equal to the lowest point.
	//SetYPos(0.0f - mLowestPoint);
	for (int y = 0; y < mHeight; y++)
	{
		// Iterate through the width.
		for (int x = 0; x < mWidth; x++)
		{
			mpHeightMap[y][x] -= mLowestPoint;
		}
	}

	// Set the X position to be half of the width.
	SetXPos(0 - (static_cast<float>(mWidth) / 2.0f));

	mHeightMapLoaded = true;

	return true;
}
Beispiel #4
0
/* LoadHeightMap - Loads in a height map (usually from a perlin noise function) and stores ptrs to the data. 
* @PARAM double ** heightMap - A dynamically allocated 2D array of type doubles, it must contain all the data to be used for the heightmap already.
* @WARNING: Must not delete the 2D array until after this class has been destroyed.
* @WARNING: Must set height and width before calling this function.
*/
void CTerrain::LoadHeightMap(double ** heightMap)
{
	// Copy the pointers to the 2D array and store them in memory.
	//mpHeightMap = heightMap;
	if (mpHeightMap == nullptr)
	{
		mpHeightMap = new double*[mHeight];

		for (int y = 0; y < mHeight; y++)
		{
			// Allocate space for the columns.
			mpHeightMap[y] = new double[mWidth];

			for (int x = 0; x < mWidth; x++)
			{
				mpHeightMap[y][x] = heightMap[y][x];
			}
		}
	}

	// Store the lowest point to be the first point.
	mLowestPoint = static_cast<float>(mpHeightMap[0][0]);
	// Store the highest point to be the first point.
	mHighestPoint = static_cast<float>(mpHeightMap[0][0]);
	
	// Outpout a log to let the user know where we're up to in the function.
	logger->GetInstance().WriteLine("Copied height map over to terrain, time to find the heights and lowest points.");
	
	// Iterate through the height.
	for (int y = 0; y < mHeight; y++)
	{
		// Iterate through the width.
		for (int x = 0; x < mWidth; x++)
		{
			/// Perform comparison.
			// If this point is lower than the one we have on record.
			if (mpHeightMap[y][x] < mLowestPoint)
			{
				// Store this as the lowest point.
				mLowestPoint = static_cast<float>(mpHeightMap[y][x]);
			}
			// If this point is higher than the highest point we have on record.
			else if (mpHeightMap[y][x] > mHighestPoint)
			{
				// Store this as the highest point.
				mHighestPoint = static_cast<float>(mpHeightMap[y][x]);
			}
		}
	}

	// Iterate through the height.
	for (int y = 0; y < mHeight; y++)
	{
		// Iterate through the width.
		for (int x = 0; x < mWidth; x++)
		{
			mpHeightMap[y][x] -= mLowestPoint;
		}
	}

	// TODO: Put this back in.
	// Adjust the Y position of the map model to be equal to the lowest point.
	//SetYPos(0.0f - mLowestPoint);

	// Set the X position to be half of the width.
	SetXPos(0 - (static_cast<float>(mWidth) / 2.0f));

	// We've loaded a map, set the flag!
	mHeightMapLoaded = true;
}