bool TutorialApplication::mouseMoved(const OIS::MouseEvent &arg)
{
    auto ret = BaseApplication::mouseMoved(arg);
//    std::cout << "moust at ("
//              << arg.state.X.abs << ","
//              << arg.state.Y.abs << ","
//              << arg.state.Z.abs << ")" << std::endl;
//    std::cout << "plane at Y = " << m_activeLevel.d << std::endl;

    Ray mouseRay = getMouseRay();

    if (m_verticalMode) {
        // ignored for now, untill I figure out how to make it intuitive
    } else {
        auto r = mouseRay.intersects(m_activeLevel);
        if (r.first) {
            auto pos = mouseRay.getPoint(r.second);
            auto gridPos =
                    Vector3(floor(pos.x / GRID_SPACING) * GRID_SPACING,
                            pos.y,
                            floor(pos.z / GRID_SPACING) * GRID_SPACING);
            m_cursorNode->setPosition(gridPos);
            auto pointPos =
                    Vector3(round(pos.x / GRID_SPACING) * GRID_SPACING,
                            pos.y,
                            round(pos.z / GRID_SPACING) * GRID_SPACING);
            m_pointNode->setPosition(pointPos);

            if (m_mode == WitchMode) {
                for (std::size_t i = 0; i < CONE_CASES.size(); i++) {
                    auto c = CONE_CASES[i];
                    bool containsCreatures = true;
                    for (Vector3 creature : m_ogres) {
                        Vector3 dir = creature - gridPos;

                        // cone is facing wrong way for creature
                        if (dir.angleBetween(c) > Degree(45)) {
                            containsCreatures = false;
                            break;
                        }

                        // creature too far away for cone
                        if (distance3(dir.x, dir.y, dir.z) > CONE_SIZE) {
                            containsCreatures = false;
                        }
                    }

                    if (containsCreatures) {
                        m_coneNodes[i]->setVisible(true);
                    } else {
                        m_coneNodes[i]->setVisible(false);
                    }
                }
            }
        }
    }
    return ret;
}
Ejemplo n.º 2
0
void SkyManager::update(float duration)
{
    if (!mEnabled) return;
    const MWWorld::Fallback* fallback=MWBase::Environment::get().getWorld()->getFallback();

    if (!mParticle.isNull())
    {
        for (unsigned int i=0; i<mParticle->mControllers.size(); ++i)
            mParticle->mControllers[i].update();
    }

    updateRain(duration);

    // UV Scroll the clouds
    mCloudAnimationTimer += duration * mCloudSpeed;
    sh::Factory::getInstance().setSharedParameter ("cloudAnimationTimer",
        sh::makeProperty<sh::FloatValue>(new sh::FloatValue(mCloudAnimationTimer)));

    /// \todo improve this
    mMasser->setPhase( static_cast<Moon::Phase>( (int) ((mDay % 32)/4.f)) );
    mSecunda->setPhase ( static_cast<Moon::Phase>( (int) ((mDay % 32)/4.f)) );

    mSecunda->setColour ( mMoonRed ? fallback->getFallbackColour("Moons_Script_Color") : ColourValue(1,1,1,1));
    mMasser->setColour (ColourValue(1,1,1,1));

    if (mSunEnabled)
    {
        // take 1/10 sec for fading the glare effect from invisible to full
        if (mGlareFade > mGlare)
        {
            mGlareFade -= duration*10;
            if (mGlareFade < mGlare) mGlareFade = mGlare;
        }
        else if (mGlareFade < mGlare)
        {
            mGlareFade += duration*10;
            if (mGlareFade > mGlare) mGlareFade = mGlare;
        }

        // increase the strength of the sun glare effect depending
        // on how directly the player is looking at the sun
        Vector3 sun = mSunGlare->getPosition();
        Vector3 cam = mCamera->getRealDirection();
        const Degree angle = sun.angleBetween( cam );
        float val = 1- (angle.valueDegrees() / 180.f);
        val = (val*val*val*val)*6;
        mSunGlare->setSize(val * mGlareFade);
    }

    mSunGlare->setVisible(mSunEnabled);
    mSun->setVisible(mSunEnabled);
    mMasser->setVisible(mMasserEnabled);
    mSecunda->setVisible(mSecundaEnabled);

    // rotate the stars by 360 degrees every 4 days
    mAtmosphereNight->roll(Degree(MWBase::Environment::get().getWorld()->getTimeScaleFactor()*duration*360 / (3600*96.f)));
}
Ejemplo n.º 3
0
void Enemy::checkLOS(Real delta) {
  Vector3 target = playerPos;

  Vector3 origin = m_pos + Vector3(0,sin(bob * 4) * 0.5f,0);
  Vector3 dir = target - origin;
  dir.normalize();
  Vector3 tmp = Vector3::NEGATIVE_UNIT_Y;
  tmp = light->getAbsoluteOrientation() * tmp;

  if (tmp.angleBetween(dir) < 34.f) {
    RaycastReport r = mPhysics->raycast(origin, dir, 5000.f, 0, 0);
    if (r.hit && r.group == 0x1) {
      lastKnown = playerPos;
      los_time += delta;
      if (los_time > 0.1f && m_state != ES_COMBAT) {
        m_state = ES_COMBAT;
        //std::cout<<"I SEE U\n";
        los_time = 0;
      } else if (los_time > 1.1f && m_state == ES_COMBAT && m_minis.size() > 0 && !m_minis.back()->attack) {
        //std::cout<<"ATTAAAACCKKK\n";

      dynamic_cast<ALSubsystem*>(Engine::getPtr()->getSubsystem("ALSubsystem"))->play2D("../media/audio/attack.ogg")->setGain(0.f, 1.f, 1.f);

        m_minis.back()->attack = true;
        Vector3 wpos = m_minis.back()->m_mesh->getAbsolutePosition();
        m_mesh->removeChild(m_minis.back()->n);
        m_minis.back()->n->removeChild(m_minis.back()->m_mesh);
        mGfx->getRootSceneNode()->addChild(m_minis.back()->m_mesh);
        mGfx->destroySceneNode(m_minis.back()->n);
        m_minis.back()->n = NULL;
        m_minis.back()->m_mesh->setPosition(wpos);
        Vector3 ad = playerPos - wpos;
        ad.normalize();
        m_minis.back()->attack_dir = ad;
        los_time = 0;
      }
    } else {
      los_time -= delta / 2.f;
    }

  } else {
    los_time -= delta / 2.f;
  }

  if (los_time < 0.f && m_state != ES_COMBAT) {
    los_time = 0.f;
  }
  if (los_time > 1.2f) {
    los_time = 1.2f;
  }
      //printf("%f.\n", los_time);
  if (los_time < -0.1 && m_state == ES_COMBAT) {
    //std::cout<<"WHERE'D HE GOOOOO???\n";
    decidePatrol(true);
    m_state = ES_PATROL;
  }
}
Ejemplo n.º 4
0
void SkyManager::update(float duration)
{
    if (!mEnabled) return;

    mCamera->getParentSceneNode ()->needUpdate ();
    mRootNode->setPosition(mCamera->getDerivedPosition());

    // UV Scroll the clouds
    mCloudAnimationTimer += duration * mCloudSpeed * (MWBase::Environment::get().getWorld()->getTimeScaleFactor()/30.f);
    sh::Factory::getInstance().setSharedParameter ("cloudAnimationTimer",
        sh::makeProperty<sh::FloatValue>(new sh::FloatValue(mCloudAnimationTimer)));

    /// \todo improve this
    mMasser->setPhase( static_cast<Moon::Phase>( (int) ((mDay % 32)/4.f)) );
    mSecunda->setPhase ( static_cast<Moon::Phase>( (int) ((mDay % 32)/4.f)) );

    mSecunda->setColour ( mMoonRed ? ColourValue(1.0, 0.0784, 0.0784) : ColourValue(1,1,1,1));
    mMasser->setColour (ColourValue(1,1,1,1));

    if (mSunEnabled)
    {
        // take 1/10 sec for fading the glare effect from invisible to full
        if (mGlareFade > mGlare)
        {
            mGlareFade -= duration*10;
            if (mGlareFade < mGlare) mGlareFade = mGlare;
        }
        else if (mGlareFade < mGlare)
        {
            mGlareFade += duration*10;
            if (mGlareFade > mGlare) mGlareFade = mGlare;
        }

        // increase the strength of the sun glare effect depending
        // on how directly the player is looking at the sun
        Vector3 sun = mSunGlare->getPosition();
        sun = Vector3(sun.x, sun.z, -sun.y);
        Vector3 cam = mCamera->getRealDirection();
        const Degree angle = sun.angleBetween( cam );
        float val = 1- (angle.valueDegrees() / 180.f);
        val = (val*val*val*val)*2;

        mSunGlare->setSize(val * mGlareFade);
    }

    mSunGlare->setVisible(mSunEnabled);
    mSun->setVisible(mSunEnabled);
    mMasser->setVisible(mMasserEnabled);
    mSecunda->setVisible(mSecundaEnabled);

    // rotate the stars by 360 degrees every 4 days
    mAtmosphereNight->roll(Degree(MWBase::Environment::get().getWorld()->getTimeScaleFactor()*duration*360 / (3600*96.f)));
}
Ejemplo n.º 5
0
void SkyManager::update(float duration)
{
    if (!mEnabled) return;

    // UV Scroll the clouds
    mCloudMaterial->getTechnique(0)->getPass(0)->getFragmentProgramParameters()->setNamedConstantFromTime("time", MWBase::Environment::get().getWorld()->getTimeScaleFactor()/30.f);

    /// \todo improve this
    mMasser->setPhase( static_cast<Moon::Phase>( (int) ((mDay % 32)/4.f)) );
    mSecunda->setPhase ( static_cast<Moon::Phase>( (int) ((mDay % 32)/4.f)) );


    if (mSunEnabled)
    {
        // take 1/5 sec for fading the glare effect from invisible to full
        if (mGlareFade > mGlare)
        {
            mGlareFade -= duration*5;
            if (mGlareFade < mGlare) mGlareFade = mGlare;
        }
        else if (mGlareFade < mGlare)
        {
            mGlareFade += duration*5;
            if (mGlareFade > mGlare) mGlareFade = mGlare;
        }

        // increase the strength of the sun glare effect depending
        // on how directly the player is looking at the sun
        Vector3 sun = mSunGlare->getPosition();
        sun = Vector3(sun.x, sun.z, -sun.y);
        Vector3 cam = mCamera->getRealDirection();
        const Degree angle = sun.angleBetween( cam );
        float val = 1- (angle.valueDegrees() / 180.f);
        val = (val*val*val*val)*2;

        mSunGlare->setSize(val * mGlareFade);
    }

    mSunGlare->setVisible(mSunEnabled);
    mSun->setVisible(mSunEnabled);
    mMasser->setVisible(mMasserEnabled);
    mSecunda->setVisible(mSecundaEnabled);

    // rotate the stars by 360 degrees every 4 days
    mAtmosphereNight->roll(Degree(MWBase::Environment::get().getWorld()->getTimeScaleFactor()*duration*360 / (3600*96.f)));
}
bool CameraBehaviorVehicle::mousePressed(const CameraManager::CameraContext &ctx, const OIS::MouseEvent& _arg, OIS::MouseButtonID _id)
{
	const OIS::MouseState ms = _arg.state;

	if ( ms.buttonDown(OIS::MB_Middle) && RoR::Application::GetInputEngine()->isKeyDown(OIS::KC_LSHIFT) )
	{
		if ( ctx.mCurrTruck && ctx.mCurrTruck->m_custom_camera_node >= 0 )
		{
			// Calculate new camera distance
			Vector3 lookAt = ctx.mCurrTruck->nodes[ctx.mCurrTruck->m_custom_camera_node].AbsPosition;
			camDist = 2.0f * gEnv->mainCamera->getPosition().distance(lookAt);

			// Calculate new camera pitch
			Vector3 camDir = (gEnv->mainCamera->getPosition() - lookAt).normalisedCopy();
			camRotY = asin(camDir.y);

			// Calculate new camera yaw
			Vector3 dir = -ctx.mCurrTruck->getDirection();
			Quaternion rotX = dir.getRotationTo(camDir, Vector3::UNIT_Y);
			camRotX = rotX.getYaw();

			// Corner case handling
			Radian angle = dir.angleBetween(camDir);
			if ( angle > Radian(Math::HALF_PI) )
			{
				if ( std::abs(Radian(camRotX).valueRadians()) < Math::HALF_PI )
				{
					if ( camRotX < Radian(0.0f) )
						camRotX -= Radian(Math::HALF_PI);
					else
						camRotX += Radian(Math::HALF_PI);
				}
			}
		}
	}

	return false;
}
Ejemplo n.º 7
0
void mouseMove(int x, int y)
{

    isDragged = true;
    vMouse =  arcGetVec(x,y);

    float angle = min(1.0f,vMouse.angleBetween(vMousePrev));
    
//	printf("angle: %f\n", angle);
    
	vAxis  = vMouse.cross(vMousePrev);
    vAxis.normalize();

	this_rot.setIdentity();	
	this_rot.rotate(angle * 100, vAxis.x, -vAxis.y, -vAxis.z);
	
	this_rot *= last_rot;
	model_mat = this_rot ;

	

  // vMousePrev = vMouse;
}
Ejemplo n.º 8
0
	void CCameraFeedbackNotifier::calculateEnemyPosition(Vector3 vPosEnemy) { 
		//Obtengo la posición del enemigo
		Ogre::Vector3 vEnemyPos = vPosEnemy;
		//Obtengo mi posición (entidad a la que han dañado)
		Ogre::Vector3 vMyPos = this->_entity->getPosition();

		//Obtengo el vector en el que estoy mirando, y me quedo sólo en el plano horizontal (quitando la altura)
		Vector3 vMyDirVision = _entity->getOrientation()*Vector3::NEGATIVE_UNIT_Z;
		vMyDirVision = Vector3(vMyDirVision.x,0,vMyDirVision.z);
		//Obtengo el vector desde el enemigo a mi posición; y me quedo sólo con el plano horizontal (quitando la altura)
		Vector3 vEnemyDirVision = vPosEnemy - vMyPos;
		vEnemyDirVision = Vector3(vEnemyDirVision.x, 0, vEnemyDirVision.z);

		//Ángulo entre ambos vectores
		Ogre::Radian rad = vMyDirVision.angleBetween(vEnemyDirVision);
		//Convierto los radianes a float porque en el mensaje mando float
		float fRadianes = (float)rad.valueRadians();

		//Cambio de sistema de coordenadas para tener la posición del enemigo respecto 
		//al jugador. Antonio el crack matemático! ^^
		Matrix4 mat;
		mat.makeTransform(_entity->getPosition(),Vector3::UNIT_SCALE,_entity->getOrientation());
		mat.inverse();
		Vector3 vec = mat * vPosEnemy; //este vector es la posicion del enemigo respecto a mi
		if (vec.x > 0) 
		{
			//El enemigo está a la derecha, así que tengo que multiplicar
			//por -1 para que se oriente bien la flecha de daño
			fRadianes *= -1.0f;
		}

		//Mando el mensaje
		std::shared_ptr<Logic::CMessageImpact> impact = std::make_shared<Logic::CMessageImpact>();
		impact->setDirectionImpact(fRadianes);							 
		_entity->emitMessage(impact);
	}
