Ejemplo n.º 1
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;
}
Ejemplo n.º 2
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;
}
Ejemplo 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);
	}
Ejemplo n.º 4
0
	void GeometryManager::_updateGeometry(Ogre::Camera* c, const Ogre::Real& timeSinceLastFrame)
	{
		// Look for current camera data
		std::vector<VClouds::CameraData>& camerasData = mVClouds->_getCamerasData();
		std::vector<VClouds::CameraData>::iterator currentCameraDataIt;

		for (currentCameraDataIt = camerasData.begin(); currentCameraDataIt != camerasData.end(); currentCameraDataIt++)
		{
			if ((*currentCameraDataIt).camera == c)
			{
				break;
			}
		}

		std::vector<VClouds::CameraData>::reference currentCameraData = (*currentCameraDataIt);

		// Calculate wind offset
		Ogre::Vector2 CameraDirection = Ogre::Vector2(c->getDerivedDirection().x, c->getDerivedDirection().z);
		float offset = - CameraDirection.dotProduct(mVClouds->getWindDirectionV2()) * mVClouds->getWindSpeed() * timeSinceLastFrame;

		// Calculate camera offset
		Ogre::Vector2 CameraOffset = Ogre::Vector2(c->getDerivedPosition().x - currentCameraData.lastPosition.x, c->getDerivedPosition().z - currentCameraData.lastPosition.z);
		offset -= CameraOffset.dotProduct(CameraDirection);

		// Update camera data
		currentCameraData.cameraOffset += CameraOffset;
		currentCameraData.lastPosition = c->getDerivedPosition();

		// Update geometry displacement
		currentCameraData.geometryDisplacement += Ogre::Vector3(offset);

		if (currentCameraData.geometryDisplacement.z < 0 || currentCameraData.geometryDisplacement.z > (mC-mB)/mNc)
		{
			currentCameraData.geometryDisplacement.z -= ((mC-mB)/mNc)*Ogre::Math::IFloor((currentCameraData.geometryDisplacement.z)/((mC-mB)/mNc));
		}

		if (currentCameraData.geometryDisplacement.y < 0 || currentCameraData.geometryDisplacement.y > (mB-mA)/mNb)
		{
			currentCameraData.geometryDisplacement.y -= ((mB-mA)/mNb)*Ogre::Math::IFloor((currentCameraData.geometryDisplacement.y)/((mB-mA)/mNb));
		}

		if (currentCameraData.geometryDisplacement.x < 0 || currentCameraData.geometryDisplacement.x > mA/mNa)
		{
			currentCameraData.geometryDisplacement.x -= (mA/mNa)*Ogre::Math::IFloor((currentCameraData.geometryDisplacement.x)/(mA/mNa));
		}

		// Check under/over cloud rendering
		mCurrentDistance = c->getDerivedPosition()-mSceneNode->_getDerivedPosition();

		for (int k = 0; k < mNumberOfBlocks; k++)
		{
			mGeometryBlocks.at(k)->setWorldOffset(mWorldOffset + currentCameraData.cameraOffset);
			mGeometryBlocks.at(k)->updateGeometry(c, currentCameraData.geometryDisplacement, mCurrentDistance);
		}
	}
Ejemplo n.º 5
0
bool TottAIStateMove::Update(float dt){
	AnimationMsg anim_msg;
	anim_msg.id = m_animation;
	anim_msg.loop = true;
	m_messenger->Notify(MSG_ANIMATION_PLAY, &anim_msg);
	m_messenger->Notify(MSG_NODE_GET_POSITION, &m_current_position);
	Ogre::Vector2 pos(m_current_position.x, m_current_position.z);
	float distance = pos.distance(m_target_position);
	if (distance <= 1.0f){
		return true;
	}
	Ogre::Vector2 dir = m_target_position - pos;
	dir.normalise();
	Ogre::Vector3 new_dir(dir.x, 0.0f, dir.y);
	m_messenger->Notify(MSG_CHARACTER_CONTROLLER_SET_DIRECTION, &new_dir);
	return false;
}
	void GeometryManager::_updateGeometry(const Ogre::Real& timeSinceLastFrame)
	{
		// Calculate wind offset
		Ogre::Vector2 CameraDirection = Ogre::Vector2(mVClouds->getCamera()->getDerivedDirection().x, mVClouds->getCamera()->getDerivedDirection().z);
		float offset = - CameraDirection.dotProduct(mVClouds->getWindDirectionV2()) * mVClouds->getWindSpeed() * timeSinceLastFrame;
		mWorldOffset += mVClouds->getWindDirectionV2() * mVClouds->getWindSpeed() * timeSinceLastFrame;

		// Calculate camera offset
		Ogre::Vector2 CameraOffset = Ogre::Vector2(mVClouds->getCamera()->getDerivedPosition().x - mLastCameraPosition.x, mVClouds->getCamera()->getDerivedPosition().z - mLastCameraPosition.z);
		offset -= CameraOffset.dotProduct(CameraDirection);
		mWorldOffset += CameraOffset;

		for (int k = 0; k < mNumberOfBlocks; k++)
		{
			mGeometryBlocks.at(k)->update(offset);
			mGeometryBlocks.at(k)->setWorldOffset(mWorldOffset);
		}
	}
