コード例 #1
0
/**
*  @brief
*    Called when a control of the input controller has been activated
*/
void Application30::OnControl(Control &cControl)
{
	// Get name of control
	String sControl = cControl.GetName();

	// Display control value
	String sValue;
	if (cControl.GetType() == ControlButton)
		sValue = static_cast<Button&>(cControl).IsPressed() ? "<pressed>" : "<released>";
	else if (cControl.GetType() == ControlAxis)
		sValue = String::Format("%5.2f", static_cast<Axis&>(cControl).GetValue());
	System::GetInstance()->GetConsole().Print("- '" + sControl + "': " + sValue + '\n');

	// LED test
	if ((cControl.GetName() == "Plus" || cControl.GetName() == "Minus") && static_cast<Button&>(cControl).IsPressed()) {
		// Get LED control
		LED *pLED = static_cast<LED*>(cControl.GetController()->GetControl("LED"));
		if (pLED) {
			// Change LED value
			uint32 nLED = pLED->GetLEDs();
			if (cControl.GetName() == "Plus")
				nLED++;
			else
				nLED--;
			if (nLED > 15)
				nLED = 0;
			pLED->SetLEDs(nLED);
		}
	}

	// Rumble test
	if (cControl.GetName() == "Button1" || cControl.GetName() == "Button2") {
		// Get rumble control (try "Rumble3" first for joystick, then "Rumble1" for WiiMote)
		Effect *pRumble = static_cast<Effect*>(cControl.GetController()->GetControl("Rumble3"));
		if (!pRumble)
			pRumble = static_cast<Effect*>(cControl.GetController()->GetControl("Rumble1"));
		if (pRumble) {
			// Enable or disable rumble?
			if (cControl.GetName() == "Button1")
				pRumble->SetValue(1.0f);
			if (cControl.GetName() == "Button2")
				pRumble->SetValue(0.0f);
		}
	}
}
コード例 #2
0
/**
*  @brief
*    Test: Controller
*/
void Application30::TestController()
{
	// Start
	System::GetInstance()->GetConsole().Print("Controller 'GameBoy'\n");
	System::GetInstance()->GetConsole().Print('\n');

	// Create test controller
	GameBoyController cController;

	// List all controls
	System::GetInstance()->GetConsole().Print("Controls:\n");
	const List<Control*> &lstControls = cController.GetControls();
	for (uint32 i=0; i<lstControls.GetNumOfElements(); i++) {
		// Get control
		Control *pControl = lstControls[i];
		if (pControl->GetType() == ControlButton)
			System::GetInstance()->GetConsole().Print("- Button '" + pControl->GetName() + "' [" + pControl->GetDescription() + "]\n");
		else if (pControl->GetType() == ControlAxis)
			System::GetInstance()->GetConsole().Print("- Axis   '" + pControl->GetName() + "' [" + pControl->GetDescription() + "]\n");
	}
	System::GetInstance()->GetConsole().Print('\n');

	// List buttons
	System::GetInstance()->GetConsole().Print("Buttons:\n");
	const List<Button*> &lstButtons = cController.GetButtons();
	for (uint32 i=0; i<lstButtons.GetNumOfElements(); i++) {
		Button *pButton = lstButtons[i];
		System::GetInstance()->GetConsole().Print("- Button   '" + pButton->GetName() + "' [" + pButton->GetDescription() + "]\n");
	}
	System::GetInstance()->GetConsole().Print('\n');

	// List axes
	System::GetInstance()->GetConsole().Print("Axes:\n");
	const List<Axis*> &lstAxes = cController.GetAxes();
	for (uint32 i=0; i<lstAxes.GetNumOfElements(); i++) {
		Axis *pAxis = lstAxes[i];
		System::GetInstance()->GetConsole().Print("- Axis '" + pAxis->GetName() + "' [" + pAxis->GetDescription() + "]\n");
	}
	System::GetInstance()->GetConsole().Print('\n');

	// Done
	System::GetInstance()->GetConsole().Print('\n');
}
コード例 #3
0
/**
*  @brief
*    Performs the picking
*/
void MyPicking::PerformPicking()
{
	// Get the default input controller of the application
	Controller *pController = reinterpret_cast<Controller*>(m_pApplication->GetInputController());
	if (pController && pController->GetActive()) {
		// Get the "MouseLeft" control
		Control *pControl = pController->GetControl("MouseLeft");
		if (pControl && pControl->GetType() == ControlButton) {
			Button *pButton = reinterpret_cast<Button*>(pControl);
			SceneNode *pPickedSceneNode = nullptr;

			// If the left mouse button is currently down, do NOT perform new picking
			if (!pButton->IsPressed()) {
				// Get the current time data
				const uint64 nPastTime = Timing::GetInstance()->GetPastTime();

				// Perform mouse picking - do not make this test each frame because it may cost some performance
				if ((nPastTime-m_nLastPickingTime) > 100) {
					m_nLastPickingTime = nPastTime;

					// Perform picking - "PerformMousePicking()" is using the current mouse position inside the main window
					// and the currently used camera in order to find the scene node under the mouse cursor
					PickingResult cPickingResult;
					if (PerformMousePicking(cPickingResult))
						pPickedSceneNode = cPickingResult.GetSceneNode();
				} else {
					// Use the previous result
					pPickedSceneNode = m_cCurrentPickedSceneNodeHandler.GetElement();
				}

				// Picked changed?
				if (pPickedSceneNode != m_cCurrentPickedSceneNodeHandler.GetElement()) {
					// Backup the currently picked scene node
					m_cCurrentPickedSceneNodeHandler.SetElement(pPickedSceneNode);
				}
			}

			// Is currently anything picked?
			if (pButton->IsHit() && pPickedSceneNode) {
				// Toggle the debug mode of the picked scene node
				if (pPickedSceneNode->GetDebugFlags() & SceneNode::DebugEnabled) {
					// Disable debug mode
					pPickedSceneNode->SetDebugFlags(pPickedSceneNode->GetDebugFlags() & ~SceneNode::DebugEnabled);
				} else {
					// Enable debug mode
					pPickedSceneNode->SetDebugFlags(pPickedSceneNode->GetDebugFlags() |SceneNode::DebugEnabled);
				}
			}
		}
	}
}
コード例 #4
0
ファイル: Gui.cpp プロジェクト: PixelLightCommunity/Plugins
void Gui::MouseScrolls(SRPWindows *pSRPWindow, Control &cControl)
{
	if (pSRPWindow)
	{
		if (pSRPWindow->GetData()->bIsVisable && pSRPWindow->GetData()->bMouseEnabled)
		{
			if (cControl.GetType() == ControlAxis)
			{
				if (cControl.GetName() == "MouseWheel")
				{
					// if all of the above is true, send mouse scroll
					pSRPWindow->GetAwesomiumWindow()->InjectMouseWheel(int(static_cast<Axis&>(cControl).GetValue()), 0);
				}
			}
		}
	}
}
コード例 #5
0
/**
*  @brief
*    Called when a control event has occurred
*/
void Application61::OnControl(Control &cControl)
{
	// Is it a button?
	if (cControl.GetType() == ControlButton && static_cast<Button&>(cControl).IsPressed()) {
		// Check whether the escape key was pressed
		if (cControl.GetName() == "KeyboardEscape") {
			// Shut down the application
			Exit(0);
		} else {
			// Get current time difference
			Timing *pTimer = Timing::GetInstance();
			const float fTimeScaleFactor = pTimer->GetTimeScaleFactor();

			// Check button
			if (cControl.GetName() == "Keyboard1") {
				// Decrease timescale
				pTimer->SetTimeScaleFactor(fTimeScaleFactor - 0.1f);
				if (pTimer->GetTimeScaleFactor() < 0.1f)
					pTimer->SetTimeScaleFactor(0.1f);
			} else if (cControl.GetName() == "Keyboard2") {
				// Increase timescale
				pTimer->SetTimeScaleFactor(fTimeScaleFactor +  0.1f);
				if (pTimer->GetTimeScaleFactor() > 4.0f)
					pTimer->SetTimeScaleFactor(4.0f);
			} else if (cControl.GetName() == "Keyboard3") {
				// Reset timescale
				pTimer->SetTimeScaleFactor();
			}

			// Time scale factor changed?
			if (fTimeScaleFactor != pTimer->GetTimeScaleFactor()) {
				// Update the time scale text node
				UpdateTimeScaleTextNode();

				// Update the pitch variable of the sound container using the time scale factor
				SceneContainer *pSceneContainer = GetScene();
				if (pSceneContainer)
					pSceneContainer->SetAttribute("Pitch", pTimer->GetTimeScaleFactor());
			}
		}
	}
}
コード例 #6
0
ファイル: Application.cpp プロジェクト: ByeDream/pixellight
/**
*  @brief
*    Called when a control event has occurred
*/
void Application::OnControl(Control &cControl)
{
	// Is it a button and was it just hit?
	if (cControl.GetType() == ControlButton) {
		// Shut down the application?
		if (cControl.GetName() == "KeyboardEscape") {
			if (reinterpret_cast<Button&>(cControl).IsHit())
				Exit(0);

		// Make a screenshot from the current render target?
		} else if (cControl.GetName() == "KeyboardF12") {
			if (reinterpret_cast<Button&>(cControl).IsHit())
				GetScreenshotTool().SaveScreenshot();

		// Toggle mouse cursor visibility?
		} else if (cControl.GetName() == "KeyboardM") {
			// Toggle mouse cursor visibility
			if (reinterpret_cast<Button&>(cControl).IsHit())
				GetFrontend().SetMouseVisible(!GetFrontend().IsMouseVisible());
		}
	}
}
コード例 #7
0
ファイル: Application67.cpp プロジェクト: ByeDream/pixellight
/**
*  @brief
*    Called when a control event has occurred
*/
void Application67::OnControl(Control &cControl)
{
	// Is it a button and was it just hit?
	if (cControl.GetType() == ControlButton && reinterpret_cast<Button&>(cControl).IsHit()) {
		// Check whether the escape key was pressed
		if (cControl.GetName() == "KeyboardEscape") {
			// Shut down the application
			Exit(0);

		// Restart the game
		} else if (cControl.GetName() == "KeyboardR") {
			Restart();

		// Toggle post processing
		} else if (cControl.GetName() == "KeyboardP") {
			// Get the camera
			const SceneNode *pCamera = reinterpret_cast<SceneNode*>(GetCamera());
			if (pCamera) {
				// Loop through all available post process scene node modifiers
				bool			   bRenderToTexture = false;
				uint32			   nIndex			= 0;
				SceneNodeModifier *pModifier		= pCamera->GetModifier("PLCompositing::SNMPostProcess", nIndex);
				while (pModifier) {
					// Toggle the active state of the post process scene node modifier
					pModifier->SetActive(!pModifier->IsActive());
					if (pModifier->IsActive())
						bRenderToTexture = true;

					// Next modifier, please
					pModifier = pCamera->GetModifier("PLCompositing::SNMPostProcess", ++nIndex);
				}

				// Enable/disable render to texture for the post processing feature
				GetSceneRendererTool().SetPassAttribute("Begin", "Flags", bRenderToTexture ? "" : "Inactive");
			}
		}
	}
}
コード例 #8
0
/**
*  @brief
*    Called when a control event has occurred
*/
void Application70::OnControl(Control &cControl)
{
	// Check whether the escape key was pressed
	if (cControl.GetType() == ControlButton && cControl.GetName() == "KeyboardEscape")
		Exit(0); // Shut down the application
}
コード例 #9
0
/**
*  @brief
*    Called when a control event has occurred
*/
void Application65::OnControl(Control &cControl)
{
	// Is it a button and was it just hit?
	if (cControl.GetType() == ControlButton && reinterpret_cast<Button&>(cControl).IsHit()) {
		// Check whether the escape key was pressed
		if (cControl.GetName() == "KeyboardEscape") {
			// Shut down the application
			Exit(0);

		// Show/hide the help text
		} else if (cControl.GetName() == "KeyboardF1") {
			// Get the info text scene node
			SceneNode *pSceneNode = GetRootScene() ? GetRootScene()->GetByName("InfoText") : nullptr;
			if (pSceneNode) {
				// Toggle the active state of the scene node
				pSceneNode->SetActive(!pSceneNode->IsActive());
			}

		// Toggle post processing
		} else if (cControl.GetName() == "KeyboardSpace") {
			// Get the currently used camera
			SceneNode *pCamera = reinterpret_cast<SceneNode*>(GetCamera());
			if (pCamera) {
				// Loop through all available post process scene node modifiers
				uint32			   nIndex    = 0;
				SceneNodeModifier *pModifier = pCamera->GetModifier("PLCompositing::SNMPostProcess", nIndex);
				while (pModifier) {
					// Toggle the active state of the post process scene node modifier
					pModifier->SetActive(!pModifier->IsActive());

					// Next modifier, please
					pModifier = pCamera->GetModifier("PLCompositing::SNMPostProcess", ++nIndex);
				}
			}

		// Next post process effect
		} else if (cControl.GetName() == "KeyboardPageUp") {
			// Get the currently used camera
			SceneNode *pCamera = reinterpret_cast<SceneNode*>(GetCamera());
			if (pCamera) {
				// Increase the current selected modifier index
				m_nCurrentSelectedModifier++;
				if (m_nCurrentSelectedModifier >= m_lstModifierClasses.GetNumOfElements())
					m_nCurrentSelectedModifier = 0;

				// Remove all old modifiers add the new one
				pCamera->ClearModifiers();
				pCamera->AddModifier(m_lstModifierClasses[m_nCurrentSelectedModifier]->GetClassName());
			}

		// Previous post process effect
		} else if (cControl.GetName() == "KeyboardPageDown") {
			// Get the currently used camera
			SceneNode *pCamera = reinterpret_cast<SceneNode*>(GetCamera());
			if (pCamera) {
				// Decrease the current selected modifier index
				if (m_nCurrentSelectedModifier)
					m_nCurrentSelectedModifier--;
				else
					m_nCurrentSelectedModifier = m_lstModifierClasses.GetNumOfElements()-1;

				// Remove all old modifiers add the new one
				pCamera->ClearModifiers();
				pCamera->AddModifier(m_lstModifierClasses[m_nCurrentSelectedModifier]->GetClassName());
			}

		// Custom post process effect: "Rainbow"
		} else if (cControl.GetName() == "Keyboard1") {
			// Get the currently used camera
			SceneNode *pCamera = reinterpret_cast<SceneNode*>(GetCamera());
			if (pCamera) {
				// Remove all old modifiers add the new one
				pCamera->ClearModifiers();
				pCamera->AddModifier("PLPostProcessEffects::SNMPostProcessCrazyBars", "ColorScaleY=\"0.002\"");
			}

		// Custom post process effect: "Cartoon"
		} else if (cControl.GetName() == "Keyboard2") {
			// Get the currently used camera
			SceneNode *pCamera = reinterpret_cast<SceneNode*>(GetCamera());
			if (pCamera) {
				// Remove all old modifiers add the new ones
				pCamera->ClearModifiers();
				pCamera->AddModifier("PLPostProcessEffects::SNMPostProcessEdgeDetect", "LuminanceConvert=\"-0.2125 -0.7154 -0.0721\"");
				pCamera->AddModifier("PLPostProcessEffects::SNMPostProcessCombineMultiplicate");
			}

		// Custom post process effect: "Animated cartoon"
		} else if (cControl.GetName() == "Keyboard3") {
			// Get the currently used camera
			SceneNode *pCamera = reinterpret_cast<SceneNode*>(GetCamera());
			if (pCamera) {
				// Remove all old modifiers add the new ones
				pCamera->ClearModifiers();
				pCamera->AddModifier("PLPostProcessEffects::SNMPostProcessEdgeDetect", "LuminanceConvert=\"-0.2125 -0.7154 -0.0721\"");
				pCamera->AddModifier("PLPostProcessEffects::SNMPostProcessOldFilm");
				pCamera->AddModifier("PLPostProcessEffects::SNMPostProcessCombineMultiplicate");
			}

		// Custom post process effect: "Animated old cartoon"
		} else if (cControl.GetName() == "Keyboard4") {
			// Get the currently used camera
			SceneNode *pCamera = reinterpret_cast<SceneNode*>(GetCamera());
			if (pCamera) {
				// Remove all old modifiers add the new ones
				pCamera->ClearModifiers();
				pCamera->AddModifier("PLPostProcessEffects::SNMPostProcessEdgeDetect", "LuminanceConvert=\"-0.2125 -0.7154 -0.0721\"");
				pCamera->AddModifier("PLPostProcessEffects::SNMPostProcessCombineMultiplicate");
				pCamera->AddModifier("PLPostProcessEffects::SNMPostProcessOldFilm");
			}

		// Custom post process effect: "Scratch"
		} else if (cControl.GetName() == "Keyboard5") {
			// Get the currently used camera
			SceneNode *pCamera = reinterpret_cast<SceneNode*>(GetCamera());
			if (pCamera) {
				// Remove all old modifiers add the new one
				pCamera->ClearModifiers();
				pCamera->AddModifier("PLPostProcessEffects::SNMPostProcessEdgeDetect", "LuminanceConvert=\"-0.2125 -0.7154 -0.0721\"");
			}

		// Custom post process effect: "Animated old scratch"
		} else if (cControl.GetName() == "Keyboard6") {
			// Get the currently used camera
			SceneNode *pCamera = reinterpret_cast<SceneNode*>(GetCamera());
			if (pCamera) {
				// Remove all old modifiers add the new ones
				pCamera->ClearModifiers();
				pCamera->AddModifier("PLPostProcessEffects::SNMPostProcessEdgeDetect", "LuminanceConvert=\"-0.2125 -0.7154 -0.0721\"");
				pCamera->AddModifier("PLPostProcessEffects::SNMPostProcessOldFilm");
			}

		// Custom post process effect: "Edge glow"
		} else if (cControl.GetName() == "Keyboard7") {
			// Get the currently used camera
			SceneNode *pCamera = reinterpret_cast<SceneNode*>(GetCamera());
			if (pCamera) {
				// Remove all old modifiers add the new one
				pCamera->ClearModifiers();
				pCamera->AddModifier("PLPostProcessEffects::SNMPostProcessEdgeDetect", "Filename=\"Data/PostProcesses/EdgeGlow.pp\"");
			}
		}
	}
}