MyEEGPlugin.uplugin

{
"FileVersion": ,
"Version": ,
"VersionName": "1.0",
"FriendlyName": "MyEEGPlugin",
"Description": "",
"Category": "Other",
"CreatedBy": "",
"CreatedByURL": "",
"DocsURL": "",
"MarketplaceURL": "",
"SupportURL": "",
"CanContainContent": true,
"IsBetaVersion": false,
"Installed": false,
"Modules": [
{
"Name": "MyEEGPlugin",
"Type": "Runtime",
"LoadingPhase": "Default"
}
]
}

MyEEGPlugin.Build.cs

// Copyright 1998-2017 Epic Games, Inc. All Rights Reserved.

using UnrealBuildTool;
using System.IO; public class MyEEGPlugin : ModuleRules
{
public MyEEGPlugin(TargetInfo Target)
{ PublicIncludePaths.AddRange(
new string[] {
"MyEEGPlugin/Public"
// ... add public include paths required here ...
}
); PrivateIncludePaths.AddRange(
new string[] {
"MyEEGPlugin/Private",
// ... add other private include paths required here ...
}
); PublicDependencyModuleNames.AddRange(
new string[]
{
"Core", "CoreUObject", "Engine", "InputCore", "Projects"
// ... add other public dependencies that you statically link with here ...
}
); PrivateDependencyModuleNames.AddRange(
new string[]
{
// ... add private dependencies that you statically link with here ...
}
); DynamicallyLoadedModuleNames.AddRange(
new string[]
{
// ... add any modules that your module loads dynamically here ...
}
); LoadThinkGearLib(Target);//添加第三方库
//LoadAlgoSdkDll(Target);//添加第三方库
} private string ThirdPartyPath
{
get
{
return Path.GetFullPath(Path.Combine(ModuleDirectory, "../ThirdParty/"));
}
} public void LoadThinkGearLib(TargetInfo Target)
{
if ((Target.Platform == UnrealTargetPlatform.Win64) || (Target.Platform == UnrealTargetPlatform.Win32))
{
string PlatformString = (Target.Platform == UnrealTargetPlatform.Win64) ? "" : "";
string LibrariesPath = Path.Combine(ThirdPartyPath, "ThinkGear", "lib"); //test your path
System.Console.WriteLine("... LibrariesPath -> " + LibrariesPath); PublicIncludePaths.Add(Path.Combine(ThirdPartyPath, "ThinkGear", "include"));
PublicAdditionalLibraries.Add(Path.Combine(LibrariesPath, "thinkgear" + PlatformString + ".lib"));
} //Definitions.Add(string.Format("MY_DEFINE={0}", 0));
} public void LoadAlgoSdkDll(TargetInfo Target)
{
if ((Target.Platform == UnrealTargetPlatform.Win64) || (Target.Platform == UnrealTargetPlatform.Win32))
{
string PlatformString = (Target.Platform == UnrealTargetPlatform.Win64) ? "" : "";
string DllPath = Path.Combine(ThirdPartyPath, "bin", "AlgoSdkDll" + PlatformString + ".dll"); PublicIncludePaths.Add(Path.Combine(ThirdPartyPath, "EEGAlgoSDK", "include"));
PublicDelayLoadDLLs.Add(DllPath);
//RuntimeDependencies.Add(new RuntimeDependency(DllPath));
}
} }

MyEEGPlugin.h

// Copyright 1998-2017 Epic Games, Inc. All Rights Reserved.

#pragma once

#include "ModuleManager.h"

class FMyEEGPluginModule : public IModuleInterface
{
public: /** IModuleInterface implementation */
virtual void StartupModule() override;
virtual void ShutdownModule() override; private:
/** Handle to the test dll we will load */
void* ExampleLibraryHandle;
};

MyEEGPlugin.cpp

// Copyright 1998-2017 Epic Games, Inc. All Rights Reserved.