Ejemplo n.º 7
0
bool LagomPlayerBase::checkConstructionRestriction(LagomActorFactory* type,const Ogre::Vector2& location)
{
	if(_selectedActorFactory == _actorFactories.end())
		return false;

	if(_constructionRestrictedType && _constructionRestrictedType != type)
		return false;

	if(location.squaredDistance(_constructionRestrictedLocation) > _constructionRestrictedTolerance*_constructionRestrictedTolerance)
		return false;

	float squareCollision = type->CollisionRange + getIntFactory().CollisionRange;
	squareCollision*=squareCollision;

	if(location.squaredLength() < squareCollision)
		return false;

	return true;
}
Ejemplo n.º 8
0
AIHall::AIHall(bool bIsAttacking, int type, int race, Ogre::Vector2 position, Ogre::Vector2 orientation)
{
    m_bIsAttacking = bIsAttacking;
    m_iType = type;
    m_vPos = position;
    m_iCollisionType = square;
    m_vPrevPos = m_vPos;
    m_vOri = orientation.normalisedCopy();
    m_dRadius = 80.0;

    MessageSystem::getSingletonPtr()->DispatchMessageToGraphFactory(this->ID(), factoryGraph, SMSG_AICreateGraphBuilding, position, m_vOri, type, race, Vector2(m_dActualHealth, m_dTotalHealth));

    m_pStateMachine = new AIStateSystem<AIHall>(this);
    m_pStateMachine->SetCurrentState(PeaceHall::Instance());

}
Ejemplo n.º 9
0
projectile::projectile(float speedboost, Ogre::Vector2 acceleration, float heaviness) : 
           movableObject("projectile", heaviness) {
 // num++;
/*  this->acceleration = acceleration;
  acceleration.normalise();
  acceleration *= speedboost;
  this->accelerate(&acceleration);
  */
  
  this->speed += acceleration;
  acceleration.normalise();
  acceleration *= speedboost;
  this->speed += acceleration;
  
  this->ObjectName = "projectile";
}
Ejemplo n.º 10
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();
	}
Ejemplo n.º 11
0
//-----------------------------------------------------------------------
void Triangulator::addConstraints(const Shape& shape, DelaunayTriangleBuffer& tbuffer)
{	
	std::vector<DelaunaySegment> segList;
	// Determine which segments should be added
	for (int i = 0; i<shape.getPoints().size()-1; i++)
	{		
		bool isAlreadyIn = false;
		for (DelaunayTriangleBuffer::iterator it = tbuffer.begin(); it!=tbuffer.end();it++)
		{
			if (it->containsSegment(i,i+1)) 
			{
					isAlreadyIn = true;
					break;
			}			
		}
		// only do something for segments not already in DT
		if (!isAlreadyIn)
		{
			segList.push_back(DelaunaySegment(i, i+1));
		}
	}
	// Re-Triangulate according to the new segments
	for (std::vector<DelaunaySegment>::iterator it=segList.begin();it!=segList.end();it++)
	{
		// TODO remove all edges intersecting *it
		// TODO build two polygons
		// TODO Triangulate each polygon (directly into DelaunayTriangleBuffer)
	}
	// Clean up segments outside of shape
	if (shape.isClosed())
	{
		for (DelaunayTriangleBuffer::iterator it = tbuffer.begin(); it!=tbuffer.end();it++)
		{
			bool isTriangleOut = false;
			for (int i=0;i<3;i++)
			{
				int ind1 = it->i[i];
				int ind2 = it->i[(1+i)%3];					
				// if side of triangle==segment, it won't tell us if outside or inside => skip
				if (abs(ind1-ind2)!=1)
				{
					Ogre::Vector2 v = shape.getPoint(ind2)-shape.getPoint(ind1);
					Ogre::Real d1 = v.dotProduct(shape.getNormalBefore(ind1));
					Ogre::Real d2 = v.dotProduct(shape.getNormalAfter(ind1));
					Ogre::Vector2 t1 = shape.getDirectionBefore(ind1);
					Ogre::Vector2 n1 = shape.getNormalAfter(ind1);
					if (t1.dotProduct(n1)>0.)
					{
						if (d1>0. || d2>0.)
						{
							isTriangleOut = true;
							break;
						}
					}
					else
					{
						if (d1>0. && d2>0.)
						{
							isTriangleOut = true;
							break;
						}
					}					
				}
			}
			if (isTriangleOut)
			{
				it = tbuffer.erase(it);
				it--;
			}
		}			
	}

}