Here is the code for my plugin, i am trying to get my hands dirty with input devices and even though the Leap Motion plugin is available i am trying to code my own.
This is the “Input Device” H and CPP
#pragma once
#include “IInputInterface.h”
#include “IInputDevice.h”
#include
#include “LeapController.h”
#include “LeapInterface.h”
struct LeapKeys {
static const FKey RightHandPosition;
static const FKey LeftHandPosition;
};
class PIXELLEAP_API FLeapInputDevice : public IInputDevice
{
public:
FLeapInputDevice(const TSharedRef& InMessageHandler);
~FLeapInputDevice();
virtual void Tick(float Delta) override;
virtual void SendControllerEvents() override;
virtual void SetMessageHandler(const TSharedRef<FGenericApplicationMessageHandler>& InMessageHandler) override;
virtual bool Exec(UWorld* InWorld, const TCHAR* Cmd, FOutputDevice& Ar) override;
virtual void SetChannelValue(int32 ControllerId, FForceFeedbackChannelType ChannelType, float Value) override;
virtual void SetChannelValues(int32 ControllerId, const FForceFeedbackValues &values) override;
void OnLeap();
private:
TSharedRef MessageHandler;
Leap::Controller Controller;
Leap::Frame Frame;
};
.CPP
#include “PixelLeapPrivatePCH.h”
#include “LeapInputDevice.h”
#include
#include “LeapBlueprintFunctionLibrary.h”
#define LOCTEXT_NAMESPACE “PixelLeap”
const FKey LeapKeys::RightHandPosition(“Right Hand Position”);
const FKey LeapKeys::LeftHandPosition(“Left Hand Position”);
FLeapInputDevice::FLeapInputDevice(const TSharedRef& InMessageHandler) : MessageHandler(InMessageHandler)
{
EKeys::AddKey(FKeyDetails(LeapKeys::RightHandPosition, LOCTEXT(“RightHandPosition”, “RightHandPosition”), FKeyDetails::EKeyFlags::VectorAxis));
EKeys::AddKey(FKeyDetails(LeapKeys::LeftHandPosition, LOCTEXT("LeftHandPosition", "LeftHandPosition"), FKeyDetails::EKeyFlags::VectorAxis));
}
FLeapInputDevice::~FLeapInputDevice()
{
}
void FLeapInputDevice::SendControllerEvents()
{
}
void FLeapInputDevice::SetMessageHandler(const TSharedRef& InMessageHandler)
{
MessageHandler = InMessageHandler;
}
void FLeapInputDevice::Tick(float DeltaTime)
{
Frame = Controller.frame();
Leap::HandList HandList = Frame.hands();
for (int h = 0; h < HandList.count(); h++) {
GEngine->AddOnScreenDebugMessage(h, 2, FColor::Yellow, FVector(HandList[h].palmPosition().x, HandList[h].palmPosition().y, HandList[h].palmPosition().z).ToString());
}
OnLeap();
}
void FLeapInputDevice::OnLeap()
{
ULeapBlueprintFunctionLibrary::OnLeap(Frame.hands().count());
}
bool FLeapInputDevice::Exec(UWorld* InWorld, const TCHAR* Cmd, FOutputDevice& Ar)
{
return true;
}
void FLeapInputDevice::SetChannelValue(int32 ControllerId, FForceFeedbackChannelType ChannlType, float Value)
{
}
void FLeapInputDevice::SetChannelValues(int32 ControllerId, const FForceFeedbackValues &values)
{
}
So essentially, i want to be able to get the Frame data which contains all the information for the hands, fingers to the Game.
The Controller.frame() retrives the data for the frame, and now i need to pass the vector position, vector rotation and other data to the game that I cannot pass through the Input Axis Keys which support only float and button Pressed, Released.
Let me know if you need more information