From f92b28f53f4766ba17cca8a28515af575c034c58 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Crozet?= Date: Mon, 22 Jul 2013 12:32:16 +0200 Subject: [PATCH] Add sphere sampling implementation for Vec3. --- src/vec_spec.rs | 51 +++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 49 insertions(+), 2 deletions(-) diff --git a/src/vec_spec.rs b/src/vec_spec.rs index b760e5f7..d26f5cf2 100644 --- a/src/vec_spec.rs +++ b/src/vec_spec.rs @@ -100,6 +100,52 @@ static SAMPLES_2_F64: [Vec2, ..21] = [ Vec2 { x: 0.95557281, y: -0.29475517 }, ]; +// Those vectors come from bullet 3d +static SAMPLES_3_F64: [Vec3, ..42] = [ + Vec3 { x: 0.000000 , y: -0.000000, z: -1.000000 }, + Vec3 { x: 0.723608 , y: -0.525725, z: -0.447219 }, + Vec3 { x: -0.276388, y: -0.850649, z: -0.447219 }, + Vec3 { x: -0.894426, y: -0.000000, z: -0.447216 }, + Vec3 { x: -0.276388, y: 0.850649 , z: -0.447220 }, + Vec3 { x: 0.723608 , y: 0.525725 , z: -0.447219 }, + Vec3 { x: 0.276388 , y: -0.850649, z: 0.447220 }, + Vec3 { x: -0.723608, y: -0.525725, z: 0.447219 }, + Vec3 { x: -0.723608, y: 0.525725 , z: 0.447219 }, + Vec3 { x: 0.276388 , y: 0.850649 , z: 0.447219 }, + Vec3 { x: 0.894426 , y: 0.000000 , z: 0.447216 }, + Vec3 { x: -0.000000, y: 0.000000 , z: 1.000000 }, + Vec3 { x: 0.425323 , y: -0.309011, z: -0.850654 }, + Vec3 { x: -0.162456, y: -0.499995, z: -0.850654 }, + Vec3 { x: 0.262869 , y: -0.809012, z: -0.525738 }, + Vec3 { x: 0.425323 , y: 0.309011 , z: -0.850654 }, + Vec3 { x: 0.850648 , y: -0.000000, z: -0.525736 }, + Vec3 { x: -0.525730, y: -0.000000, z: -0.850652 }, + Vec3 { x: -0.688190, y: -0.499997, z: -0.525736 }, + Vec3 { x: -0.162456, y: 0.499995 , z: -0.850654 }, + Vec3 { x: -0.688190, y: 0.499997 , z: -0.525736 }, + Vec3 { x: 0.262869 , y: 0.809012 , z: -0.525738 }, + Vec3 { x: 0.951058 , y: 0.309013 , z: 0.000000 }, + Vec3 { x: 0.951058 , y: -0.309013, z: 0.000000 }, + Vec3 { x: 0.587786 , y: -0.809017, z: 0.000000 }, + Vec3 { x: 0.000000 , y: -1.000000, z: 0.000000 }, + Vec3 { x: -0.587786, y: -0.809017, z: 0.000000 }, + Vec3 { x: -0.951058, y: -0.309013, z: -0.000000 }, + Vec3 { x: -0.951058, y: 0.309013 , z: -0.000000 }, + Vec3 { x: -0.587786, y: 0.809017 , z: -0.000000 }, + Vec3 { x: -0.000000, y: 1.000000 , z: -0.000000 }, + Vec3 { x: 0.587786 , y: 0.809017 , z: -0.000000 }, + Vec3 { x: 0.688190 , y: -0.499997, z: 0.525736 }, + Vec3 { x: -0.262869, y: -0.809012, z: 0.525738 }, + Vec3 { x: -0.850648, y: 0.000000 , z: 0.525736 }, + Vec3 { x: -0.262869, y: 0.809012 , z: 0.525738 }, + Vec3 { x: 0.688190 , y: 0.499997 , z: 0.525736 }, + Vec3 { x: 0.525730 , y: 0.000000 , z: 0.850652 }, + Vec3 { x: 0.162456 , y: -0.499995, z: 0.850654 }, + Vec3 { x: -0.425323, y: -0.309011, z: 0.850654 }, + Vec3 { x: -0.425323, y: 0.309011 , z: 0.850654 }, + Vec3 { x: 0.162456 , y: 0.499995 , z: 0.850654 } +]; + impl UniformSphereSample for Vec2 { pub fn sample(f: &fn(&'static Vec2)) @@ -111,8 +157,9 @@ impl UniformSphereSample for Vec2 impl UniformSphereSample for Vec3 { - pub fn sample(_: &fn(&'static Vec3)) + pub fn sample(f: &fn(&'static Vec3)) { - fail!("UniformSphereSample for Vec3 is not yet implemented.") + for SAMPLES_3_F64.iter().advance |sample| + { f(sample) } } }