#include "backdrop.h"
#include "goatvr.h"
#include "opt.h"
+#include "fs.h"
+
+static void draw_scene();
int win_width, win_height;
float win_aspect;
static float cam_theta, cam_phi;
static float cam_height = 1.65;
-static Mesh *mesh_torus;
static bool bnstate[16];
static int prev_x, prev_y;
Mesh::use_custom_sdr_attr = false;
- mesh_torus = new Mesh;
- gen_torus(mesh_torus, 1.0, 0.25, 32, 32);
-
if(!init_backdrop()) {
return false;
}
+ if(!init_fs()) {
+ return false;
+ }
+
return true;
}
if(opt.vr) {
goatvr_shutdown();
}
- delete mesh_torus;
cleanup_backdrop();
}
glMatrixMode(GL_MODELVIEW);
glLoadMatrixf(view_matrix[0]);
- draw_backdrop();
+ draw_scene();
}
goatvr_draw_done();
glMatrixMode(GL_MODELVIEW);
glLoadMatrixf(view_matrix[0]);
- draw_backdrop();
+ draw_scene();
app_swap_buffers();
app_redraw(); // since we added animation we need to redisplay even in non-VR mode
assert(glGetError() == GL_NO_ERROR);
}
+static void draw_scene()
+{
+ draw_backdrop();
+ draw_fs();
+}
+
void app_reshape(int x, int y)
{
glViewport(0, 0, x, y);
--- /dev/null
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include "fs.h"
+#include "icon.h"
+#include "gmath/gmath.h"
+#include "opengl.h"
+#include "app.h"
+
+static IconRenderer *iconrend;
+
+bool init_fs()
+{
+ iconrend = new ShapesIcons;
+ if(!iconrend->init()) {
+ return false;
+ }
+
+ return true;
+}
+
+void cleanup_fs()
+{
+ delete iconrend;
+}
+
+void draw_fs()
+{
+ FSNode test;
+ test.type = FSNODE_DIR;
+
+ Mat4 xform;
+ xform.rotate(time_sec, 0, 0);
+ xform.rotate(0, 0, time_sec * 0.5);
+ xform.translate(0, 2, -5);
+
+ glPushMatrix();
+ glMultMatrixf(xform[0]);
+
+ glUseProgram(0);
+ glDisable(GL_TEXTURE_2D);
+ iconrend->draw(&test);
+
+ glPopMatrix();
+}
+
+// ---- FSNode implementation ----
+FSNode::FSNode()
+{
+ type = FSNODE_UNKNOWN;
+ abs_path = name = suffix = 0;
+}
+
+FSNode::~FSNode()
+{
+ if(abs_path) {
+ delete [] abs_path;
+ }
+}
+
+void FSNode::set_path(const char *s)
+{
+ int len = strlen(s);
+ if(!len) return;
+
+ delete [] abs_path;
+
+ const char *slash = s + len - 1;
+ while(slash > s && *slash != '/') {
+ --slash;
+ }
+ if(name == s) { // no slashes found
+ char buf[1024];
+ if(!getcwd(buf, sizeof buf)) {
+ abort();
+ }
+
+ int dirlen = strlen(buf);
+ abs_path = new char[len + dirlen + 2];
+ sprintf(abs_path, "%s/%s", buf, s);
+
+ name = abs_path + dirlen + 1;
+ suffix = abs_path + len + dirlen - 1;
+ } else {
+ abs_path = new char[len + 1];
+ memcpy(abs_path, s, len + 1);
+
+ name = abs_path + (slash - s);
+ suffix = abs_path + len - 1;
+ }
+
+ while(suffix > name && *suffix != '.') {
+ --suffix;
+ }
+ if(suffix == name) {
+ suffix = 0;
+ }
+}
char *abs_path;
char *name, *suffix;
+ FSNode();
+ ~FSNode();
+
void set_path(const char *s);
};
+bool init_fs();
+void cleanup_fs();
+
+void draw_fs();
+
#endif // FS_H_
priv->shape[i] = new Mesh;
}
- gen_geosphere(priv->shape[SHAPE_SPHERE], 1.0, 2);
+ Mat4 xform;
+
+ gen_geosphere(priv->shape[SHAPE_SPHERE], 0.5, 0);
gen_box(priv->shape[SHAPE_BOX], 1, 1, 1);
- gen_torus(priv->shape[SHAPE_TORUS], 0.9, 0.2, 16, 8);
- gen_cone(priv->shape[SHAPE_CONE], 0.8, 1.0, 8, 2);
+ gen_torus(priv->shape[SHAPE_TORUS], 0.4, 0.1, 12, 6);
+
+ gen_cone(priv->shape[SHAPE_CONE], 0.5, 1.0, 8, 2, 1);
+ xform.translation(0, -0.33, 0);
+ priv->shape[SHAPE_CONE]->apply_xform(xform, Mat4::identity);
return true;
}
}
}
+static int fstype_shape(FSNodeType type)
+{
+ switch(type) {
+ case FSNODE_FILE:
+ return SHAPE_SPHERE;
+ case FSNODE_DIR:
+ return SHAPE_BOX;
+ case FSNODE_DEV:
+ return SHAPE_TORUS;
+ default:
+ break;
+ }
+ return SHAPE_CONE;
+}
+
void ShapesIcons::draw(FSNode *node) const
{
+ int s = fstype_shape(node->type);
+ priv->shape[s]->draw();
}
{
int nidx = nfaces * 3;
if(nidx && num != nidx) {
- fprintf(stderr, "%s: index count missmatch (%d instead of %d)\n", __FUNCTION__, num, nidx);
+ fprintf(stderr, "%s: index count mismatch (%d instead of %d)\n", __FUNCTION__, num, nidx);
return 0;
}
nfaces = num / 3;
((Mesh*)this)->update_wire_ibo();
+ int num_faces = get_poly_count();
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, wire_ibo);
- glDrawElements(GL_LINES, nfaces * 6, GL_UNSIGNED_INT, 0);
+ glDrawElements(GL_LINES, num_faces * 6, GL_UNSIGNED_INT, 0);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
post_draw();
glGenBuffers(1, &wire_ibo);
}
- unsigned int *wire_idxarr = new unsigned int[nfaces * 6];
+ int num_faces = get_poly_count();
+
+ unsigned int *wire_idxarr = new unsigned int[num_faces * 6];
unsigned int *dest = wire_idxarr;
if(ibo_valid) {
// we're dealing with an indexed mesh
const unsigned int *idxarr = ((const Mesh*)this)->get_index_data();
- for(unsigned int i=0; i<nfaces; i++) {
+ for(int i=0; i<num_faces; i++) {
*dest++ = idxarr[0];
*dest++ = idxarr[1];
*dest++ = idxarr[1];
}
} else {
// not an indexed mesh ...
- for(unsigned int i=0; i<nfaces; i++) {
+ for(int i=0; i<num_faces; i++) {
int vidx = i * 3;
*dest++ = vidx;
*dest++ = vidx + 1;
}
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, wire_ibo);
- glBufferData(GL_ELEMENT_ARRAY_BUFFER, nfaces * 6 * sizeof(unsigned int), wire_idxarr, GL_STATIC_DRAW);
+ glBufferData(GL_ELEMENT_ARRAY_BUFFER, num_faces * 6 * sizeof(unsigned int), wire_idxarr, GL_STATIC_DRAW);
delete [] wire_idxarr;
wire_ibo_valid = true;
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);