예제 #1
0
	bool PlaypenApp::processUnbufferedMouseInput(Ogre::Real dt)
	{
		// The following code checks how far the mouse has move since 
		// the last poll.  This data can be used to rotate the camera 
		// around its X and Y axes (pitch and yaw, respectively).
		Ogre::Degree rotY = -mInputDevice->getMouseRelativeX() * mRotateSpeed;
		Ogre::Degree rotX = -mInputDevice->getMouseRelativeY() * mRotateSpeed;

		// Use the relative mouse motion to rotate the camera.
		mPhysicalCamera->yawRelative(rotY.valueDegrees());
		mPhysicalCamera->pitchRelative(rotX.valueDegrees());

		// Check mouse button states.
		if (true == mInputDevice->getMouseButton(0))
		{
			// The left mouse button is down.
			mPhysicalCamera->grasp();
		}
		else
		{
			// The left mouse button is up.
			mPhysicalCamera->release();
		}

		// Return true to continue looping.
		return true;
	}
예제 #2
0
 void Astronomy::getHorizontalMoonPosition (
         LongReal jday,
         Ogre::Degree longitude, Ogre::Degree latitude,
         Ogre::Degree &azimuth, Ogre::Degree &altitude)
 {
     LongReal az, al;
     getHorizontalMoonPosition(jday, longitude.valueDegrees (), latitude.valueDegrees (), az, al);
     azimuth = Ogre::Degree(az);                
     altitude = Ogre::Degree(al);  
 }
