13 #include <DirectXMath.h>
33 DirectX::XMFLOAT4X4 world_;
45 bb_max_ = bb_min_ = p;
58 bb_max_ = max(p, bb_max_);
59 bb_min_ = min(p, bb_min_);
64 inline V
center()
const {
return bb_min_ + (bb_max_ - bb_min_)/2.0f; };
67 inline V
bb_max()
const {
return bb_max_; };
70 inline V
bb_min()
const {
return bb_min_; };
79 inline const DirectX::XMFLOAT4X4&
world()
94 bool is_visible(
const aabb<DirectX::XMFLOAT3>& bbox,
const DirectX::XMFLOAT4X4& to_clip);
115 {
"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 },
116 {
"NORMAL", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 12, D3D11_INPUT_PER_VERTEX_DATA, 0 },
117 {
"TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 24, D3D11_INPUT_PER_VERTEX_DATA, 0 },
132 ID3D11VertexShader* vs_;
133 ID3D11PixelShader* ps_;
135 ID3D11InputLayout* vertex_layout_;
137 INT diffuse_tex_slot_;
138 INT normal_tex_slot_;
139 INT specular_tex_slot_;
150 virtual void set_shader(ID3D11Device* device, ID3DBlob* input_binary, ID3D11VertexShader* vs, ID3D11PixelShader* ps);
155 INT specular_tex = -1)
157 diffuse_tex_slot_ = diffuse_tex;
158 normal_tex_slot_ = normal_tex;
159 specular_tex_slot_ = specular_tex;
163 virtual void create(ID3D11Device* device,
const tstring& filename) = 0;
177 virtual void render(ID3D11DeviceContext* context, DirectX::XMFLOAT4X4* to_clip =
nullptr) = 0;
191 void load_model(ID3D11Device* device,
const tstring& file, std::shared_ptr<d3d_mesh>& ptr);
virtual void destroy()
Destroy a mesh and free all its resources.
Definition: mesh.cpp:42
void load_model(ID3D11Device *device, const tstring &file, std::shared_ptr< d3d_mesh > &ptr)
Load a model specified by a filename.
Definition: mesh.cpp:16
virtual void set_shader(ID3D11Device *device, ID3DBlob *input_binary, ID3D11VertexShader *vs, ID3D11PixelShader *ps)
Sets the input layout, vertex- and pixel shader of this mesh.
Definition: mesh.cpp:59
void update_bb(const V &p)
Update the bounding-box with a new point.
Definition: mesh.h:56
bool is_visible(const aabb< DirectX::XMFLOAT3 > &bbox, const DirectX::XMFLOAT4X4 &to_clip)
Check if a bounding-box is visible given a clipping matrix.
Definition: mesh.cpp:74
virtual size_t num_vertices()=0
Returns the number of vertices of a mesh.
virtual void set_world(const DirectX::XMFLOAT4X4 &world)
Update the world matrix of this mesh.
Definition: mesh.h:73
An axis-aligned bounding-box.
Definition: mesh.h:28
void init_bb(const V &p)
Initialize the bounding-box with a first point.
Definition: mesh.h:43
virtual void create(ID3D11Device *device, const tstring &filename)=0
Create a mesh from a given filename.
const DirectX::XMFLOAT4X4 & world()
Returns the current world matrix of this mesh.
Definition: mesh.h:79
V bb_min() const
Returns the minimum (lower/left/front) of the bounding-box.
Definition: mesh.h:70
virtual size_t num_faces()=0
Returns the number of faces of a mesh.
const D3D11_INPUT_ELEMENT_DESC standard_vertex_desc[]
The standard layout of a d3d_mesh.
Definition: mesh.h:113
virtual void set_shader_slots(INT diffuse_tex=-1, INT normal_tex=-1, INT specular_tex=-1)
Sets three register numbers to identify the slots the pixel shader is looking for surface textures...
Definition: mesh.h:153
Basic interface of a mesh.
Definition: mesh.h:102
virtual void render(ID3D11DeviceContext *context, DirectX::XMFLOAT4X4 *to_clip=nullptr)=0
Renders the mesh using the shaders previously set.
V center() const
Returns the center of the bounding-box.
Definition: mesh.h:64
Main D3D mesh interface class.
Definition: mesh.h:129
V bb_max() const
Returns the maximum (upper/right/back) of the bounding-box.
Definition: mesh.h:67