-
Notifications
You must be signed in to change notification settings - Fork 0
/
tree.h
53 lines (45 loc) · 1.3 KB
/
tree.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
#pragma once
#include "d3dwrap.h"
#include <functional>
#include <memory>
class Camera;
struct TreeLod
{
VertexBuffer mVertexBuffer[2];
IndexBuffer mIndexBuffer[2];
int mIndexCount[2];
VertexBuffer mInstanceBuffer;
int mInstanceCount;
D3DXVECTOR4 mSphere[2];
TreeLod() noexcept
: mVertexBuffer{ makeVertexBuffer(), makeVertexBuffer() }
, mIndexBuffer{ makeIndexBuffer(), makeIndexBuffer() }
, mIndexCount{ 0, 0 }
, mInstanceBuffer{ makeVertexBuffer() }
, mInstanceCount{ 0 }
, mSphere{ { 0, 0, 0, 0 }, { 0, 0, 0, 0 } }
{
}
};
enum class TreeRenderMode { ALPHA_CLIP, ALPHA_BLEND, CASTER };
class Tree
{
public:
Tree(std::shared_ptr<IDirect3DDevice9> pDevice, Camera* pCamera, IDirect3DTexture9* pShadowZ);
bool init(const std::function<float(float, float)>& height, const std::function<float(float, float)>& angle);
void update([[maybe_unused]] float tick = 1.0f);
void draw(TreeRenderMode mode, const D3DXMATRIX& matLightViewProj) const;
private:
void createInstances();
std::shared_ptr<IDirect3DDevice9> mDevice;
Camera* mCamera;
IDirect3DTexture9* mShadowZ;
TreeLod mLod[3];
Texture mTexture[3];
Effect mEffect;
VertexDeclaration mVertexDeclaration;
D3DXVECTOR3 mCamPos;
D3DXVECTOR3 mCamDir;
std::function<float(float, float)> mHeight;
std::function<float(float, float)> mAngle;
};