void LandVehicleSimulation::UpdateVehicle(Actor* vehicle, float seconds_since_last_frame)
{
    if (vehicle->isBeingReset() || vehicle->ar_physics_paused || vehicle->ar_replay_mode)
        return;
#ifdef USE_ANGELSCRIPT
    if (vehicle->ar_vehicle_ai && vehicle->ar_vehicle_ai->IsActive())
        return;
#endif // USE_ANGELSCRIPT

    EngineSim* engine = vehicle->ar_engine;

    if (engine && engine->HasStarterContact() &&
        engine->GetAutoShiftMode() == SimGearboxMode::AUTO &&
        engine->getAutoShift() != EngineSim::NEUTRAL)
    {
        Ogre::Vector3 dirDiff = vehicle->getDirection();
        Ogre::Degree pitchAngle = Ogre::Radian(asin(dirDiff.dotProduct(Ogre::Vector3::UNIT_Y)));

        if (std::abs(pitchAngle.valueDegrees()) > 2.0f)
        {
            if (engine->getAutoShift() > EngineSim::NEUTRAL && vehicle->ar_avg_wheel_speed < +0.02f && pitchAngle.valueDegrees() > 0.0f ||
                engine->getAutoShift() < EngineSim::NEUTRAL && vehicle->ar_avg_wheel_speed > -0.02f && pitchAngle.valueDegrees() < 0.0f)
            {
                // anti roll back in SimGearboxMode::AUTO (DRIVE, TWO, ONE) mode
                // anti roll forth in SimGearboxMode::AUTO (REAR) mode
                float g = std::abs(App::GetSimTerrain()->getGravity());
                float downhill_force = std::abs(sin(pitchAngle.valueRadians()) * vehicle->getTotalMass()) * g;
                float engine_force = std::abs(engine->GetTorque()) / vehicle->getAvgPropedWheelRadius();
                float ratio = std::max(0.0f, 1.0f - (engine_force / downhill_force));
                if (vehicle->ar_avg_wheel_speed * pitchAngle.valueDegrees() > 0.0f)
                {
                    ratio *= sqrt((0.02f - vehicle->ar_avg_wheel_speed) / 0.02f);
                }
                vehicle->ar_brake = sqrt(ratio);
            }
        }
        else if (vehicle->ar_brake == 0.0f && !vehicle->ar_parking_brake && engine->GetTorque() == 0.0f)
        {
            float ratio = std::max(0.0f, 0.2f - std::abs(vehicle->ar_avg_wheel_speed)) / 0.2f;
            vehicle->ar_brake = ratio;
        }
    }

    if (vehicle->cc_mode)
    {
        LandVehicleSimulation::UpdateCruiseControl(vehicle, seconds_since_last_frame);
    }
    if (vehicle->sl_enabled)
    {
        LandVehicleSimulation::CheckSpeedLimit(vehicle, seconds_since_last_frame);
    }
}
예제 #4
0
파일: Entity.cpp 프로젝트: DeejStar/q-gears
void
Entity::SetRotation( const Ogre::Degree& rotation )
{
    assert( m_model_root_node );
    float angle = rotation.valueDegrees() - Ogre::Math::Floor( rotation.valueDegrees() / 360.0f ) * 360.0f;

    if( angle < 0 )
    {
        angle = 360 + angle;
    }

    Ogre::Quaternion q;
    Ogre::Vector3 vec = Ogre::Vector3::UNIT_Z;
    q.FromAngleAxis( Ogre::Radian( Ogre::Degree( angle ) ), vec );
    m_model_root_node->setOrientation( q );
    m_DirectionNode->setOrientation( q );
}
예제 #5
0
void XMLHelper::fillElementFromQuaternion(TiXmlElement& elem, const Ogre::Quaternion& quaternion) {
	//split the quaternion into an axis and a degree (our format allows us to store the angle element as a radian too, but I prefer degrees)
	Ogre::Degree degrees;
	Ogre::Vector3 axis;
	quaternion.ToAngleAxis(degrees, axis);
	fillElementFromVector3(elem, axis);
	elem.SetDoubleAttribute("degrees", degrees.valueDegrees());
}
예제 #6
0
TEST_F(TestDataProxyConverters, TestDegree)
{
  Ogre::Degree res = mDataProxy.get<Ogre::Degree>("degree").first;
  ASSERT_FLOAT_EQ(10.1, res.valueDegrees());
  res = Ogre::Degree(50.5);
  mDataProxy.put("degree_m", res);

  ASSERT_EQ(mDataProxy.get<std::string>("degree_m").first, "50.500000");
}
예제 #7
0
	void PointStarfield::setObserverLongitude (Ogre::Degree value)
    {
		if (!Math::RealEqual (
                mObserverLongitude.valueDegrees (), 
                value.valueDegrees (),
                this->getObserverPositionRebuildDelta ().valueDegrees ()))
        {
			mObserverLongitude = value;
			invalidateGeometry ();
		}
	}
	CEntity* CEntityFactory::createEntityByTypeTransform(const std::string &type, Matrix4 transform, CMap *map)
	{
		//solo hacemos creamos algo a partir de un arquetipo así que nos aseguramos de que exista
		ArchetypeMap::iterator find = _archetypes.find(type);
		if( find == _archetypes.end())
		{
			return NULL;
		}

		//nos aseguramos de construir un nombre unico
		//int id = EntityID::_nextId;
		
		std::string uniqueName = type;

		//Hacer un new para que no se desreferencie en el futuro
		Map::CEntity *entityInfo = new Map::CEntity(uniqueName);

		//El tipo
		entityInfo->setType(type);

		//La posicion
		Vector3 pos;
		Vector3 scale;
		Quaternion quat;

		transform.decomposition(pos, scale, quat);

		std::string string = std::to_string(pos.x)+','+std::to_string(pos.y)+','+std::to_string(pos.z);
		entityInfo->setAttribute("position", string );
		
		//El nombre unico
		entityInfo->setName(entityInfo->getName()+std::to_string(EntityID::_nextId));

		//La orientacion
		Vector3 axis;
		Ogre::Degree angle;
		quat.ToAngleAxis(angle, axis);

		string = std::to_string(axis.x) +","+std::to_string(axis.y)+","+std::to_string(axis.z);
		entityInfo->setAttribute("orientation",string);
		//std::cout<<string<<std::endl;
		string = std::to_string(angle.valueDegrees());
		//std::cout<<string<<std::endl;
		entityInfo->setAttribute("orientation_angle", string);

		//meterlo en la cola de entidades del parser para que se borren al recargar mapas
		Map::CMapParser::getSingletonPtr()->addEntityInfo(entityInfo);

		return createEntity(entityInfo, map);

	}
