Esempio n. 1
0
void HugeObjectCount::HandleUpdate(StringHash eventType, VariantMap& eventData)
{
    using namespace Update;

    // Take the frame time step, which is stored as a float
    float timeStep = eventData[P_TIMESTEP].GetFloat();
    
    // Toggle animation with space
    Input* input = GetSubsystem<Input>();
    if (input->GetKeyPress(KEY_SPACE))
        animate_ = !animate_;

    // Toggle grouped / ungrouped mode
    if (input->GetKeyPress('G'))
    {
        useGroups_ = !useGroups_;
        CreateScene();
    }

    // Move the camera, scale movement with time step
    MoveCamera(timeStep);
    
    // Animate scene if enabled
    if (animate_)
        AnimateObjects(timeStep);
}
Esempio n. 2
0
void Labyrinth::HandleUpdate(StringHash eventType, VariantMap& eventData)
{
    using namespace Update;

    // Take the frame time step, which is stored as a float
    float timeStep = eventData[P_TIMESTEP].GetFloat();
    
    // Toggle animation with space
    Input* input = GetSubsystem<Input>();
    if (input->GetKeyPress(KEY_SPACE))
        animate_ = !animate_;

    // Toggle grouped / ungrouped mode
    // TODO CHECK treba dorobit tak aby vedel dat bloky do jednej grupy, a tiez treba zistit ako to funguje ???
    if (input->GetKeyPress('G'))
    {
        useGroups_ = !useGroups_;
        CreateScene();
    }
    
    if (input->GetKeyPress(KEY_SPACE))
    {
        drawDebug_ = !drawDebug_;
	//scene_->GetComponent<PhysicsWorld>()->DrawDebugGeometry(true);
    }
    
    // CAMERA Move the camera, scale movement with time step
    MoveCamera(timeStep);
}
Esempio n. 3
0
void CharacterDemo::HandleUpdate(StringHash eventType, VariantMap& eventData)
{
    using namespace Update;
    
    float timeStep = eventData[P_TIMESTEP].GetFloat();
    Input* input = GetSubsystem<Input>();

    if (character_)
    {
        UI* ui = GetSubsystem<UI>();
        
        // Get movement controls and assign them to the character logic component. If UI has a focused element, clear controls
        if (!ui->GetFocusElement())
        {
            character_->controls_.Set(CTRL_FORWARD, input->GetKeyDown('W'));
            character_->controls_.Set(CTRL_BACK, input->GetKeyDown('S'));
            character_->controls_.Set(CTRL_LEFT, input->GetKeyDown('A'));
            character_->controls_.Set(CTRL_RIGHT, input->GetKeyDown('D'));
            character_->controls_.Set(CTRL_JUMP, input->GetKeyDown(KEY_SPACE));
            
            // Add character yaw & pitch from the mouse motion
            character_->controls_.yaw_ += (float)input->GetMouseMoveX() * YAW_SENSITIVITY;
            character_->controls_.pitch_ += (float)input->GetMouseMoveY() * YAW_SENSITIVITY;
            // Limit pitch
            character_->controls_.pitch_ = Clamp(character_->controls_.pitch_, -80.0f, 80.0f);
            
            // Switch between 1st and 3rd person
            if (input->GetKeyPress('F'))
                firstPerson_ = !firstPerson_;

            // Check for loading / saving the scene
            if (input->GetKeyPress(KEY_F5))
            {
                File saveFile(context_, GetSubsystem<FileSystem>()->GetProgramDir() + "Data/Scenes/CharacterDemo.xml",
                    FILE_WRITE);
                scene_->SaveXML(saveFile);
            }
            if (input->GetKeyPress(KEY_F7))
            {
                File loadFile(context_, GetSubsystem<FileSystem>()->GetProgramDir() + "Data/Scenes/CharacterDemo.xml", FILE_READ);
                scene_->LoadXML(loadFile);
                // After loading we have to reacquire the weak pointer to the Character component, as it has been recreated
                // Simply find the character's scene node by name as there's only one of them
                Node* characterNode = scene_->GetChild("Jack", true);
                if (characterNode)
                    character_ = characterNode->GetComponent<Character>();
            }
        }
        else
            character_->controls_.Set(CTRL_FORWARD | CTRL_BACK | CTRL_LEFT | CTRL_RIGHT | CTRL_JUMP, false);
        
        // Set rotation already here so that it's updated every rendering frame instead of every physics frame
        character_->GetNode()->SetRotation(Quaternion(character_->controls_.yaw_, Vector3::UP));
    }
}
Esempio n. 4
0
void Physics::MoveCamera(float timeStep)
{
    // Do not move if the UI has a focused element (the console)
    if (GetSubsystem<UI>()->GetFocusElement())
        return;

    Input* input = GetSubsystem<Input>();

    // Movement speed as world units per second
    const float MOVE_SPEED = 20.0f;
    // Mouse sensitivity as degrees per pixel
    const float MOUSE_SENSITIVITY = 0.1f;

    // Use this frame's mouse motion to adjust camera node yaw and pitch. Clamp the pitch between -90 and 90 degrees
    IntVector2 mouseMove = input->GetMouseMove();
    yaw_ += MOUSE_SENSITIVITY * mouseMove.x_;
    pitch_ += MOUSE_SENSITIVITY * mouseMove.y_;
    pitch_ = Clamp(pitch_, -90.0f, 90.0f);

    // Construct new orientation for the camera scene node from yaw and pitch. Roll is fixed to zero
    cameraNode_->SetRotation(Quaternion(pitch_, yaw_, 0.0f));

    // Read WASD keys and move the camera scene node to the corresponding direction if they are pressed
    if (input->GetKeyDown(KEY_W))
        cameraNode_->Translate(Vector3::FORWARD * MOVE_SPEED * timeStep);
    if (input->GetKeyDown(KEY_S))
        cameraNode_->Translate(Vector3::BACK * MOVE_SPEED * timeStep);
    if (input->GetKeyDown(KEY_A))
        cameraNode_->Translate(Vector3::LEFT * MOVE_SPEED * timeStep);
    if (input->GetKeyDown(KEY_D))
        cameraNode_->Translate(Vector3::RIGHT * MOVE_SPEED * timeStep);

    // "Shoot" a physics object with left mousebutton
    if (input->GetMouseButtonPress(MOUSEB_LEFT))
        SpawnObject();

    // Check for loading/saving the scene. Save the scene to the file Data/Scenes/Physics.xml relative to the executable
    // directory
    if (input->GetKeyPress(KEY_F5))
    {
        File saveFile(context_, GetSubsystem<FileSystem>()->GetProgramDir() + "Data/Scenes/Physics.xml", FILE_WRITE);
        scene_->SaveXML(saveFile);
    }
    if (input->GetKeyPress(KEY_F7))
    {
        File loadFile(context_, GetSubsystem<FileSystem>()->GetProgramDir() + "Data/Scenes/Physics.xml", FILE_READ);
        scene_->LoadXML(loadFile);
    }

    // Toggle physics debug geometry with space
    if (input->GetKeyPress(KEY_SPACE))
        drawDebug_ = !drawDebug_;
}
Esempio n. 5
0
void DebugCameraController::Update(float timeStep)
{
    // Do not move if the UI has a focused element
    if (GetUI()->GetFocusElement())
        return;

    // Do not move if interacting with UI controls
    if (GetSystemUI()->IsAnyItemActive())
        return;

    Input* input = GetInput();

    // Movement speed as world units per second
    float moveSpeed_ = speed_;
    if (input->GetKeyDown(KEY_SHIFT))
    {
        moveSpeed_ *= 2;

        if (input->GetKeyPress(KEY_KP_PLUS))
            speed_ += 1.f;
        else if (input->GetKeyPress(KEY_KP_MINUS))
            speed_ -= 1.f;
    }

    if (input->GetMouseButtonDown(MOUSEB_RIGHT))
    {
        IntVector2 delta = input->GetMouseMove();

        if (input->IsMouseVisible() && delta != IntVector2::ZERO)
            input->SetMouseVisible(false);

        auto yaw = GetNode()->GetRotation().EulerAngles().x_;
        if ((yaw > -90.f && yaw < 90.f) || (yaw <= -90.f && delta.y_ > 0) || (yaw >= 90.f && delta.y_ < 0))
            GetNode()->RotateAround(Vector3::ZERO, Quaternion(mouseSensitivity_ * delta.y_, Vector3::RIGHT), TS_LOCAL);
        GetNode()->RotateAround(GetNode()->GetPosition(), Quaternion(mouseSensitivity_ * delta.x_, Vector3::UP), TS_WORLD);
    }
    else if (!input->IsMouseVisible())
        input->SetMouseVisible(true);

    // Read WASD keys and move the camera scene node to the corresponding direction if they are pressed
    if (input->GetKeyDown(KEY_W))
        GetNode()->Translate(Vector3::FORWARD * moveSpeed_ * timeStep);
    if (input->GetKeyDown(KEY_S))
        GetNode()->Translate(Vector3::BACK * moveSpeed_ * timeStep);
    if (input->GetKeyDown(KEY_A))
        GetNode()->Translate(Vector3::LEFT * moveSpeed_ * timeStep);
    if (input->GetKeyDown(KEY_D))
        GetNode()->Translate(Vector3::RIGHT * moveSpeed_ * timeStep);
}
Esempio n. 6
0
void VehicleDemo::HandleUpdate(StringHash eventType, VariantMap& eventData)
{
    using namespace Update;
    
    float timeStep = eventData[P_TIMESTEP].GetFloat();
    Input* input = GetSubsystem<Input>();

    if (vehicle_)
    {
        UI* ui = GetSubsystem<UI>();
        
        // Get movement controls and assign them to the vehicle component. If UI has a focused element, clear controls
        if (!ui->GetFocusElement())
        {
            vehicle_->controls_.Set(CTRL_FORWARD, input->GetKeyDown('W'));
            vehicle_->controls_.Set(CTRL_BACK, input->GetKeyDown('S'));
            vehicle_->controls_.Set(CTRL_LEFT, input->GetKeyDown('A'));
            vehicle_->controls_.Set(CTRL_RIGHT, input->GetKeyDown('D'));
        
            // Add yaw & pitch from the mouse motion. Used only for the camera, does not affect motion
            vehicle_->controls_.yaw_ += (float)input->GetMouseMoveX() * YAW_SENSITIVITY;
            vehicle_->controls_.pitch_ += (float)input->GetMouseMoveY() * YAW_SENSITIVITY;
            // Limit pitch
            vehicle_->controls_.pitch_ = Clamp(vehicle_->controls_.pitch_, 0.0f, 80.0f);

            // Check for loading / saving the scene
            if (input->GetKeyPress(KEY_F5))
            {
                File saveFile(context_, GetSubsystem<FileSystem>()->GetProgramDir() + "Data/Scenes/VehicleDemo.xml",
                    FILE_WRITE);
                scene_->SaveXML(saveFile);
            }
            if (input->GetKeyPress(KEY_F7))
            {
                File loadFile(context_, GetSubsystem<FileSystem>()->GetProgramDir() + "Data/Scenes/VehicleDemo.xml", FILE_READ);
                scene_->LoadXML(loadFile);
                // After loading we have to reacquire the weak pointer to the Vehicle component, as it has been recreated
                // Simply find the vehicle's scene node by name as there's only one of them
                Node* vehicleNode = scene_->GetChild("Vehicle", true);
                if (vehicleNode)
                    vehicle_ = vehicleNode->GetComponent<Vehicle>();
            }
        }
        else
            vehicle_->controls_.Set(CTRL_FORWARD | CTRL_BACK | CTRL_LEFT | CTRL_RIGHT, false);
    }
}
Esempio n. 7
0
void DebugCameraController2D::Update(float timeStep)
{
    // Do not move if the UI has a focused element
    if (GetUI()->GetFocusElement())
        return;

    // Do not move if interacting with UI controls
    if (GetSystemUI()->IsAnyItemActive())
        return;

    Input* input = GetInput();

    // Movement speed as world units per second
    float moveSpeed_ = speed_;
    if (input->GetKeyDown(KEY_SHIFT))
    {
        moveSpeed_ *= 2;

        if (input->GetKeyPress(KEY_KP_PLUS))
            speed_ += 1.f;
        else if (input->GetKeyPress(KEY_KP_MINUS))
            speed_ -= 1.f;
    }

    if (input->GetMouseButtonDown(MOUSEB_RIGHT))
    {
        IntVector2 delta = input->GetMouseMove();

        if (input->IsMouseVisible() && delta != IntVector2::ZERO)
            input->SetMouseVisible(false);
        GetNode()->Translate2D(Vector2{(float)delta.x_ * -1.f, (float)delta.y_} * moveSpeed_ * timeStep);
    }
    else if (!input->IsMouseVisible())
        input->SetMouseVisible(true);

    // Read WASD keys and move the camera scene node to the corresponding direction if they are pressed
    if (input->GetKeyDown(KEY_W))
        GetNode()->Translate(Vector3::UP * moveSpeed_ * timeStep);
    if (input->GetKeyDown(KEY_S))
        GetNode()->Translate(Vector3::DOWN * moveSpeed_ * timeStep);
    if (input->GetKeyDown(KEY_A))
        GetNode()->Translate(Vector3::LEFT * moveSpeed_ * timeStep);
    if (input->GetKeyDown(KEY_D))
        GetNode()->Translate(Vector3::RIGHT * moveSpeed_ * timeStep);
}
Esempio n. 8
0
void MultipleViewports::MoveCamera(float timeStep)
{
     // Do not move if the UI has a focused element (the console)
    if (GetSubsystem<UI>()->GetFocusElement())
        return;
    
    Input* input = GetSubsystem<Input>();
    
    // Movement speed as world units per second
    const float MOVE_SPEED = 20.0f;
    // Mouse sensitivity as degrees per pixel
    const float MOUSE_SENSITIVITY = 0.1f;
    
    // Use this frame's mouse motion to adjust camera node yaw and pitch. Clamp the pitch between -90 and 90 degrees
    IntVector2 mouseMove = input->GetMouseMove();
    yaw_ += MOUSE_SENSITIVITY * mouseMove.x_;
    pitch_ += MOUSE_SENSITIVITY * mouseMove.y_;
    pitch_ = Clamp(pitch_, -90.0f, 90.0f);
    
    // Construct new orientation for the camera scene node from yaw and pitch. Roll is fixed to zero
    cameraNode_->SetRotation(Quaternion(pitch_, yaw_, 0.0f));
    
    // Read WASD keys and move the camera scene node to the corresponding direction if they are pressed
    if (input->GetKeyDown('W'))
        cameraNode_->Translate(Vector3::FORWARD * MOVE_SPEED * timeStep);
    if (input->GetKeyDown('S'))
        cameraNode_->Translate(Vector3::BACK * MOVE_SPEED * timeStep);
    if (input->GetKeyDown('A'))
        cameraNode_->Translate(Vector3::LEFT * MOVE_SPEED * timeStep);
    if (input->GetKeyDown('D'))
        cameraNode_->Translate(Vector3::RIGHT * MOVE_SPEED * timeStep);
    
    // Toggle post processing effects on the front viewport. Note that the rear viewport is unaffected
    RenderPath* effectRenderPath = GetSubsystem<Renderer>()->GetViewport(0)->GetRenderPath();
    if (input->GetKeyPress('B'))
        effectRenderPath->ToggleEnabled("Bloom");
    if (input->GetKeyPress('F'))
        effectRenderPath->ToggleEnabled("FXAA2");
    
    // Toggle debug geometry with space
    if (input->GetKeyPress(KEY_SPACE))
        drawDebug_ = !drawDebug_;
}
Esempio n. 9
0
void Urho2DConstraints::HandleUpdate(StringHash eventType, VariantMap& eventData)
{
    using namespace Update;

    // Take the frame time step, which is stored as a float
    float timeStep = eventData[P_TIMESTEP].GetFloat();

    // Move the camera, scale movement with time step
    MoveCamera(timeStep);

    Input* input = GetSubsystem<Input>();

    // Toggle physics debug geometry with space
    if (input->GetKeyPress(KEY_SPACE))
        drawDebug_ = !drawDebug_;

    // Save scene
    if (input->GetKeyPress(KEY_F5))
    {
        File saveFile(context_, GetSubsystem<FileSystem>()->GetProgramDir() + "Data/Scenes/Constraints.xml", FILE_WRITE);
        scene_->SaveXML(saveFile);
    }
}
Esempio n. 10
0
void Navigation::MoveCamera(float timeStep)
{
    // Right mouse button controls mouse cursor visibility: hide when pressed
    UI* ui = GetSubsystem<UI>();
    Input* input = GetSubsystem<Input>();
    ui->GetCursor()->SetVisible(!input->GetMouseButtonDown(MOUSEB_RIGHT));
    
    // Do not move if the UI has a focused element (the console)
    if (ui->GetFocusElement())
        return;
    
    // Movement speed as world units per second
    const float MOVE_SPEED = 20.0f;
    // Mouse sensitivity as degrees per pixel
    const float MOUSE_SENSITIVITY = 0.1f;
    
    // Use this frame's mouse motion to adjust camera node yaw and pitch. Clamp the pitch between -90 and 90 degrees
    // Only move the camera when the cursor is hidden
    if (!ui->GetCursor()->IsVisible())
    {
        IntVector2 mouseMove = input->GetMouseMove();
        yaw_ += MOUSE_SENSITIVITY * mouseMove.x_;
        pitch_ += MOUSE_SENSITIVITY * mouseMove.y_;
        pitch_ = Clamp(pitch_, -90.0f, 90.0f);
        
        // Construct new orientation for the camera scene node from yaw and pitch. Roll is fixed to zero
        cameraNode_->SetRotation(Quaternion(pitch_, yaw_, 0.0f));
    }
    
    // Read WASD keys and move the camera scene node to the corresponding direction if they are pressed
    if (input->GetKeyDown('W'))
        cameraNode_->TranslateRelative(Vector3::FORWARD * MOVE_SPEED * timeStep);
    if (input->GetKeyDown('S'))
        cameraNode_->TranslateRelative(Vector3::BACK * MOVE_SPEED * timeStep);
    if (input->GetKeyDown('A'))
        cameraNode_->TranslateRelative(Vector3::LEFT * MOVE_SPEED * timeStep);
    if (input->GetKeyDown('D'))
        cameraNode_->TranslateRelative(Vector3::RIGHT * MOVE_SPEED * timeStep);
    
    // Set route start/endpoint with left mouse button, recalculate route if applicable
    if (input->GetMouseButtonPress(MOUSEB_LEFT))
        SetPathPoint();
    // Add or remove objects with middle mouse button, then rebuild navigation mesh partially
    if (input->GetMouseButtonPress(MOUSEB_MIDDLE))
        AddOrRemoveObject();
        
    // Toggle debug geometry with space
    if (input->GetKeyPress(KEY_SPACE))
        drawDebug_ = !drawDebug_;
}
void DynamicGeometry::HandleUpdate(StringHash eventType, VariantMap& eventData)
{
    using namespace Update;

    // Take the frame time step, which is stored as a float
    float timeStep = eventData[P_TIMESTEP].GetFloat();

    // Toggle animation with space
    Input* input = GetSubsystem<Input>();
    if (input->GetKeyPress(KEY_SPACE))
        animate_ = !animate_;

    // Move the camera, scale movement with time step
    MoveCamera(timeStep);

    // Animate objects' vertex data if enabled
    if (animate_)
        AnimateObjects(timeStep);
}
Esempio n. 12
0
	void Sample::MoveCamera(float timeStep)
	{
		// Do not move if the UI has a focused element (the console)
		if (GetSubsystem<UI>()->GetFocusElement())
			return;

		Input* input = GetSubsystem<Input>();

		// Movement speed as world units per second
		float MOVE_SPEED = 20.0f;
		if (input->GetKeyDown(KEY_SHIFT))
		{
			MOVE_SPEED = 60.0f;
		}
		// Mouse sensitivity as degrees per pixel
		const float MOUSE_SENSITIVITY = 0.1f;

		// Use this frame's mouse motion to adjust camera node yaw and pitch. Clamp the pitch between -90 and 90 degrees
		IntVector2 mouseMove = input->GetMouseMove();
		yaw_ += MOUSE_SENSITIVITY * mouseMove.x_;
		pitch_ += MOUSE_SENSITIVITY * mouseMove.y_;
		pitch_ = Clamp(pitch_, -90.0f, 90.0f);

		// Construct new orientation for the camera scene node from yaw and pitch. Roll is fixed to zero
		camNode_->SetRotation(Quaternion(pitch_, yaw_, 0.0f));

		// Read WASD keys and move the camera scene node to the corresponding direction if they are pressed
		if (input->GetKeyDown('W'))
			camNode_->Translate(Vector3::FORWARD * MOVE_SPEED * timeStep);
		if (input->GetKeyDown('S'))
			camNode_->Translate(Vector3::BACK * MOVE_SPEED * timeStep);
		if (input->GetKeyDown('A'))
			camNode_->Translate(Vector3::LEFT * MOVE_SPEED * timeStep);
		if (input->GetKeyDown('D'))
			camNode_->Translate(Vector3::RIGHT * MOVE_SPEED * timeStep);

		// Toggle debug geometry with space
		if (input->GetKeyPress(KEY_SPACE))
			drawDebug_ = !drawDebug_;
	}
