UE4读取脑电波MindWave插件(展示如何使用第三方库制作UE4插件)
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插件)的更多相关文章
- 常用iOS第三方库以及XCode插件介绍
第三方库 CocoaPod CocoaPod并不是iOS上的第三方库 而是大名鼎鼎的第三方库的管理工具 在CocoaPod没有出现之前 第三方库的管理是非常痛苦的 尤其是一些大型的库(比如nimbus ...
- 个人常用iOS第三方库以及XCode插件介绍
第三方库 CocoaPod CocoaPod并不是iOS上的第三方库 而是大名鼎鼎的第三方库的管理工具 在CocoaPod没有出现之前 第三方库的管理是非常痛苦的 尤其是一些大型的库(比如nimbus ...
- 【转】个人常用iOS第三方库以及XCode插件介绍 -- 不错
原文网址:http://adad184.com/2015/07/08/my-favorite-libraries-and-plugins/ 第三方库是现在的程序员离不开的东西 不光是APP开发 基本上 ...
- iOS之第三方库以及XCode插件介绍
前言 第三方库是现在的程序员离不开的东西 不光是APP开发 基本上所有的商业项目 都会或多或少的使用到第三方库 Github上Star>100的开源库数量如下 可以看到JS以绝对的优势排名第一 ...
- python 技巧 之 pyCharm快速添加第三方库和插件
学习python有几个月,安装第三方库都是通过 pip install 或者 easy_install.每次都要打开命令行感觉太麻烦.还好Pycharm提供了安装第三方库和安装插件的功能. 首先打开P ...
- UE4读取scv文件 -- 数据驱动游戏性元素
官方文档链接:http://docs.unrealengine.com/latest/CHN/Gameplay/DataDriven/index.html 略懒,稍微麻烦重复的工作,总希望能找人帮忙一 ...
- 使用python制作ArcGIS插件(6)案例分析
利用ArcPy制作航空制图插件 By 李远祥 这是笔者两年多前写的一个面向航路图做的一个插件,基本上将航路图的制作进行流程化,制作成为可交互的插件,只要有航路和机场的信息,就可以直接生成一个航路图,每 ...
- iOS 第三方库、插件、知名博客总结
iOS 第三方库.插件.知名博客总结 用到的组件 1.通过CocoaPods安装 项目名称 项目信息 AFNetworking 网络请求组件 FMDB 本地数据库组件 SDWebImage 多个缩略图 ...
- UE4使用第三方库读写xml文件
原文链接:http://gad.qq.com/article/detail/7181031 本文首发腾讯GAD开发者平台,未经允许,不得转载 在游戏开发过程中,读写xml几乎已经成为不可或缺的功能,但 ...
随机推荐
- dvwa 源码分析(四) --- dvwaPhpIds.inc.php分析
根据文件名就知道是IDS相关的 <?php if( !defined( 'DVWA_WEB_PAGE_TO_ROOT' ) ) { define( 'DVWA System error- WEB ...
- 实战入侵(突破FCK+安全狗上传)
PS:有点尴尬,二次上传突破FCK,免杀马儿过狗. 刚开始和超霸一起弄,TMDGB.弄到四点多,早上尼玛七点多的又去考试,虽然考试还是睡着了,但是TMDGB感觉日子好充实啊! FCK上传地址如下所示: ...
- 关于pthread_cond_wait使用while循环判断的理解
在Stevens的<Unix 环境高级编程>中第11章线程关于pthread_cond_wait的介绍中有一个生产者-消费者的例子P311,在进入pthread_cond_wait前使用w ...
- java父子进程通信
1.利用进程的管道通信传输流 2.子进程没有控制台,正常测试的时候也是没办法看到子进程的输出的,需要传到主线程 3.测试主进程传参给子进程再传回来 4.父进程启动子进程只要执行runtime.exec ...
- MySql: ”Commands out of sync“Error (Connect/C++)
使用 Connector/C++ 查询 Mysql , 连续调用存储过程时 会出现如下: Commands out of sync; you can't run this command now,st ...
- 修改jvm内存大小
- -27979 LoadRunner 错误27979 找不到请求表单 Action.c(73): Error -27979: Requested form not found
LoadRunner请求无法找到:在录制Web协议脚本回放脚本的过程中,会出现请求无法找到的现象,而导致脚本运行停止. 错误现象:Action.c(41): Error -27979: Request ...
- ANSI 标准是为了确保 C++ 的便携性
ANSI 标准ANSI 标准是为了确保 C++ 的便携性 —— 您所编写的代码在 Mac.UNIX.Windows.Alpha 计算机上都能通过编译. 由于 ANSI 标准已稳定使用了很长的时间,所有 ...
- gsoap 学习 1-如何使用
新年伊始,想把onvif和gsoap boa这三个东西学习下,并作下笔记,当然为了省时间,我昨天下午看了一个下午的gsaop官网pdf感触良多,也做了小测试,废话少说,一下也有一些是摘自网友博客,大部 ...
- c网络编程-多播
/* 编译通过环境,Windows XP sp2,Windows 2003 server SDK,VC++6.0 sp5. */ /********************************** ...