コード例 #1
0
ファイル: DepthOfFieldEffect.cpp プロジェクト: tizbac/ror-ng
bool DOFManager::frameStarted(const FrameEvent& evt)
{
	// Focusing
	switch (mFocusMode)
	{
		case Auto:
		{
			// TODO: Replace with accurate ray/triangle collision detection
			Real currentFocalDistance = mLens->getFocalDistance();

			// TODO: Continuous AF / triggered
			mAutoTime -= evt.timeSinceLastFrame;
			if (mAutoTime <= 0.0f)
			{
				mAutoTime = 0.5f;

				Vector3 lookAt(Vector3::ZERO);

				Beam* currTruck = BeamFactory::getSingleton().getCurrentTruck();
				if ( currTruck )
				{
					lookAt = currTruck->getPosition();
				} else
				{
					lookAt = gEnv->player->getPosition();
				}

				targetFocalDistance = gEnv->mainCamera->getPosition().distance(lookAt) / 2.0f; // Needs further investigation

				setLensFOV(Radian(gEnv->mainCamera->getFOVy()));

				/*
				targetFocalDistance = currentFocalDistance;

				// Ryan Booker's (eyevee99) ray scene query auto focus
				Ray focusRay;
				focusRay.setOrigin(camera->getDerivedPosition());
				focusRay.setDirection(camera->getDerivedDirection());
				Vector3 v;
				Vector3 vn;
				
				mRaySceneQuery->setRay(focusRay);
				Ogre::RaySceneQueryResult &qryResult = mRaySceneQuery->execute();
				for (Ogre::RaySceneQueryResult::iterator it = qryResult.begin();it != qryResult.end(); it++)
				{
					if (it->worldFragment)
					{
						if (debugNode) debugNode->setPosition(it->worldFragment->singleIntersection + Vector3(0.5,0,0));
						targetFocalDistance = (gEnv->mainCamera->getPosition() - it->worldFragment->singleIntersection).length();
						break;
					} else
					{
						// this wont work since we would need to go down to the polygon level :(
						//if (debugNode) debugNode->setPosition(focusRay.getPoint(it->distance));
						//targetFocalDistance = it->distance;
						//break;
					}

				}
				//*/
			}

			// Slowly adjust the focal distance (emulate auto focus motor)
			if (currentFocalDistance < targetFocalDistance)
			{
				mLens->setFocalDistance(std::min(currentFocalDistance + mAutoSpeed * evt.timeSinceLastFrame, targetFocalDistance));
			} else if (currentFocalDistance > targetFocalDistance)
			{
				mLens->setFocalDistance(std::max(currentFocalDistance - mAutoSpeed * evt.timeSinceLastFrame, targetFocalDistance));
			}

			break;
		}

		case Manual:
			//we set the values elsewhere
			break;
	}

	// Update Depth of Field effect
	if (mFocusMode != Pinhole)
	{
		mDepthOfFieldEffect->setEnabled(true);

		// Calculate and set depth of field using lens
		float nearDepth, focalDepth, farDepth;
		mLens->recalculateDepthOfField(nearDepth, focalDepth, farDepth);
		mDepthOfFieldEffect->setFocalDepths(nearDepth, focalDepth, farDepth);
	} else
	{
		mDepthOfFieldEffect->setEnabled(false);
	}

	return true;
}
コード例 #2
0
ファイル: Console.cpp プロジェクト: CyberSys/rigs-of-rods
/*
All commands are here
*/
void Console::eventCommandAccept(MyGUI::Edit* _sender)
{
	UTFString msg = convertFromMyGUIString(m_Console_TextBox->getCaption());

	// we did not autoComplete, so try to handle the message
	m_Console_TextBox->setCaption("");

	if (msg.empty())
	{
		// discard the empty message
		return;
	}
	if (msg[0] == '/' || msg[0] == '\\')
	{
		Ogre::StringVector args = StringUtil::split(msg, " ");
		sTextHistory[iText] = msg;
		iText++; //Used for text history
		if (args[0] == "/help")
		{
			putMessage(CONSOLE_MSGTYPE_INFO, CONSOLE_TITLE, _L("Available commands:"), "help.png");
			putMessage(CONSOLE_MSGTYPE_INFO, CONSOLE_HELP, _L("/help - information on commands (this)"), "help.png");
			putMessage(CONSOLE_MSGTYPE_INFO, CONSOLE_HELP, _L("/ver - shows the Rigs of Rods version"), "information.png");
			putMessage(CONSOLE_MSGTYPE_INFO, CONSOLE_HELP, _L("/pos - outputs the current position"), "world.png");
			putMessage(CONSOLE_MSGTYPE_INFO, CONSOLE_HELP, _L("/goto <x> <y> <z> - jumps to the mentioned position"), "world.png");


			//if (gEnv->terrainManager->getHeightFinder()) //Not needed imo -max98
			putMessage(CONSOLE_MSGTYPE_INFO, CONSOLE_HELP, _L("/terrainheight - get height of terrain at current position"), "world.png");

			putMessage(CONSOLE_MSGTYPE_INFO, CONSOLE_HELP, _L("/log - toggles log output on the console"), "table_save.png");

			putMessage(CONSOLE_MSGTYPE_INFO, CONSOLE_HELP, _L("/quit - exit Rigs of Rods"), "table_save.png");

#ifdef USE_ANGELSCRIPT	
			putMessage(CONSOLE_MSGTYPE_INFO, CONSOLE_HELP, _L("/as <code here> - interpret angel code using console"), "script_go.png");
#endif // USE_ANGELSCRIPT

			putMessage(CONSOLE_MSGTYPE_INFO, CONSOLE_HELP, _L("/gravity <real> or <text string> - changes gravity constant. Outputs current value if no argument is given"), "script_go.png");
			putMessage(CONSOLE_MSGTYPE_INFO, CONSOLE_HELP, _L("Possible values: \n earth \n moon \n jupiter \n A random number (use negative)"), "script_go.png");

			putMessage(CONSOLE_MSGTYPE_INFO, CONSOLE_HELP, _L("/setwaterlevel <real> - changes water's level"), "script_go.png");

			putMessage(CONSOLE_MSGTYPE_INFO, CONSOLE_TITLE, _L("Tips:"), "help.png");
			putMessage(CONSOLE_MSGTYPE_INFO, CONSOLE_HELP, _L("- use Arrow Up/Down Keys in the InputBox to reuse old messages"), "information.png");
			return;
		} else if (args[0] == "/gravity")
		{
			float gValue;

			if (args.size() > 1)
			{
				if (args[1] == "earth")
					gValue = -9.81;
				else if (args[1] == "moon")
					gValue = -1.6;
				else if (args[1] == "jupiter")
					gValue = -50;
				else
					gValue = boost::lexical_cast<float>(args[1].c_str());
			} else
			{
				putMessage(CONSOLE_MSGTYPE_INFO, CONSOLE_SYSTEM_REPLY, _L("Current gravity is: ") + StringConverter::toString(gEnv->terrainManager->getGravity()), "information.png");
				return;
			}

			gEnv->terrainManager->setGravity(gValue);
			putMessage(CONSOLE_MSGTYPE_INFO, CONSOLE_SYSTEM_REPLY, _L("Gravity set to: ") + StringConverter::toString(gValue), "information.png");
			return;
		} else if (args[0] == "/setwaterlevel")
		{
			if (gEnv->terrainManager && gEnv->terrainManager->getWater() && args.size() > 1)
			{
				IWater* water = gEnv->terrainManager->getWater();
				water->setCamera(gEnv->mainCamera);
				water->setHeight(boost::lexical_cast<float>(args[1].c_str()));
				water->update();
				putMessage(CONSOLE_MSGTYPE_INFO, CONSOLE_SYSTEM_REPLY, _L("Water level set to: ") + StringConverter::toString(water->getHeight()), "information.png");
			}
			else
			{
				putMessage(CONSOLE_MSGTYPE_INFO, CONSOLE_SYSTEM_ERROR, _L("Please enter a correct value. "), "information.png");
			}
			return;
		}
		else if (args[0] == "/pos" && (gEnv->frameListener->loading_state == TERRAIN_LOADED || gEnv->frameListener->loading_state == ALL_LOADED))
		{
			Beam *b = BeamFactory::getSingleton().getCurrentTruck();
			if (!b && gEnv->player)
			{
				Vector3 pos = gEnv->player->getPosition();
				putMessage(CONSOLE_MSGTYPE_INFO, CONSOLE_SYSTEM_REPLY, _L("Character position: ") + String("x: ") + TOSTRING(pos.x) + String(" y: ") + TOSTRING(pos.y) + String(" z: ") + TOSTRING(pos.z), "world.png");
			}
			else if (b)
			{
				Vector3 pos = b->getPosition();
				putMessage(CONSOLE_MSGTYPE_INFO, CONSOLE_SYSTEM_REPLY, _L("Vehicle position: ") + String("x: ") + TOSTRING(pos.x) + String(" y: ") + TOSTRING(pos.y) + String(" z: ") + TOSTRING(pos.z), "world.png");
			}

			return;
		}
		else if (args[0] == "/goto" && (gEnv->frameListener->loading_state == TERRAIN_LOADED || gEnv->frameListener->loading_state == ALL_LOADED))
		{
			if (args.size() != 4)
			{
				putMessage(CONSOLE_MSGTYPE_INFO, CONSOLE_HELP, ChatSystem::commandColour + _L("usage: /goto x y z"), "information.png");
				return;
			}

			Vector3 pos = Vector3(PARSEREAL(args[1]), PARSEREAL(args[2]), PARSEREAL(args[3]));

			Beam *b = BeamFactory::getSingleton().getCurrentTruck();
			if (!b && gEnv->player)
			{
				gEnv->player->setPosition(pos);
				putMessage(CONSOLE_MSGTYPE_INFO, CONSOLE_SYSTEM_REPLY, _L("Character position set to: ") + String("x: ") + TOSTRING(pos.x) + String(" y: ") + TOSTRING(pos.y) + String(" z: ") + TOSTRING(pos.z), "world.png");
			}
			else if (b)
			{
				b->resetPosition(pos, false);
				putMessage(CONSOLE_MSGTYPE_INFO, CONSOLE_SYSTEM_REPLY, _L("Vehicle position set to: ") + String("x: ") + TOSTRING(pos.x) + String(" y: ") + TOSTRING(pos.y) + String(" z: ") + TOSTRING(pos.z), "world.png");
			}

			return;
		}
		else if (args[0] == "/terrainheight" && (gEnv->frameListener->loading_state == TERRAIN_LOADED || gEnv->frameListener->loading_state == ALL_LOADED))
		{
			if (!gEnv->terrainManager->getHeightFinder()) return;
			Vector3 pos = Vector3::ZERO;

			Beam *b = BeamFactory::getSingleton().getCurrentTruck();
			if (!b && gEnv->player)
			{
				pos = gEnv->player->getPosition();
			}
			else if (b)
			{
				pos = b->getPosition();
			}

			Real h = gEnv->terrainManager->getHeightFinder()->getHeightAt(pos.x, pos.z);
			putMessage(CONSOLE_MSGTYPE_INFO, CONSOLE_SYSTEM_REPLY, _L("Terrain height at position: ") + String("x: ") + TOSTRING(pos.x) + String("z: ") + TOSTRING(pos.z) + _L(" = ")  + TOSTRING(h), "world.png");

			return;
		}
		else if (args[0] == "/ver")
		{
			putMessage(CONSOLE_MSGTYPE_INFO, CONSOLE_TITLE, "Rigs of Rods:", "information.png");
			putMessage(CONSOLE_MSGTYPE_INFO, CONSOLE_SYSTEM_REPLY, " Version: " + String(ROR_VERSION_STRING), "information.png");
			putMessage(CONSOLE_MSGTYPE_INFO, CONSOLE_SYSTEM_REPLY, " Protocol version: " + String(RORNET_VERSION), "information.png");
			putMessage(CONSOLE_MSGTYPE_INFO, CONSOLE_SYSTEM_REPLY, " build time: " + String(__DATE__) + ", " + String(__TIME__), "information.png");
			return;

		}
		else if (args[0] == "/quit")
		{
			Application::GetMainThreadLogic()->RequestExitCurrentLoop();
			Application::GetMainThreadLogic()->RequestShutdown();
			return;

		}
#ifdef USE_ANGELSCRIPT
		else if (args[0] == "/as" && (gEnv->frameListener->loading_state == TERRAIN_LOADED || gEnv->frameListener->loading_state == ALL_LOADED))
		{
			// we want to notify any running scripts that we might change something (prevent cheating)
			ScriptEngine::getSingleton().triggerEvent(SE_ANGELSCRIPT_MANIPULATIONS);

			String command = msg.substr(args[0].length());

			StringUtil::trim(command);
			if (command.empty()) return;

			String nmsg = ChatSystem::scriptCommandColour + ">>> " + ChatSystem::normalColour + command;
			putMessage(CONSOLE_MSGTYPE_SCRIPT, CONSOLE_LOCAL_SCRIPT, nmsg, "script_go.png");
			int res = ScriptEngine::getSingleton().executeString(command);
			return;
		}
#endif //ANGELSCRIPT
		else if (args[0] == "/log")
		{
			// switch to console logging
			bool logging = BSETTING("Enable Ingame Console", false);
			if (!logging)
			{
				putMessage(CONSOLE_MSGTYPE_INFO, CONSOLE_SYSTEM_NOTICE, _L(" logging to console enabled"), "information.png");
				SETTINGS.setSetting("Enable Ingame Console", "Yes");
			}
			else
			{
				putMessage(CONSOLE_MSGTYPE_INFO, CONSOLE_SYSTEM_NOTICE, _L(" logging to console disabled"), "information.png");
				SETTINGS.setSetting("Enable Ingame Console", "No");
			}
			return;
		}
		else
		{
			//TODO: Angelscript here
			putMessage(CONSOLE_MSGTYPE_INFO, CONSOLE_SYSTEM_ERROR, _L("unknown command: ") + msg, "error.png");
		}
	}

}