Skip to content

Instantly share code, notes, and snippets.

[
{
"id": 1,
"mac": "AA:AA:AA:AA:AA",
"min_rssi": -21,
"max_rssi": -80.2,
"name": "Tag_C1"
}
]
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 June 25, 2019 13:27
Vive Tracker without HMD in Unreal Engine
// 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 April 22, 2019 14:14
Tracker Tutorial: Tick
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 April 22, 2019 14:10
Tracker Tutorial: Update Tracker
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 April 22, 2019 13:58
Tracker Tutorial: BeginPlay
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 April 22, 2019 14:04
Tutorial Tracker: Constructor
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 April 22, 2019 14:01
Tracker Tutorial: Header Projtected
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 April 22, 2019 13:44
Tracker Tutorial: Header Includes
/* 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 April 22, 2019 13:34
Tracker Example Build Post
PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore", "OpenVR", "SteamVR", "SteamVRController", "HeadMountedDisplay" });