Difference between revisions of "Virtual Reality Cameras"

From PowerUI
Jump to: navigation, search
(Created page with "In virtual reality, it's common to see the middle of the screen being used as the input pointer. Think Minecraft and similar. Here's how you set that up in PowerUI using the C...")
 
 
(6 intermediate revisions by 3 users not shown)
Line 1: Line 1:
In virtual reality, it's common to see the middle of the screen being used as the input pointer. Think Minecraft and similar. Here's how you set that up in PowerUI using the CameraPointer class.
+
In virtual reality, it's common to see the middle of the screen being used as the [[Input Pointers|input pointer]]. Think Minecraft and similar. Here's how you set that up in PowerUI using the CameraPointer class.
  
First, you'll probably want to turn off the mouse pointer (It's used on desktops only). It's the input pointer which is controlled by the mouse. To disable it, do this:
+
Note that the UI's you create would almost always be one or more [[World UI|WorldUI's]].
 +
 
 +
== Creating a CameraPointer ==
 +
 
 +
* You'll probably want to turn off the mouse pointer (It's used on desktops only). It's the input pointer which is controlled by the mouse.
 +
* In an Awake method, create a CameraPointer for a particular camera.
 +
 
 +
Here's an example:
  
 
<syntaxhighlight lang="csharp">
 
<syntaxhighlight lang="csharp">
PowerUI.Input.CreateSystemMouse=false;
+
 
 +
CameraPointer MyPointer;
 +
 
 +
void Awake(){
 +
 
 +
  // Disable the system mouse:
 +
  PowerUI.Input.CreateSystemMouse=false;
 +
 
 +
  // Create a camera pointer that sits in the middle of the screen (50%,50%):
 +
  MyPointer = new CameraPointer(Camera.main,0.5f,0.5f);
 +
 
 +
  // Add it now:
 +
  MyPointer.Add();
 +
 
 +
}
 +
 
 
</syntaxhighlight>
 
</syntaxhighlight>
  
Some point before you setup your UI. Usually dropping it in an Awake works great. ''(Specifically, it must happen before UI.Start() is called which happens inside the PowerUIManager's Start method)''.
+
Whenever the camera you gave is transformed (i.e. rotated or moved around), the pointer automatically updates itself.
  
Next, you'll then want to create the camera pointer itself. That's like this:
+
== Laser Pointers ==
  
<syntaxhighlight lang="csharp">
+
You can also entirely override the raycast to create a clickable/ hoverable input ray in any direction. Check out the [[Input Pointers#Virtual Reality|input pointers]] page for an example custom laser input pointer.  
// Create a camera pointer that sits in the middle of the screen (50%,50%):
 
CameraPointer pointer=new CameraPointer(Camera.main,0.5f,0.5f);
 
  
// Add it now:
+
== Making it click ==
pointer.Add();
 
</syntaxhighlight>
 
  
And that's all it takes! Whenever your camera is transformed (i.e. rotated or moved around), the pointer automatically updates itself.
+
See the section on [[Input Pointers#Making it click|input pointers]] about making them click.

Latest revision as of 04:08, 1 May 2017

In virtual reality, it's common to see the middle of the screen being used as the input pointer. Think Minecraft and similar. Here's how you set that up in PowerUI using the CameraPointer class.

Note that the UI's you create would almost always be one or more WorldUI's.

Creating a CameraPointer

  • You'll probably want to turn off the mouse pointer (It's used on desktops only). It's the input pointer which is controlled by the mouse.
  • In an Awake method, create a CameraPointer for a particular camera.

Here's an example:

CameraPointer MyPointer;

void Awake(){

  // Disable the system mouse:
  PowerUI.Input.CreateSystemMouse=false;
  
  // Create a camera pointer that sits in the middle of the screen (50%,50%):
  MyPointer = new CameraPointer(Camera.main,0.5f,0.5f);
  
  // Add it now:
  MyPointer.Add();

}

Whenever the camera you gave is transformed (i.e. rotated or moved around), the pointer automatically updates itself.

Laser Pointers

You can also entirely override the raycast to create a clickable/ hoverable input ray in any direction. Check out the input pointers page for an example custom laser input pointer.

Making it click

See the section on input pointers about making them click.