예제 #9
0
void QuaternionAdapter::updateGui(const Ogre::Quaternion& quaternion)
{
	mSelfUpdate = true;

	if (&quaternion) {
		Ogre::Vector3 axis;
		Ogre::Degree angle;
		quaternion.ToAngleAxis( angle, axis);
		mVectorAdapter.updateGui(axis);
		if (mDegreeWindow) {
			mDegreeWindow->setText(Ogre::StringConverter::toString(angle.valueDegrees()));
		}
	} else {
		mVectorAdapter.updateGui(Ogre::Vector3::ZERO);
		if (mDegreeWindow) {
			mDegreeWindow->setText("");
		}
	}
	mSelfUpdate = false;
}
예제 #10
0
파일: combat.cpp 프로젝트: Chiur/openmw
    bool blockMeleeAttack(const MWWorld::Ptr &attacker, const MWWorld::Ptr &blocker, const MWWorld::Ptr &weapon, float damage)
    {
        if (!blocker.getClass().hasInventoryStore(blocker))
            return false;

        if (blocker.getClass().getCreatureStats(blocker).getKnockedDown()
                || blocker.getClass().getCreatureStats(blocker).getHitRecovery())
            return false;

        MWWorld::InventoryStore& inv = blocker.getClass().getInventoryStore(blocker);
        MWWorld::ContainerStoreIterator shield = inv.getSlot(MWWorld::InventoryStore::Slot_CarriedLeft);
        if (shield == inv.end() || shield->getTypeName() != typeid(ESM::Armor).name())
            return false;

        Ogre::Degree angle = signedAngle (Ogre::Vector3(attacker.getRefData().getPosition().pos) - Ogre::Vector3(blocker.getRefData().getPosition().pos),
                                          blocker.getRefData().getBaseNode()->getOrientation().yAxis(), Ogre::Vector3(0,0,1));

        const MWWorld::Store<ESM::GameSetting>& gmst = MWBase::Environment::get().getWorld()->getStore().get<ESM::GameSetting>();
        if (angle.valueDegrees() < gmst.find("fCombatBlockLeftAngle")->getFloat())
            return false;
        if (angle.valueDegrees() > gmst.find("fCombatBlockRightAngle")->getFloat())
            return false;

        MWMechanics::CreatureStats& blockerStats = blocker.getClass().getCreatureStats(blocker);
        if (blockerStats.getDrawState() == DrawState_Spell)
            return false;

        MWMechanics::CreatureStats& attackerStats = attacker.getClass().getCreatureStats(attacker);

        float blockTerm = blocker.getClass().getSkill(blocker, ESM::Skill::Block) + 0.2 * blockerStats.getAttribute(ESM::Attribute::Agility).getModified()
            + 0.1 * blockerStats.getAttribute(ESM::Attribute::Luck).getModified();
        float enemySwing = attackerStats.getAttackStrength();
        float swingTerm = enemySwing * gmst.find("fSwingBlockMult")->getFloat() + gmst.find("fSwingBlockBase")->getFloat();

        float blockerTerm = blockTerm * swingTerm;
        if (blocker.getClass().getMovementSettings(blocker).mPosition[1] <= 0)
            blockerTerm *= gmst.find("fBlockStillBonus")->getFloat();
        blockerTerm *= blockerStats.getFatigueTerm();

        float attackerSkill = attacker.getClass().getSkill(attacker, weapon.getClass().getEquipmentSkill(weapon));
        float attackerTerm = attackerSkill + 0.2 * attackerStats.getAttribute(ESM::Attribute::Agility).getModified()
                + 0.1 * attackerStats.getAttribute(ESM::Attribute::Luck).getModified();
        attackerTerm *= attackerStats.getFatigueTerm();

        int x = int(blockerTerm - attackerTerm);
        int iBlockMaxChance = gmst.find("iBlockMaxChance")->getInt();
        int iBlockMinChance = gmst.find("iBlockMinChance")->getInt();
        x = std::min(iBlockMaxChance, std::max(iBlockMinChance, x));

        int roll = std::rand()/ (static_cast<double> (RAND_MAX) + 1) * 100; // [0, 99]
        if (roll < x)
        {
            // Reduce shield durability by incoming damage
            if (shield->getCellRef().mCharge == -1)
                shield->getCellRef().mCharge = shield->getClass().getItemMaxHealth(*shield);
            shield->getCellRef().mCharge -= std::min(shield->getCellRef().mCharge, int(damage));
            if (!shield->getCellRef().mCharge)
                inv.unequipItem(*shield, blocker);

            // Reduce blocker fatigue
            const float fFatigueBlockBase = gmst.find("fFatigueBlockBase")->getFloat();
            const float fFatigueBlockMult = gmst.find("fFatigueBlockMult")->getFloat();
            const float fWeaponFatigueBlockMult = gmst.find("fWeaponFatigueBlockMult")->getFloat();
            MWMechanics::DynamicStat<float> fatigue = blockerStats.getFatigue();
            float normalizedEncumbrance = blocker.getClass().getEncumbrance(blocker) / blocker.getClass().getCapacity(blocker);
            normalizedEncumbrance = std::min(1.f, normalizedEncumbrance);
            float fatigueLoss = fFatigueBlockBase + normalizedEncumbrance * fFatigueBlockMult;
            fatigueLoss += weapon.getClass().getWeight(weapon) * attackerStats.getAttackStrength() * fWeaponFatigueBlockMult;
            fatigue.setCurrent(fatigue.getCurrent() - fatigueLoss);
            blockerStats.setFatigue(fatigue);

            blockerStats.setBlock(true);

            if (blocker.getClass().isNpc())
                blocker.getClass().skillUsageSucceeded(blocker, ESM::Skill::Block, 0);

            return true;
        }
        return false;
    }
    void PropertiesWindow::addPropertyQuaternion(const Property& prop,
        CEGUI::MultiColumnList* table, const CeGuiString& key)
    {
        // Check column count
        // if count = 3 | MainTable
        // if count = 2 | Array table
        int colCount = table->getColumnCount();
        int rowCount = table->getRowCount();

        Ogre::Quaternion quat = prop.toQuaternion();
        Ogre::Degree angle;
        Ogre::Vector3 axis;

        quat.ToAngleAxis( angle, axis );

        char buf_angle [50];
        sprintf(buf_angle, "%1.2f", angle.valueDegrees());
        char buf_v1 [50];
        sprintf(buf_v1, "%1.2f", axis.x);
        char buf_v2 [50];
        sprintf(buf_v2, "%1.2f", axis.y);
        char buf_v3 [50];
        sprintf(buf_v3, "%1.2f", axis.z);

        // Table has the three columns Key, Type, Value
        if ( colCount == 3 )
        {
            // Add row for the first IntTriple value
            table->addRow(rowCount);
            table->setItem(new ListboxTextItem(key + "  "), 0, rowCount);
            table->setItem(new ListboxTextItem("Quaternion  "), 1, rowCount);
            table->setItem(new ListboxTextItem("Axis:   ( " +
                CEGUI::String(buf_v1) + ", " +
                CEGUI::String(buf_v2) + ", " +
                CEGUI::String(buf_v3) + " )"),
                2,
                rowCount);

            // Add second for the second IntTriple value
            table->addRow(rowCount + 1);
            table->setItem(new ListboxTextItem("Degree: " +
                CEGUI::String(buf_angle)),
                2,
                rowCount + 1);
        }
        // Table has the two columns Type, Value
        else if ( colCount == 2 )
        {
            table->addRow(rowCount);
            table->setItem(new ListboxTextItem("Quaternion  "), 0, rowCount);
            table->setItem(new ListboxTextItem("Axis:   ( " +
                CEGUI::String(buf_v1) + ", " +
                CEGUI::String(buf_v2) + ", " +
                CEGUI::String(buf_v3) + " )"),
                2,
                rowCount);

            // Add second for the second IntTriple value
            table->addRow(rowCount + 1);
            table->setItem(new ListboxTextItem("Degree " +
                CEGUI::String(buf_angle)),
                2,
                rowCount + 1);
        }

    }