#include "MyEEGPlugin.h"
#include "Core.h"
#include "ModuleManager.h"
#include "IPluginManager.h"
//#include "ExampleLibrary.h" #define LOCTEXT_NAMESPACE "FMyEEGPluginModule" void FMyEEGPluginModule::StartupModule()
{
// This code will execute after your module is loaded into memory; the exact timing is specified in the .uplugin file per-module // Get the base directory of this plugin
FString BaseDir = IPluginManager::Get().FindPlugin("MyEEGPlugin")->GetBaseDir(); // Add on the relative location of the third party dll and load it
FString LibraryPath;
#if PLATFORM_WINDOWS
LibraryPath = FPaths::Combine(*BaseDir, TEXT("Binaries/ThirdParty/MyEEGPluginLibrary/Win64/ExampleLibrary.dll"));
#elif PLATFORM_MAC
LibraryPath = FPaths::Combine(*BaseDir, TEXT("Source/ThirdParty/MyEEGPluginLibrary/Mac/Release/libExampleLibrary.dylib"));
#endif // PLATFORM_WINDOWS ExampleLibraryHandle = !LibraryPath.IsEmpty() ? FPlatformProcess::GetDllHandle(*LibraryPath) : nullptr; if (ExampleLibraryHandle)
{
// Call the test function in the third party library that opens a message box
//ExampleLibraryFunction();
}
else
{
//FMessageDialog::Open(EAppMsgType::Ok, LOCTEXT("ThirdPartyLibraryError", "Failed to load example third party library"));
}
} void FMyEEGPluginModule::ShutdownModule()
{
// This function may be called during shutdown to clean up your module. For modules that support dynamic reloading,
// we call this function before unloading the module. // Free the dll handle
FPlatformProcess::FreeDllHandle(ExampleLibraryHandle);
ExampleLibraryHandle = nullptr;
} #undef LOCTEXT_NAMESPACE IMPLEMENT_MODULE(FMyEEGPluginModule, MyEEGPlugin)

MyEEGReceiver.h

// Fill out your copyright notice in the Description page of Project Settings.

#pragma once
#include "Engine.h"
#include "GameFramework/Actor.h"
#include "MyEEGReceiver.generated.h" UCLASS()
class AMyEEGReceiver : public AActor
{
GENERATED_BODY() public:
// Sets default values for this actor's properties
AMyEEGReceiver(); protected:
// Called when the game starts or when spawned
virtual void BeginPlay() override;
int rawDataIndex;
int lerpDataIndex;
float totalAngle; UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "EEG")
float v;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "EEG")
float s;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "EEG")
float a;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "EEG")
TArray<float> rawAttentions;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "EEG")
TArray<float> rawMeditations;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "EEG")
TArray<float> lerpAttentions;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "EEG")
TArray<float> lerpMeditations;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "EEG")
float attention1;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "EEG")
float attention2;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "EEG")
float meditation1;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "EEG")
float meditation2;
public:
// Called every frame
virtual void Tick(float DeltaTime) override; /** Called whenever this actor is being removed from a level */
virtual void EndPlay(const EEndPlayReason::Type EndPlayReason) override; UFUNCTION(BlueprintImplementableEvent, Category = "EEG")
void BPEvent_GetNewAttention(float newAttention); UFUNCTION(BlueprintCallable, Category = "EEG")
void IndexFunc(); UFUNCTION(BlueprintCallable, Category = "EEG")
void ComputeNewPos(float factor, UStaticMeshComponent* cube, float DeltaTime, float scaleFactorAtten=, float scaleFactorMedi = , bool debug=false); UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "EEG")
int32 LatestMeditation; //最新放松度
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "EEG")
int32 LatestAttention; //最新专注度 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "EEG")
bool ShowOnScreenDebugMessages; FORCEINLINE void ScreenMsg(const FString& Msg)
{
if (!ShowOnScreenDebugMessages) return;
GEngine->AddOnScreenDebugMessage(-, .f, FColor::Red, *Msg);
}
FORCEINLINE void ScreenMsg(const FString& Msg, const int32 Value)
{
if (!ShowOnScreenDebugMessages) return;
GEngine->AddOnScreenDebugMessage(-, .f, FColor::Red, FString::Printf(TEXT("%s %d"), *Msg, Value));
}
};

MyEEGReceiver.cpp

