Skip to content
Newer
Older
100644 56 lines (44 sloc) 1.6 KB
6e33440 @snogglethorpe Rename sample_xxx functions to xxx_sample
authored Aug 16, 2010
1 // tangent-disk-sample.h -- Sample a disk tangent to a sphere
24ca66f @snogglethorpe Add sample_tangent_disk function
authored Feb 19, 2010
2 //
31e0a94 @snogglethorpe Tweak syntax of include-file guard macros
authored Sep 11, 2011
3 // Copyright (C) 2010, 2011 Miles Bader <miles@gnu.org>
24ca66f @snogglethorpe Add sample_tangent_disk function
authored Feb 19, 2010
4 //
5 // This source code is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License as
7 // published by the Free Software Foundation; either version 3, or (at
8 // your option) any later version. See the file COPYING for more details.
9 //
10 // Written by Miles Bader <miles@gnu.org>
11 //
12
31e0a94 @snogglethorpe Tweak syntax of include-file guard macros
authored Sep 11, 2011
13 #ifndef SNOGRAY_TANGENT_DISK_SAMPLE_H
14 #define SNOGRAY_TANGENT_DISK_SAMPLE_H
24ca66f @snogglethorpe Add sample_tangent_disk function
authored Feb 19, 2010
15
16 #include "uv.h"
17 #include "vec.h"
18 #include "frame.h"
6e33440 @snogglethorpe Rename sample_xxx functions to xxx_sample
authored Aug 16, 2010
19 #include "disk-sample.h"
24ca66f @snogglethorpe Add sample_tangent_disk function
authored Feb 19, 2010
20
21
22 namespace snogray {
23
24
25 // Given a sphere defined by SPHERE_CENTER and SPHERE_RADIUS, sample
26 // over a disk with the same radius (SPHERE_RADIUS), whose center is
27 // tangent to the sphere in direction DIR from the sphere's center.
28 // PARAM is the sample parameter.
29 //
30 static inline Pos
6e33440 @snogglethorpe Rename sample_xxx functions to xxx_sample
authored Aug 16, 2010
31 tangent_disk_sample (const Pos &sphere_center, dist_t sphere_radius,
24ca66f @snogglethorpe Add sample_tangent_disk function
authored Feb 19, 2010
32 const Vec &dir, const UV &param)
33 {
34 // FRAME is located at the center of the the sphere, and pointed in
35 // the direction DIR (where the center of the disk should be tangent
36 // to the sphere).
37 //
38 Frame frame (sphere_center, dir);
39
40 // Choose a sample point on a disk with radius SPHERE_RADIUS.
41 //
42 coord_t px, py;
6e33440 @snogglethorpe Rename sample_xxx functions to xxx_sample
authored Aug 16, 2010
43 disk_sample (sphere_radius, param, px, py);
24ca66f @snogglethorpe Add sample_tangent_disk function
authored Feb 19, 2010
44
45 // Now move the point PX,PY on the disk, SCENE_RADIUS units away
46 // along the z-axis in FRAME's coordinate system, and transform the
47 // resulting position back to world coordinates.
48 //
49 return frame.from (Pos (px, py, sphere_radius));
50 }
51
52
53 }
54
31e0a94 @snogglethorpe Tweak syntax of include-file guard macros
authored Sep 11, 2011
55 #endif // SNOGRAY_TANGENT_DISK_SAMPLE_H
Something went wrong with that request. Please try again.