-
Notifications
You must be signed in to change notification settings - Fork 0
/
0009modify-instances-count.diff
138 lines (128 loc) · 4.49 KB
/
0009modify-instances-count.diff
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
diff -bNur 0008multi-material/data_bulk.c 0009modify-instances-count/data_bulk.c
--- 0008multi-material/data_bulk.c 2019-03-03 15:08:52.172915452 -0600
+++ 0009modify-instances-count/data_bulk.c 2019-03-03 15:08:52.176914583 -0600
@@ -265,7 +265,7 @@
0,
},
{
- "Other Cube",
+ "Bullet",
offsetof(struct data_model_index, other_cube) / sizeof(uint32_t),
sizeof(data_model_index->other_cube) / sizeof(uint32_t),
1,
diff -bNur 0008multi-material/libdata.c 0009modify-instances-count/libdata.c
--- 0008multi-material/libdata.c 2019-03-03 15:08:52.176914583 -0600
+++ 0009modify-instances-count/libdata.c 2019-03-03 15:08:52.180913714 -0600
@@ -1,15 +1,23 @@
#include "data_bulk.h"
+#include <assert.h>
#include <math.h>
#include <stdbool.h>
+#include <string.h>
+
+inline static void player_shoot();
void key_callback(GLFWwindow *window, int key, int scancode, int action,
int mods)
{
+ if (action == GLFW_PRESS)
switch (key)
{
case GLFW_KEY_ESCAPE:
glfwSetWindowShouldClose(window, true);
break;
+ case GLFW_KEY_X:
+ player_shoot();
+ break;
}
}
@@ -65,33 +73,60 @@
glm_mat4_copy(rot0, *model);
}
+inline static void setup_model_instance(data_model_instance_t *inst);
#define SUBO data_model_shared_ubo
struct shared_ubo *SUBO = NULL;
+inline static void player_shoot()
+{
+ data_model_instance_t *this_instance = NULL,
+ bullet_instance = {
+ "Bullet Object",
+ 1,
+ shoot_forward,
+ NULL,
+ {NULL, NULL},
+ NULL,
+ VK_NULL_HANDLE,
+ };
+
+ this_instance = malloc(sizeof(bullet_instance));
+ assert(this_instance && "Out of memory.");
+ *this_instance = bullet_instance;
+ setup_model_instance(this_instance);
+
+ {
+ material_1_ubo_t *this_ubo = this_instance->ubo;
+ {
+ static const material_1_ubo_t empty_data_material_ubo_s;
+ *this_ubo = empty_data_material_ubo_s;
+ }
+ glm_mat4_copy(GLM_MAT4_IDENTITY, this_ubo->bones[0]);
+
+ {
+ mat4 trans0;
+ glm_translate_to(GLM_MAT4_IDENTITY, SUBO->viewPos, trans0);
+ glm_rotate_y(trans0, center_dir, this_ubo->model);
+ glm_translate_z(this_ubo->model, 1.25f);
+ }
+ }
+
+ list_add_tail(&this_instance->list, &data_model_instances);
+}
typedef struct
{
data_model_instance_t obj;
- data_model_instance_t other_obj;
} model_instance_t;
model_instance_t model_instance;
struct list_head data_model_instances = {&(model_instance.obj.list),
- &(model_instance.other_obj.list)};
+ &(model_instance.obj.list)};
model_instance_t model_instance = {
{
"Object",
0,
NULL,
NULL,
- {&(model_instance.other_obj.list), &(data_model_instances)},
- NULL,
- VK_NULL_HANDLE,
- },
- {
- "Other Object",
- 1,
- shoot_forward,
- NULL,
- {&(data_model_instances), &(model_instance.obj.list)},
+ {&(data_model_instances), &(data_model_instances)},
NULL,
VK_NULL_HANDLE,
},
@@ -201,12 +236,10 @@
void data_init(VkExtent2D extent)
{
- material_0_ubo_t *ubo_0, *ubo_1;
- data_model_instance_t *inst;
- list_for_each_entry(inst, &data_model_instances, list)
+ material_0_ubo_t *ubo_0;
+ data_model_instance_t *inst = list_entry(data_model_instances.next, data_model_instance_t, list);
setup_model_instance(inst);
- ubo_0 = (list_entry(data_model_instances.next, data_model_instance_t, list))->ubo;
- ubo_1 = (list_entry(data_model_instances.prev, data_model_instance_t, list))->ubo;
+ ubo_0 = inst->ubo;
glfwSetKeyCallback(data_window, key_callback);
@@ -242,9 +275,6 @@
update_vp();
- *ubo_1 = *ubo_0;
- glm_rotate_y(GLM_MAT4_IDENTITY, CGLM_PI / 2, ubo_1->model);
-
previous_frame = glfwGetTime();
}