// Fill out your copyright notice in the Description page of Project Settings.

#include "MyEEGPlugin.h"
#include "MyEEGReceiver.h"
#include "thinkgear.h" #define NUM 3
// Sets default values
AMyEEGReceiver::AMyEEGReceiver()
{
// Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it.
PrimaryActorTick.bCanEverTick = true; ShowOnScreenDebugMessages = true;
v = ; a = ; s = ;
rawDataIndex = ;
lerpDataIndex = ;
rawAttentions.Init(, NUM);
rawMeditations.Init(, NUM);
totalAngle = ;
} long raw_data_count = ;
short *raw_data = NULL;
bool bRunning = false;
bool bInited = false;
char *comPortName = NULL;
int dllVersion = ;
int connectionId = -;
int packetsRead = ;
int errCode = ;
bool bConnectedHeadset = false; // Called when the game starts or when spawned
void AMyEEGReceiver::BeginPlay()
{
Super::BeginPlay(); /* Print driver version number */
dllVersion = TG_GetVersion();
ScreenMsg("ThinkGear DLL version:",dllVersion);
//GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, FString::Printf(TEXT("ThinkGear DLL version: %d\n"), dllVersion));
/* Get a connection ID handle to ThinkGear */
connectionId = TG_GetNewConnectionId();
if (connectionId < ) {
ScreenMsg("Failed to new connection ID");
}
else {
/* Attempt to connect the connection ID handle to serial port "COM5" */
/* NOTE: On Windows, COM10 and higher must be preceded by \\.\, as in
* "\\\\.\\COM12" (must escape backslashes in strings). COM9
* and lower do not require the \\.\, but are allowed to include
* them. On Mac OS X, COM ports are named like
* "/dev/tty.MindSet-DevB-1".
*/
comPortName = "\\\\.\\COM6";
errCode = TG_Connect(connectionId,
comPortName,
TG_BAUD_57600,
TG_STREAM_PACKETS);
if (errCode < )
{
ScreenMsg("TG_Connect() failed", errCode);
}
else
{
ScreenMsg("TG_Connect OK",connectionId);
}
} } // Called every frame
void AMyEEGReceiver::Tick(float DeltaTime)
{
Super::Tick(DeltaTime); v = v + a*DeltaTime;
s += v*DeltaTime;
/* Read all currently available Packets, one at a time... */
do {
/* Read a single Packet from the connection */
packetsRead = TG_ReadPackets(connectionId, ); /* If TG_ReadPackets() was able to read a Packet of data... */
if (packetsRead == ) {
//ScreenMsg("TG_ReadPackets");
/* If the Packet containted a new raw wave value... */
if (TG_GetValueStatus(connectionId, TG_DATA_RAW) != ) {
int rawData = (int)TG_GetValue(connectionId, TG_DATA_RAW);
//ScreenMsg("TG_DATA_RAW",rawData);
} /* end "If Packet contained a raw wave value..." */ if (TG_GetValueStatus(connectionId, TG_DATA_POOR_SIGNAL) != ) {
int ps=TG_GetValue(connectionId, TG_DATA_POOR_SIGNAL);
//ScreenMsg("TG_DATA_POOR_SIGNAL",ps);
} if (TG_GetValueStatus(connectionId, TG_DATA_MEDITATION) != ) {
float medi = TG_GetValue(connectionId, TG_DATA_MEDITATION);
LatestMeditation = (int32)medi;
//ScreenMsg("TG_DATA_MEDITATION", LatestMeditation);
rawMeditations[rawDataIndex] = medi;
float total = ;
for (int i = ; i < NUM; i++)
total += rawMeditations[i];
float avg_medi = total / NUM;
lerpMeditations.Add(avg_medi);
} if (TG_GetValueStatus(connectionId, TG_DATA_ATTENTION) != ) {
float atten = TG_GetValue(connectionId, TG_DATA_ATTENTION);
LatestAttention = (int32)atten;
rawAttentions[rawDataIndex] = atten;
float total = ;
for (int i = ; i < NUM; i++)
total += rawAttentions[i];
float avg_atten = total / NUM;
lerpAttentions.Add(avg_atten); rawDataIndex++;
if (rawDataIndex == NUM)
{
rawDataIndex = ;
} ScreenMsg("avg_atten", avg_atten);
//BPEvent_GetNewAttention(TG_GetValue(connectionId, TG_DATA_ATTENTION));
//float atten=TG_GetValue(connectionId, TG_DATA_ATTENTION);
//float delta = atten - s;
//a = delta;
ScreenMsg("TG_DATA_ATTENTION", LatestAttention);
//ScreenMsg("delta", delta);
//ScreenMsg("s", s);
} } /* end "If TG_ReadPackets() was able to read a Packet..." */ } while (packetsRead > ); /* Keep looping until all Packets read */
} void AMyEEGReceiver::EndPlay(const EEndPlayReason::Type EndPlayReason)
{
Super::EndPlay(EndPlayReason); /* Clean up */
TG_FreeConnection(connectionId);
} void AMyEEGReceiver::IndexFunc()
{
int lerpNum = lerpAttentions.Num();
if (lerpNum ==)
return;
int idx1 = lerpDataIndex - ;
int idx2 = lerpDataIndex;
idx1 = FMath::Max(idx1,);
idx2 = FMath::Min(idx2, lerpNum-);
attention1 = lerpAttentions[idx1];
attention2 = lerpAttentions[idx2];
meditation1 = lerpMeditations[idx1];
meditation2 = lerpMeditations[idx2];
if (lerpDataIndex < lerpNum-)
{
lerpDataIndex++;
}
} void AMyEEGReceiver::ComputeNewPos(float factor, UStaticMeshComponent* cube, float DeltaTime,
float scaleFactorAtten/*=1*/, float scaleFactorMedi/* = 1*/, bool debug/* = false*/)
{
float tmpAtten = FMath::Lerp(attention1, attention2, factor);
float tmpMedit = FMath::Lerp(meditation1, meditation2, factor);
static float testTime = ;
if (debug)
{
tmpMedit = + sin(testTime) * ;
tmpAtten = + sin(testTime) * ; testTime += DeltaTime;
}
float s0 = tmpMedit*DeltaTime*scaleFactorMedi;
FVector oldPos = cube->GetComponentLocation();
float angle = FMath::Atan(s0 / (oldPos.Size()));
FVector normalVec = oldPos.GetSafeNormal();
FVector newPos = normalVec*( + tmpAtten*scaleFactorAtten);
cube->SetWorldLocation(newPos.RotateAngleAxis(FMath::RadiansToDegrees(angle),FVector(,,)));
FRotator Rotator = FRotator::ZeroRotator;
totalAngle += FMath::RadiansToDegrees(angle);
Rotator.Add(-totalAngle, , );
if (totalAngle >= )
{
totalAngle = ;
}
cube->SetWorldRotation(Rotator);
UTextRenderComponent* text = dynamic_cast<UTextRenderComponent*>(cube->GetChildComponent());
if (text)
{
FString t1 = FString::FromInt(tmpAtten);
FString t2 = FString::FromInt(tmpMedit);
FString t3 = FString::FromInt(totalAngle);
FString tmp(", ");
tmp = t1 + tmp + t2;
text->SetText(FText::FromString(tmp));
}
}

