Skip to content

Instantly share code, notes, and snippets.

View Tags.json
[
{
"id": 1,
"mac": "AA:AA:AA:AA:AA",
"min_rssi": -21,
"max_rssi": -80.2,
"name": "Tag_C1"
}
]
View CharacterController
public GameObject target;
void OnTriggerEnter()
{
CharacterController controller = target.GetComponent<CharacterController>();
if (controller != null)
{
controller.enabled = false;
target.transform.position = new Vector3(target.transform.position.x, target.transform.position.y, target.transform.position.z + 2500);
controller.enabled = true;
}
@Adamcbrz
Adamcbrz / Tracker.cpp
Created Jun 25, 2019
Vive Tracker without HMD in Unreal Engine
View Tracker.cpp
// Fill out your copyright notice in the Description page of Project Settings.
#include "Tracker.h"
// Sets default values
ATracker::ATracker()
{
// 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;
@Adamcbrz
Adamcbrz / Tracker.cpp
Created Apr 22, 2019
Tracker Tutorial: Tick
View Tracker.cpp
void ATracker::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
// Find Tracker if trackerID is -1 else update tracker
if (trackerID == -1)
{
// Loop through tracker ids skipping the first one because that is our null HMD.
for (uint32_t i = 1; i <= 8; i++) {
vr::HmdMatrix34_t posMat = UpdateTracker(i);
// Verify the postion of the tracker isn't vector zero.
@Adamcbrz
Adamcbrz / Tracker.cpp
Created Apr 22, 2019
Tracker Tutorial: Update Tracker
View Tracker.cpp
vr::HmdMatrix34_t ATracker::UpdateTracker(int id)
{
//Get Tracker Pose
vr::VRControllerState_t *state = new vr::VRControllerState_t();
vr::TrackedDevicePose_t *pose = new vr::TrackedDevicePose_t();
vrSystem->GetControllerStateWithPose(vr::ETrackingUniverseOrigin::TrackingUniverseStanding, id, state, sizeof(vr::VRControllerState_t), pose);
//Get Pose Position
vr::HmdMatrix34_t posMat = pose->mDeviceToAbsoluteTracking;
// Update tracker only if we have decided which tracker to use
if (trackerID != -1)
@Adamcbrz
Adamcbrz / Tracker.cpp
Created Apr 22, 2019
Tracker Tutorial: BeginPlay
View Tracker.cpp
void ATracker::BeginPlay()
{
Super::BeginPlay();
// Grab player controller so we can setup the camera and enable input
APlayerController* playerController = UGameplayStatics::GetPlayerController(this, 0);
EnableInput(playerController); // This is probably not needed unless you need to receive input like keyboard events.
playerController->SetViewTargetWithBlend(this, 0);
}
@Adamcbrz
Adamcbrz / Tracker.cpp
Last active Apr 22, 2019
Tutorial Tracker: Constructor
View Tracker.cpp
ATracker::ATracker()
{
// 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;
// Initialize VR
vr::EVRInitError peError;
vrSystem = vr::VR_Init(&peError, vr::EVRApplicationType::VRApplication_Other);
// Setup trackerID to -1 so we can test when it is set
@Adamcbrz
Adamcbrz / Tracker.h
Last active Apr 22, 2019
Tracker Tutorial: Header Projtected
View Tracker.h
protected:
// Called when the game starts or when spawned
virtual void BeginPlay() override;
// Our connnection to the VR System
vr::IVRSystem* vrSystem;
// ID for which tracker to utilize
uint32_t trackerID;
// I always add a scene component as my root object as default
@Adamcbrz
Adamcbrz / Tracker.h
Created Apr 22, 2019
Tracker Tutorial: Header Includes
View Tracker.h
/* insert after Actor.h */
#include "openvr.h"
#include "Runtime/Engine/Classes/Camera/CameraComponent.h"
#include "Runtime/Core/Public/GenericPlatform/GenericPlatformMath.h"
#include "Kismet/GameplayStatics.h"
/* leave Tracker.generate.h at the end */
@Adamcbrz
Adamcbrz / TrackerExample.Build.cs
Created Apr 22, 2019
Tracker Example Build Post
View TrackerExample.Build.cs
PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore", "OpenVR", "SteamVR", "SteamVRController", "HeadMountedDisplay" });