OpenGothic
Open source reimplementation of Gothic I and II
Loading...
Searching...
No Matches
inventoryrenderer.cpp
Go to the documentation of this file.
1#include "inventoryrenderer.h"
2
5
6#include "shaders.h"
7
8using namespace Tempest;
9
11 :visual(scene,std::pair<Vec3,Vec3>()),itmGroup(visual) {
12 Tempest::Matrix4x4 p, mv, shMv[Resources::ShadowLayers];
13 p.identity();
14 mv.identity();
15 mv.scale(0.8f,1.f,1.f);
16 scene.setViewProject(mv,p,0,1,shMv);
17 }
18
19void InventoryRenderer::draw(Tempest::Encoder<CommandBuffer>& cmd) {
20 Tempest::Matrix4x4 mv = Tempest::Matrix4x4::mkIdentity();
21 mv.translate(0, 0, 0.5f);
22 mv.scale(0.8f,1.f,1.f);
23
24 auto& pso = Shaders::inst().inventory;
25 for(auto& i:items) {
26 cmd.setViewport(i.x,i.y,i.w,i.h);
27 for(size_t r=0;r<i.mesh.nodesCount();++r) {
28 auto n = i.mesh.node(r);
29 auto& m = n.material();
30
31 if(auto s = n.mesh()) {
32 auto sl = n.meshSlice();
33 auto p = mv;
34 p.scale(1, 1, 0.25f);
35
36 p.mul(n.position());
37 p.mul(i.viewMat);
38
39 cmd.setBinding(0, *m.tex);
40 cmd.setPushData(p);
41 cmd.setPipeline(pso);
42 cmd.draw(s->vbo, s->ibo, sl.first, sl.second);
43 }
44 }
45 }
46 }
47
48void InventoryRenderer::reset(bool full) {
49 items.clear();
50 }
51
52void InventoryRenderer::drawItem(int x, int y, int w, int h, const ::Item& item) {
53 auto& itData = item.handle();
54 if(auto mesh = Resources::loadMesh(itData.visual)) {
55 float sz = (mesh->bbox[1]-mesh->bbox[0]).length();
56 auto mv = (mesh->bbox[1]+mesh->bbox[0])*0.5f;
57 ItmFlags flg = ItmFlags(item.mainFlag());
58
59 mv = Vec3(mv.x,mv.y,mv.z);
60
61 sz = 2.f/sz;
62 if(sz>0.1f)
63 sz=0.1f;
64
65 Tempest::Matrix4x4 mat;
66 mat.identity();
67
68 float rotx = float(itData.inv_rot_x);
69 float roty = float(itData.inv_rot_y);
70 float rotz = float(itData.inv_rot_z);
71
72 if(flg&(ITM_CAT_NF | ITM_CAT_FF | ITM_CAT_MUN)) {
73 static const float invX = -45;
74 static const float invY = 0;
75 static const float invZ = 90;
76 mat.rotateOX(invX+rotx);
77 mat.rotateOZ(invZ+rotz);
78 mat.rotateOY(invY+roty);
79 }
80 else if(flg&ITM_CAT_ARMOR) {
81 static const float invX = 0;
82 static const float invY = -90;
83 static const float invZ = 180;
84 mat.rotateOX(invX+rotx);
85 mat.rotateOZ(invZ+rotz);
86 mat.rotateOY(invY+roty);
87 }
88 else if(flg&ITM_CAT_RUNE) {
89 static const float invX = 90;
90 static const float invY = 0;
91 static const float invZ = 90;
92 mat.rotateOX(invX+rotx);
93 mat.rotateOZ(invZ+rotz);
94 mat.rotateOY(invY+roty);
95 }
96 else if((flg&ITM_CAT_MAGIC) || (ItmFlags(itData.flags)&ITM_RING)) {
97 static const float invX = 200;
98 static const float invY = 0;
99 static const float invZ = 90;
100 mat.rotateOX(invX+rotx);
101 mat.rotateOZ(invZ+rotz);
102 mat.rotateOY(invY+roty);
103 }
104 else if(flg&ITM_CAT_POTION) {
105 static const float invX = 180;
106 static const float invY = 0;
107 static const float invZ = 0;
108 mat.rotateOX(invX+rotx);
109 mat.rotateOZ(invZ+rotz);
110 mat.rotateOY(invY+roty);
111 }
112 else if(flg&ITM_CAT_FOOD) {
113 static const float invX = 180;
114 static const float invY = 0;
115 static const float invZ = 45;
116 mat.rotateOX(invX+rotx);
117 mat.rotateOZ(invZ+rotz);
118 mat.rotateOY(invY+roty);
119 }
120 else if(flg&ITM_CAT_DOCS) {
121 static const float invX = 180;
122 static const float invY = 90;
123 static const float invZ = -90;
124 mat.rotateOX(invX);
125 mat.rotateOZ(invZ);
126 mat.rotateOY(invY);
127 }
128 else if(flg&ITM_CAT_NONE) {
129 static float invXa = 135;
130 static float invYa = 90;
131 static float invZa = 45;
132 //invXa++;
133 mat.rotateOX(invXa-rotx);
134 mat.rotateOZ(invZa-rotz);
135 mat.rotateOY(invYa-roty);
136 } else {
137 static const float invX = 180;
138 static const float invY = -90;
139 static const float invZ = -90;
140 mat.rotateOX(invX+rotx);
141 mat.rotateOZ(invZ+rotz);
142 mat.rotateOY(invY+roty);
143 }
144
145 for(int i=0; i<3; ++i){
146 auto trX = mat.at(i,0);
147 auto trY = mat.at(i,2);
148 mat.set(i,0,trY);
149 mat.set(i,2,trX);
150 }
151 mat.scale(sz);
152 mat.translate(-mv);
153
154 Itm itm;
155 itm.mesh = MeshObjects::Mesh(itmGroup,*mesh,itData.material,0,itData.material,false);
156 itm.mesh.setObjMatrix(Matrix4x4::mkIdentity());
157 itm.viewMat = mat;
158 itm.x = x;
159 itm.y = y;
160 itm.w = w;
161 itm.h = h;
162 items.push_back(std::move(itm));
163 }
164 }
void reset(bool full=false)
void draw(Tempest::Encoder< Tempest::CommandBuffer > &cmd)
void drawItem(int x, int y, int w, int h, const Item &item)
@ ShadowLayers
Definition resources.h:49
static const ProtoMesh * loadMesh(std::string_view name)
void setViewProject(const Tempest::Matrix4x4 &view, const Tempest::Matrix4x4 &proj, float zNear, float zFar, const Tempest::Matrix4x4 *sh)
static Shaders & inst()
Definition shaders.cpp:39
Tempest::RenderPipeline inventory
Definition shaders.h:124
ItmFlags
Definition constants.h:312
@ ITM_CAT_MAGIC
Definition constants.h:323
@ ITM_CAT_NONE
Definition constants.h:313
@ ITM_CAT_NF
Definition constants.h:314
@ ITM_CAT_FOOD
Definition constants.h:318
@ ITM_CAT_FF
Definition constants.h:315
@ ITM_CAT_RUNE
Definition constants.h:322
@ ITM_CAT_DOCS
Definition constants.h:319
@ ITM_RING
Definition constants.h:325
@ ITM_CAT_MUN
Definition constants.h:316
@ ITM_CAT_POTION
Definition constants.h:320
@ ITM_CAT_ARMOR
Definition constants.h:317