UE4读取脑电波MindWave插件(展示如何使用第三方库制作UE4插件)的更多相关文章

  1. 常用iOS第三方库以及XCode插件介绍

    第三方库 CocoaPod CocoaPod并不是iOS上的第三方库 而是大名鼎鼎的第三方库的管理工具 在CocoaPod没有出现之前 第三方库的管理是非常痛苦的 尤其是一些大型的库(比如nimbus ...

  2. 个人常用iOS第三方库以及XCode插件介绍

    第三方库 CocoaPod CocoaPod并不是iOS上的第三方库 而是大名鼎鼎的第三方库的管理工具 在CocoaPod没有出现之前 第三方库的管理是非常痛苦的 尤其是一些大型的库(比如nimbus ...

  3. 【转】个人常用iOS第三方库以及XCode插件介绍 -- 不错

    原文网址:http://adad184.com/2015/07/08/my-favorite-libraries-and-plugins/ 第三方库是现在的程序员离不开的东西 不光是APP开发 基本上 ...

  4. iOS之第三方库以及XCode插件介绍

    前言 第三方库是现在的程序员离不开的东西 不光是APP开发 基本上所有的商业项目 都会或多或少的使用到第三方库 Github上Star>100的开源库数量如下 可以看到JS以绝对的优势排名第一 ...

  5. python 技巧 之 pyCharm快速添加第三方库和插件

    学习python有几个月,安装第三方库都是通过 pip install 或者 easy_install.每次都要打开命令行感觉太麻烦.还好Pycharm提供了安装第三方库和安装插件的功能. 首先打开P ...

  6. UE4读取scv文件 -- 数据驱动游戏性元素

    官方文档链接:http://docs.unrealengine.com/latest/CHN/Gameplay/DataDriven/index.html 略懒,稍微麻烦重复的工作,总希望能找人帮忙一 ...

  7. 使用python制作ArcGIS插件(6)案例分析

    利用ArcPy制作航空制图插件 By 李远祥 这是笔者两年多前写的一个面向航路图做的一个插件,基本上将航路图的制作进行流程化,制作成为可交互的插件,只要有航路和机场的信息,就可以直接生成一个航路图,每 ...

  8. iOS 第三方库、插件、知名博客总结

    iOS 第三方库.插件.知名博客总结 用到的组件 1.通过CocoaPods安装 项目名称 项目信息 AFNetworking 网络请求组件 FMDB 本地数据库组件 SDWebImage 多个缩略图 ...

  9. UE4使用第三方库读写xml文件

    原文链接:http://gad.qq.com/article/detail/7181031 本文首发腾讯GAD开发者平台,未经允许,不得转载 在游戏开发过程中,读写xml几乎已经成为不可或缺的功能,但 ...

随机推荐

  1. UserAgent判断浏览器类型或爬虫类型

    ### 浏览器------------------------------- IEMozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; T ...

  2. linux并发concurrency控制

    解决竞态(race conditions)最根本的途径是对共享资源的互斥访问,访问共享资源的代码区被称为临界区(critical sections),对临界区的代码需要以某种互斥机制加以保护.常见的互 ...

  3. PHP无限极分类 - 3 - 分类目录

    结合zui---Tree组件,实现分类目录. 目录结构同上一篇: 效果: 代码: <!DOCTYPE html> <html lang="en"> < ...

  4. ci框架model中的进行增删改的写法

    <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); // 商品类别模型class Categor ...

  5. Nginx之虚拟目录-root与alias的区别

    最近在nginx上部署日志分析工具awstats时,在配置awstats分析结果可供网页浏览这步时,分析结果页面访问总是404.后来查阅了一些资料,发现是root和alias的用法区别没搞懂导致的,这 ...

  6. 'cl.exe' 不是内部或外部命令,也不是可运行的程序 或批处理文件。

    1.首先找到vcvars32.bat文件,一般在C:\\Program Files (x86)\\Microsoft Visual Studio 12.0\\VC\\bin文件夹下 2.打开cmd黑窗 ...

  7. UML---UML中的几种关系(依赖,关联,泛化,实现)

    关于设计模式的总结没有落实到代码上,而且设计模式自己确实动手实现的非常少.所以在这一周里,除了看网站开发的视频,着手开始对设计模式进行实现以下.设计模式非常经典,每次看都有不同的收获,写一下自己的收获 ...

  8. javascript删除字符串最后一个字符

    搜到很多无用的答案,这对新手来讲是很耗费时间的事情,我把正确的方法贴出来,以便有的新手不再踩这个坑. JavaScript slice() 方法 定义和用法 slice() 方法可提取字符串的某个部分 ...

  9. MySql csv文件导入导出

    一.导出到csv(本地导出) 通过mysql客户端shell连接到服务器,选择使用的数据库,输入sql代码: select * from test_info into outfile '/tmp/te ...

  10. e581. Animating an Array of Images in an Application

    This is the simplest application to animate an array of images. import java.awt.*; import javax.swin ...