Skip to content

Commit

Permalink
Update euclid.
Browse files Browse the repository at this point in the history
  • Loading branch information
emilio committed Jul 22, 2019
1 parent 5c0eb61 commit a33ef5b
Show file tree
Hide file tree
Showing 11 changed files with 54 additions and 54 deletions.
2 changes: 1 addition & 1 deletion webxr-api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ path = "lib.rs"
ipc = ["serde", "typetag", "ipc-channel", "euclid/serde"]

[dependencies]
euclid = "0.19"
euclid = "0.20"
gleam = "0.6"
ipc-channel = { version = "0.11", optional = true }
serde = { version = "1.0", optional = true }
Expand Down
12 changes: 6 additions & 6 deletions webxr-api/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ use crate::SessionMode;
use crate::Viewport;
use crate::Views;

use euclid::default::Size2D as UntypedSize2D;
use euclid::RigidTransform3D;
use euclid::Size2D;
use euclid::TypedRigidTransform3D;
use euclid::TypedSize2D;

use gleam::gl::GLsync;

Expand All @@ -30,19 +30,19 @@ pub trait Discovery: 'static {
/// A trait for using an XR device
pub trait Device: 'static {
/// The transform from native coordinates to the floor.
fn floor_transform(&self) -> TypedRigidTransform3D<f32, Native, Floor>;
fn floor_transform(&self) -> RigidTransform3D<f32, Native, Floor>;

/// The transforms from viewer coordinates to the eyes, and their associated viewports.
fn views(&self) -> Views;