예제 #12
0
파일: main.cpp 프로젝트: sub77/hobbycode
void handleInput(Ogre::Real elapsedRealTime)
{
	// This variable can be used to keep keys from repeating too fast.
	static Ogre::Real toggleTimer = 0;
	if (toggleTimer >= 0)
	{
		toggleTimer -= elapsedRealTime;
	}

	OIS::Keyboard* keyboard = gEngine.getKeyboard();

	if (keyboard->isKeyDown(OIS::KC_W))
	{
		gCar->forward();
	}
	else if (keyboard->isKeyDown(OIS::KC_S))
	{
		gCar->reverse();
	}
	else
	{
		gCar->idle();
	}

	if (keyboard->isKeyDown(OIS::KC_A))
	{
		gCar->setSteering(-1);
	}
	else if (keyboard->isKeyDown(OIS::KC_D))
	{
		gCar->setSteering(1);
	}
	else
	{
		gCar->setSteering(0);
	}

	// If available, get data from the game controller.
	if (gGamePad)
	{
		// Update the game controller state.
		SDL_JoystickUpdate();

		Ogre::Real joy0X = (Ogre::Real)SDL_JoystickGetAxis(gGamePad, 0) / 
			(Ogre::Real)32768;
		Ogre::Real joy0Y = (Ogre::Real)SDL_JoystickGetAxis(gGamePad, 1) / 
			(Ogre::Real)32768;
		Ogre::Real joy1X = (Ogre::Real)SDL_JoystickGetAxis(gGamePad, 4) / 
			(Ogre::Real)32768;
		Ogre::Real joy1Y = (Ogre::Real)SDL_JoystickGetAxis(gGamePad, 3) / 
			(Ogre::Real)32768;

		if (fabs(joy0Y) > 0.1)
		{
			gCar->setThrottle(-joy0Y);
		}
		else
		{
			gCar->idle();
		}

		if (fabs(joy0X) > 0.1)
		{
			gCar->setSteering(joy0X);
		}
		else
		{
			gCar->setSteering(0);
		}

		if (joy1X > 0.2 || joy1X < -0.2)
		{
			Ogre::Degree rotAroundY = -Ogre::Degree(joy1X);
			gEngine.getCamera()->yawRelative(rotAroundY.valueDegrees());
		}

		if (joy1Y > 0.2 || joy1Y < -0.2)
		{
			Ogre::Degree rotAroundX = -Ogre::Degree(joy1Y);
			gEngine.getCamera()->pitchRelative(rotAroundX.valueDegrees());
		}
	}

	// Toggle GUI.
	if (keyboard->isKeyDown(OIS::KC_G) && toggleTimer <= 0)
	{
		Ogre::Overlay* debugOverlay = Ogre::OverlayManager::getSingleton().
			getByName("Verve/Debug");

		if (debugOverlay->isVisible())
        {
			debugOverlay->hide();
			gAgentDebugger->setDisplayEnabled(false);
		}
		else
		{
			debugOverlay->show();
			gAgentDebugger->setDisplayEnabled(true);
		}

		toggleTimer = 0.5;
	}
}
예제 #13
0
void RenderedCompassImpl::rotate(const Ogre::Degree& degree)
{
	auto rotation = CEGUI::Quaternion::axisAngleDegrees(CEGUI::Vector3f(0, 0, 1), degree.valueDegrees() + 45.0f);

	mPointerElement->setRotation(rotation);
}