Skip to content

Instantly share code, notes, and snippets.

View jackbrookes's full-sized avatar
🌱

Dr Jack Brookes jackbrookes

🌱
View GitHub Profile
@jackbrookes
jackbrookes / WorldToScreenVR.cs
Created July 8, 2021 10:38
Unity method for calculating screen-space position a world space object. Useful for showing something on screen that is not visible in VR.
/// <summary>
/// Calculates screen-space position a world space object. Useful for showing something on screen that is not visible in VR.
/// For example, it can be used to update the position of a marker that highlights the gaze of the player, using eye tracking.
/// </summary>
/// <param name="camera">The camera used for VR rendering.</param>
/// <param name="worldPos">World position of a point.</param>
/// <returns>Screen position of a point.</returns>
static Vector2 WorldToScreenVR(Camera camera, Vector3 worldPos)
{
Vector3 screenPoint = camera.WorldToViewportPoint(worldPos);
@jackbrookes
jackbrookes / EyeTracker.cs
Last active July 16, 2023 10:00
Script for supporting Eye Tracking from the Vive Pro Eye with UXF.
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UXF;
using ViveSR.anipal.Eye;
//
@jackbrookes
jackbrookes / LerpEnumerator.cs
Last active June 23, 2021 10:17
Unity3D Lerp (Linear Interpolation) Coroutines. Contains methods for creating routines which can be used as coroutines to easy lerp over a time period.
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
/// <summary>
/// Contains methods for creating routines which can be used as coroutines to easy lerp over a time period.
///
/// Example moves an object between two points over 5 seconds:
import pygame
import random
clr_red = (255, 0, 0)
clr_green = (0, 255, 0)
clr_blue = (0, 0, 255)
txt_red = "red"
txt_green = "green"
txt_blue = "blue"
{
"example_string": "aaa",
"example_bool": true,
"example_int": 3,
"example_float": "3.14",
"example_array": [
1,
2,
3,
4
@jackbrookes
jackbrookes / CoroutineTest.cs
Last active January 22, 2023 10:55
Simple extended Unity3D Coroutine interface. Allows checking if coroutine has finished, and a method to end the Coroutine early.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
/// Used to test the ExtendedCoroutine interface.
public class CoroutineTest : MonoBehaviour
{
// Start is called before the first frame update
IEnumerator Start()
@jackbrookes
jackbrookes / PositionAdjuster.cs
Last active September 11, 2019 20:12
Adjust height of a GameObject, and/or re-center your VR CameraRig with a keyboard press.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PositionAdjuster : MonoBehaviour
{
// amount by which each button press changes the height by
public float heightIncrement = 0.01f;
// keys on the keyboard we wish to use for adjusting position
@jackbrookes
jackbrookes / Texture2DExtensions.cs
Last active April 27, 2019 16:06
Extensions for the Unity Texture2D class allowing add/subtract/multiply operations on other textures as well as singe colours.
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public static class Texture2DExtensions
{
public static void Add(this Texture2D tex1, Texture2D tex2)
@jackbrookes
jackbrookes / SteamVROverlayCheck.cs
Last active August 18, 2018 16:00
Unity script that enables/disables a gameobject (like a warning text) when the user presses the System Button in SteamVR
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class SteamVROverlayCheck : MonoBehaviour
{
public GameObject warningDisplay;
void OnEnable()
{
"n_practice_trials": 5,
"n_main_trials": 10,
"size": 1
}