goat3d

changeset 78:53ea5b25426e

progress
author John Tsiombikas <nuclear@member.fsf.org>
date Thu, 08 May 2014 16:25:04 +0300
parents 4b653386a154
children a42f6cd4e2fa
files goatview/Makefile goatview/src/goatview.cc goatview/src/goatview.h
diffstat 3 files changed, 54 insertions(+), 6 deletions(-) [+]
line diff
     1.1 --- a/goatview/Makefile	Thu May 08 13:55:13 2014 +0300
     1.2 +++ b/goatview/Makefile	Thu May 08 16:25:04 2014 +0300
     1.3 @@ -10,7 +10,7 @@
     1.4  goat_root = ..
     1.5  
     1.6  CXXFLAGS = -std=c++11 -pedantic -Wall -g $(pic) -I$(goat_root)/src $(qtinc)
     1.7 -LDFLAGS = $(libgoat) $(libgl) $(qtlib)
     1.8 +LDFLAGS = $(libgoat) $(libgl) $(qtlib) -lvmath
     1.9  MOC = moc
    1.10  
    1.11  qtinc = `pkg-config --cflags Qt5Gui Qt5Core Qt5OpenGL`
     2.1 --- a/goatview/src/goatview.cc	Thu May 08 13:55:13 2014 +0300
     2.2 +++ b/goatview/src/goatview.cc	Thu May 08 16:25:04 2014 +0300
     2.3 @@ -1,9 +1,12 @@
     2.4 +#include <stdio.h>
     2.5  #include <QtOpenGL/QtOpenGL>
     2.6  #include <GL/glu.h>
     2.7  #include <vmath/vmath.h>
     2.8  #include "goatview.h"
     2.9  #include "goat3d.h"
    2.10  
    2.11 +static void draw_node(goat3d_node *node);
    2.12 +
    2.13  goat3d *scene;
    2.14  QSettings *settings;
    2.15  
    2.16 @@ -151,6 +154,9 @@
    2.17  void GoatViewport::initializeGL()
    2.18  {
    2.19  	glClearColor(0.1, 0.1, 0.1, 1);
    2.20 +
    2.21 +	glEnable(GL_DEPTH_TEST);
    2.22 +	glEnable(GL_CULL_FACE);
    2.23  }
    2.24  
    2.25  void GoatViewport::resizeGL(int xsz, int ysz)
    2.26 @@ -161,8 +167,6 @@
    2.27  	gluPerspective(60.0, (float)xsz / (float)ysz, 0.5, 5000.0);
    2.28  }
    2.29  
    2.30 -static void draw_node(goat3d_node *node);
    2.31 -
    2.32  void GoatViewport::paintGL()
    2.33  {
    2.34  	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    2.35 @@ -177,7 +181,9 @@
    2.36  		int node_count = goat3d_get_node_count(scene);
    2.37  		for(int i=0; i<node_count; i++) {
    2.38  			goat3d_node *node = goat3d_get_node(scene, i);
    2.39 -			draw_node(node);
    2.40 +			if(!goat3d_get_node_parent(node)) {
    2.41 +				draw_node(node);	// only draw root nodes, the rest will be drawn recursively
    2.42 +			}
    2.43  		}
    2.44  	}
    2.45  }
    2.46 @@ -186,7 +192,14 @@
    2.47  {
    2.48  	float xform[16];
    2.49  	goat3d_get_node_matrix(node, xform, anim_time);
    2.50 -	glMultMatrixf(xform);
    2.51 +	for(int i=0; i<4; i++) {
    2.52 +		float *row = xform + i * 4;
    2.53 +		printf("[%3.3f %3.3f %3.3f %3.3f]\n", row[0], row[1], row[2], row[3]);
    2.54 +	}
    2.55 +	putchar('\n');
    2.56 +
    2.57 +	glPushMatrix();
    2.58 +	glMultTransposeMatrixf(xform);
    2.59  
    2.60  	if(goat3d_get_node_type(node) == GOAT3D_NODE_MESH) {
    2.61  		goat3d_mesh *mesh = (goat3d_mesh*)goat3d_get_node_object(node);
    2.62 @@ -223,4 +236,36 @@
    2.63  	for(int i=0; i<num_child; i++) {
    2.64  		draw_node(goat3d_get_node_child(node, i));
    2.65  	}
    2.66 -}
    2.67 \ No newline at end of file
    2.68 +
    2.69 +	glPopMatrix();
    2.70 +}
    2.71 +
    2.72 +
    2.73 +static float prev_x, prev_y;
    2.74 +void GoatViewport::mousePressEvent(QMouseEvent *ev)
    2.75 +{
    2.76 +	prev_x = ev->x();
    2.77 +	prev_y = ev->y();
    2.78 +}
    2.79 +
    2.80 +void GoatViewport::mouseMoveEvent(QMouseEvent *ev)
    2.81 +{
    2.82 +	int dx = ev->x() - prev_x;
    2.83 +	int dy = ev->y() - prev_y;
    2.84 +
    2.85 +	if(!dx && !dy) return;
    2.86 +
    2.87 +	if(ev->buttons() & Qt::LeftButton) {
    2.88 +		cam_theta += dx  * 0.5;
    2.89 +		cam_phi += dy * 0.5;
    2.90 +
    2.91 +		if(cam_phi < -90) cam_phi = -90;
    2.92 +		if(cam_phi > 90) cam_phi = 90;
    2.93 +	}
    2.94 +	if(ev->buttons() & Qt::RightButton) {
    2.95 +		cam_dist += dy * 0.1;
    2.96 +
    2.97 +		if(cam_dist < 0.0) cam_dist = 0.0;
    2.98 +	}
    2.99 +	updateGL();
   2.100 +}
     3.1 --- a/goatview/src/goatview.h	Thu May 08 13:55:13 2014 +0300
     3.2 +++ b/goatview/src/goatview.h	Thu May 08 16:25:04 2014 +0300
     3.3 @@ -39,6 +39,9 @@
     3.4  	void initializeGL();
     3.5  	void resizeGL(int xsz, int ysz);
     3.6  	void paintGL();
     3.7 +
     3.8 +	void mousePressEvent(QMouseEvent *ev);
     3.9 +	void mouseMoveEvent(QMouseEvent *ev);
    3.10  };
    3.11  
    3.12  #endif	// GOATVIEW_H_