int flat_panel::init() {
// Initialization part
float vertices[] = {
- -1.0, 0, 1.0,
- 1.0, 0, 1.0,
- 1.0, 0, -1.0,
- -1.0, 0, 1.0,
- 1.0, 0, -1.0,
- -1.0, 0, -1.0,
+ -1.0, 1.0,
+ 1.0, 1.0,
+ 1.0, -1.0,
+ -1.0, 1.0,
+ 1.0, -1.0,
+ -1.0, -1.0,
};
glGenBuffers(1, &vbuf);
glBindBuffer(GL_SHADER_STORAGE_BUFFER, vbuf);
glBufferData(GL_SHADER_STORAGE_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
- program = make_program("panel_vertex_shader.glsl",0, 0, 0, "loaded_object_fragment_shader.glsl");
+ program = make_program("normal_panel_vertex_shader.glsl",0, 0, 0, "loaded_object_fragment_shader.glsl");
if (!program)
return 1;
glGenBuffers(1, &models_buffer);
glGenBuffers(1, &scales_buffer);
+ glGenBuffers(1, &normals_buffer);
+ glGenBuffers(1, &ups_buffer);
+ glGenBuffers(1, &object_scales_buffer);
v_attrib = glGetAttribLocation(program, "in_vertex");
mvp_uniform = glGetUniformLocation(program, "vp");
return 0;
}
-void flat_panel::addpanel(glm::vec3 location, glm::vec2 object_scale, glm::vec2 texture_scale){
+void flat_panel::addpanel(glm::vec3 location, glm::vec2 object_scale, glm::vec2 texture_scale, glm::vec3 normal, glm::vec3 up){
locations.push_back(location);
object_scales.push_back(object_scale);
texture_scales.push_back(texture_scale);
+ normals.push_back(glm::vec4(glm::normalize(normal), 1.0f));
+ ups.push_back(glm::vec4(glm::normalize(up), 1.0f));
+}
+
+void flat_panel::rotate(size_t index, float angle, glm::vec3 axis){
+
+}
+void flat_panel::set_normal(size_t index, glm::vec3 normal){
+ normals[index] = glm::vec4(glm::normalize(normal), 1.0f);
+}
+
+void flat_panel::set_up(size_t index, glm::vec3 up){
+ ups[index] = glm::vec4(glm::normalize(up), 1.0f);
}
std::vector<glm::mat4> flat_panel::create_models(){
for(size_t i = 0; i < locations.size(); i++){
glm::mat4 new_model = glm::mat4(1.0f);
new_model = glm::translate(new_model, locations[i]);
- new_model = glm::scale(new_model, glm::vec3(object_scales[i].x, 1.0f, object_scales[i].y));
models.push_back(new_model);
}
return models;
void flat_panel::draw(glm::mat4 vp) {
glUseProgram(program);
data_mutex.lock();
- std::vector<glm::mat4> models = create_models();
- glBindBuffer(GL_SHADER_STORAGE_BUFFER, models_buffer);
- glBufferData(GL_SHADER_STORAGE_BUFFER, models.size() * sizeof(glm::mat4), models.data(), GL_STATIC_DRAW);
- glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 0, models_buffer);
-
+ std::vector<glm::mat4> models = create_models();
+ glBindBuffer(GL_SHADER_STORAGE_BUFFER, models_buffer);
+ glBufferData(GL_SHADER_STORAGE_BUFFER, models.size() * sizeof(glm::mat4), models.data(), GL_STATIC_DRAW);
+ glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 0, models_buffer);
+
glBindBuffer(GL_SHADER_STORAGE_BUFFER, scales_buffer);
- glBufferData(GL_SHADER_STORAGE_BUFFER, texture_scales.size() * sizeof(glm::vec2), texture_scales.data(), GL_STATIC_DRAW);
- glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 1, scales_buffer);
+ glBufferData(GL_SHADER_STORAGE_BUFFER, texture_scales.size() * sizeof(glm::vec2), texture_scales.data(), GL_STATIC_DRAW);
+ glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 1, scales_buffer);
+
+ glBindBuffer(GL_SHADER_STORAGE_BUFFER, normals_buffer);
+ glBufferData(GL_SHADER_STORAGE_BUFFER, normals.size() * sizeof(normals[0]), normals.data(), GL_STATIC_DRAW);
+ glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 2, normals_buffer);
+
+ glBindBuffer(GL_SHADER_STORAGE_BUFFER, ups_buffer);
+ glBufferData(GL_SHADER_STORAGE_BUFFER, ups.size() * sizeof(ups[0]), ups.data(), GL_STATIC_DRAW);
+ glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 3, ups_buffer);
+
+ glBindBuffer(GL_SHADER_STORAGE_BUFFER, object_scales_buffer);
+ glBufferData(GL_SHADER_STORAGE_BUFFER, object_scales.size() * sizeof(object_scales[0]), object_scales.data(), GL_STATIC_DRAW);
+ glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 4, object_scales_buffer);
data_mutex.unlock();
glEnableVertexAttribArray(v_attrib);
glBindBuffer(GL_ARRAY_BUFFER, vbuf);
- glVertexAttribPointer(v_attrib, 3, GL_FLOAT, GL_FALSE, 0, 0);
+ glVertexAttribPointer(v_attrib, 2, GL_FLOAT, GL_FALSE, 0, 0);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, tex);
#pragma once
/* TODO:
- * Normal Vector for panel to set orientation
* Collision detection (can't move through panel)
*/
class flat_panel : public gameobject {
public:
std::vector<glm::vec2> object_scales, texture_scales;
- unsigned scales_buffer;
+ std::vector<glm::vec4> normals, ups;
+ unsigned scales_buffer, normals_buffer, ups_buffer, object_scales_buffer;
const char *texturefile;
flat_panel(const char* tf) : texturefile(tf) {}
int init() override;
void draw(glm::mat4 vp) override;
std::vector<glm::mat4> create_models();
- void addpanel(glm::vec3 location, glm::vec2 object_scale, glm::vec2 texture_scale);
+ void addpanel(glm::vec3 location, glm::vec2 object_scale, glm::vec2 texture_scale, glm::vec3 normal = glm::vec3(0, 1, 0), glm::vec3 up = glm::vec3(0, 0, 1));
+ void rotate(size_t index, float angle, glm::vec3 axis);
+ void set_normal(size_t index, glm::vec3 normal);
+ void set_up(size_t index, glm::vec3 normal);
};
+class rotating_panel : public flat_panel {
+public:
+ float angle = 0.0f;
+ rotating_panel(const char* tf) : flat_panel(tf) {}
+ void move(int elapsed_time){
+ angle = elapsed_time * 0.000003f;
+ for(size_t i = 0; i < normals.size(); i++){
+ normals[i] = glm::rotate(glm::mat4(1.0f), angle, glm::vec3(ups[i].x, ups[i].y, ups[i].z)) * normals[i];
+ }
+ }
+};
+
+class y_rotating_panel : public flat_panel {
+public:
+ float angle = 0.0f;
+ y_rotating_panel(const char* tf) : flat_panel(tf) {}
+ void move(int elapsed_time){
+ angle = elapsed_time * 0.000003f;
+ for(size_t i = 0; i < normals.size(); i++){
+ normals[i] = glm::rotate(glm::mat4(1.0f), angle, glm::vec3(0, 1, 0)) * normals[i];
+ ups[i] = glm::rotate(glm::mat4(1.0f), angle, glm::vec3(0, 1, 0)) * ups[i];
+ }
+ }
+};
+
+class face_player_panel : public flat_panel {
+public:
+ face_player_panel(const char* tf) : flat_panel(tf) {}
+ void move(int elapsed_time){
+ for(size_t i = 0; i < locations.size(); i++)
+ set_normal(i, locations[i] - player_position);
+ }
+};
int hud::init(){
std::vector<float> vertices;
+ vertices.reserve(3600);
/* 100 character display, 3 lines */
for(float y = y_space; y >= -y_space; y -= y_space)
for(int i = 0; i < char_width; i++){
p.addpanel(glm::vec3(32, -9.99, 450), glm::vec2(5, 5), glm::vec2(2.0, 2.0));
p.addpanel(glm::vec3(21, -9.99, 450), glm::vec2(5, 5), glm::vec2(0.5, 0.5));
p.addpanel(glm::vec3(10, -9.99, 450), glm::vec2(5, 5), glm::vec2(1, 1));
+ p.addpanel(glm::vec3(-20, 0, 410), glm::vec2(10, 10), glm::vec2(1, 1), glm::vec4(0, 0, 1, 1), glm::vec4(0, 1, 0, 1));
objects.push_back(&p);
+
+ rotating_panel rp("RhodeIslandRed.jpg");
+ rp.addpanel(glm::vec3(-120, 10, 400), glm::vec2(10, 10), glm::vec2(1, 1), glm::vec3(0, 0, 1), glm::vec3(1, 1, 0));
+ rp.addpanel(glm::vec3(-160, 10, 400), glm::vec2(10, 10), glm::vec2(1, 1), glm::vec3(0, 0, 1), glm::vec3(0, 1, 0));
+ rp.addpanel(glm::vec3(-200, 10, 400), glm::vec2(10, 10), glm::vec2(1, 1), glm::vec3(0, 0, 1), glm::vec3(-1, 1, 0));
+ objects.push_back(&rp);
+
+ y_rotating_panel yrp("JerseyGiant.jpg");
+ yrp.addpanel(glm::vec3(-300, -5, 300), glm::vec2(10, 10), glm::vec2(1, 1), glm::vec3(0, 1, -1), glm::vec3(0, 1, 1));
+ yrp.addpanel(glm::vec3(-300, -5, 350), glm::vec2(10, 10), glm::vec2(1, 1), glm::vec3(0, 1, 0), glm::vec3(0, 0, 1));
+ yrp.addpanel(glm::vec3(-300, -5, 400), glm::vec2(10, 10), glm::vec2(1, 1), glm::vec3(0, 0.5, 1), glm::vec3(0, 0.5, -1));
+ objects.push_back(&yrp);
+
+ face_player_panel fpp("BarredRock.jpg");
+ fpp.addpanel(glm::vec3(-30, 0, 500), glm::vec2(10, 10), glm::vec2(2.0, 2.0), glm::vec3(0, 0, 1), glm::vec3(0, 1, 0));
+ objects.push_back(&fpp);
+
aimpoint main_aimpoint;
objects.push_back(&main_aimpoint);
--- /dev/null
+#version 460
+
+layout(packed, binding=0) buffer model_list {
+ mat4 models[];
+};
+layout(packed, binding=1) buffer scale_list {
+ vec2 scales[];
+};
+layout(packed, binding=2) buffer normal_list {
+ vec3 normals[];
+};
+layout(packed, binding=3) buffer up_list {
+ vec3 ups[];
+};
+layout(packed, binding=4) buffer object_scale_list {
+ vec2 object_scales[];
+};
+in vec2 in_vertex;
+uniform mat4 vp;
+out vec2 frag_texcoord;
+out vec4 gl_Position;
+
+void main(void) {
+ vec3 sideways = normalize(cross(ups[gl_InstanceID], normals[gl_InstanceID]));
+ vec3 pos = in_vertex.x * object_scales[gl_InstanceID].x * ups[gl_InstanceID]
+ + in_vertex.y * object_scales[gl_InstanceID].y * sideways;
+ gl_Position = vp * models[gl_InstanceID] * vec4(pos, 1.0);
+ frag_texcoord = (vec2(in_vertex.y, -in_vertex.x) * 0.5 + vec2(0.5, 0.5)) * scales[gl_InstanceID];
+}
countdown--;
return;
}
- countdown = 314;
+ countdown = 50;
if(!current_target->locations.size())
return;
for(auto l : locations){