X-Git-Url: http://git.mutantstargoat.com?a=blobdiff_plain;f=src%2Fmain.cc;h=01f67161874b3817c52218cbf349343dc343fa29;hb=a65a977df6fa8fee831c91cdc754d62e023b6630;hp=307f64770053abad45babfd414762f80653ded5f;hpb=32d7e487f9b74900081f23bb501b7f2c094160af;p=hair diff --git a/src/main.cc b/src/main.cc index 307f647..01f6716 100644 --- a/src/main.cc +++ b/src/main.cc @@ -10,8 +10,9 @@ #include "mesh.h" #include "hair.h" +#include "object.h" -#define MAX_NUM_SPAWNS 4 +#define MAX_NUM_SPAWNS 400 #define THRESH 0.5 static bool init(); @@ -32,6 +33,7 @@ static int win_width, win_height; static float cam_theta, cam_phi = 25, cam_dist = 8; static float head_rz, head_rx; /* rot angles x, z axis */ static Mat4 head_xform; +static CollSphere coll_sphere; /* sphere used for collision detection */ int main(int argc, char **argv) { @@ -103,11 +105,16 @@ static bool init() return false; } + coll_sphere.radius = 1.0; + coll_sphere.center = Vec3(0, 0.6, 0.53); + if(!hair.init(mesh_head, MAX_NUM_SPAWNS, THRESH)) { fprintf(stderr, "Failed to initialize hair\n"); return false; } + hair.add_collider(&coll_sphere); + return true; } @@ -120,6 +127,11 @@ static void cleanup() static void display() { + static unsigned long prev_time; + unsigned long msec = glutGet(GLUT_ELAPSED_TIME); + float dt = (float)(msec - prev_time) / 1000.0; + prev_time = msec; + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); head_xform = Mat4::identity; @@ -131,16 +143,47 @@ static void display() glTranslatef(0, 0, -cam_dist); glRotatef(cam_phi, 1, 0, 0); glRotatef(cam_theta, 0, 1, 0); - + /* multiplying with the head rot matrix */ + glPushMatrix(); glMultMatrixf(head_xform[0]); - + glPushAttrib(GL_LINE_BIT); + glLineWidth(1); + glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); for(size_t i=0; idraw(); } + glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); + glPopAttrib(); + + glPopMatrix(); hair.set_transform(head_xform); + hair.update(dt); hair.draw(); +/* + glPushAttrib(GL_ENABLE_BIT); + glDisable(GL_DEPTH_TEST); + glDisable(GL_LIGHTING); + glBegin(GL_POINTS); + for (int i=0; i<500; i++) { + Vec3 p; + p.x = (float)rand() / RAND_MAX * 8 - 4; + p.y = (float)rand() / RAND_MAX * 4; + p.z = 0; + + Vec3 tmp = inverse(head_xform) * p; + if(coll_sphere.contains(tmp)) { + glColor3f(1, 0, 0); + } + else glColor3f(0, 1, 0); + + glVertex3f(p.x, p.y, p.z); + } + glEnd(); + glPopAttrib(); + */ + glutSwapBuffers(); assert(glGetError() == GL_NO_ERROR); } @@ -211,7 +254,7 @@ static void motion(int x, int y) if(head_rx > 45) head_rx = 45; if(head_rz < -90) head_rz = -90; - if(head_rz > 90) head_rx = 90; + if(head_rz > 90) head_rz = 30; } } else {