-
Notifications
You must be signed in to change notification settings - Fork 3
/
instance.h
96 lines (73 loc) · 2.53 KB
/
instance.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
// instance.h -- Transformed virtual instance of a surface
//
// Copyright (C) 2007-2012 Miles Bader <miles@gnu.org>
//
// This source code is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License as
// published by the Free Software Foundation; either version 3, or (at
// your option) any later version. See the file COPYING for more details.
//
// Written by Miles Bader <miles@gnu.org>
//
#ifndef SNOGRAY_INSTANCE_H
#define SNOGRAY_INSTANCE_H
#include "xform.h"
#include "model.h"
#include "local-surface.h"
namespace snogray {
class Instance : public LocalSurface
{
public:
Instance (const Ref<Model> &_model, const Xform &local_to_world_xform)
: LocalSurface (local_to_world_xform), model (_model)
{ }
// If this surface intersects RAY, change RAY's maximum bound (Ray::t1)
// to reflect the point of intersection, and return a Surface::IsecInfo
// object describing the intersection (which should be allocated using
// placement-new with CONTEXT); otherwise return zero.
//
virtual IsecInfo *intersect (Ray &ray, RenderContext &context) const;
// Return true if this surface intersects RAY.
//
virtual bool intersects (const Ray &ray, RenderContext &context) const;
// Return true if this surface completely occludes RAY. If it does
// not completely occlude RAY, then return false, and multiply
// TOTAL_TRANSMITTANCE by the transmittance of the surface in medium
// MEDIUM.
//
// Note that this method does not try to handle non-trivial forms of
// transparency/translucency (for instance, a "glass" material is
// probably considered opaque because it changes light direction as
// well as transmitting it).
//
virtual bool occludes (const Ray &ray, const Medium &medium,
Color &total_transmittance,
RenderContext &context)
const;
// Return a bounding box for this surface.
//
virtual BBox bbox () const;
private:
struct IsecInfo : public Surface::IsecInfo
{
IsecInfo (const Ray &ray,
const Instance &_instance,
const Surface::IsecInfo *_model_isec_info)
: Surface::IsecInfo (ray),
instance (_instance),
model_isec_info (_model_isec_info)
{ }
virtual Intersect make_intersect (const Media &media,
RenderContext &context)
const;
virtual TexCoords tex_coords () const;
virtual Vec normal () const;
const Instance &instance;
const Surface::IsecInfo *model_isec_info;
};
// Model that we're transforming.
//
Ref<Model> model;
};
}
#endif // SNOGRAY_INSTANCE_H