projects
/
hair
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
6a620a8
)
head motion
author
Eleni Maria Stea
<estea@igalia.com>
Tue, 1 Jan 2019 16:37:51 +0000
(18:37 +0200)
committer
Eleni Maria Stea
<estea@igalia.com>
Tue, 1 Jan 2019 16:37:51 +0000
(18:37 +0200)
Makefile
patch
|
blob
|
history
src/main.cc
patch
|
blob
|
history
diff --git
a/Makefile
b/Makefile
index
660400a
..
4ca72b2
100644
(file)
--- a/
Makefile
+++ b/
Makefile
@@
-6,11
+6,11
@@
bin = hair
dbg = -g
opt = -O0
dbg = -g
opt = -O0
-inc = -Isrc -Isrc/shaders -Isrc/math
+inc = -Isrc -Isrc/shaders -Isrc/math -I/home/eleni/igalia/install/include
CXX = g++
CXXFLAGS = -pedantic -Wall $(dbg) $(opt) $(inc)
CXX = g++
CXXFLAGS = -pedantic -Wall $(dbg) $(opt) $(inc)
-LDFLAGS = -lGL -lGLU -lglut -lGLEW -limago -lassimp -lgmath
+LDFLAGS = -lGL -lGLU -lglut -lGLEW -limago -lassimp -lgmath -L/home/eleni/igalia/install/lib/libglut.so
$(bin): $(obj)
$(CXX) -o $@ $(obj) $(LDFLAGS)
$(bin): $(obj)
$(CXX) -o $@ $(obj) $(LDFLAGS)
diff --git
a/src/main.cc
b/src/main.cc
index
5a93d0e
..
ef26c3c
100644
(file)
--- a/
src/main.cc
+++ b/
src/main.cc
@@
-6,6
+6,8
@@
#include <stdio.h>
#include <string>
#include <stdio.h>
#include <string>
+#include <gmath/gmath.h>
+
#include "mesh.h"
#include "hair.h"
#include "mesh.h"
#include "hair.h"
@@
-20,6
+22,7
@@
static void keydown(unsigned char key, int x, int y);
static void keyup(unsigned char key, int x, int y);
static void mouse(int bn, int st, int x, int y);
static void motion(int x, int y);
static void keyup(unsigned char key, int x, int y);
static void mouse(int bn, int st, int x, int y);
static void motion(int x, int y);
+static void idle();
static std::vector<Mesh*> meshes;
static Mesh *mesh_head;
static std::vector<Mesh*> meshes;
static Mesh *mesh_head;
@@
-27,7
+30,8
@@
static Hair hair;
static int win_width, win_height;
static float cam_theta, cam_phi = 25, cam_dist = 8;
static int win_width, win_height;
static float cam_theta, cam_phi = 25, cam_dist = 8;
-static float hair_deg;
+static float head_rz, head_rx; /* rot angles x, z axis */
+static Mat4 head_xform;
int main(int argc, char **argv)
{
int main(int argc, char **argv)
{
@@
-36,12
+40,16
@@
int main(int argc, char **argv)
glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE);
glutCreateWindow("hair test");
glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE);
glutCreateWindow("hair test");
+ /* for the keydown, keyup functions to work */
+ glutSetKeyRepeat(GLUT_KEY_REPEAT_OFF);
+
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutKeyboardFunc(keydown);
glutKeyboardUpFunc(keyup);
glutMouseFunc(mouse);
glutMotionFunc(motion);
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutKeyboardFunc(keydown);
glutKeyboardUpFunc(keyup);
glutMouseFunc(mouse);
glutMotionFunc(motion);
+ glutIdleFunc(idle);
if(!init()) {
return 1;
if(!init()) {
return 1;
@@
-114,12
+122,18
@@
static void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+ head_xform = Mat4::identity;
+ head_xform.rotate_x(gph::deg_to_rad(head_rx));
+ head_xform.rotate_z(-gph::deg_to_rad(head_rz));
+
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(0, 0, -cam_dist);
glRotatef(cam_phi, 1, 0, 0);
glRotatef(cam_theta, 0, 1, 0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(0, 0, -cam_dist);
glRotatef(cam_phi, 1, 0, 0);
glRotatef(cam_theta, 0, 1, 0);
+ glMultMatrixf(head_xform[0]);
+
for(size_t i=0; i<meshes.size(); i++) {
meshes[i]->draw();
}
for(size_t i=0; i<meshes.size(); i++) {
meshes[i]->draw();
}
@@
-141,12
+155,13
@@
static void reshape(int x, int y)
gluPerspective(50.0, (float)x / (float)y, 0.5, 500.0);
}
gluPerspective(50.0, (float)x / (float)y, 0.5, 500.0);
}
+static bool hpressed;
static void keydown(unsigned char key, int /*x*/, int /*y*/)
{
switch(key) {
case 'h':
case 'H':
static void keydown(unsigned char key, int /*x*/, int /*y*/)
{
switch(key) {
case 'h':
case 'H':
- printf("key %u down\n", key);
+ hpressed = true;
break;
case 27:
exit(0);
break;
case 27:
exit(0);
@@
-158,12
+173,12
@@
static void keydown(unsigned char key, int /*x*/, int /*y*/)
static void keyup(unsigned char key, int /*x*/, int /*y*/)
{
switch(key) {
static void keyup(unsigned char key, int /*x*/, int /*y*/)
{
switch(key) {
- case 'h':
- case 'H':
- printf("key %u up\n", key);
- break;
- default:
- break;
+ case 'h':
+ case 'H':
+ hpressed = false;
+ break;
+ default:
+ break;
}
}
}
}
@@
-186,17
+201,34
@@
static void motion(int x, int y)
if(!dx && !dy) return;
if(!dx && !dy) return;
- if(bnstate[0]) {
- cam_theta += dx * 0.5;
- cam_phi += dy * 0.5;
+ if(hpressed) {
+ if(bnstate[0]) {
+ head_rz += dx * 0.5;
+ head_rx += dy * 0.5;
- if(cam_phi < -90) cam_phi = -90;
- if(cam_phi > 90) cam_phi = 90;
- glutPostRedisplay();
+ if(head_rx < -45) head_rx = -45;
+ if(head_rx > 45) head_rx = 45;
+
+ if(head_rz < -90) head_rz = -90;
+ if(head_rz > 90) head_rx = 90;
+ }
}
}
- if(bnstate[2]) {
- cam_dist += dy * 0.1;
- if(cam_dist < 0) cam_dist = 0;
- glutPostRedisplay();
+ else {
+ if(bnstate[0]) {
+ cam_theta += dx * 0.5;
+ cam_phi += dy * 0.5;
+
+ if(cam_phi < -90) cam_phi = -90;
+ if(cam_phi > 90) cam_phi = 90;
+ }
+ if(bnstate[2]) {
+ cam_dist += dy * 0.1;
+ if(cam_dist < 0) cam_dist = 0;
+ }
}
}
}
}
+
+static void idle()
+{
+ glutPostRedisplay();
+}