Work on back projection, f32 -> f64

This commit is contained in:
2018-07-23 10:12:37 +02:00
parent 674b49430f
commit 6807773b38
11 changed files with 89 additions and 109 deletions
+2 -2
View File
@@ -126,10 +126,10 @@ macro_rules! impl_center {
}
impl_center!(BoundingBox2, Vector2, f32);
impl_center!(BoundingBox2, Vector2, f64);
impl_center!(BoundingBox3, Vector3, f32);
impl_center!(BoundingBox3, Vector3, f64);
impl_center!(BoundingBox4, Vector4, f32);
impl_center!(BoundingBox2, Vector2, f64);
impl_center!(BoundingBox3, Vector3, f64);
impl_center!(BoundingBox4, Vector4, f64);
+3 -3
View File
@@ -26,7 +26,7 @@ impl Frustum {
}
/// Creates a frustum for a camera matrix.
pub fn from_matrix(m: &Matrix4<f32>) -> Frustum {
pub fn from_matrix(m: &Matrix4<f64>) -> Frustum {
// let m0 = m[(0, 0)]; let m1 = m[(0, 1)]; let m2 = m[(0, 2)]; let m3 = m[(0, 3)];
// let m4 = m[(1, 0)]; let m5 = m[(1, 1)]; let m6 = m[(1, 2)]; let m7 = m[(1, 3)];
@@ -52,11 +52,11 @@ impl Frustum {
}
/// Returns true if the intersection of the frustum and the bounding box is not empty.
pub fn intersects_box(&self, bbox: BoundingBox3<f32>) -> bool {
pub fn intersects_box(&self, bbox: BoundingBox3<f64>) -> bool {
use num::Zero;
let mut p = Vector3::<f32>::zero();
let mut p = Vector3::<f64>::zero();
for plane in &self.planes {
+9 -9
View File
@@ -6,15 +6,15 @@ use math::vector::Vector3;
#[derive(Copy, Clone)]
pub struct Plane {
/// The normal of the plane.
normal: Vector3<f32>,
normal: Vector3<f64>,
/// The constant, offset of the plane from the origin.
constant: f32,
constant: f64,
}
impl Plane {
/// Creates a new plane from its normal and its constant.
pub fn from_coordinates(a: f32, b: f32, c: f32, w: f32) -> Plane {
pub fn from_coordinates(a: f64, b: f64, c: f64, w: f64) -> Plane {
let mut p = Plane {
normal: Vector3::new(a, b, c),
constant: w,
@@ -24,18 +24,18 @@ impl Plane {
}
/// Creates a new plane from its normal and its constant.
pub fn from_normal_and_constant(normal: Vector3<f32>, constant: f32) -> Plane {
pub fn from_normal_and_constant(normal: Vector3<f64>, constant: f64) -> Plane {
Plane::from_coordinates(normal.x(), normal.y(), normal.z(), constant)
}
/// Creates a new plane from its normal and a point of the plane.
pub fn from_normal_and_point(normal: Vector3<f32>, point: Vector3<f32>) -> Plane {
pub fn from_normal_and_point(normal: Vector3<f64>, point: Vector3<f64>) -> Plane {
Plane::from_normal_and_constant(normal, - point.dot(normal))
}
/// Creates a new plane from three points.
pub fn from_points(p1: Vector3<f32>, p2: Vector3<f32>, p3: Vector3<f32>) -> Plane {
pub fn from_points(p1: Vector3<f64>, p2: Vector3<f64>, p3: Vector3<f64>) -> Plane {
let p1p2 = p2 - p1;
let p1p3 = p3 - p1;
Plane::from_normal_and_point(p1p2.cross_product(p1p3), p1)
@@ -49,17 +49,17 @@ impl Plane {
}
/// Returns the normal of the plane.
pub fn normal(&self) -> Vector3<f32> {
pub fn normal(&self) -> Vector3<f64> {
self.normal
}
/// Returns the constant of the plane.
pub fn constant(&self) -> f32 {
pub fn constant(&self) -> f64 {
self.constant
}
/// Returns the distance between the plane and the point.
pub fn distance_to_point(&self, point: Vector3<f32>) -> f32 {
pub fn distance_to_point(&self, point: Vector3<f64>) -> f64 {
self.normal.dot(point) + self.constant
}
}
+4 -4
View File
@@ -247,9 +247,9 @@ make_vector!(Vector2, 2, (T, T), (x, x_mut, 0), (y, y_mut, 1));
make_vector!(Vector3, 3, (T, T, T), (x, x_mut, 0), (y, y_mut, 1), (z, z_mut, 2));
make_vector!(Vector4, 4, (T, T, T, T), (x, x_mut, 0), (y, y_mut, 1), (z, z_mut, 2), (t, t_mut, 3));
impl Vector2<f32> {
impl Vector2<f64> {
/// Returns a orthogonal vector to the one passed as parameter.
pub fn orthogonal(&self) -> Vector2<f32> {
pub fn orthogonal(&self) -> Vector2<f64> {
Vector2::new(
self.y(),
self.x() * -1.0,
@@ -291,10 +291,10 @@ impl Vector3<f64> {
}
type Vector2f32 = Vector2<f32>; implement_vertex!(Vector2f32, data);
type Vector2f64 = Vector2<f64>; implement_vertex!(Vector2f64, data);
type Vector3f32 = Vector3<f32>; implement_vertex!(Vector3f32, data);
type Vector3f64 = Vector3<f64>; implement_vertex!(Vector3f64, data);
type Vector4f32 = Vector4<f32>; implement_vertex!(Vector4f32, data);
type Vector2f64 = Vector2<f64>; implement_vertex!(Vector2f64, data);
type Vector3f64 = Vector3<f64>; implement_vertex!(Vector3f64, data);
type Vector4f64 = Vector4<f64>; implement_vertex!(Vector4f64, data);
#[cfg(test)]