Skip to content

input_system::double_axis

Paweł Waligóra edited this page May 22, 2024 · 3 revisions

Usage

Meant for tracking values controlled by 4 keys. Eg. forward/backward/left/right movement.

To Use construct double_axis object in game::your_script scope. To get axis value call double_axis::raw() or double_axis.normalized().

double_axis::normalized() will make sure vector made from 2 axis states is normalized. double_axis::raw() will treat 2 axis independently.

Example

following example shows how to use input_system::double_axis in a script.

#include"axis.h"
#include"time_system.h"
#include<glm/glm.hpp>

namespace game {
	class my_script {
	private:
		input_system::double_axis a = input_system::axis(GLFW_KEY_UP, GLFW_KEY_DOWN, GLFW_KEY_LEFT, GLFW_KEY_RIGHT); // constuct axis object
		glm::vec2 r = glm::vec2(0.0f);
		glm::vec2 n = glm::vec2(0.0f);
		
		// ...
	public:
		virtual void update();
		
		// ...
	};
}

// ...

void game::my_script::update(){
	r += a.raw() * (float)time::delta_time; // get axis raw value using double_axis::raw();
	n += a.normalized() * (float)time::delta_time; // get axis normalized value using double_axis::normalized();

	// ...
}

See also

Home

Git Workflow

Issues

Coding Rules

Skrypty-Tutorial

Useful resources

Game Structure

Code Structure

Clone this wiki locally