void Arrow::setDirection( const Ogre::Vector3& direction )
{
  if( !direction.isZeroLength() )
  {
    setOrientation( Ogre::Vector3::NEGATIVE_UNIT_Z.getRotationTo( direction ));
  }
}
void SmallShip::translate(Ogre::Vector3 _up, Ogre::Vector3 _right, Ogre::Vector3 _forward)
{
	if(!_up.isZeroLength()){
		up = _up;
		drift_Direction += _up * accel_Rate;
	}
	if(!_right.isZeroLength()){
		right = _right;
		drift_Direction += _right * accel_Rate;
	}
	if(!_forward.isZeroLength()){
		direction = _forward;
		drift_Direction += _forward * accel_Rate;
	}
	
	m_pNode->needUpdate();
}
void AnimalThirdPersonControler::alignAnimalToCamera(double i_timeSinceLastFrame)
{
	if (!(m_pAnimal != nullptr && m_pCamera != nullptr))
		return;

	// Find new orientation of avatar
	Ogre::Vector3 camY = m_pCamera->getDirection();
	Ogre::Vector3 aniX = m_pAnimal->m_pNode->getOrientation().xAxis();
	Ogre::Vector3 aniY = m_pAnimal->m_pNode->getOrientation().yAxis();
	Ogre::Vector3 newAniX = camY.dotProduct(aniX) * aniX + camY.dotProduct(aniY) * aniY;
	if (newAniX.isZeroLength())
		return;
	newAniX.normalise();
	m_pAnimal->turn(newAniX, i_timeSinceLastFrame);
}
void CollisionResponse::Response(IPhysical* object, Ogre::Vector3 point, Ogre::Vector3 normal)
{		
    Ogre::Vector3 vretreat = object->GetPosition()-Owner->GetPosition();
    vretreat.normalise();

    object->SetForces(Ogre::Vector3::ZERO);
    object->AddCollisionImpulse(point, (normal+vretreat)*Owner->GetMass()/object->GetMass(), &Owner->GetDescriptor()); //*object->GetMass()/10	

    Ogre::Vector3 linvel = object->GetLinVelocity();	
    Ogre::Vector3 throttle = object->GetThrottle();
    if (!throttle.isZeroLength())
        object->SetThrottle(-throttle);	
    else
        object->AddForce(point, (normal+vretreat)*Owner->GetMass()/object->GetMass()); //*object->GetMass()/2

    object->SetCollided(true); //Descriptor->Collided=true;
}
void AIInConeAttackStrategy::Step(unsigned timeMs)
{        
    IScenable *scen = Parent->GetScenable();
	
	if (TargetID<0)
	{		
		return;
	}
	if (TargetID==0)
	{
		if (Owner)
		{
			TargetID = Owner->SelectTargetID();			
		}
		if (TargetID<=0)
		{
			TargetID=-1;
			IEquipped *eq = Parent->GetEquipped();
			eq->SetTargetPosition(Ogre::Vector3::ZERO);
			eq->SetShooting(false);
			return;
		}
	}
		
	IAAObject *obj = CommonDeclarations::GetIDObject(TargetID);
	if (NULL==obj)
	{		
		TargetID=0;
		return;
	}
		
	IScenable* Target;	
	Target = obj->GetScenable();
	if (NULL==Target/* || phys->IsCollided()*/)
		return;
	
	if(RotationUnit.mRotating)
	{
		RotationUnit.Step();
		if(RotationUnit.mRotating)                                // Process timed rotation
		{				
			Ogre::Quaternion delta = RotationUnit.Slerp();	
			scen->SetOrientation(delta);
		}
	}// else
	{	
		int actual_rotation_speed = RotationSpeed;
		IPhysical *phys = Parent->GetPhysical();
        AICommander *commander = Owner->GetCommander();
        Ogre::Vector3 src = Ogre::Vector3::ZERO;
        if (commander)
        {
            IAAObject *obj = commander->GetParent();
            if (obj)
            {
                IScenable *scen = obj->GetScenable();
                if (scen)
                {
                    src = scen->GetOrientation()*Ogre::Vector3::NEGATIVE_UNIT_Z;
                }
            }
        } else
        {
            src = -phys->GetForwardDirection(); //OurOrientation * Ogre::Vector3::NEGATIVE_UNIT_Z;
        }
		
		Ogre::Vector3 direction = Target->GetPosition()-scen->GetPosition();
        direction.normalise();

        Ogre::Real cs = src.dotProduct(direction);
        if (src.isZeroLength() || cs>=AngleCosinusModule)
        {
			actual_rotation_speed = actual_rotation_speed/2;
			/*char log[100];
			sprintf(log,"in cone %f %f %f\n",direction.x, direction.y, direction.z);
			Debugging::Log("icas",log);*/			
        } else
		{			
			direction = src;
			/*char log[100];
			sprintf(log,"not in cone %f %f %f\n",direction.x, direction.y, direction.z);
			Debugging::Log("icas",log);*/
		}

        Ogre::Vector3 up =CommonDeclarations::GetUpVector();

		Ogre::Quaternion OurOrientation = scen->GetOrientation();
		Vector3 xVec = up.crossProduct(direction);
		xVec.normalise();
		Vector3 yVec = direction.crossProduct(xVec);
		yVec.normalise();
		Quaternion unitZToTarget = Quaternion(xVec, yVec, direction);

		Quaternion targetOrientation = Quaternion(-unitZToTarget.y, -unitZToTarget.z, unitZToTarget.w, unitZToTarget.x);

		RotationUnit.StartRotation(OurOrientation, targetOrientation, actual_rotation_speed);
	}

	std::pair<bool, Ogre::Real> intersection_res;
		
	IEquipped *eq = Parent->GetEquipped();
	Ogre::Ray pl_ray = eq->GetSightRay();

	intersection_res = pl_ray.intersects(Target->GetBoundingBox(true));
	if (intersection_res.first)
	{
        eq->SetTargetPosition(Target->GetPosition(), intersection_res.second);
		eq->SetShooting(true);
	} else
    {
        eq->SetTargetPosition(Ogre::Vector3::ZERO);
        eq->SetShooting(false);
    }
		
}
Exemple #6
0
	bool PlaypenApp::appFrameStarted(opal::real dt)
	{
		// Do per-frame application-specific things here.

		// Handle speech input.
		bool keepLooping = true;
		bool makeObject = false;
		std::string material;
		ObjectType type;
		std::string outputString;
		while (voce::getRecognizerQueueSize() > 0)
		{
			std::string s = voce::popRecognizedString();

			//// Check if the string contains 'quit'.
			//if (std::string::npos != s.rfind("quit"))
			//{
			//	keepLooping = false;
			//}

			// Check if we should reset.
			if (std::string::npos != s.rfind("reset"))
			{
				// Make sure the PhysicalCamera isn't grabbing anything.
				mPhysicalCamera->release();
				destroyAllPhysicalEntities();
				setupInitialPhysicalEntities();
				voce::synthesize("reset");
				return true;
			}

			// Check for material color.
			if (std::string::npos != s.rfind("yellow"))
			{
				outputString += "yellow";
				material = "Plastic/Yellow";
			}
			else if (std::string::npos != s.rfind("red"))
			{
				outputString += "red";
				material = "Plastic/Red";
			}
			else if (std::string::npos != s.rfind("blue"))
			{
				outputString += "blue";
				material = "Plastic/Blue";
			}
			else if (std::string::npos != s.rfind("green"))
			{
				outputString += "green";
				material = "Plastic/Green";
			}
			else if (std::string::npos != s.rfind("purple"))
			{
				outputString += "purple";
				material = "Plastic/Purple";
			}
			else if (std::string::npos != s.rfind("orange"))
			{
				outputString += "orange";
				material = "Plastic/Orange";
			}
			else
			{
				// Default to dark gray.
				material = "Plastic/DarkGray";
			}

			// Check for object type.
			if (std::string::npos != s.rfind("box"))
			{
				outputString += " box";
				type = OBJECT_TYPE_BOX;
				makeObject = true;
			}
			else if (std::string::npos != s.rfind("sphere"))
			{
				outputString += " sphere";
				type = OBJECT_TYPE_SPHERE;
				makeObject = true;
			}
			else if (std::string::npos != s.rfind("wall"))
			{
				outputString += " wall";
				type = OBJECT_TYPE_WALL;
				makeObject = true;
			}
			else if (std::string::npos != s.rfind("tower"))
			{
				outputString += " tower";
				type = OBJECT_TYPE_TOWER;
				makeObject = true;
			}
			else if (std::string::npos != s.rfind("character"))
			{
				outputString += " character";
				type = OBJECT_TYPE_RAGDOLL;
				makeObject = true;
			}

			if (makeObject)
			{
				voce::synthesize(outputString);
				createObject(material, type);
			}
		}

		// Update the grasping spring line.
		if (mPhysicalCamera->isGrasping())
		{
			Ogre::Entity* pickingSphere = 
				mSceneMgr->getEntity("pickingSphere");
			if (!pickingSphere->isVisible())
			{
				pickingSphere->setVisible(true);
			}

			Ogre::Entity* springLine = 
				mSceneMgr->getEntity("springLine");
			if (!springLine->isVisible())
			{
				springLine->setVisible(true);
			}

			opal::Point3r desiredPos = 
				mPhysicalCamera->getGraspGlobalPos();
			Ogre::Vector3 point0(desiredPos[0], desiredPos[1], desiredPos[2]);

			opal::Point3r attachPos = mPhysicalCamera->getAttachGlobalPos();
			Ogre::Vector3 point1(attachPos[0], attachPos[1], attachPos[2]);

			pickingSphere->getParentSceneNode()->setPosition(point1);

			Ogre::Vector3 lineVec = point0 - point1;
			if (!lineVec.isZeroLength())
			{
				Ogre::SceneNode* springLineNode = 
					springLine->getParentSceneNode();
				springLineNode->setPosition(0.5 * (point0 + point1));
				
				springLineNode->setDirection(lineVec);
				springLineNode->setScale(0.1, 0.1, lineVec.length());
			}
			else
			{
				springLine->setVisible(false);
			}
		}
		else
		{
			Ogre::Entity* pickingSphere = 
				mSceneMgr->getEntity("pickingSphere");
			if (pickingSphere->isVisible())
			{
				pickingSphere->setVisible(false);
			}

			Ogre::Entity* springLine = 
				mSceneMgr->getEntity("springLine");
			if (springLine->isVisible())
			{
				springLine->setVisible(false);
			}
		}

		// Return true to continue looping.
		return keepLooping;
	}