Esempio n. 13
0
void UIDrag::HandleUpdate(StringHash eventType, VariantMap& eventData)
{
    UI* ui = GetSubsystem<UI>();
    UIElement* root = ui->GetRoot();

    Input* input = GetSubsystem<Input>();

    unsigned n = input->GetNumTouches();
    for (unsigned i = 0; i < n; i++)
    {
        Text* t = (Text*)root->GetChild("Touch " + String(i));
        TouchState* ts = input->GetTouch(i);
        t->SetText("Touch " + String(ts->touchID_));

        IntVector2 pos = ts->position_;
        pos.y_ -= 30;

        t->SetPosition(pos);
        t->SetVisible(true);
    }

    for (unsigned i = n; i < 10; i++)
    {
        Text* t = (Text*)root->GetChild("Touch " + String(i));
        t->SetVisible(false);
    }
    
    if (input->GetKeyPress(KEY_SPACE))
    {
        PODVector<UIElement*> elements;
        root->GetChildrenWithTag(elements, "SomeTag");
        for (PODVector<UIElement*>::ConstIterator i = elements.Begin(); i != elements.End(); ++i)
        {
            UIElement* element = *i;
            element->SetVisible(!element->IsVisible());
        }
    }
}
Esempio n. 14
0
void VehicleDemo::HandleUpdate(StringHash eventType, VariantMap& eventData)
{
    using namespace Update;

    Input* input = GetSubsystem<Input>();

    if (vehicle_)
    {
        UI* ui = GetSubsystem<UI>();

        // Get movement controls and assign them to the vehicle component. If UI has a focused element, clear controls
        if (!ui->GetFocusElement())
        {
            vehicle_->controls_.Set(CTRL_FORWARD, input->GetKeyDown(KEY_W));
            vehicle_->controls_.Set(CTRL_BACK, input->GetKeyDown(KEY_S));
            vehicle_->controls_.Set(CTRL_LEFT, input->GetKeyDown(KEY_A));
            vehicle_->controls_.Set(CTRL_RIGHT, input->GetKeyDown(KEY_D));

            // Add yaw & pitch from the mouse motion or touch input. Used only for the camera, does not affect motion
            if (touchEnabled_)
            {
                for (unsigned i = 0; i < input->GetNumTouches(); ++i)
                {
                    TouchState* state = input->GetTouch(i);
                    if (!state->touchedElement_)    // Touch on empty space
                    {
                        Camera* camera = cameraNode_->GetComponent<Camera>();
                        if (!camera)
                            return;

                        Graphics* graphics = GetSubsystem<Graphics>();
                        vehicle_->controls_.yaw_ += TOUCH_SENSITIVITY * camera->GetFov() / graphics->GetHeight() * state->delta_.x_;
                        vehicle_->controls_.pitch_ += TOUCH_SENSITIVITY * camera->GetFov() / graphics->GetHeight() * state->delta_.y_;
                    }
                }
            }
            else
            {
                vehicle_->controls_.yaw_ += (float)input->GetMouseMoveX() * YAW_SENSITIVITY;
                vehicle_->controls_.pitch_ += (float)input->GetMouseMoveY() * YAW_SENSITIVITY;
            }
            // Limit pitch
            vehicle_->controls_.pitch_ = Clamp(vehicle_->controls_.pitch_, 0.0f, 80.0f);

            // Check for loading / saving the scene
            if (input->GetKeyPress(KEY_F5))
            {
                File saveFile(context_, GetSubsystem<FileSystem>()->GetProgramDir() + "Data/Scenes/VehicleDemo.xml",
                    FILE_WRITE);
                scene_->SaveXML(saveFile);
            }
            if (input->GetKeyPress(KEY_F7))
            {
                File loadFile(context_, GetSubsystem<FileSystem>()->GetProgramDir() + "Data/Scenes/VehicleDemo.xml", FILE_READ);
                scene_->LoadXML(loadFile);
                // After loading we have to reacquire the weak pointer to the Vehicle component, as it has been recreated
                // Simply find the vehicle's scene node by name as there's only one of them
                Node* vehicleNode = scene_->GetChild("Vehicle", true);
                if (vehicleNode)
                    vehicle_ = vehicleNode->GetComponent<Vehicle>();
            }
        }
        else
            vehicle_->controls_.Set(CTRL_FORWARD | CTRL_BACK | CTRL_LEFT | CTRL_RIGHT, false);
    }
}
Esempio n. 15
0
void SoccerInput::ProcessInput(const Input& input)
{
    switch (input.mId)
        {
        default:
            return;

        case CmdPlayerSelectMode:
            if (input.GetKeyPress())
            {
                mCmdMode = CmdModePlayerSelect;
            }
            break;
        
        case CmdSelectNextAgent:
            if (input.GetKeyPress())
                {
                    SendCommand("(select)");
                }
            break;
        
        case CmdResetSelection:
            if (input.GetKeyPress())
                {
                    SendCommand("(select (unum -1))");
                }
            break;
            
        case CmdKillSelection:
            if (input.GetKeyPress())
                {
                    SendCommand("(kill)");
                }
            break;
            
        case CmdReposSelection:
            if (input.GetKeyPress())
                {
                    SendCommand("(repos)");
                }
            break;
            
        case CmdKickOff:
            if (input.GetKeyPress())
                {
                    SendCommand("(kickOff Left)");
                }
            break;
        case CmdKickOffRight:
            if (input.GetKeyPress())
                {
                    SendCommand("(kickOff Right)");
                }
            break;
           
        case CmdMoveAgent:
            if (input.GetKeyPress())
                {
                    SendCommand("(agent)");
                }
            break;
        case CmdDropBall:
            if (input.GetKeyPress())
                {
                    SendCommand("(dropBall)");
                }
            break;
        case CmdShootBall:
            if (input.GetKeyPress())
                {
                    //SendCommand("(ball (vel -4.0 0.0 2.0))");
                }
            break;
        case CmdMoveBall:
            if (input.GetKeyPress())
                {
                    //SendCommand("(ball (pos -42.0 0.0 0.3))");
                }
            break;

        case CmdOne:
        case CmdTwo:
        case CmdThree:
        case CmdFour:
        case CmdFive:
        case CmdSix:
        case CmdSeven:
        case CmdEight:
        case CmdNine:
        case CmdZero:
            if (input.GetKeyPress())
                {
                    if (mCmdMode == CmdModeDefault)
                        SelectCamera(input.mId - CmdOne);
                    else
                    {
                        ostringstream u_ss;
                        u_ss << "(select (unum " << (input.mId - CmdOne + 1) << ") ";
                        if (mCmdMode == CmdModeLeftPlayerSelect)
                        {
                            u_ss << "(team Left))";
                            SendCommand(u_ss.str());
                            mCmdMode = CmdModeDefault;
                        }
                        else if (mCmdMode == CmdModeRightPlayerSelect)
                        {
                            u_ss << "(team Right))";
                            SendCommand(u_ss.str());
                            mCmdMode = CmdModeDefault;
                        }
                    }
                }
            break;
        case CmdLeft:
            if (input.GetKeyPress())
                {
                    if (mCmdMode == CmdModeDefault)
                        SendCommand("(playMode free_kick_left)");
                    else if (mCmdMode == CmdModePlayerSelect || mCmdMode == CmdModeRightPlayerSelect)
                        mCmdMode = CmdModeLeftPlayerSelect;
                }
            break;
        case CmdRight:
            if (input.GetKeyPress())
                {
                    if (mCmdMode == CmdModeDefault)
                        SendCommand("(playMode free_kick_right)");
                    else if (mCmdMode == CmdModePlayerSelect || mCmdMode == CmdModeLeftPlayerSelect)
                        mCmdMode = CmdModeRightPlayerSelect;
                }
            break;
        };
}
Esempio n. 16
0
void CharacterDemo::HandleUpdate(StringHash eventType, VariantMap& eventData)
{
    using namespace Update;

    Input* input = GetSubsystem<Input>();

    if (character_)
    {
        // Clear previous controls
        character_->controls_.Set(CTRL_FORWARD | CTRL_BACK | CTRL_LEFT | CTRL_RIGHT | CTRL_JUMP, false);

        // Update controls using touch utility class
        if (touch_)
            touch_->UpdateTouches(character_->controls_);

        // Update controls using keys
        UI* ui = GetSubsystem<UI>();
        if (!ui->GetFocusElement())
        {
            if (!touch_ || !touch_->useGyroscope_)
            {
                character_->controls_.Set(CTRL_FORWARD, input->GetKeyDown(KEY_W));
                character_->controls_.Set(CTRL_BACK, input->GetKeyDown(KEY_S));
                character_->controls_.Set(CTRL_LEFT, input->GetKeyDown(KEY_A));
                character_->controls_.Set(CTRL_RIGHT, input->GetKeyDown(KEY_D));
            }
            character_->controls_.Set(CTRL_JUMP, input->GetKeyDown(KEY_SPACE));

            // Add character yaw & pitch from the mouse motion or touch input
            if (touchEnabled_)
            {
                for (unsigned i = 0; i < input->GetNumTouches(); ++i)
                {
                    TouchState* state = input->GetTouch(i);
                    if (!state->touchedElement_)    // Touch on empty space
                    {
                        Camera* camera = cameraNode_->GetComponent<Camera>();
                        if (!camera)
                            return;

                        Graphics* graphics = GetSubsystem<Graphics>();
                        character_->controls_.yaw_ += TOUCH_SENSITIVITY * camera->GetFov() / graphics->GetHeight() * state->delta_.x_;
                        character_->controls_.pitch_ += TOUCH_SENSITIVITY * camera->GetFov() / graphics->GetHeight() * state->delta_.y_;
                    }
                }
            }
            else
            {
                character_->controls_.yaw_ += (float)input->GetMouseMoveX() * YAW_SENSITIVITY;
                character_->controls_.pitch_ += (float)input->GetMouseMoveY() * YAW_SENSITIVITY;
            }
            // Limit pitch
            character_->controls_.pitch_ = Clamp(character_->controls_.pitch_, -80.0f, 80.0f);
            // Set rotation already here so that it's updated every rendering frame instead of every physics frame
            character_->GetNode()->SetRotation(Quaternion(character_->controls_.yaw_, Vector3::UP));

            // Switch between 1st and 3rd person
            if (input->GetKeyPress(KEY_F))
                firstPerson_ = !firstPerson_;

            // Turn on/off gyroscope on mobile platform
            if (touch_ && input->GetKeyPress(KEY_G))
                touch_->useGyroscope_ = !touch_->useGyroscope_;

            // Check for loading / saving the scene
            if (input->GetKeyPress(KEY_F5))
            {
                File saveFile(context_, GetSubsystem<FileSystem>()->GetProgramDir() + "Data/Scenes/CharacterDemo.xml", FILE_WRITE);
                scene_->SaveXML(saveFile);
            }
            if (input->GetKeyPress(KEY_F7))
            {
                File loadFile(context_, GetSubsystem<FileSystem>()->GetProgramDir() + "Data/Scenes/CharacterDemo.xml", FILE_READ);
                scene_->LoadXML(loadFile);
                // After loading we have to reacquire the weak pointer to the Character component, as it has been recreated
                // Simply find the character's scene node by name as there's only one of them
                Node* characterNode = scene_->GetChild("Jack", true);
                if (characterNode)
                    character_ = characterNode->GetComponent<Character>();
            }
        }
    }
}
Esempio n. 17
0
void SoccerInput::ProcessInput(const Input& input)
{
    // get list of registered SoccerMonitor objects
    TLeafList soccerMonitorList;
    mMonitorClient->ListChildrenSupportingClass<SoccerMonitor>(soccerMonitorList);

    if (soccerMonitorList.empty())
    {
        GetLog()->Error()
            << "ERROR: (SoccerInput) Unable to get SoccerMonitor\n";
        return;
    }

    shared_ptr<SoccerMonitor> soccerMonitor =
        shared_static_cast<SoccerMonitor>(soccerMonitorList.front());
    
    switch (input.mId)
        {
        default:
            return;

        case CmdKickOff:
            if (input.GetKeyPress())
                {
                    SendCommand("(kickOff Left)");
                }
            break;
        case CmdKickOffRight:
            if (input.GetKeyPress())
                {
                    SendCommand("(kickOff Right)");
                }
            break;
           
        case CmdMoveAgent:
            if (input.GetKeyPress())
                {
                    //SendCommand("(agent (team Left)(unum 1)(pos -2.0 1.0 3.5))");
                }
            break;
        case CmdDropBall:
            if (input.GetKeyPress())
                {
                    SendCommand("(dropBall)");
                }
            break;
        case CmdShootBall:
            if (input.GetKeyPress())
                {
                    //SendCommand("(ball (vel -4.0 0.0 2.0))");
                }
            break;
        case CmdMoveBall:
            if (input.GetKeyPress())
                {
                    //SendCommand("(ball (pos -42.0 0.0 0.3))");
                }
            break;
        case CmdCameraLeftGoal:
            if (input.GetKeyPress())
                {
                    salt::Vector2f fieldSize = soccerMonitor->GetFieldSize();
                    salt::Vector3f pos(-fieldSize.x()*0.8, 0.0, fieldSize.x()*0.4);
                    mCameraBody->SetPosition(pos);
                    mFPS->SetHAngleDeg(90);
                    mFPS->SetVAngleDeg(35);
                }
            break;
        case CmdCameraLeftCorner:
            if (input.GetKeyPress())
                {
                    salt::Vector2f fieldSize = soccerMonitor->GetFieldSize();
                    salt::Vector3f pos(-fieldSize.x()*0.8, -fieldSize.y(), fieldSize.x()*0.4);
                    mCameraBody->SetPosition(pos);
                    mFPS->SetHAngleDeg(50);
                    mFPS->SetVAngleDeg(30);
                }
            break;
        case CmdCameraMiddleLeft:
            if (input.GetKeyPress())
                {
                    salt::Vector2f fieldSize = soccerMonitor->GetFieldSize();
                    salt::Vector3f pos(0, -fieldSize.y(), fieldSize.x()*0.4);
                    mCameraBody->SetPosition(pos);
                    mFPS->SetHAngleDeg(salt::gRadToDeg(-0.625));
                    mFPS->SetVAngleDeg(40);
                }
            break;
        case CmdCameraMiddleRight:
            if (input.GetKeyPress())
                {
                    salt::Vector2f fieldSize = soccerMonitor->GetFieldSize();
                    salt::Vector3f pos(0, -fieldSize.y(), fieldSize.x()*0.4);
                    mCameraBody->SetPosition(pos);
                    mFPS->SetHAngleDeg(salt::gRadToDeg(0.625));
                    mFPS->SetVAngleDeg(40);
                }
            break;
        case CmdCameraMiddle:
            if (input.GetKeyPress())
                {
                    salt::Vector2f fieldSize = soccerMonitor->GetFieldSize();
                    salt::Vector3f pos(0, -fieldSize.y()*1.1, fieldSize.x()*0.6);
                    mCameraBody->SetPosition(pos);
                    mFPS->SetHAngleDeg(0);
                    mFPS->SetVAngleDeg(45);
                }
            break;
        case CmdCameraRightCorner:
            if (input.GetKeyPress())
                {
                    salt::Vector2f fieldSize = soccerMonitor->GetFieldSize();
                    salt::Vector3f pos(fieldSize.x()*0.8, -fieldSize.y(), fieldSize.x()*0.4);
                    mCameraBody->SetPosition(pos);
                    mFPS->SetHAngleDeg(-50);
                    mFPS->SetVAngleDeg(30);
                }
            break;
        case CmdCameraRightGoal:
            if (input.GetKeyPress())
                {
                    salt::Vector2f fieldSize = soccerMonitor->GetFieldSize();
                    salt::Vector3f pos(fieldSize.x()*0.8, 0.0, fieldSize.x()*0.4);
                    mCameraBody->SetPosition(pos);
                    mFPS->SetHAngleDeg(-90);
                    mFPS->SetVAngleDeg(35);
                }
            break;
        case CmdFreeKickLeft:
            if (input.GetKeyPress())
                {
                    SendCommand("(playMode free_kick_left)");
                }
            break;
        case CmdFreeKickRight:
            if (input.GetKeyPress())
                {
                    SendCommand("(playMode free_kick_right)");
                }
            break;
        };
}
void SoccerInputLogPlayer::ProcessInput(const Input& input)
{

    switch (input.mId)
        {
        default:
            return;

        case CmdPause:
            if (input.GetKeyPress())
                {
                    mScriptServer->Eval("monitorLogServer = get($serverPath+ \
                                    'simulation/SparkMonitorLogFileServer')");
                    mScriptServer->Eval("monitorLogServer.pauseMode()");
                }
            break;

        case CmdStepForward:
            if (input.GetKeyPress())
                {
                    mScriptServer->Eval("monitorLogServer = get($serverPath+ \
                                    'simulation/SparkMonitorLogFileServer')");
                    mScriptServer->Eval("monitorLogServer.stepForward()");
                }
            break;

        case CmdStepBackward:
            if (input.GetKeyPress())
                {
                    mScriptServer->Eval("monitorLogServer = get($serverPath+ \
                                    'simulation/SparkMonitorLogFileServer')");
                    mScriptServer->Eval("monitorLogServer.stepBackward()");
                }
            break;

        case CmdBPlayback:
            if (input.GetKeyPress())
                {
                    mScriptServer->Eval("monitorLogServer = get($serverPath+ \
                                    'simulation/SparkMonitorLogFileServer')");
                    mScriptServer->Eval("monitorLogServer.playBackward()");
                }
            break;
        case CmdCameraLeftGoal:
            if (input.GetKeyPress())
                {
                    salt::Vector3f pos(-12*0.8, 0.0, 12*0.4);
                    mCameraBody->SetPosition(pos);
                    mFPS->SetHAngleDeg(90);
                    mFPS->SetVAngleDeg(35);
                }
            break;
        case CmdCameraLeftCorner:
            if (input.GetKeyPress())
                {
                    salt::Vector3f pos(-12*0.8, -8, 12*0.4);
                    mCameraBody->SetPosition(pos);
                    mFPS->SetHAngleDeg(50);
                    mFPS->SetVAngleDeg(30);
                }
            break;
        case CmdCameraMiddleLeft:
            if (input.GetKeyPress())
                {
                    salt::Vector3f pos(0, -8, 12*0.4);
                    mCameraBody->SetPosition(pos);
                    mFPS->SetHAngleDeg(salt::gRadToDeg(-0.625));
                    mFPS->SetVAngleDeg(40);
                }
            break;
        case CmdCameraMiddleRight:
            if (input.GetKeyPress())
                {
                    salt::Vector3f pos(0, -8, 12*0.4);
                    mCameraBody->SetPosition(pos);
                    mFPS->SetHAngleDeg(salt::gRadToDeg(0.625));
                    mFPS->SetVAngleDeg(40);
                }
            break;
        case CmdCameraMiddle:
            if (input.GetKeyPress())
                {
                    salt::Vector3f pos(0, -8*1.1, 12*0.6);
                    mCameraBody->SetPosition(pos);
                    mFPS->SetHAngleDeg(0);
                    mFPS->SetVAngleDeg(45);
                }
            break;
        case CmdCameraRightCorner:
            if (input.GetKeyPress())
                {
                    salt::Vector3f pos(12*0.8, -8, 12*0.4);
                    mCameraBody->SetPosition(pos);
                    mFPS->SetHAngleDeg(-50);
                    mFPS->SetVAngleDeg(30);
                }
            break;
        case CmdCameraRightGoal:
            if (input.GetKeyPress())
                {
                    salt::Vector3f pos(12*0.8, 0.0, 12*0.4);
                    mCameraBody->SetPosition(pos);
                    mFPS->SetHAngleDeg(-90);
                    mFPS->SetVAngleDeg(35);
                }
            break;
        };
}