/// A resolution large enough to contain all the viewports.
/// https://immersive-web.github.io/webxr/#native-webgl-framebuffer-resolution
fn recommended_framebuffer_resolution(&self) -> TypedSize2D<i32, Viewport> {
fn recommended_framebuffer_resolution(&self) -> Size2D<i32, Viewport> {
let viewport = match self.views() {
Views::Mono(view) => view.viewport,
Views::Stereo(left, right) => left.viewport.union(&right.viewport),
};
TypedSize2D::new(viewport.max_x(), viewport.max_y())
Size2D::new(viewport.max_x(), viewport.max_y())
}

/// This method should block waiting for the next frame,
Expand All @@ -52,7 +52,7 @@ pub trait Device: 'static {
/// This method should render a GL texture to the device.
/// While this method is being called, the device has unique access
/// to the texture. The texture should be sync'd using glWaitSync before being used.
fn render_animation_frame(&mut self, texture_id: u32, size: Size2D<i32>, sync: GLsync);
fn render_animation_frame(&mut self, texture_id: u32, size: UntypedSize2D<i32>, sync: GLsync);

/// Inputs registered with the device on initialization. More may be added, which
/// should be communicated through a yet-undecided event mechanism
Expand Down
4 changes: 2 additions & 2 deletions webxr-api/frame.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::InputFrame;
use crate::Native;
use crate::Viewer;

use euclid::TypedRigidTransform3D;
use euclid::RigidTransform3D;

/// The per-frame data that is provided by the device.
/// https://www.w3.org/TR/webxr/#xrframe
Expand All @@ -18,7 +18,7 @@ pub struct Frame {
///
/// This is equivalent to the pose of the viewer in native coordinates.
/// This is the inverse of the view matrix.
pub transform: TypedRigidTransform3D<f32, Viewer, Native>,
pub transform: RigidTransform3D<f32, Viewer, Native>,

/// Frame information for each connected input source
pub inputs: Vec<InputFrame>,
Expand Down
4 changes: 2 additions & 2 deletions webxr-api/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use crate::Input;
use crate::Native;

use euclid::TypedRigidTransform3D;
use euclid::RigidTransform3D;

#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "ipc", derive(serde::Serialize, serde::Deserialize))]
Expand Down Expand Up @@ -39,5 +39,5 @@ pub struct InputSource {
#[cfg_attr(feature = "ipc", derive(serde::Serialize, serde::Deserialize))]
pub struct InputFrame {
pub id: InputId,
pub target_ray_origin: TypedRigidTransform3D<f32, Input, Native>,
pub target_ray_origin: RigidTransform3D<f32, Input, Native>,
}
8 changes: 4 additions & 4 deletions webxr-api/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::Receiver;
use crate::Viewer;
use crate::Views;

use euclid::TypedRigidTransform3D;
use euclid::RigidTransform3D;

#[cfg(feature = "ipc")]
use serde::{Deserialize, Serialize};
Expand All @@ -27,17 +27,17 @@ pub trait MockDiscovery: 'static {
#[derive(Clone, Debug)]
#[cfg_attr(feature = "ipc", derive(Serialize, Deserialize))]
pub struct MockDeviceInit {
pub floor_origin: TypedRigidTransform3D<f32, Floor, Native>,
pub floor_origin: RigidTransform3D<f32, Floor, Native>,
pub supports_immersive: bool,
pub supports_unbounded: bool,
pub viewer_origin: TypedRigidTransform3D<f32, Viewer, Native>,
pub viewer_origin: RigidTransform3D<f32, Viewer, Native>,
pub views: Views,
}

#[derive(Debug)]
#[cfg_attr(feature = "ipc", derive(Serialize, Deserialize))]
pub enum MockDeviceMsg {
SetViewerOrigin(TypedRigidTransform3D<f32, Viewer, Native>),
SetViewerOrigin(RigidTransform3D<f32, Viewer, Native>),
SetViews(Views),
Focus,
Blur,
Expand Down
12 changes: 6 additions & 6 deletions webxr-api/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ use crate::Viewport;
use crate::Views;
use crate::WebGLExternalImageApi;

use euclid::TypedRigidTransform3D;
use euclid::TypedSize2D;
use euclid::RigidTransform3D;
use euclid::Size2D;

use std::thread;
use std::time::Duration;
Expand Down Expand Up @@ -58,15 +58,15 @@ enum SessionMsg {
/// https://www.w3.org/TR/webxr/#xrsession-interface
#[cfg_attr(feature = "ipc", derive(Serialize, Deserialize))]
pub struct Session {
floor_transform: TypedRigidTransform3D<f32, Native, Floor>,
floor_transform: RigidTransform3D<f32, Native, Floor>,
views: Views,
resolution: TypedSize2D<i32, Viewport>,
resolution: Size2D<i32, Viewport>,
sender: Sender<SessionMsg>,
initial_inputs: Vec<InputSource>,
}

impl Session {
pub fn floor_transform(&self) -> TypedRigidTransform3D<f32, Native, Floor> {
pub fn floor_transform(&self) -> RigidTransform3D<f32, Native, Floor> {
self.floor_transform.clone()
}

Expand All @@ -78,7 +78,7 @@ impl Session {
self.views.clone()
}

pub fn recommended_framebuffer_resolution(&self) -> TypedSize2D<i32, Viewport> {
pub fn recommended_framebuffer_resolution(&self) -> Size2D<i32, Viewport> {
self.resolution
}

Expand Down
12 changes: 6 additions & 6 deletions webxr-api/view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

//! This crate uses `euclid`'s typed units, and exposes different coordinate spaces.

use euclid::TypedRect;
use euclid::TypedRigidTransform3D;
use euclid::TypedTransform3D;
use euclid::Rect;
use euclid::RigidTransform3D;
use euclid::Transform3D;

#[cfg(feature = "ipc")]
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -68,9 +68,9 @@ pub enum Input {}
#[derive(Clone, Debug)]
#[cfg_attr(feature = "ipc", derive(Serialize, Deserialize))]
pub struct View<Eye> {
pub transform: TypedRigidTransform3D<f32, Viewer, Eye>,
pub projection: TypedTransform3D<f32, Eye, Display>,
pub viewport: TypedRect<i32, Viewport>,
pub transform: RigidTransform3D<f32, Viewer, Eye>,
pub projection: Transform3D<f32, Eye, Display>,
pub viewport: Rect<i32, Viewport>,
}

/// Whether a device is mono or stereo, and the views it supports.
Expand Down
2 changes: 1 addition & 1 deletion webxr-api/webgl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
//! The WebGL functionality needed by WebXR.

use crate::Error;
use euclid::Size2D;
use euclid::default::Size2D;
use gleam::gl::GLsync;
use gleam::gl::GLuint;

Expand Down
2 changes: 1 addition & 1 deletion webxr/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ ipc = ["webxr-api/ipc"]

[dependencies]
webxr-api = { path = "../webxr-api" }
euclid = "0.19"
euclid = "0.20"
gleam = "0.6"
glutin = { version = "0.21", optional = true }
log = "0.4"
40 changes: 20 additions & 20 deletions webxr/glwindow/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */

use euclid::default::Size2D as UntypedSize2D;
use euclid::Angle;
use euclid::Point2D;
use euclid::Rect;
use euclid::RigidTransform3D;
use euclid::Size2D;
use euclid::Transform3D;
use euclid::Trig;
use euclid::TypedPoint2D;
use euclid::TypedRect;
use euclid::TypedRigidTransform3D;
use euclid::TypedSize2D;
use euclid::TypedTransform3D;
use euclid::TypedVector3D;
use euclid::Vector3D;

use gleam::gl;
use gleam::gl::GLsizei;
Expand Down Expand Up @@ -45,7 +45,7 @@ const FAR: f32 = 100.0;
pub trait GlWindow {
fn make_current(&mut self);
fn swap_buffers(&mut self);
fn size(&self) -> Size2D<GLsizei>;
fn size(&self) -> UntypedSize2D<GLsizei>;
fn new_window(&self) -> Result<Box<dyn GlWindow>, ()>;
}

Expand Down Expand Up @@ -86,9 +86,9 @@ pub struct GlWindowDevice {
}

impl Device for GlWindowDevice {
fn floor_transform(&self) -> TypedRigidTransform3D<f32, Native, Floor> {
let translation = TypedVector3D::new(-HEIGHT, 0.0, 0.0);
TypedRigidTransform3D::from_translation(translation)
fn floor_transform(&self) -> RigidTransform3D<f32, Native, Floor> {
let translation = Vector3D::new(-HEIGHT, 0.0, 0.0);
RigidTransform3D::from_translation(translation)
}

fn views(&self) -> Views {
Expand All @@ -99,15 +99,15 @@ impl Device for GlWindowDevice {

fn wait_for_animation_frame(&mut self) -> Frame {
self.window.swap_buffers();
let translation = TypedVector3D::new(0.0, 0.0, -5.0);
let transform = TypedRigidTransform3D::from_translation(translation);
let translation = Vector3D::new(0.0, 0.0, -5.0);
let transform = RigidTransform3D::from_translation(translation);
Frame {
transform,
inputs: vec![],
}
}

fn render_animation_frame(&mut self, texture_id: u32, size: Size2D<i32>, sync: GLsync) {
fn render_animation_frame(&mut self, texture_id: u32, size: UntypedSize2D<i32>, sync: GLsync) {
self.window.make_current();

let width = size.width as GLsizei;
Expand Down Expand Up @@ -168,26 +168,26 @@ impl GlWindowDevice {

fn view<Eye>(&self, is_right: bool) -> View<Eye> {
let window_size = self.window.size();
let viewport_size = TypedSize2D::new(window_size.width / 2, window_size.height);
let viewport_size = Size2D::new(window_size.width / 2, window_size.height);
let viewport_x_origin = if is_right { viewport_size.width } else { 0 };
let viewport_origin = TypedPoint2D::new(viewport_x_origin, 0);
let viewport = TypedRect::new(viewport_origin, viewport_size);
let viewport_origin = Point2D::new(viewport_x_origin, 0);
let viewport = Rect::new(viewport_origin, viewport_size);
let projection = self.perspective(NEAR, FAR);
let eye_distance = if is_right {
EYE_DISTANCE
} else {
-EYE_DISTANCE
};
let translation = TypedVector3D::new(eye_distance, 0.0, 0.0);
let transform = TypedRigidTransform3D::from_translation(translation);
let translation = Vector3D::new(eye_distance, 0.0, 0.0);
let transform = RigidTransform3D::from_translation(translation);
View {
transform,
projection,
viewport,
}
}

fn perspective<Eye>(&self, near: f32, far: f32) -> TypedTransform3D<f32, Eye, Display> {
fn perspective<Eye>(&self, near: f32, far: f32) -> Transform3D<f32, Eye, Display> {
// https://github.com/toji/gl-matrix/blob/bd3307196563fbb331b40fc6ebecbbfcc2a4722c/src/mat4.js#L1271
let size = self.window.size();
let width = size.width as f32;
Expand All @@ -201,7 +201,7 @@ impl GlWindowDevice {
{
#[rustfmt::skip]
// Sigh, row-major vs column-major
return TypedTransform3D::row_major(
return Transform3D::row_major(
f / aspect, 0.0, 0.0, 0.0,
0.0, f, 0.0, 0.0,
0.0, 0.0, (far + near) * nf, -1.0,
Expand Down
10 changes: 5 additions & 5 deletions webxr/headless/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ use webxr_api::SessionMode;
use webxr_api::Viewer;
use webxr_api::Views;

use euclid::Size2D;
use euclid::TypedRigidTransform3D;
use euclid::default::Size2D;
use euclid::RigidTransform3D;

use gleam::gl;
use gleam::gl::GLsync;
Expand All @@ -41,8 +41,8 @@ struct HeadlessDiscovery {

struct HeadlessDevice {
gl: Rc<dyn Gl>,
floor_transform: TypedRigidTransform3D<f32, Native, Floor>,
viewer_origin: TypedRigidTransform3D<f32, Viewer, Native>,
floor_transform: RigidTransform3D<f32, Native, Floor>,
viewer_origin: RigidTransform3D<f32, Viewer, Native>,
views: Views,
receiver: Receiver<MockDeviceMsg>,
}
Expand Down Expand Up @@ -88,7 +88,7 @@ impl Discovery for HeadlessDiscovery {
}

impl Device for HeadlessDevice {
fn floor_transform(&self) -> TypedRigidTransform3D<f32, Native, Floor> {
fn floor_transform(&self) -> RigidTransform3D<f32, Native, Floor> {
self.floor_transform.clone()
}

Expand Down

0 comments on commit a33ef5b

Please sign in to comment.