Exemple #7
0
	bool PlaypenApp::appFrameStarted(opal::real dt)
	{
		// Do per-frame application-specific things here.

		// Update the grasping spring line.
		if (mPhysicalCamera->isGrasping())
		{
			Ogre::Entity* pickingSphere = 
				mSceneMgr->getEntity("pickingSphere");
			if (!pickingSphere->isVisible())
			{
				pickingSphere->setVisible(true);
			}

			Ogre::Entity* springLine = 
				mSceneMgr->getEntity("springLine");
			if (!springLine->isVisible())
			{
				springLine->setVisible(true);
			}

			opal::Point3r desiredPos = 
				mPhysicalCamera->getGraspGlobalPos();
			Ogre::Vector3 point0(desiredPos[0], desiredPos[1], desiredPos[2]);

			opal::Point3r attachPos = mPhysicalCamera->getAttachGlobalPos();
			Ogre::Vector3 point1(attachPos[0], attachPos[1], attachPos[2]);

			pickingSphere->getParentSceneNode()->setPosition(point1);

			Ogre::Vector3 lineVec = point0 - point1;
			if (!lineVec.isZeroLength())
			{
				Ogre::SceneNode* springLineNode = 
					springLine->getParentSceneNode();
				springLineNode->setPosition(0.5 * (point0 + point1));
				
				springLineNode->setDirection(lineVec, Ogre::Node::TS_WORLD);
				springLineNode->setScale(0.1, 0.1, lineVec.length());
			}
			else
			{
				springLine->setVisible(false);
			}
		}
		else
		{
			Ogre::Entity* pickingSphere = 
				mSceneMgr->getEntity("pickingSphere");
			if (pickingSphere->isVisible())
			{
				pickingSphere->setVisible(false);
			}

			Ogre::Entity* springLine = 
				mSceneMgr->getEntity("springLine");
			if (springLine->isVisible())
			{
				springLine->setVisible(false);
			}
		}

		// Return true to continue looping.
		return true;
	}