Ejemplo n.º 9
0
	void MissionScreen::ShowTarget(int levelLength)
	{
		m_targetIcon->hide();
		m_arrowRight->hide();
		m_arrowLeft->hide();
		m_arrowUp->hide();
		m_arrowDown->hide();

		const Vector3 &targetPosition = m_game.GetAsteroidManager().GetTargetPosition();
		const float targetDistance = (targetPosition - m_game.GetCamera().getPosition()).length();
		const Vector2 screenPos = m_game.Convert3DPointTo2D(targetPosition);
		const bool isVisible = m_game.IsInFrontOfCamera(targetPosition);

		if (isVisible &&
			screenPos.x >= 0 && screenPos.x < m_game.GetWidth() &&
			screenPos.y >= 0 && screenPos.y < m_game.GetHeight())
		{
			assert(m_targetIcon);
			
			const Vector2 distanceVector = Vector2(screenPos.x - m_game.GetWidth() / 2, screenPos.y - m_game.GetHeight() / 2);
			float borderFactor = distanceVector.length() / static_cast<float>(m_game.GetHeight() / 2);
			borderFactor = std::min(1.0f, std::max(0.2f, borderFactor));
			m_targetIcon->setAlpha(borderFactor);

			const float posX = screenPos.x / m_game.GetWidth() - m_targetIconSize.x / 2;
			const float posY = screenPos.y / m_game.GetHeight() - m_targetIconSize.y / 2;
			m_targetIcon->setPosition(CEGUI::UVector2(CEGUI::UDim(posX, 0), CEGUI::UDim(posY, 0)));

			m_targetIcon->show();
		}
		else
		{
			// Find out direction of the target by calculating 4 angles
			// for all 4 directions and then choosing the closest one
			Vector3 leftRotation = m_game.GetCamera().getRight() * -Vector3::UNIT_SCALE;
			const float leftAngle = leftRotation.angleBetween(targetPosition).valueRadians();
			
			Vector3 rightRotation = m_game.GetCamera().getRight();
			const float rightAngle = rightRotation.angleBetween(targetPosition).valueRadians();
			
			Vector3 upRotation = m_game.GetCamera().getUp();
			const float upAngle = upRotation.angleBetween(targetPosition).valueRadians();

			Vector3 downRotation = m_game.GetCamera().getUp() * -Vector3::UNIT_SCALE;
			const float downAngle = downRotation.angleBetween(targetPosition).valueRadians();

			// Find out direction and screen coordinates on the screen borders
			const float xPosPercent = 0.5f + (leftAngle - Math::PI / 2.0f) * 0.6f;
			const float yPosPercent = 0.5f + (upAngle - Math::PI / 2.0f) * 0.85f;
			float posX = xPosPercent - m_arrowSize.x;
			posX = std::min(1.0f, std::max(0.0f, posX));
			float posY = yPosPercent - m_arrowSize.y;
			posY = std::min(1.0f, std::max(0.0f, posY));

			// First try, just get the closest angle
			if (leftAngle < rightAngle &&
				leftAngle < upAngle &&
				leftAngle < downAngle)
			{
				m_arrowLeft->setPosition(CEGUI::UVector2(CEGUI::UDim(0, 0), CEGUI::UDim(posY, 0)));
				m_arrowLeft->show();
			}
			else if (rightAngle < upAngle &&
				rightAngle < downAngle)
			{
				m_arrowRight->setPosition(CEGUI::UVector2(CEGUI::UDim(1.0f - m_arrowSize.x, 0), CEGUI::UDim(posY, 0)));
				m_arrowRight->show();
			}
			else if (upAngle < downAngle)
			{
				m_arrowUp->setPosition(CEGUI::UVector2(CEGUI::UDim(posX, 0), CEGUI::UDim(0, 0)));
				m_arrowUp->show();
			}
			else
			{
				m_arrowDown->setPosition(CEGUI::UVector2(CEGUI::UDim(posX, 0), CEGUI::UDim(1.0f - m_arrowSize.y, 0)));
				m_arrowDown->show();
			}
		} // if (isVisible...
	}