-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathObject.h
More file actions
95 lines (78 loc) · 3.21 KB
/
Copy pathObject.h
File metadata and controls
95 lines (78 loc) · 3.21 KB
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
// *********************************************************
// Object Class
// Author : Tamy Boubekeur (boubek@gmail.com).
// Copyright (C) 2010 Tamy Boubekeur.
// All rights reserved.
// *********************************************************
#ifndef OBJECT_H
#define OBJECT_H
#include <iostream>
#include <vector>
#include "Mesh.h"
#include "Material.h"
#include "BoundingBox.h"
#include "Surfel.h"
class Object {
public:
inline Object () : fBumpsLevel(0.0f) {}
inline Object (const Mesh & mesh, const Material & mat) : mesh (mesh), mat (mat), fBumpsLevel(0.0f) {
updateBoundingBox ();
generateBumps();
}
virtual ~Object () {}
inline const Vec3Df & getTrans () const { return trans;}
inline void setTrans (const Vec3Df & t) { trans = t; }
inline const Mesh & getMesh () const { return mesh; }
inline Mesh & getMesh () { return mesh; }
inline const Material & getMaterial () const { return mat; }
inline Material & getMaterial () { return mat; }
inline const BoundingBox & getBoundingBox () const { return bbox; }
void updateBoundingBox ();
void GetPointCloud (
std::vector< Surfel* >& oPointCloud
) const;
void generateBumps(float std = 1.0f);
inline float getBumpLevel() const { return fBumpsLevel; } //!< Returns bump amplitude.
inline void setBumpLevel(float val) { fBumpsLevel = val; } //!< Sets bump amplitude (0 = no bumps).
/*! \brief Computes normal at requested point, affected by bump map application.
\param[in] trgIndex Number of triangle in object's mesh.
\param[in] u Barycentric coordinate of the point in which the normal is requested.
\param[in] v Barycentric coordinate of the point in which the normal is requested.
\return normal in point (u,v) of triangle trgIndex.
*/
inline Vec3Df getBumpedNormal(unsigned int trgIndex, float u, float v) const {
Triangle trg = mesh.getTriangles()[trgIndex];
Vertex
v0 = mesh.getVertices()[ trg.getVertex(0) ],
v1 = mesh.getVertices()[ trg.getVertex(1) ],
v2 = mesh.getVertices()[ trg.getVertex(2) ];
Vec3Df normal = ( 1 - u - v ) * v0.getNormal ()
+ u * v1.getNormal ()
+ v * v2.getNormal ();
normal.normalize ();
int
x = u * Vec3Df::distance(v1.getPos(), v0.getPos()) * BUMP_MAP_SCALE,
y = v * Vec3Df::distance(v2.getPos(), v0.getPos()) * BUMP_MAP_SCALE;
normal += fBumps[x % BUMP_MAP_SIZE][y % BUMP_MAP_SIZE] * fBumpsLevel;
normal.normalize();
return normal;
}
private:
Mesh mesh;
Material mat;
BoundingBox bbox;
Vec3Df trans;
static const int
BUMP_MAP_SIZE = 100, //!< Size of bump map
BUMP_MAP_SCALE = 1000; //!< Bump map scale factor
typedef std::vector<std::vector<Vec3Df>> normalmap; //!< Just a vector field.
normalmap fBumps; //!< Bump map (generated by \a generateBumps(...) )
float fBumpsLevel; //!< Bump amplitude
};
#endif // Scene_H
// Some Emacs-Hints -- please don't remove:
//
// Local Variables:
// mode:C++
// tab-width:4
// End: