Exemplo n.º 1
0
std::list<Ogre::Vector2> WindManager::subdivideCurrent(Ogre::Vector2 origin, Ogre::Vector2 current)
{
	// The list for storing the subdivided vector
	std::list<Ogre::Vector2> subdivideList;

	Ogre::Vector2 subVector;

	// While the wind current vector is too long
	while(current.length() > this->mWorld->getWindMap()->getAlphaVector().length())
	{
		// Calculate the subvector to the size of the alpha vector
		subVector = current.normalisedCopy() * this->mWorld->getWindMap()->getAlphaVector().length();

		// Move the origin forward to the end of the next subvector
		origin += subVector;

		// Store the found subvector in the subdivision list
		subdivideList.push_back(origin);

		// Cut off the subVector
		current -= subVector;
	}

	// Add the final point of the wind current
	subdivideList.push_back(origin + current);

	// Return the subdivided wind current vector
	return subdivideList;
}
Exemplo n.º 2
0
void WindManager::addPoint(Ogre::Vector2& newPosition)
{
	// Sanitize the point to world border if it's out of bounds.
	if (newPosition.x > mWorld->getWorldBounds().x - mWorld->getWindMap()->getOffset().x) {
		newPosition.x = mWorld->getWorldBounds().x - mWorld->getWindMap()->getOffset().x;
	} if (newPosition.x < mWorld->getWindMap()->getOffset().x - mWorld->getWorldBounds().x) {
		newPosition.x = mWorld->getWindMap()->getOffset().x - mWorld->getWorldBounds().x;
	} if (newPosition.y > mWorld->getWorldBounds().y - mWorld->getWindMap()->getOffset().y) {
		newPosition.y = mWorld->getWorldBounds().y - mWorld->getWindMap()->getOffset().y;
	} if(newPosition.y < mWorld->getWindMap()->getOffset().y - mWorld->getWorldBounds().y) {
		newPosition.y = mWorld->getWindMap()->getOffset().y - mWorld->getWorldBounds().y;
	}

	// If we've already started creating the wind current
	if(mCurrentPosition != Ogre::Vector2::ZERO)
	{
		// Calculate the delta between the new position and the previous position
		Ogre::Vector2 deltaVector = newPosition - mCurrentPosition;

		// Only add the new position if the delta isn't zero
		if(deltaVector.length() > mEssentiallyZero.length())
		{
			// Create the arrow facing in the direction of the created current
			createArrow(mCurrentPosition, deltaVector, ArrowType::RED);

			// Add the new point to the wind current
			this->mWindCurrent->addPoint(mCurrentPosition, deltaVector);
		} else {
			return;
		}
	}

	// Update the current position, because we're dynamic
	mCurrentPosition = newPosition;
}
Exemplo n.º 3
0
	Ogre::Vector2 Mesh::getGridPosition(const Ogre::Vector2 &Position)
	{
		if (mOptions.MeshSize.Width == 0 && mOptions.MeshSize.Height == 0)
		{
			return Position;
		}

		if (!isPointInGrid(Position))
		{
			return Ogre::Vector2(-1,-1);
		}

		Ogre::AxisAlignedBox WordMeshBox = mEntity->getWorldBoundingBox();

		// Get our mesh grid rectangle: (Only a,b,c corners)
		// c
		// |           
		// |           
		// |           
		// a-----------b
		Ogre::Vector3
			a = WordMeshBox.getCorner(Ogre::AxisAlignedBox::FAR_LEFT_BOTTOM),
			b = WordMeshBox.getCorner(Ogre::AxisAlignedBox::FAR_RIGHT_BOTTOM),
			c = WordMeshBox.getCorner(Ogre::AxisAlignedBox::NEAR_LEFT_BOTTOM);

		// Transform all corners to Ogre::Vector2 array
		Ogre::Vector2 Corners2D[3] =
		   {Ogre::Vector2(a.x, a.z), 
		    Ogre::Vector2(b.x, b.z), 
		    Ogre::Vector2(c.x, c.z)};

		// Get segments AB and AC
		Ogre::Vector2 AB = Corners2D[1]-Corners2D[0],
			          AC = Corners2D[2]-Corners2D[0];

		// Find the X/Y position projecting the Position point to AB and AC segments.
		Ogre::Vector2 XProjectedPoint = Position-AC,
			          YProjectedPoint = Position-AB;

		// Fint the intersections points
		Ogre::Vector2 XPoint = Math::intersectionOfTwoLines(Corners2D[0],Corners2D[1],Position,XProjectedPoint),
			          YPoint = Math::intersectionOfTwoLines(Corners2D[0],Corners2D[2],Position,YProjectedPoint);
		
		// Find lengths
		Ogre::Real ABLength = AB.length(),
			       ACLength = AC.length(),
				   XLength  = (XPoint-Corners2D[0]).length(),
				   YLength  = (YPoint-Corners2D[0]).length();

		// Find final x/y grid positions in [0,1] range
		Ogre::Real XFinal = XLength / ABLength,
			       YFinal = YLength / ACLength;

		return Ogre::Vector2(XFinal,YFinal);
	}
Exemplo n.º 4
0
	void GodRaysManager::_updateRays()
	{
		// Get frustum corners to calculate far plane dimensions
		const Ogre::Vector3 *FrustumCorners = mProjectorCamera->getWorldSpaceCorners();
		// Calcule far plane dimensions
		float FarWidth   = (FrustumCorners[4] - FrustumCorners[5]).length();
		Ogre::Real RaysLength = mProjectorCamera->getFarClipDistance();

		mManualGodRays->beginUpdate(0);

		Ogre::Vector2 Pos;
		Ogre::Real Dis, RayLength;

		// Rays are modeled as piramids, 12 vertex each ray
		//        
		//       // 0\\
		//      /|    | |
		//      ||    | |
		//      ||    | |     (0,0)   (1,0)
		//      ||    | |     A       B
		//      ||    | |
		//      |A----|-|B    (0,1)   (1,1)
		//      |/    |/      C       D
		//     C------D

		for(int k = 0; k < mNumberOfRays; k++)
		{
			Pos       = _calculateRayPosition(k);
			Dis       = mRaysSize*RaysLength;
            RayLength = RaysLength*(0.95+Pos.length());

            Pos *= FarWidth/2;

			// 4 Planes, 3 vertices each plane, 12 vertices per ray
			// ----> 1/4
		    // 0
            mManualGodRays->position(0, 0, 0);
		    // A
            mManualGodRays->position(Pos.x, Pos.y, -RayLength);
		    // B
            mManualGodRays->position(Pos.x+Dis, Pos.y, -RayLength);
			// ----> 2/4
		    // 0
            mManualGodRays->position(0, 0, 0);
		    // D
            mManualGodRays->position(Pos.x+Dis, Pos.y+Dis, -RayLength);
		    // B
            mManualGodRays->position(Pos.x+Dis, Pos.y, -RayLength);
			// ----> 3/4
		    // 0
            mManualGodRays->position(0, 0, 0);
		    // C
            mManualGodRays->position(Pos.x, Pos.y+Dis, -RayLength);
		    // D
            mManualGodRays->position(Pos.x+Dis, Pos.y+Dis, -RayLength);
			// ----> 4/4
		    // 0
            mManualGodRays->position(0, 0, 0);
		    // C
            mManualGodRays->position(Pos.x, Pos.y+Dis, -RayLength);
		    // A
            mManualGodRays->position(Pos.x, Pos.y, -RayLength);
		}

		mManualGodRays->end();
	}