Exemple #8
0
void AACamera::Frame(unsigned timeMs)
{
	//Ogre::Quaternion q = Ogre::Quaternion::IDENTITY;
    /*if(CameraAdditionalRotation.mRotating)
    {
        CameraAdditionalRotation.Step();
        if(CameraAdditionalRotation.mRotating)
        {                
            RelativeOrientation = CameraAdditionalRotation.Slerp();                
			q = RelativeOrientation;
        }
    }*/
   
    Ogre::Vector3 accel = -PlayersObject->GetPhysical()->GetThrottle();
    accel.normalise();
	
	/*char log[100];
	sprintf(log,"1 %f %f %f\n", accel.x, accel.y, accel.z);
	Debugging::Log("cam",log);*/

    bool accel_is_zero = accel.isZeroLength();
	if (!accel_is_zero)
	{
		if (accel.x==0) {
			AdditionalRelativePosition.x*=RelativeShiftCoeffDump;
		}
		if (accel.y==0) {
			AdditionalRelativePosition.y*=RelativeShiftCoeffDump;
		}
		if (accel.z==0) {
			AdditionalRelativePosition.z*=RelativeShiftCoeffDump;
		}

		Ogre::Vector3 shift_size;
		
		shift_size.x = abs(AdditionalRelativePosition.x);
		shift_size.y = abs(AdditionalRelativePosition.y);
		shift_size.z = abs(AdditionalRelativePosition.z);
		
		if (shift_size.x>=RelativeShiftMax) {
			accel.x=0;
		} else
			if (shift_size.x>RelativeShiftMax-RelativeShiftSlowerBuffer)
			{
				accel.x/=2;
			}

		
		if (abs(AdditionalRelativePosition.y)>=RelativeShiftMax) {
			accel.y=0;
		} else
			if (shift_size.y>RelativeShiftMax-RelativeShiftSlowerBuffer)
			{
				accel.y/=2;
			}

		if (abs(AdditionalRelativePosition.z)>=RelativeShiftMax) {
			accel.z=0;
		} else
			if (shift_size.z>RelativeShiftMax-RelativeShiftSlowerBuffer)
			{
				accel.z/=2;
			}

		if (!accel.isZeroLength())
			AdditionalRelativePosition+=accel*RelativeShiftCoeffGrow;
	}
	else
		if (accel_is_zero && !AdditionalRelativePosition.isZeroLength())
			AdditionalRelativePosition*=RelativeShiftCoeffDump;
	
	//Node->setPosition(Position+AdditionalRelativePosition);
	
    HandleCameraCollision();

	UpdatePosition();
}
Exemple #9
0
void AILookStrategy::Step(unsigned timeMs)
{		
    IPhysical *phys = Parent->GetPhysical();
    IScenable *scen = Parent->GetScenable();
	
	if(RotationUnit.mRotating)
	{
		RotationUnit.Step();
		if(RotationUnit.mRotating)                                // Process timed rotation
		{				
			Ogre::Quaternion delta = RotationUnit.Slerp();	
			scen->SetOrientation(delta);
		}
	} else
	{
		Ogre::Quaternion OurOrientation = scen->GetOrientation();
		
		//Ogre::Vector3 src = OurOrientation * Ogre::Vector3::NEGATIVE_UNIT_Z;
		Ogre::Vector3 direction = Ogre::Vector3::ZERO;
		switch(LookType) {
		case LT_FORWARD:
			direction = -phys->GetForwardDirection();
			break;
		case LT_DIRECTION:			
			direction = Direction;
			break;
		case LT_OBJECT:
			{
				if (TargetID<0)
				{
					assert(false);					
				}

				if (TargetID==0)
				{
					if (Owner)
					{
						TargetID = Owner->SelectTargetID();			
					}					
				}

				IAAObject *obj = CommonDeclarations::GetIDObject(TargetID);
				//assert(obj);
				if (obj)
					direction = obj->GetPosition()-scen->GetPosition();			
				break;
			}
		};
				
		if (!direction.isZeroLength())
		{
			Vector3 xVec = Ogre::Vector3::UNIT_Y.crossProduct(direction);
			xVec.normalise();
			Vector3 yVec = direction.crossProduct(xVec);
			yVec.normalise();
			Quaternion unitZToTarget = Quaternion(xVec, yVec, direction);

			Quaternion targetOrientation = Quaternion(-unitZToTarget.y, -unitZToTarget.z, unitZToTarget.w, unitZToTarget.x);

			RotationUnit.StartRotation(OurOrientation, targetOrientation);
		}		

	}
}