Commit 1e6720cf by Kai Westerkamp

init broken

parent 82e1ae6d
File added
File added
#include "camera.h"
Camera::Camera(bool persp)
{
this->persp = persp;
setHome(new QQuaternion(), new QVector3D(0.0,0.0,-4.0));
}
void Camera::home()
{
this->rotation = homeRotation;
this->translation = homeTranslation;
}
void Camera::setHome(QQuaternion *rotation, QVector3D *translation)
{
//qDebug()<<*rotation<<" trans:"<<*translation;
this->homeRotation = rotation;
this->homeTranslation = translation;
home();
}
void Camera::rotate(QQuaternion newPos )
{
if(persp){
QQuaternion newRot = newPos * *rotation;
rotation = new QQuaternion(newRot.toVector4D());
}
}
void Camera::move(QVector3D newPos)
{
QVector3D newTrans = newPos + *translation;
translation = new QVector3D(newTrans);
}
void Camera::setupCamera(GLdouble aspect )
{
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
if(persp){
perspective(45.0,aspect,0.01,100.0);
} else {
int size = 4;
glOrtho(-size*aspect,size*aspect,-size,size,0.01,100.0);
}
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
//Camera Tranforations
QMatrix4x4 mat = QMatrix4x4();
mat.translate(*translation);
glMultMatrixf(mat.data());
mat = QMatrix4x4();
mat.rotate(*rotation);
glMultMatrixf(mat.data());
}
void Camera::perspective(GLdouble fovy, GLdouble aspect, GLdouble zNear, GLdouble zFar)
{
GLdouble xmin, xmax, ymin, ymax;
ymax = zNear * tan( fovy * M_PI / 360.0 );
ymin = -ymax;
xmin = ymin * aspect;
xmax = ymax * aspect;
glFrustum( xmin, xmax, ymin, ymax, zNear, zFar );
}
#ifndef CAMERA_H
#define CAMERA_H
#include <QtGui>
#include <QtOpenGL>
#include <QQuaternion>
#include <QVector3D>
class Camera: public QObject
{
Q_OBJECT
private:
bool persp;
// QQuaternion *rotation;
// QVector3D *translation;
QQuaternion *homeRotation;
QVector3D *homeTranslation;
void perspective(GLdouble fovy, GLdouble aspect, GLdouble zNear, GLdouble zFar);
public slots:
void home();
public:
QQuaternion *rotation;
QVector3D *translation;
Camera(bool persp);
void setHome(QQuaternion *rotation, QVector3D *translation);
void rotate(QQuaternion newPos );
void move(QVector3D newPos );
void setupCamera(GLdouble aspect);
};
#endif // CAMERA_H
#include "controler.h"
#include "camera.h"
#include "glview.h"
#include "scene.h"
#include "mainwindow.h"
Controler::Controler(MainWindow *mainwindow,Scene *scene)
{
this->mainwindow = mainwindow;
this->scene = scene;
viewMode = CAMERA;
}
void Controler::mousePressed(GLView* view, QMouseEvent *event)
{
activeView = view;
mainwindow->setActiveView(view);
lastSpeherePos = trackballPoint(event->pos().x(),event->pos().y());
lastScreenPos = new QPointF(event->screenPos());
event->accept();
}
void Controler::mouseMoveEvent(GLView* view, QMouseEvent *event)
{
if(activeView != view)
qDebug()<<"Active view Change";
if (event->buttons() & Qt::LeftButton) {
rotate(trackballPoint(event->pos().x(),event->pos().y()));
event->accept();
} else if (event->buttons() & Qt::RightButton) {
move(new QPointF(event->screenPos()));
event->accept();
}
}
void Controler::wheelEvent(GLView* view, QWheelEvent *event ) {
activeView = view;
mainwindow->setActiveView(view);
bool ctrlPressed = QApplication::keyboardModifiers() & Qt::ControlModifier;
QVector3D vec;
if(event->delta()<0)
vec = QVector3D(0.0,0.0,1.0);
else
vec = QVector3D(0.0,0.0,-1.0);
if((viewMode == CAMERA) ^ ctrlPressed){
activeView->getCamera()->move(vec);
} else if((viewMode == EDIT) ^ ctrlPressed){
vec = activeView->getCamera()->rotation->conjugate().rotatedVector(vec);
scene->moveActive(vec);
} else{
qDebug()<<"möp"<<viewMode<<" "<<CAMERA<<" "<<EDIT;
}
mainwindow->updateGL();
}
QVector3D* Controler::trackballPoint(int x, int y){
float xo,yo,zo;
// qDebug()<<"x:"<< x << " y:"<<y;
xo = ((2.0*x)-activeView->width())/ activeView->height();
yo = (activeView->height()-(2.0*y))/activeView->width();
float d = sqrt(xo*xo+yo*yo);
zo = qMax(qCos(M_PI_2*d),qreal(0.0)); //qMin(d,1.0f)
QVector3D *pos = new QVector3D(xo,yo,zo);
pos->normalize();
// qDebug()<<"x:"<< xo << " y:"<<yo<<" z:"<<zo;
return pos;
}
void Controler::rotate(QVector3D *newPos )
{
QVector3D axis = QVector3D::crossProduct(*lastSpeherePos,*newPos);
float angle = 180 / M_PI * asin(sqrt(QVector3D::dotProduct(axis, axis)));
axis.normalize();
//axis = rotation->conjugate().rotatedVector(axis);
bool ctrlPressed = QApplication::keyboardModifiers() & Qt::ControlModifier;
if((viewMode == CAMERA) ^ ctrlPressed){
activeView->getCamera()->rotate(QQuaternion::fromAxisAndAngle(axis, angle));
} else if((viewMode == EDIT) ^ ctrlPressed){
scene->rotateActive(QQuaternion::fromAxisAndAngle(axis, angle));
} else{
qDebug()<<"möp"<<viewMode<<" "<<CAMERA<<" "<<EDIT;
}
lastSpeherePos = newPos;
mainwindow->updateGL();
}
void Controler::move(QPointF * newPos){
QPointF dt = *newPos;
dt -= *lastScreenPos;
dt *= 0.01f;
float dx = dt.x();
float dy = dt.y()*-1.0;
bool ctrlPressed = QApplication::keyboardModifiers() & Qt::ControlModifier;
if((viewMode == CAMERA) ^ ctrlPressed){
activeView->getCamera()->move(QVector3D(dx,dy,0.0));
} else if((viewMode == EDIT) ^ ctrlPressed){
QVector3D vec = activeView->getCamera()->rotation->conjugate().rotatedVector(QVector3D(dx,dy,0.0));
scene->moveActive(vec);
} else{
qDebug()<<"möp"<<viewMode<<" "<<CAMERA<<" "<<EDIT;
}
lastScreenPos = newPos;
mainwindow->updateGL();
}
void Controler::setCamMode(){
viewMode = CAMERA;
}
void Controler::setEditMode(){
viewMode = EDIT;
}
#ifndef CONTROLER_H
#define CONTROLER_H
#include <QObject>
#include <QtGui>
class camera;
class GLView;
class Scene;
class MainWindow;
enum Mode{CAMERA, EDIT};
class Controler: public QObject
{
Q_OBJECT
public:
Controler(MainWindow *mainwindow,Scene *scene);
void mousePressed(GLView* view, QMouseEvent *event);
void mouseMoveEvent(GLView* view, QMouseEvent *event);
void wheelEvent(GLView* view, QWheelEvent *event );
public slots:
void setCamMode();
void setEditMode();
private:
MainWindow *mainwindow;
Scene *scene;
GLView *activeView;
QVector3D *lastSpeherePos;
QPointF * lastScreenPos;
Mode viewMode;
QVector3D* trackballPoint(int x, int y);
void rotate(QVector3D *newPos );
void move(QPointF * newPos);
};
#endif // CONTROLER_H
#include "cubewidget.h"
CubeWidget::CubeWidget(QWidget *parent)
: QGLWidget(QGLFormat(QGL::SampleBuffers), parent)
{
}
QSize CubeWidget::minimumSizeHint() const
{
return QSize(50, 50);
}
QSize CubeWidget::sizeHint() const
{
return QSize(600, 400);
}
void CubeWidget::initializeGL ()
{
glClearColor(0.0, 0.0, 0.0, 0.0);
glEnable(GL_DEPTH_TEST);
tesselation = 0;
prepareShader();
// enable default shading
home();
showFlat();
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
static GLfloat lightPosition[4] = { 0.5, 0.0, 2.0, 1.0 };
glLightfv(GL_LIGHT0, GL_POSITION, lightPosition);
//GLfloat white[] = {1.0,1.0,1.0};
//glLightfv(GL_LIGHT0, GL_DIFFUSE, white);
//glLightfv(GL_LIGHT0, GL_SPECULAR, white);
//glLightf(GL_LIGHT0, GL_LINEAR_ATTENUATION, 2.0f);
}
void CubeWidget::prepareShader()
{
QGLShader *vertex = new QGLShader(QGLShader::Vertex);
if(!vertex->compileSourceFile(QLatin1String(":/phong.vert")))
qCritical()<< "Vertex Shader failed"<< vertex->log();
QGLShader *fragment = new QGLShader(QGLShader::Fragment);
if(!fragment->compileSourceFile(QLatin1String(":/phong.frag")))
qCritical()<< "Fragment Shader failed"<< fragment->log();
shader = new QGLShaderProgram(this);
shader->addShader(vertex);
shader->addShader(fragment);
if(!shader->link())
qCritical()<< "Linking failed"<<shader->log();
}
void CubeWidget::setMaterial(GLfloat *color )
{
glMaterialfv(GL_FRONT,GL_AMBIENT,color);
GLfloat white[] = {1.0,1.0,1.0};
glMaterialfv(GL_FRONT,GL_DIFFUSE,color);
glMaterialfv(GL_FRONT,GL_SPECULAR,white);
GLfloat mShininess[] = {128};
glMaterialfv(GL_FRONT,GL_SHININESS,mShininess);
}
void CubeWidget::paintGL ( )
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glMultMatrixf(translation->data());
QMatrix4x4 mat = QMatrix4x4();
mat.rotate(*rotation);
glMultMatrixf(mat.data());
GLfloat red[] = {1.0,0.0,0.0};
GLfloat green[] = {0.0,1.0,0.0};
GLfloat blue[] = {0.0,0.0,1.0};
GLfloat cyan[] = {0.0,1.0,1.0};
GLfloat magenta[] = {1.0,0.0,1.0};
GLfloat yellow[] = {1.0,1.0,0.0};
float increment = 1.0/(pow(2,tesselation));
setMaterial(red);
glBegin(GL_QUADS);
glNormal3f(0,1,0);
for (float x = -0.5; x < 0.5 ; x+= increment) {
for (float y = -0.5; y < 0.5 ; y+= increment ) {
glVertex3f( x+increment, 0.5f,y);
glVertex3f(x, 0.5f,y);
glVertex3f(x, 0.5f, y+increment);
glVertex3f( x+increment, 0.5f, y+increment);
}
}
glEnd();
setMaterial(magenta);
glBegin(GL_QUADS);
glNormal3f(0,-1,0);
for (float x = -0.5; x < 0.5 ; x+= increment) {
for (float y = -0.5; y < 0.5 ; y+= increment ) {
glVertex3f( x+increment, -0.5f,y+increment);
glVertex3f(x, -0.5f,y+increment);
glVertex3f(x, -0.5f, y);
glVertex3f( x+increment, -0.5f, y);
}
}
glEnd();
setMaterial(green);
glBegin(GL_QUADS);
glNormal3f(0,0,1);
for (float x = -0.5; x < 0.5 ; x+= increment) {
for (float y = -0.5; y < 0.5 ; y+= increment ) {
glVertex3f( x+increment,y+increment, 0.5f);
glVertex3f(x, y+increment, 0.5f);
glVertex3f(x, y, 0.5f);
glVertex3f( x+increment, y, 0.5f);
}
}
glEnd();
setMaterial(yellow);
glBegin(GL_QUADS);
glNormal3f(0,0,-1);
for (float x = -0.5; x < 0.5 ; x+= increment) {
for (float y = -0.5; y < 0.5 ; y+= increment ) {
glVertex3f( x+increment,y, -0.5f);
glVertex3f(x, y,-0.5f);
glVertex3f(x, y+increment,-0.5f);
glVertex3f( x+increment,y+increment, -0.5f);
}
}
glEnd();
setMaterial(blue);
glBegin(GL_QUADS);
glNormal3f(-1,0,0);
for (float x = -0.5; x < 0.5 ; x+= increment) {
for (float y = -0.5; y < 0.5 ; y+= increment ) {
glVertex3f( -0.5f, x+increment,y+increment);
glVertex3f( -0.5f,x+increment,y);
glVertex3f( -0.5f,x, y);
glVertex3f( -0.5f,x, y+increment);
}
}
glEnd();
setMaterial(cyan);
glBegin(GL_QUADS);
glNormal3f(1,0,0);
for (float x = -0.5; x < 0.5 ; x+= increment) {
for (float y = -0.5; y < 0.5 ; y+= increment ) {
glVertex3f( 0.5f, x+increment,y);
glVertex3f( 0.5f,x+increment,y+increment);
glVertex3f( 0.5f,x, y+increment);
glVertex3f( 0.5f,x, y);
}
}
glEnd();
}
void CubeWidget::resizeGL(int width , int height )
{
glMatrixMode(GL_PROJECTION);
glViewport(0, 0, width, height);
glLoadIdentity();
perspective(45.0,1.0*width/height,0.01,100.0);
glMatrixMode(GL_MODELVIEW);
}
void CubeWidget::perspective(GLdouble fovy, GLdouble aspect, GLdouble zNear, GLdouble zFar)
{
GLdouble xmin, xmax, ymin, ymax;
ymax = zNear * tan( fovy * M_PI / 360.0 );
ymin = -ymax;
xmin = ymin * aspect;
xmax = ymax * aspect;
glFrustum( xmin, xmax, ymin, ymax, zNear, zFar );
}
void CubeWidget::showWireframe()
{
qDebug("show Wireframe");
glShadeModel(GL_FLAT);
glPolygonMode(GL_FRONT_AND_BACK,GL_LINE);
shader->release();
updateGL();
}
void CubeWidget::showFlat()
{
qDebug("show Flat");
glShadeModel(GL_FLAT);
glPolygonMode(GL_FRONT_AND_BACK,GL_FILL);
shader->release();
updateGL();
}
void CubeWidget::showGouraut()
{
qDebug("show Gouraut");
glShadeModel(GL_SMOOTH);
glPolygonMode(GL_FRONT_AND_BACK,GL_FILL);
shader->release();
updateGL();
}
void CubeWidget::showPhong()
{
qDebug("show Phong");
glPolygonMode(GL_FRONT_AND_BACK,GL_FILL);
shader->bind();
updateGL();
}
void CubeWidget::setTessellation(int t)
{
tesselation = t;
updateGL();
qDebug()<<"Tesselation" << t;
}
void CubeWidget::home()
{
translation = new QMatrix4x4();
translation->translate(0.0,0.0,-3.0);
rotation = new QQuaternion();
updateGL();
}
void CubeWidget::mousePressEvent(QMouseEvent *event )
{
lastSpeherePos = trackballPoint(event->pos().x(),event->pos().y());
lastScreenPos = new QPointF(event->screenPos());
event->accept();
}
void CubeWidget::mouseMoveEvent(QMouseEvent *event )
{
if (event->buttons() & Qt::LeftButton) {
rotate(trackballPoint(event->pos().x(),event->pos().y()));
event->accept();
} else if (event->buttons() & Qt::RightButton) {
move(new QPointF(event->screenPos()));
event->accept();
}
}
void CubeWidget::rotate(QVector3D *newPos )
{
QVector3D axis = QVector3D::crossProduct(*lastSpeherePos,*newPos);
//warum so besser
float angle = 180 / M_PI * asin(sqrt(QVector3D::dotProduct(axis, axis)));
axis.normalize();
//axis = rotation->conjugate().rotatedVector(axis);
QQuaternion newRot = QQuaternion::fromAxisAndAngle(axis, angle) * *rotation;
rotation = new QQuaternion(newRot.toVector4D());
lastSpeherePos = newPos;
updateGL();
}
void CubeWidget::move(QPointF * newPos){
QPointF dt = *newPos;
dt -= *lastScreenPos;
dt *= 0.01f;
float dx = dt.x();
float dy = dt.y()*-1.0;
translation->translate(dx,dy,0.0);
lastScreenPos = newPos;
updateGL();
}
QVector3D* CubeWidget::trackballPoint(int x, int y){
float xo,yo,zo;
// qDebug()<<"x:"<< x << " y:"<<y;
xo = ((2.0*x)-width())/ height();
yo = (height()-(2.0*y))/width();
float d = sqrt(xo*xo+yo*yo);
zo = qMax(qCos(M_PI_2*d),qreal(0.0)); //qMin(d,1.0f)
QVector3D *pos = new QVector3D(xo,yo,zo);
pos->normalize();
// qDebug()<<"x:"<< xo << " y:"<<yo<<" z:"<<zo;
return pos;
}
void CubeWidget::wheelEvent(QWheelEvent *event )
{
if(event->delta()<0)
//TODO
translation->translate(0.0,0.0,1.0);
else
translation->translate(0.0,0.0,-1.0);
updateGL();
}
#ifndef CUBEWIDGET_H
#define CUBEWIDGET_H
#include <QtGui>
#include <QtOpenGL>
#include <QGLFunctions>
#include <QOpenGLFunctions>
#include <math.h>
#include <QMatrix4x4>
#include <QQuaternion>
#include <QVector3D>
#include <algorithm>
class CubeWidget : public QGLWidget
{
Q_OBJECT
protected :
void initializeGL ( ) ;
void paintGL ( ) ;
void resizeGL(int width , int height ) ;
void mousePressEvent(QMouseEvent *event ) ;
void mouseMoveEvent(QMouseEvent *event ) ;
void wheelEvent(QWheelEvent *event ) ;
public:
CubeWidget(QWidget *parent = 0);
QSize minimumSizeHint() const;
QSize sizeHint() const;
public slots:
void showWireframe();
void showFlat();
void showGouraut();
void showPhong();
void home();
void setTessellation(int t );
private:
int tesselation;
int zoom;
QVector3D *lastSpeherePos;
QPointF * lastScreenPos;
QQuaternion *rotation;
QMatrix4x4 * translation;
QGLShaderProgram *shader;
void prepareShader();
void perspective(GLdouble fovy, GLdouble aspect, GLdouble zNear, GLdouble zFar);
void setMaterial(GLfloat *color );
void rotate(QVector3D *newPos );
void move(QPointF *newPos );
QVector3D *trackballPoint(int x, int y);
};
#endif // CUBEWIDGET_H
uniform sampler2D Texture;
uniform sampler2D TextureID;
uniform int active;
varying vec4 qt_TexCoord0;
void main(void)
{
gl_FragColor = texture2D(Texture,gl_TexCoord[0].st);
//gl_FragColor = texture2D(TextureID,gl_TexCoord[0].st)/255;
//gl_FragColor = vec4(active);
// gl_FragColor = vec4(gl_TexCoord[0].st,0,1);
}
attribute vec4 gl_Vertex;
uniform mat4 gl_ModelViewProjectionMatrix;
void main(void)
{
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
gl_TexCoord[0] = gl_MultiTexCoord0;
}
#ifndef __glut_h__
#define __glut_h__
/* Copyright (c) Mark J. Kilgard, 1994, 1995, 1996, 1998. */
/* This program is freely distributable without licensing fees and is
provided without guarantee or warrantee expressed or implied. This
program is -not- in the public domain. */
#if defined(_WIN32)
/* GLUT 3.7 now tries to avoid including <windows.h>
to avoid name space pollution, but Win32's <GL/gl.h>
needs APIENTRY and WINGDIAPI defined properly. */
# if 0
/* This would put tons of macros and crap in our clean name space. */
# define WIN32_LEAN_AND_MEAN
# include <windows.h>
# else
/* XXX This is from Win32's <windef.h> */
# ifndef APIENTRY
# define GLUT_APIENTRY_DEFINED
# if (_MSC_VER >= 800) || defined(_STDCALL_SUPPORTED) || defined(__BORLANDC__) || defined(__LCC__)
# define APIENTRY __stdcall
# else
# define APIENTRY
# endif
# endif
/* XXX This is from Win32's <winnt.h> */
# ifndef CALLBACK
# if (defined(_M_MRX000) || defined(_M_IX86) || defined(_M_ALPHA) || defined(_M_PPC)) && !defined(MIDL_PASS) || defined(__LCC__)
# define CALLBACK __stdcall
# else
# define CALLBACK
# endif
# endif
/* XXX Hack for lcc compiler. It doesn't support __declspec(dllimport), just __stdcall. */
# if defined( __LCC__ )
# undef WINGDIAPI
# define WINGDIAPI __stdcall
# else
/* XXX This is from Win32's <wingdi.h> and <winnt.h> */
# ifndef WINGDIAPI
# define GLUT_WINGDIAPI_DEFINED
# define WINGDIAPI __declspec(dllimport)
# endif
# endif
/* XXX This is from Win32's <ctype.h> */
# ifndef _WCHAR_T_DEFINED
typedef unsigned short wchar_t;
# define _WCHAR_T_DEFINED
# endif
# endif
/* To disable automatic library usage for GLUT, define GLUT_NO_LIB_PRAGMA
in your compile preprocessor options. */
# if !defined(GLUT_BUILDING_LIB) && !defined(GLUT_NO_LIB_PRAGMA)
# pragma comment (lib, "winmm.lib") /* link with Windows MultiMedia lib */
/* To enable automatic SGI OpenGL for Windows library usage for GLUT,
define GLUT_USE_SGI_OPENGL in your compile preprocessor options. */
# ifdef GLUT_USE_SGI_OPENGL
# pragma comment (lib, "opengl.lib") /* link with SGI OpenGL for Windows lib */
# pragma comment (lib, "glu.lib") /* link with SGI OpenGL Utility lib */
# pragma comment (lib, "glut.lib") /* link with Win32 GLUT for SGI OpenGL lib */
# else
# pragma comment (lib, "opengl32.lib") /* link with Microsoft OpenGL lib */
# pragma comment (lib, "glu32.lib") /* link with Microsoft OpenGL Utility lib */
# pragma comment (lib, "glut32.lib") /* link with Win32 GLUT lib */
# endif
# endif
/* To disable supression of annoying warnings about floats being promoted
to doubles, define GLUT_NO_WARNING_DISABLE in your compile preprocessor
options. */
# ifndef GLUT_NO_WARNING_DISABLE
# pragma warning (disable:4244) /* Disable bogus VC++ 4.2 conversion warnings. */
# pragma warning (disable:4305) /* VC++ 5.0 version of above warning. */
# endif
/* Win32 has an annoying issue where there are multiple C run-time
libraries (CRTs). If the executable is linked with a different CRT
from the GLUT DLL, the GLUT DLL will not share the same CRT static
data seen by the executable. In particular, atexit callbacks registered
in the executable will not be called if GLUT calls its (different)
exit routine). GLUT is typically built with the
"/MD" option (the CRT with multithreading DLL support), but the Visual
C++ linker default is "/ML" (the single threaded CRT).
One workaround to this issue is requiring users to always link with
the same CRT as GLUT is compiled with. That requires users supply a
non-standard option. GLUT 3.7 has its own built-in workaround where
the executable's "exit" function pointer is covertly passed to GLUT.
GLUT then calls the executable's exit function pointer to ensure that
any "atexit" calls registered by the application are called if GLUT
needs to exit.
Note that the __glut*WithExit routines should NEVER be called directly.
To avoid the atexit workaround, #define GLUT_DISABLE_ATEXIT_HACK. */
/* XXX This is from Win32's <process.h> */
# if !defined(_MSC_VER) && !defined(__cdecl)
/* Define __cdecl for non-Microsoft compilers. */
# define __cdecl
# define GLUT_DEFINED___CDECL
# endif
# ifndef _CRTIMP
# ifdef _NTSDK
/* Definition compatible with NT SDK */
# define _CRTIMP
# else
/* Current definition */
# ifdef _DLL
# define _CRTIMP __declspec(dllimport)
# else
# define _CRTIMP
# endif
# endif
# define GLUT_DEFINED__CRTIMP
# endif
/* GLUT API entry point declarations for Win32. */
# ifdef GLUT_BUILDING_LIB
# define GLUTAPI __declspec(dllexport)
# else
# ifdef _DLL
# define GLUTAPI __declspec(dllimport)
# else
# define GLUTAPI extern
# endif
# endif
/* GLUT callback calling convention for Win32. */
# define GLUTCALLBACK __cdecl
#endif /* _WIN32 */
#include <GL/gl.h>
#include <GL/glu.h>
#ifdef __cplusplus
extern "C" {
#endif
#if defined(_WIN32)
# ifndef GLUT_BUILDING_LIB
extern _CRTIMP void __cdecl exit(int);
# endif
#else
/* non-Win32 case. */
/* Define APIENTRY and CALLBACK to nothing if we aren't on Win32. */
# define APIENTRY
# define GLUT_APIENTRY_DEFINED
# define CALLBACK
/* Define GLUTAPI and GLUTCALLBACK as below if we aren't on Win32. */
# define GLUTAPI extern
# define GLUTCALLBACK
/* Prototype exit for the non-Win32 case (see above). */
extern void exit(int);
#endif
/**
GLUT API revision history:
GLUT_API_VERSION is updated to reflect incompatible GLUT
API changes (interface changes, semantic changes, deletions,
or additions).
GLUT_API_VERSION=1 First public release of GLUT. 11/29/94
GLUT_API_VERSION=2 Added support for OpenGL/GLX multisampling,
extension. Supports new input devices like tablet, dial and button
box, and Spaceball. Easy to query OpenGL extensions.
GLUT_API_VERSION=3 glutMenuStatus added.
GLUT_API_VERSION=4 glutInitDisplayString, glutWarpPointer,
glutBitmapLength, glutStrokeLength, glutWindowStatusFunc, dynamic
video resize subAPI, glutPostWindowRedisplay, glutKeyboardUpFunc,
glutSpecialUpFunc, glutIgnoreKeyRepeat, glutSetKeyRepeat,
glutJoystickFunc, glutForceJoystickFunc (NOT FINALIZED!).
**/
#ifndef GLUT_API_VERSION /* allow this to be overriden */
#define GLUT_API_VERSION 3
#endif
/**
GLUT implementation revision history:
GLUT_XLIB_IMPLEMENTATION is updated to reflect both GLUT
API revisions and implementation revisions (ie, bug fixes).
GLUT_XLIB_IMPLEMENTATION=1 mjk's first public release of
GLUT Xlib-based implementation. 11/29/94
GLUT_XLIB_IMPLEMENTATION=2 mjk's second public release of
GLUT Xlib-based implementation providing GLUT version 2
interfaces.
GLUT_XLIB_IMPLEMENTATION=3 mjk's GLUT 2.2 images. 4/17/95
GLUT_XLIB_IMPLEMENTATION=4 mjk's GLUT 2.3 images. 6/?/95
GLUT_XLIB_IMPLEMENTATION=5 mjk's GLUT 3.0 images. 10/?/95
GLUT_XLIB_IMPLEMENTATION=7 mjk's GLUT 3.1+ with glutWarpPoitner. 7/24/96
GLUT_XLIB_IMPLEMENTATION=8 mjk's GLUT 3.1+ with glutWarpPoitner
and video resize. 1/3/97
GLUT_XLIB_IMPLEMENTATION=9 mjk's GLUT 3.4 release with early GLUT 4 routines.
GLUT_XLIB_IMPLEMENTATION=11 Mesa 2.5's GLUT 3.6 release.
GLUT_XLIB_IMPLEMENTATION=12 mjk's GLUT 3.6 release with early GLUT 4 routines + signal handling.
GLUT_XLIB_IMPLEMENTATION=13 mjk's GLUT 3.7 beta with GameGLUT support.
GLUT_XLIB_IMPLEMENTATION=14 mjk's GLUT 3.7 beta with f90gl friend interface.
GLUT_XLIB_IMPLEMENTATION=15 mjk's GLUT 3.7 beta sync'ed with Mesa <GL/glut.h>
**/
#ifndef GLUT_XLIB_IMPLEMENTATION /* Allow this to be overriden. */
#define GLUT_XLIB_IMPLEMENTATION 15
#endif
/* Display mode bit masks. */
#define GLUT_RGB 0
#define GLUT_RGBA GLUT_RGB
#define GLUT_INDEX 1
#define GLUT_SINGLE 0
#define GLUT_DOUBLE 2
#define GLUT_ACCUM 4
#define GLUT_ALPHA 8
#define GLUT_DEPTH 16
#define GLUT_STENCIL 32
#if (GLUT_API_VERSION >= 2)
#define GLUT_MULTISAMPLE 128
#define GLUT_STEREO 256
#endif
#if (GLUT_API_VERSION >= 3)
#define GLUT_LUMINANCE 512
#endif
/* Mouse buttons. */
#define GLUT_LEFT_BUTTON 0
#define GLUT_MIDDLE_BUTTON 1
#define GLUT_RIGHT_BUTTON 2
#define GLUT_WHEEL_UP 3
#define GLUT_WHEEL_DOWN 4
#define GLUT_XBUTTON1 5
#define GLUT_XBUTTON2 6
/* Mouse button state. */
#define GLUT_DOWN 0
#define GLUT_UP 1
#if (GLUT_API_VERSION >= 2)
/* function keys */
#define GLUT_KEY_F1 1
#define GLUT_KEY_F2 2
#define GLUT_KEY_F3 3
#define GLUT_KEY_F4 4
#define GLUT_KEY_F5 5
#define GLUT_KEY_F6 6
#define GLUT_KEY_F7 7
#define GLUT_KEY_F8 8
#define GLUT_KEY_F9 9
#define GLUT_KEY_F10 10
#define GLUT_KEY_F11 11
#define GLUT_KEY_F12 12
/* directional keys */
#define GLUT_KEY_LEFT 100
#define GLUT_KEY_UP 101
#define GLUT_KEY_RIGHT 102
#define GLUT_KEY_DOWN 103
#define GLUT_KEY_PAGE_UP 104
#define GLUT_KEY_PAGE_DOWN 105
#define GLUT_KEY_HOME 106
#define GLUT_KEY_END 107
#define GLUT_KEY_INSERT 108
#endif
/* Entry/exit state. */
#define GLUT_LEFT 0
#define GLUT_ENTERED 1
/* Menu usage state. */
#define GLUT_MENU_NOT_IN_USE 0
#define GLUT_MENU_IN_USE 1
/* Visibility state. */
#define GLUT_NOT_VISIBLE 0
#define GLUT_VISIBLE 1
/* Window status state. */
#define GLUT_HIDDEN 0
#define GLUT_FULLY_RETAINED 1
#define GLUT_PARTIALLY_RETAINED 2
#define GLUT_FULLY_COVERED 3
/* Color index component selection values. */
#define GLUT_RED 0
#define GLUT_GREEN 1
#define GLUT_BLUE 2
#if defined(_WIN32)
/* Stroke font constants (use these in GLUT program). */
#define GLUT_STROKE_ROMAN ((void*)0)
#define GLUT_STROKE_MONO_ROMAN ((void*)1)
/* Bitmap font constants (use these in GLUT program). */
#define GLUT_BITMAP_9_BY_15 ((void*)2)
#define GLUT_BITMAP_8_BY_13 ((void*)3)
#define GLUT_BITMAP_TIMES_ROMAN_10 ((void*)4)
#define GLUT_BITMAP_TIMES_ROMAN_24 ((void*)5)
#if (GLUT_API_VERSION >= 3)
#define GLUT_BITMAP_HELVETICA_10 ((void*)6)
#define GLUT_BITMAP_HELVETICA_12 ((void*)7)
#define GLUT_BITMAP_HELVETICA_18 ((void*)8)
#endif
#else
/* Stroke font opaque addresses (use constants instead in source code). */
GLUTAPI void *glutStrokeRoman;
GLUTAPI void *glutStrokeMonoRoman;
/* Stroke font constants (use these in GLUT program). */
#define GLUT_STROKE_ROMAN (&glutStrokeRoman)
#define GLUT_STROKE_MONO_ROMAN (&glutStrokeMonoRoman)
/* Bitmap font opaque addresses (use constants instead in source code). */
GLUTAPI void *glutBitmap9By15;
GLUTAPI void *glutBitmap8By13;
GLUTAPI void *glutBitmapTimesRoman10;
GLUTAPI void *glutBitmapTimesRoman24;
GLUTAPI void *glutBitmapHelvetica10;
GLUTAPI void *glutBitmapHelvetica12;
GLUTAPI void *glutBitmapHelvetica18;
/* Bitmap font constants (use these in GLUT program). */
#define GLUT_BITMAP_9_BY_15 (&glutBitmap9By15)
#define GLUT_BITMAP_8_BY_13 (&glutBitmap8By13)
#define GLUT_BITMAP_TIMES_ROMAN_10 (&glutBitmapTimesRoman10)
#define GLUT_BITMAP_TIMES_ROMAN_24 (&glutBitmapTimesRoman24)
#if (GLUT_API_VERSION >= 3)
#define GLUT_BITMAP_HELVETICA_10 (&glutBitmapHelvetica10)
#define GLUT_BITMAP_HELVETICA_12 (&glutBitmapHelvetica12)
#define GLUT_BITMAP_HELVETICA_18 (&glutBitmapHelvetica18)
#endif
#endif
/* glutGet parameters. */
#define GLUT_WINDOW_X ((GLenum) 100)
#define GLUT_WINDOW_Y ((GLenum) 101)
#define GLUT_WINDOW_WIDTH ((GLenum) 102)
#define GLUT_WINDOW_HEIGHT ((GLenum) 103)
#define GLUT_WINDOW_BUFFER_SIZE ((GLenum) 104)
#define GLUT_WINDOW_STENCIL_SIZE ((GLenum) 105)
#define GLUT_WINDOW_DEPTH_SIZE ((GLenum) 106)
#define GLUT_WINDOW_RED_SIZE ((GLenum) 107)
#define GLUT_WINDOW_GREEN_SIZE ((GLenum) 108)
#define GLUT_WINDOW_BLUE_SIZE ((GLenum) 109)
#define GLUT_WINDOW_ALPHA_SIZE ((GLenum) 110)
#define GLUT_WINDOW_ACCUM_RED_SIZE ((GLenum) 111)
#define GLUT_WINDOW_ACCUM_GREEN_SIZE ((GLenum) 112)
#define GLUT_WINDOW_ACCUM_BLUE_SIZE ((GLenum) 113)
#define GLUT_WINDOW_ACCUM_ALPHA_SIZE ((GLenum) 114)
#define GLUT_WINDOW_DOUBLEBUFFER ((GLenum) 115)
#define GLUT_WINDOW_RGBA ((GLenum) 116)
#define GLUT_WINDOW_PARENT ((GLenum) 117)
#define GLUT_WINDOW_NUM_CHILDREN ((GLenum) 118)
#define GLUT_WINDOW_COLORMAP_SIZE ((GLenum) 119)
#if (GLUT_API_VERSION >= 2)
#define GLUT_WINDOW_NUM_SAMPLES ((GLenum) 120)
#define GLUT_WINDOW_STEREO ((GLenum) 121)
#endif
#if (GLUT_API_VERSION >= 3)
#define GLUT_WINDOW_CURSOR ((GLenum) 122)
#endif
#define GLUT_SCREEN_WIDTH ((GLenum) 200)
#define GLUT_SCREEN_HEIGHT ((GLenum) 201)
#define GLUT_SCREEN_WIDTH_MM ((GLenum) 202)
#define GLUT_SCREEN_HEIGHT_MM ((GLenum) 203)
#define GLUT_MENU_NUM_ITEMS ((GLenum) 300)
#define GLUT_DISPLAY_MODE_POSSIBLE ((GLenum) 400)
#define GLUT_INIT_WINDOW_X ((GLenum) 500)
#define GLUT_INIT_WINDOW_Y ((GLenum) 501)
#define GLUT_INIT_WINDOW_WIDTH ((GLenum) 502)
#define GLUT_INIT_WINDOW_HEIGHT ((GLenum) 503)
#define GLUT_INIT_DISPLAY_MODE ((GLenum) 504)
#if (GLUT_API_VERSION >= 2)
#define GLUT_ELAPSED_TIME ((GLenum) 700)
#endif
#if (GLUT_API_VERSION >= 4 || GLUT_XLIB_IMPLEMENTATION >= 13)
#define GLUT_WINDOW_FORMAT_ID ((GLenum) 123)
#endif
#if (GLUT_API_VERSION >= 2)
/* glutDeviceGet parameters. */
#define GLUT_HAS_KEYBOARD ((GLenum) 600)
#define GLUT_HAS_MOUSE ((GLenum) 601)
#define GLUT_HAS_SPACEBALL ((GLenum) 602)
#define GLUT_HAS_DIAL_AND_BUTTON_BOX ((GLenum) 603)
#define GLUT_HAS_TABLET ((GLenum) 604)
#define GLUT_NUM_MOUSE_BUTTONS ((GLenum) 605)
#define GLUT_NUM_SPACEBALL_BUTTONS ((GLenum) 606)
#define GLUT_NUM_BUTTON_BOX_BUTTONS ((GLenum) 607)
#define GLUT_NUM_DIALS ((GLenum) 608)
#define GLUT_NUM_TABLET_BUTTONS ((GLenum) 609)
#endif
#if (GLUT_API_VERSION >= 4 || GLUT_XLIB_IMPLEMENTATION >= 13)
#define GLUT_DEVICE_IGNORE_KEY_REPEAT ((GLenum) 610)
#define GLUT_DEVICE_KEY_REPEAT ((GLenum) 611)
#define GLUT_HAS_JOYSTICK ((GLenum) 612)
#define GLUT_OWNS_JOYSTICK ((GLenum) 613)
#define GLUT_JOYSTICK_BUTTONS ((GLenum) 614)
#define GLUT_JOYSTICK_AXES ((GLenum) 615)
#define GLUT_JOYSTICK_POLL_RATE ((GLenum) 616)
#endif
#if (GLUT_API_VERSION >= 3)
/* glutLayerGet parameters. */
#define GLUT_OVERLAY_POSSIBLE ((GLenum) 800)
#define GLUT_LAYER_IN_USE ((GLenum) 801)
#define GLUT_HAS_OVERLAY ((GLenum) 802)
#define GLUT_TRANSPARENT_INDEX ((GLenum) 803)
#define GLUT_NORMAL_DAMAGED ((GLenum) 804)
#define GLUT_OVERLAY_DAMAGED ((GLenum) 805)
#if (GLUT_API_VERSION >= 4 || GLUT_XLIB_IMPLEMENTATION >= 9)
/* glutVideoResizeGet parameters. */
#define GLUT_VIDEO_RESIZE_POSSIBLE ((GLenum) 900)
#define GLUT_VIDEO_RESIZE_IN_USE ((GLenum) 901)
#define GLUT_VIDEO_RESIZE_X_DELTA ((GLenum) 902)
#define GLUT_VIDEO_RESIZE_Y_DELTA ((GLenum) 903)
#define GLUT_VIDEO_RESIZE_WIDTH_DELTA ((GLenum) 904)
#define GLUT_VIDEO_RESIZE_HEIGHT_DELTA ((GLenum) 905)
#define GLUT_VIDEO_RESIZE_X ((GLenum) 906)
#define GLUT_VIDEO_RESIZE_Y ((GLenum) 907)
#define GLUT_VIDEO_RESIZE_WIDTH ((GLenum) 908)
#define GLUT_VIDEO_RESIZE_HEIGHT ((GLenum) 909)
#endif
/* glutUseLayer parameters. */
#define GLUT_NORMAL ((GLenum) 0)
#define GLUT_OVERLAY ((GLenum) 1)
/* glutGetModifiers return mask. */
#define GLUT_ACTIVE_SHIFT 1
#define GLUT_ACTIVE_CTRL 2
#define GLUT_ACTIVE_ALT 4
/* glutSetCursor parameters. */
/* Basic arrows. */
#define GLUT_CURSOR_RIGHT_ARROW 0
#define GLUT_CURSOR_LEFT_ARROW 1
/* Symbolic cursor shapes. */
#define GLUT_CURSOR_INFO 2
#define GLUT_CURSOR_DESTROY 3
#define GLUT_CURSOR_HELP 4
#define GLUT_CURSOR_CYCLE 5
#define GLUT_CURSOR_SPRAY 6
#define GLUT_CURSOR_WAIT 7
#define GLUT_CURSOR_TEXT 8
#define GLUT_CURSOR_CROSSHAIR 9
/* Directional cursors. */
#define GLUT_CURSOR_UP_DOWN 10
#define GLUT_CURSOR_LEFT_RIGHT 11
/* Sizing cursors. */
#define GLUT_CURSOR_TOP_SIDE 12
#define GLUT_CURSOR_BOTTOM_SIDE 13
#define GLUT_CURSOR_LEFT_SIDE 14
#define GLUT_CURSOR_RIGHT_SIDE 15
#define GLUT_CURSOR_TOP_LEFT_CORNER 16
#define GLUT_CURSOR_TOP_RIGHT_CORNER 17
#define GLUT_CURSOR_BOTTOM_RIGHT_CORNER 18
#define GLUT_CURSOR_BOTTOM_LEFT_CORNER 19
/* Inherit from parent window. */
#define GLUT_CURSOR_INHERIT 100
/* Blank cursor. */
#define GLUT_CURSOR_NONE 101
/* Fullscreen crosshair (if available). */
#define GLUT_CURSOR_FULL_CROSSHAIR 102
#endif
/* GLUT initialization sub-API. */
GLUTAPI void APIENTRY glutInit(int *argcp, char **argv);
#if defined(_WIN32) && !defined(GLUT_DISABLE_ATEXIT_HACK)
GLUTAPI void APIENTRY __glutInitWithExit(int *argcp, char **argv, void (__cdecl *exitfunc)(int));
#ifndef GLUT_BUILDING_LIB
static void APIENTRY glutInit_ATEXIT_HACK(int *argcp, char **argv) { __glutInitWithExit(argcp, argv, exit); }
#define glutInit glutInit_ATEXIT_HACK
#endif
#endif
GLUTAPI void APIENTRY glutInitDisplayMode(unsigned int mode);
#if (GLUT_API_VERSION >= 4 || GLUT_XLIB_IMPLEMENTATION >= 9)
GLUTAPI void APIENTRY glutInitDisplayString(const char *string);
#endif
GLUTAPI void APIENTRY glutInitWindowPosition(int x, int y);
GLUTAPI void APIENTRY glutInitWindowSize(int width, int height);
GLUTAPI void APIENTRY glutMainLoop(void);
/* GLUT window sub-API. */
GLUTAPI int APIENTRY glutCreateWindow(const char *title);
#if defined(_WIN32) && !defined(GLUT_DISABLE_ATEXIT_HACK)
GLUTAPI int APIENTRY __glutCreateWindowWithExit(const char *title, void (__cdecl *exitfunc)(int));
#ifndef GLUT_BUILDING_LIB
static int APIENTRY glutCreateWindow_ATEXIT_HACK(const char *title) { return __glutCreateWindowWithExit(title, exit); }
#define glutCreateWindow glutCreateWindow_ATEXIT_HACK
#endif
#endif
GLUTAPI int APIENTRY glutCreateSubWindow(int win, int x, int y, int width, int height);
GLUTAPI void APIENTRY glutDestroyWindow(int win);
GLUTAPI void APIENTRY glutPostRedisplay(void);
#if (GLUT_API_VERSION >= 4 || GLUT_XLIB_IMPLEMENTATION >= 11)
GLUTAPI void APIENTRY glutPostWindowRedisplay(int win);
#endif
GLUTAPI void APIENTRY glutSwapBuffers(void);
GLUTAPI int APIENTRY glutGetWindow(void);
GLUTAPI void APIENTRY glutSetWindow(int win);
GLUTAPI void APIENTRY glutSetWindowTitle(const char *title);
GLUTAPI void APIENTRY glutSetIconTitle(const char *title);
GLUTAPI void APIENTRY glutPositionWindow(int x, int y);
GLUTAPI void APIENTRY glutReshapeWindow(int width, int height);
GLUTAPI void APIENTRY glutPopWindow(void);
GLUTAPI void APIENTRY glutPushWindow(void);
GLUTAPI void APIENTRY glutIconifyWindow(void);
GLUTAPI void APIENTRY glutShowWindow(void);
GLUTAPI void APIENTRY glutHideWindow(void);
#if (GLUT_API_VERSION >= 3)
GLUTAPI void APIENTRY glutFullScreen(void);
GLUTAPI void APIENTRY glutSetCursor(int cursor);
#if (GLUT_API_VERSION >= 4 || GLUT_XLIB_IMPLEMENTATION >= 9)
GLUTAPI void APIENTRY glutWarpPointer(int x, int y);
#endif
/* GLUT overlay sub-API. */
GLUTAPI void APIENTRY glutEstablishOverlay(void);
GLUTAPI void APIENTRY glutRemoveOverlay(void);
GLUTAPI void APIENTRY glutUseLayer(GLenum layer);
GLUTAPI void APIENTRY glutPostOverlayRedisplay(void);
#if (GLUT_API_VERSION >= 4 || GLUT_XLIB_IMPLEMENTATION >= 11)
GLUTAPI void APIENTRY glutPostWindowOverlayRedisplay(int win);
#endif
GLUTAPI void APIENTRY glutShowOverlay(void);
GLUTAPI void APIENTRY glutHideOverlay(void);
#endif
/* GLUT menu sub-API. */
GLUTAPI int APIENTRY glutCreateMenu(void (GLUTCALLBACK *func)(int));
#if defined(_WIN32) && !defined(GLUT_DISABLE_ATEXIT_HACK)
GLUTAPI int APIENTRY __glutCreateMenuWithExit(void (GLUTCALLBACK *func)(int), void (__cdecl *exitfunc)(int));
#ifndef GLUT_BUILDING_LIB
static int APIENTRY glutCreateMenu_ATEXIT_HACK(void (GLUTCALLBACK *func)(int)) { return __glutCreateMenuWithExit(func, exit); }
#define glutCreateMenu glutCreateMenu_ATEXIT_HACK
#endif
#endif
GLUTAPI void APIENTRY glutDestroyMenu(int menu);
GLUTAPI int APIENTRY glutGetMenu(void);
GLUTAPI void APIENTRY glutSetMenu(int menu);
GLUTAPI void APIENTRY glutAddMenuEntry(const char *label, int value);
GLUTAPI void APIENTRY glutAddSubMenu(const char *label, int submenu);
GLUTAPI void APIENTRY glutChangeToMenuEntry(int item, const char *label, int value);
GLUTAPI void APIENTRY glutChangeToSubMenu(int item, const char *label, int submenu);
GLUTAPI void APIENTRY glutRemoveMenuItem(int item);
GLUTAPI void APIENTRY glutAttachMenu(int button);
GLUTAPI void APIENTRY glutDetachMenu(int button);
/* GLUT window callback sub-API. */
GLUTAPI void APIENTRY glutDisplayFunc(void (GLUTCALLBACK *func)(void));
GLUTAPI void APIENTRY glutReshapeFunc(void (GLUTCALLBACK *func)(int width, int height));
GLUTAPI void APIENTRY glutKeyboardFunc(void (GLUTCALLBACK *func)(unsigned char key, int x, int y));
GLUTAPI void APIENTRY glutMouseFunc(void (GLUTCALLBACK *func)(int button, int state, int x, int y));
GLUTAPI void APIENTRY glutMotionFunc(void (GLUTCALLBACK *func)(int x, int y));
GLUTAPI void APIENTRY glutPassiveMotionFunc(void (GLUTCALLBACK *func)(int x, int y));
GLUTAPI void APIENTRY glutEntryFunc(void (GLUTCALLBACK *func)(int state));
GLUTAPI void APIENTRY glutVisibilityFunc(void (GLUTCALLBACK *func)(int state));
GLUTAPI void APIENTRY glutIdleFunc(void (GLUTCALLBACK *func)(void));
GLUTAPI void APIENTRY glutTimerFunc(unsigned int millis, void (GLUTCALLBACK *func)(int value), int value);
GLUTAPI void APIENTRY glutMenuStateFunc(void (GLUTCALLBACK *func)(int state));
#if (GLUT_API_VERSION >= 2)
GLUTAPI void APIENTRY glutSpecialFunc(void (GLUTCALLBACK *func)(int key, int x, int y));
GLUTAPI void APIENTRY glutSpaceballMotionFunc(void (GLUTCALLBACK *func)(int x, int y, int z));
GLUTAPI void APIENTRY glutSpaceballRotateFunc(void (GLUTCALLBACK *func)(int x, int y, int z));
GLUTAPI void APIENTRY glutSpaceballButtonFunc(void (GLUTCALLBACK *func)(int button, int state));
GLUTAPI void APIENTRY glutButtonBoxFunc(void (GLUTCALLBACK *func)(int button, int state));
GLUTAPI void APIENTRY glutDialsFunc(void (GLUTCALLBACK *func)(int dial, int value));
GLUTAPI void APIENTRY glutTabletMotionFunc(void (GLUTCALLBACK *func)(int x, int y));
GLUTAPI void APIENTRY glutTabletButtonFunc(void (GLUTCALLBACK *func)(int button, int state, int x, int y));
#if (GLUT_API_VERSION >= 3)
GLUTAPI void APIENTRY glutMenuStatusFunc(void (GLUTCALLBACK *func)(int status, int x, int y));
GLUTAPI void APIENTRY glutOverlayDisplayFunc(void (GLUTCALLBACK *func)(void));
#if (GLUT_API_VERSION >= 4 || GLUT_XLIB_IMPLEMENTATION >= 9)
GLUTAPI void APIENTRY glutWindowStatusFunc(void (GLUTCALLBACK *func)(int state));
#endif
#if (GLUT_API_VERSION >= 4 || GLUT_XLIB_IMPLEMENTATION >= 13)
GLUTAPI void APIENTRY glutKeyboardUpFunc(void (GLUTCALLBACK *func)(unsigned char key, int x, int y));
GLUTAPI void APIENTRY glutSpecialUpFunc(void (GLUTCALLBACK *func)(int key, int x, int y));
GLUTAPI void APIENTRY glutJoystickFunc(void (GLUTCALLBACK *func)(unsigned int buttonMask, int x, int y, int z), int pollInterval);
#endif
#endif
#endif
/* GLUT color index sub-API. */
GLUTAPI void APIENTRY glutSetColor(int, GLfloat red, GLfloat green, GLfloat blue);
GLUTAPI GLfloat APIENTRY glutGetColor(int ndx, int component);
GLUTAPI void APIENTRY glutCopyColormap(int win);
/* GLUT state retrieval sub-API. */
GLUTAPI int APIENTRY glutGet(GLenum type);
GLUTAPI int APIENTRY glutDeviceGet(GLenum type);
#if (GLUT_API_VERSION >= 2)
/* GLUT extension support sub-API */
GLUTAPI int APIENTRY glutExtensionSupported(const char *name);
#endif
#if (GLUT_API_VERSION >= 3)
GLUTAPI int APIENTRY glutGetModifiers(void);
GLUTAPI int APIENTRY glutLayerGet(GLenum type);
#endif
/* GLUT font sub-API */
GLUTAPI void APIENTRY glutBitmapCharacter(void *font, int character);
GLUTAPI int APIENTRY glutBitmapWidth(void *font, int character);
GLUTAPI void APIENTRY glutStrokeCharacter(void *font, int character);
GLUTAPI int APIENTRY glutStrokeWidth(void *font, int character);
#if (GLUT_API_VERSION >= 4 || GLUT_XLIB_IMPLEMENTATION >= 9)
GLUTAPI int APIENTRY glutBitmapLength(void *font, const unsigned char *string);
GLUTAPI int APIENTRY glutStrokeLength(void *font, const unsigned char *string);
#endif
/* GLUT pre-built models sub-API */
GLUTAPI void APIENTRY glutWireSphere(GLdouble radius, GLint slices, GLint stacks);
GLUTAPI void APIENTRY glutSolidSphere(GLdouble radius, GLint slices, GLint stacks);
GLUTAPI void APIENTRY glutWireCone(GLdouble base, GLdouble height, GLint slices, GLint stacks);
GLUTAPI void APIENTRY glutSolidCone(GLdouble base, GLdouble height, GLint slices, GLint stacks);
GLUTAPI void APIENTRY glutWireCube(GLdouble size);
GLUTAPI void APIENTRY glutSolidCube(GLdouble size);
GLUTAPI void APIENTRY glutWireTorus(GLdouble innerRadius, GLdouble outerRadius, GLint sides, GLint rings);
GLUTAPI void APIENTRY glutSolidTorus(GLdouble innerRadius, GLdouble outerRadius, GLint sides, GLint rings);
GLUTAPI void APIENTRY glutWireDodecahedron(void);
GLUTAPI void APIENTRY glutSolidDodecahedron(void);
GLUTAPI void APIENTRY glutWireTeapot(GLdouble size);
GLUTAPI void APIENTRY glutSolidTeapot(GLdouble size);
GLUTAPI void APIENTRY glutWireOctahedron(void);
GLUTAPI void APIENTRY glutSolidOctahedron(void);
GLUTAPI void APIENTRY glutWireTetrahedron(void);
GLUTAPI void APIENTRY glutSolidTetrahedron(void);
GLUTAPI void APIENTRY glutWireIcosahedron(void);
GLUTAPI void APIENTRY glutSolidIcosahedron(void);
#if (GLUT_API_VERSION >= 4 || GLUT_XLIB_IMPLEMENTATION >= 9)
/* GLUT video resize sub-API. */
GLUTAPI int APIENTRY glutVideoResizeGet(GLenum param);
GLUTAPI void APIENTRY glutSetupVideoResizing(void);
GLUTAPI void APIENTRY glutStopVideoResizing(void);
GLUTAPI void APIENTRY glutVideoResize(int x, int y, int width, int height);
GLUTAPI void APIENTRY glutVideoPan(int x, int y, int width, int height);
/* GLUT debugging sub-API. */
GLUTAPI void APIENTRY glutReportErrors(void);
#endif
#if (GLUT_API_VERSION >= 4 || GLUT_XLIB_IMPLEMENTATION >= 13)
/* GLUT device control sub-API. */
/* glutSetKeyRepeat modes. */
#define GLUT_KEY_REPEAT_OFF 0
#define GLUT_KEY_REPEAT_ON 1
#define GLUT_KEY_REPEAT_DEFAULT 2
/* Joystick button masks. */
#define GLUT_JOYSTICK_BUTTON_A 1
#define GLUT_JOYSTICK_BUTTON_B 2
#define GLUT_JOYSTICK_BUTTON_C 4
#define GLUT_JOYSTICK_BUTTON_D 8
GLUTAPI void APIENTRY glutIgnoreKeyRepeat(int ignore);
GLUTAPI void APIENTRY glutSetKeyRepeat(int repeatMode);
GLUTAPI void APIENTRY glutForceJoystickFunc(void);
/* GLUT game mode sub-API. */
/* glutGameModeGet. */
#define GLUT_GAME_MODE_ACTIVE ((GLenum) 0)
#define GLUT_GAME_MODE_POSSIBLE ((GLenum) 1)
#define GLUT_GAME_MODE_WIDTH ((GLenum) 2)
#define GLUT_GAME_MODE_HEIGHT ((GLenum) 3)
#define GLUT_GAME_MODE_PIXEL_DEPTH ((GLenum) 4)
#define GLUT_GAME_MODE_REFRESH_RATE ((GLenum) 5)
#define GLUT_GAME_MODE_DISPLAY_CHANGED ((GLenum) 6)
GLUTAPI void APIENTRY glutGameModeString(const char *string);
GLUTAPI int APIENTRY glutEnterGameMode(void);
GLUTAPI void APIENTRY glutLeaveGameMode(void);
GLUTAPI int APIENTRY glutGameModeGet(GLenum mode);
#endif
#ifdef __cplusplus
}
#endif
#ifdef GLUT_APIENTRY_DEFINED
# undef GLUT_APIENTRY_DEFINED
# undef APIENTRY
#endif
#ifdef GLUT_WINGDIAPI_DEFINED
# undef GLUT_WINGDIAPI_DEFINED
# undef WINGDIAPI
#endif
#ifdef GLUT_DEFINED___CDECL
# undef GLUT_DEFINED___CDECL
# undef __cdecl
#endif
#ifdef GLUT_DEFINED__CRTIMP
# undef GLUT_DEFINED__CRTIMP
# undef _CRTIMP
#endif
#endif /* __glut_h__ */
#include "glview.h"
GLView::GLView(Scene *scene,Camera * camera,Controler *controler )
{
this->camera = camera;
this->scene = scene;
this->controler = controler;
gridSize = 5;
gridStepSize = 1;
isGridEnabled = false;
}
QSize GLView::minimumSizeHint() const
{
return QSize(50, 50);
}
QSize GLView::sizeHint() const
{
return QSize(600, 400);
}
void GLView::initializeGL ( ) {
glClearColor(0.0, 0.0, 0.0, 0.0);
glEnable(GL_DEPTH_TEST);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
static GLfloat lightPosition[4] = { 0.0, 0.0, 4.0, 1.0 };
glLightfv(GL_LIGHT0, GL_POSITION, lightPosition);
//Shader Setup
initShader();
shader->bind();
}
void GLView::initShader()
{
QGLShader *vertex = new QGLShader(QGLShader::Vertex);
if(!vertex->compileSourceFile(QLatin1String(":/phong.vert")))
qCritical()<< "Vertex Shader failed"<< vertex->log();
QGLShader *fragment = new QGLShader(QGLShader::Fragment);
if(!fragment->compileSourceFile(QLatin1String(":/phong.frag")))
qCritical()<< "Fragment Shader failed"<< fragment->log();
shader = new QGLShaderProgram(this);
shader->addShader(vertex);
shader->addShader(fragment);
shader->bindAttributeLocation("pickID",4);
if(!shader->link())
qCritical()<< "Linking failed"<<shader->log();
vertex = new QGLShader(QGLShader::Vertex);
if(!vertex->compileSourceFile(QLatin1String(":/display.vert")))
qCritical()<< "Vertex Shader 2 failed"<< vertex->log();
fragment = new QGLShader(QGLShader::Fragment);
if(!fragment->compileSourceFile(QLatin1String(":/display.frag")))
qCritical()<< "Fragment Shader 2 failed"<< fragment->log();
displayShader = new QGLShaderProgram(this);
displayShader->addShader(vertex);
displayShader->addShader(fragment);
if(!displayShader->link())
qCritical()<< "Linking failed"<<displayShader->log();
}
void GLView::home(){
camera->home();
updateGL();
}
void GLView::paintGL ()
{
bool useFBO = true;
//QOpenGLFunctions functions = QOpenGLContext::currentContext()->functions();
QGLFunctions functions = QGLFunctions(this->context());
// QOpenGLFunctions_4_3_Core functions = *this;
shader->bind();
if(useFBO){
functions.glBindFramebuffer(GL_FRAMEBUFFER,fbo);
GLenum buffers[] = {GL_COLOR_ATTACHMENT0,GL_COLOR_ATTACHMENT1};
// functions.glDrawBuffers(2,buffers);
//http://stackoverflow.com/questions/7207422/setting-up-opengl-multiple-render-targets
}
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glEnable(GL_DEPTH_TEST);
glViewport(0,0,this->width(),this->height());
glMatrixMode (GL_MODELVIEW);
glLoadIdentity ();
glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
shader->setUniformValue("shaded",true);
//qDebug()<<"IsLinked"<<shader->isLinked();
//set Projection and Camera Rotation
camera->setupCamera(aspect);
//draw Scene
scene->draw(shader);
shader->setAttributeValue(3,0);
if(isGridEnabled){
drawGrid();
}
if(isActive){
glDisable(GL_DEPTH_TEST);
glMatrixMode (GL_MODELVIEW);
glLoadIdentity ();
glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
shader->setUniformValue("shaded",false);
glLineWidth(10);
GLfloat color[] = {1.0,1.0,0.0};
glMaterialfv(GL_FRONT,GL_AMBIENT,color);
glMaterialfv(GL_FRONT,GL_DIFFUSE,color);
glMaterialfv(GL_FRONT,GL_SPECULAR,color);
glMaterialf(GL_FRONT,GL_SHININESS,128);
glBegin (GL_LINE_LOOP);
glVertex3i (-1, -1, 0);
glVertex3i (1, -1, 0);
glVertex3i (1, 1, 0);
glVertex3i (-1, 1, 0);
glEnd ();
}
shader->release();
if(useFBO){
displayShader->bind();
//
functions.glBindFramebuffer(GL_FRAMEBUFFER,0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glViewport(0,0,this->width(),this->height());
glMatrixMode (GL_MODELVIEW);
glLoadIdentity ();
glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
functions.glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D,color);
displayShader->setUniformValue("Texture",0);
functions.glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D,picID);
displayShader->setUniformValue("TextureID",1);
displayShader->setUniformValue("active",scene->getActive()->getID());
glBegin (GL_QUADS);
glTexCoord2d(0,0);
glVertex3i (-1, -1, 0);
glTexCoord2d(1,0);
glVertex3i (1, -1, 0);
glTexCoord2d(1,1);
glVertex3i (1, 1, 0);
glTexCoord2d(0,1);
glVertex3i (-1, 1, 0);
glEnd ();
displayShader->release();
}
}
void GLView::drawGrid()
{
shader->release();
GLfloat specularColor[] = {0,0,0};
GLfloat shininess[] = {128};
glMaterialfv(GL_FRONT,GL_SPECULAR,specularColor);
glMaterialfv(GL_FRONT,GL_SHININESS, shininess);
GLfloat grey[] = {1,0.5,0.5};
glMaterialfv(GL_FRONT,GL_DIFFUSE,grey);
glNormal3f(0,1,0);
glDisable(GL_LIGHTING);
glEnable(GL_COLOR_MATERIAL);
glLineWidth(1);
glPolygonMode(GL_FRONT_AND_BACK,GL_LINES);
glBegin(GL_LINES);
float stepSize = gridStepSize;
float x = stepSize;
float y = stepSize;
if (stepSize <= 0) stepSize = 1;
for(; x < gridSize; x += stepSize){
glVertex3f(x,0,-gridSize);
glVertex3f(x,0,gridSize);
glVertex3f(-x,0,-gridSize);
glVertex3f(-x,0,gridSize);
}
for (; y < gridSize; y += stepSize){
glVertex3f(-gridSize, 0, y);
glVertex3f(gridSize,0,y);
glVertex3f(-gridSize,0,-y);
glVertex3f(gridSize,0,-y);
}
glEnd();
glBegin(GL_LINES);
x = stepSize;
y = stepSize;
if (stepSize <= 0) stepSize = 1;
for(; x < gridSize; x += stepSize){
glVertex3f(0,x,-gridSize);
glVertex3f(0,x,gridSize);
glVertex3f(0,-x,-gridSize);
glVertex3f(0,-x,gridSize);
}
for (; y < gridSize; y += stepSize){
glVertex3f(0,-gridSize, y);
glVertex3f(0,gridSize,y);
glVertex3f(0,-gridSize,-y);
glVertex3f(0,gridSize,-y);
}
glEnd();
glBegin(GL_LINES);
x = stepSize;
y = stepSize;
if (stepSize <= 0) stepSize = 1;
for(; x < gridSize; x += stepSize){
glVertex3f(x,-gridSize,0);
glVertex3f(x,gridSize,0);
glVertex3f(-x,-gridSize,0);
glVertex3f(-x,gridSize,0);
}
for (; y < gridSize; y += stepSize){
glVertex3f(-gridSize, y,0);
glVertex3f(gridSize,y,0);
glVertex3f(-gridSize,-y,0);
glVertex3f(gridSize,-y,0);
}
glEnd();
glBegin(GL_LINES);
glVertex3f(0,0,-gridSize);
glVertex3f(0,0,gridSize);
glEnd();
glBegin(GL_LINES);
glVertex3f(-gridSize,0,0);
glVertex3f(gridSize,0,0);
glEnd();
glBegin(GL_LINES);
glVertex3f(0,-gridSize,0);
glVertex3f(0,gridSize,0);
glEnd();
glPolygonMode(GL_FRONT,GL_FILL);
glEnable(GL_LIGHTING);
shader->bind();
}
void GLView::resizeGL(int width , int height )
{
aspect = 1.0*width/height;
QGLFunctions functions = QGLFunctions(this->context());
functions.glGenFramebuffers(1, &fbo);
functions.glBindFramebuffer(GL_FRAMEBUFFER,fbo);
// Create the color buffer
glGenTextures(1, &color);
glBindTexture(GL_TEXTURE_2D, color);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
// Create the color buffer
glGenTextures(1, &picID);
glBindTexture(GL_TEXTURE_2D, picID);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
// Create the depth buffer
functions.glGenRenderbuffers(1, &depth);
functions.glBindRenderbuffer(GL_RENDERBUFFER, depth);
functions.glRenderbufferStorage(GL_RENDERBUFFER,GL_DEPTH_COMPONENT,width,height);
functions.glFramebufferTexture2D(GL_FRAMEBUFFER,GL_COLOR_ATTACHMENT0,GL_TEXTURE_2D,color,0);
functions.glFramebufferTexture2D(GL_FRAMEBUFFER,GL_COLOR_ATTACHMENT1,GL_TEXTURE_2D,picID,0);
functions.glFramebufferRenderbuffer(GL_FRAMEBUFFER,GL_DEPTH_ATTACHMENT,GL_RENDERBUFFER,depth);
GLenum err = functions.glCheckFramebufferStatus(GL_FRAMEBUFFER);
if(err == GL_FRAMEBUFFER_COMPLETE){
qDebug()<<"FBO OK";
} else {
qDebug()<<"FBO ERROR"<<err;
}
functions.glBindFramebuffer(GL_FRAMEBUFFER, 0);
}
void GLView::setAcive(bool active)
{
this->isActive = active;
updateGL();
}
Camera *GLView::getCamera()
{
return this->camera;
}
void GLView::mousePressEvent(QMouseEvent *event )
{
controler->mousePressed(this,event);
}
void GLView::mouseMoveEvent(QMouseEvent *event )
{
controler->mouseMoveEvent(this,event);
}
void GLView::wheelEvent(QWheelEvent *event )
{
controler->wheelEvent(this,event);
}
#ifndef GLVIEW_H
#define GLVIEW_H
#include <QtGui>
#include <QtOpenGL>
#include <controler.h>
#include <camera.h>
#include <scene.h>
#include <gl/GLU.h>
#include <QGLFunctions>
#include <QOpenGLFunctions_4_3_Core>
class GLView : public QGLWidget, public QOpenGLFunctions_4_3_Core
{
Q_OBJECT
protected :
void initializeGL ( ) ;
void paintGL ( ) ;
void resizeGL(int width , int height ) ;
void mousePressEvent(QMouseEvent *event ) ;
void mouseMoveEvent(QMouseEvent *event ) ;
void wheelEvent(QWheelEvent *event ) ;
public slots:
void home();
void setGridSize(int size){gridSize = size;}
void setGridStepSize(int size){gridStepSize = size;}
void showGrid(bool bo){isGridEnabled = bo;}
public:
GLView(Scene *scene,Camera * camera,Controler *controler );
void setHome(QQuaternion *rotation, QVector3D *translation);
QSize minimumSizeHint() const;
QSize sizeHint() const;
void setAcive(bool active);
Camera *getCamera();
private:
QGLShaderProgram *shader;
QGLShaderProgram *displayShader;
Scene *scene;
Controler *controler;
Camera *camera;
bool isActive;
GLdouble aspect;
GLuint fbo;
GLuint color;
GLuint picID;
GLuint depth;
void drawGrid();
void initShader();
float gridStepSize;
float gridSize;
bool isGridEnabled;
};
#endif // GLVIEW_H
#-------------------------------------------------
#
# Project created by QtCreator 2015-10-20T21:54:27
#
#-------------------------------------------------
QT += core gui opengl
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = hellocube
TEMPLATE = app
LIBS += -lglut64
LIBS += -L$$PWD/glut
SOURCES += main.cpp\
mainwindow.cpp \
cubewidget.cpp \
glview.cpp \
scene.cpp \
controler.cpp \
camera.cpp \
sceneprimitive.cpp \
sceneobject.cpp \
scenenode.cpp \
treedelegate.cpp \
scenevolume.cpp
HEADERS += mainwindow.h \
cubewidget.h \
glview.h \
scene.h \
controler.h \
camera.h \
sceneprimitive.h \
sceneobject.h \
scenenode.h \
glut.h \
treedelegate.h \
scenevolume.h
RESOURCES += \
hellocube.qrc
DISTFILES += \
phong.frag \
phong.vert \
display.frag \
display.vert
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject>
<!-- Written by QtCreator 3.5.1, 2015-12-03T11:54:44. -->
<qtcreator>
<data>
<variable>EnvironmentId</variable>
<value type="QByteArray">{6caf6096-6900-4b02-8e0b-a6f627b8fa95}</value>
</data>
<data>
<variable>ProjectExplorer.Project.ActiveTarget</variable>
<value type="int">0</value>
</data>
<data>
<variable>ProjectExplorer.Project.EditorSettings</variable>
<valuemap type="QVariantMap">
<value type="bool" key="EditorConfiguration.AutoIndent">true</value>
<value type="bool" key="EditorConfiguration.AutoSpacesForTabs">false</value>
<value type="bool" key="EditorConfiguration.CamelCaseNavigation">true</value>
<valuemap type="QVariantMap" key="EditorConfiguration.CodeStyle.0">
<value type="QString" key="language">Cpp</value>
<valuemap type="QVariantMap" key="value">
<value type="QByteArray" key="CurrentPreferences">CppGlobal</value>
</valuemap>
</valuemap>
<valuemap type="QVariantMap" key="EditorConfiguration.CodeStyle.1">
<value type="QString" key="language">QmlJS</value>
<valuemap type="QVariantMap" key="value">
<value type="QByteArray" key="CurrentPreferences">QmlJSGlobal</value>
</valuemap>
</valuemap>
<value type="int" key="EditorConfiguration.CodeStyle.Count">2</value>
<value type="QByteArray" key="EditorConfiguration.Codec">UTF-8</value>
<value type="bool" key="EditorConfiguration.ConstrainTooltips">false</value>
<value type="int" key="EditorConfiguration.IndentSize">4</value>
<value type="bool" key="EditorConfiguration.KeyboardTooltips">false</value>
<value type="int" key="EditorConfiguration.MarginColumn">80</value>
<value type="bool" key="EditorConfiguration.MouseHiding">true</value>
<value type="bool" key="EditorConfiguration.MouseNavigation">true</value>
<value type="int" key="EditorConfiguration.PaddingMode">1</value>
<value type="bool" key="EditorConfiguration.ScrollWheelZooming">true</value>
<value type="bool" key="EditorConfiguration.ShowMargin">false</value>
<value type="int" key="EditorConfiguration.SmartBackspaceBehavior">0</value>
<value type="bool" key="EditorConfiguration.SpacesForTabs">true</value>
<value type="int" key="EditorConfiguration.TabKeyBehavior">0</value>
<value type="int" key="EditorConfiguration.TabSize">8</value>
<value type="bool" key="EditorConfiguration.UseGlobal">true</value>
<value type="int" key="EditorConfiguration.Utf8BomBehavior">1</value>
<value type="bool" key="EditorConfiguration.addFinalNewLine">true</value>
<value type="bool" key="EditorConfiguration.cleanIndentation">true</value>
<value type="bool" key="EditorConfiguration.cleanWhitespace">true</value>
<value type="bool" key="EditorConfiguration.inEntireDocument">false</value>
</valuemap>
</data>
<data>
<variable>ProjectExplorer.Project.PluginSettings</variable>
<valuemap type="QVariantMap"/>
</data>
<data>
<variable>ProjectExplorer.Project.Target.0</variable>
<valuemap type="QVariantMap">
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Desktop Qt 5.4.2 MSVC2013 OpenGL 64bit</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Desktop Qt 5.4.2 MSVC2013 OpenGL 64bit</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">qt.54.win64_msvc2013_64_opengl_kit</value>
<value type="int" key="ProjectExplorer.Target.ActiveBuildConfiguration">0</value>
<value type="int" key="ProjectExplorer.Target.ActiveDeployConfiguration">0</value>
<value type="int" key="ProjectExplorer.Target.ActiveRunConfiguration">0</value>
<valuemap type="QVariantMap" key="ProjectExplorer.Target.BuildConfiguration.0">
<value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory">D:/Projekte/GraPa/build-hellocube-Desktop_Qt_5_4_2_MSVC2013_OpenGL_64bit-Debug</value>
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0">
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0">
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">qmake</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">QtProjectManager.QMakeBuildStep</value>
<value type="bool" key="QtProjectManager.QMakeBuildStep.LinkQmlDebuggingLibrary">false</value>
<value type="bool" key="QtProjectManager.QMakeBuildStep.LinkQmlDebuggingLibraryAuto">true</value>
<value type="QString" key="QtProjectManager.QMakeBuildStep.QMakeArguments"></value>
<value type="bool" key="QtProjectManager.QMakeBuildStep.QMakeForced">false</value>
<value type="bool" key="QtProjectManager.QMakeBuildStep.SeparateDebugInfo">false</value>
<value type="bool" key="QtProjectManager.QMakeBuildStep.UseQtQuickCompiler">false</value>
</valuemap>
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.1">
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Make</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.MakeStep</value>
<valuelist type="QVariantList" key="Qt4ProjectManager.MakeStep.AutomaticallyAddedMakeArguments"/>
<value type="bool" key="Qt4ProjectManager.MakeStep.Clean">false</value>
<value type="QString" key="Qt4ProjectManager.MakeStep.MakeArguments"></value>
<value type="QString" key="Qt4ProjectManager.MakeStep.MakeCommand"></value>
</valuemap>
<value type="int" key="ProjectExplorer.BuildStepList.StepsCount">2</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Build</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Build</value>
</valuemap>
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.1">
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0">
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Make</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.MakeStep</value>
<valuelist type="QVariantList" key="Qt4ProjectManager.MakeStep.AutomaticallyAddedMakeArguments"/>
<value type="bool" key="Qt4ProjectManager.MakeStep.Clean">true</value>
<value type="QString" key="Qt4ProjectManager.MakeStep.MakeArguments">clean</value>
<value type="QString" key="Qt4ProjectManager.MakeStep.MakeCommand"></value>
</valuemap>
<value type="int" key="ProjectExplorer.BuildStepList.StepsCount">1</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Clean</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Clean</value>
</valuemap>
<value type="int" key="ProjectExplorer.BuildConfiguration.BuildStepListCount">2</value>
<value type="bool" key="ProjectExplorer.BuildConfiguration.ClearSystemEnvironment">false</value>
<valuelist type="QVariantList" key="ProjectExplorer.BuildConfiguration.UserEnvironmentChanges"/>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Debug</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.Qt4BuildConfiguration</value>
<value type="int" key="Qt4ProjectManager.Qt4BuildConfiguration.BuildConfiguration">2</value>
<value type="bool" key="Qt4ProjectManager.Qt4BuildConfiguration.UseShadowBuild">true</value>
</valuemap>
<valuemap type="QVariantMap" key="ProjectExplorer.Target.BuildConfiguration.1">
<value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory">D:/Projekte/GraPa/build-hellocube-Desktop_Qt_5_4_2_MSVC2013_OpenGL_64bit-Release</value>
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0">
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0">
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">qmake</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">QtProjectManager.QMakeBuildStep</value>
<value type="bool" key="QtProjectManager.QMakeBuildStep.LinkQmlDebuggingLibrary">false</value>
<value type="bool" key="QtProjectManager.QMakeBuildStep.LinkQmlDebuggingLibraryAuto">true</value>
<value type="QString" key="QtProjectManager.QMakeBuildStep.QMakeArguments"></value>
<value type="bool" key="QtProjectManager.QMakeBuildStep.QMakeForced">false</value>
<value type="bool" key="QtProjectManager.QMakeBuildStep.SeparateDebugInfo">false</value>
<value type="bool" key="QtProjectManager.QMakeBuildStep.UseQtQuickCompiler">false</value>
</valuemap>
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.1">
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Make</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.MakeStep</value>
<valuelist type="QVariantList" key="Qt4ProjectManager.MakeStep.AutomaticallyAddedMakeArguments"/>
<value type="bool" key="Qt4ProjectManager.MakeStep.Clean">false</value>
<value type="QString" key="Qt4ProjectManager.MakeStep.MakeArguments"></value>
<value type="QString" key="Qt4ProjectManager.MakeStep.MakeCommand"></value>
</valuemap>
<value type="int" key="ProjectExplorer.BuildStepList.StepsCount">2</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Build</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Build</value>
</valuemap>
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.1">
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0">
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Make</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.MakeStep</value>
<valuelist type="QVariantList" key="Qt4ProjectManager.MakeStep.AutomaticallyAddedMakeArguments"/>
<value type="bool" key="Qt4ProjectManager.MakeStep.Clean">true</value>
<value type="QString" key="Qt4ProjectManager.MakeStep.MakeArguments">clean</value>
<value type="QString" key="Qt4ProjectManager.MakeStep.MakeCommand"></value>
</valuemap>
<value type="int" key="ProjectExplorer.BuildStepList.StepsCount">1</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Clean</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Clean</value>
</valuemap>
<value type="int" key="ProjectExplorer.BuildConfiguration.BuildStepListCount">2</value>
<value type="bool" key="ProjectExplorer.BuildConfiguration.ClearSystemEnvironment">false</value>
<valuelist type="QVariantList" key="ProjectExplorer.BuildConfiguration.UserEnvironmentChanges"/>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Release</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.Qt4BuildConfiguration</value>
<value type="int" key="Qt4ProjectManager.Qt4BuildConfiguration.BuildConfiguration">0</value>
<value type="bool" key="Qt4ProjectManager.Qt4BuildConfiguration.UseShadowBuild">true</value>
</valuemap>
<value type="int" key="ProjectExplorer.Target.BuildConfigurationCount">2</value>
<valuemap type="QVariantMap" key="ProjectExplorer.Target.DeployConfiguration.0">
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0">
<value type="int" key="ProjectExplorer.BuildStepList.StepsCount">0</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Deploy</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Deploy</value>
</valuemap>
<value type="int" key="ProjectExplorer.BuildConfiguration.BuildStepListCount">1</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Deploy locally</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.DefaultDeployConfiguration</value>
</valuemap>
<value type="int" key="ProjectExplorer.Target.DeployConfigurationCount">1</value>
<valuemap type="QVariantMap" key="ProjectExplorer.Target.PluginSettings"/>
<valuemap type="QVariantMap" key="ProjectExplorer.Target.RunConfiguration.0">
<valuelist type="QVariantList" key="Analyzer.Valgrind.AddedSuppressionFiles"/>
<value type="bool" key="Analyzer.Valgrind.Callgrind.CollectBusEvents">false</value>
<value type="bool" key="Analyzer.Valgrind.Callgrind.CollectSystime">false</value>
<value type="bool" key="Analyzer.Valgrind.Callgrind.EnableBranchSim">false</value>
<value type="bool" key="Analyzer.Valgrind.Callgrind.EnableCacheSim">false</value>
<value type="bool" key="Analyzer.Valgrind.Callgrind.EnableEventToolTips">true</value>
<value type="double" key="Analyzer.Valgrind.Callgrind.MinimumCostRatio">0.01</value>
<value type="double" key="Analyzer.Valgrind.Callgrind.VisualisationMinimumCostRatio">10</value>
<value type="bool" key="Analyzer.Valgrind.FilterExternalIssues">true</value>
<value type="int" key="Analyzer.Valgrind.LeakCheckOnFinish">1</value>
<value type="int" key="Analyzer.Valgrind.NumCallers">25</value>
<valuelist type="QVariantList" key="Analyzer.Valgrind.RemovedSuppressionFiles"/>
<value type="int" key="Analyzer.Valgrind.SelfModifyingCodeDetection">1</value>
<value type="bool" key="Analyzer.Valgrind.Settings.UseGlobalSettings">true</value>
<value type="bool" key="Analyzer.Valgrind.ShowReachable">false</value>
<value type="bool" key="Analyzer.Valgrind.TrackOrigins">true</value>
<value type="QString" key="Analyzer.Valgrind.ValgrindExecutable">valgrind</value>
<valuelist type="QVariantList" key="Analyzer.Valgrind.VisibleErrorKinds">
<value type="int">0</value>
<value type="int">1</value>
<value type="int">2</value>
<value type="int">3</value>
<value type="int">4</value>
<value type="int">5</value>
<value type="int">6</value>
<value type="int">7</value>
<value type="int">8</value>
<value type="int">9</value>
<value type="int">10</value>
<value type="int">11</value>
<value type="int">12</value>
<value type="int">13</value>
<value type="int">14</value>
</valuelist>
<value type="int" key="PE.EnvironmentAspect.Base">2</value>
<valuelist type="QVariantList" key="PE.EnvironmentAspect.Changes"/>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">hellocube</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">hellocube2</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.Qt4RunConfiguration:D:/Projekte/GraPa/A3/hellocube.pro</value>
<value type="QString" key="Qt4ProjectManager.Qt4RunConfiguration.CommandLineArguments"></value>
<value type="QString" key="Qt4ProjectManager.Qt4RunConfiguration.ProFile">hellocube.pro</value>
<value type="bool" key="Qt4ProjectManager.Qt4RunConfiguration.UseDyldImageSuffix">false</value>
<value type="bool" key="Qt4ProjectManager.Qt4RunConfiguration.UseTerminal">false</value>
<value type="QString" key="Qt4ProjectManager.Qt4RunConfiguration.UserWorkingDirectory"></value>
<value type="uint" key="RunConfiguration.QmlDebugServerPort">3768</value>
<value type="bool" key="RunConfiguration.UseCppDebugger">false</value>
<value type="bool" key="RunConfiguration.UseCppDebuggerAuto">true</value>
<value type="bool" key="RunConfiguration.UseMultiProcess">false</value>
<value type="bool" key="RunConfiguration.UseQmlDebugger">false</value>
<value type="bool" key="RunConfiguration.UseQmlDebuggerAuto">true</value>
</valuemap>
<value type="int" key="ProjectExplorer.Target.RunConfigurationCount">1</value>
</valuemap>
</data>
<data>
<variable>ProjectExplorer.Project.TargetCount</variable>
<value type="int">1</value>
</data>
<data>
<variable>ProjectExplorer.Project.Updater.FileVersion</variable>
<value type="int">18</value>
</data>
<data>
<variable>Version</variable>
<value type="int">18</value>
</data>
</qtcreator>
<RCC>
<qresource prefix="/">
<file>img/cam_home.png</file>
<file>img/flat.png</file>
<file>img/gouraud.png</file>
<file>img/phong.png</file>
<file>img/wireframe.png</file>
<file>phong.frag</file>
<file>phong.vert</file>
<file>img/box.png</file>
<file>img/camera.png</file>
<file>img/cone.png</file>
<file>img/cylinder.png</file>
<file>img/select.png</file>
<file>img/sphere.png</file>
<file>img/torus.png</file>
<file>img/view-dual.png</file>
<file>img/viewports.png</file>
<file>img/view-single.png</file>
<file>img/delete.png</file>
<file>display.frag</file>
<file>display.vert</file>
</qresource>
</RCC>
File added
#include "mainwindow.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}
#include "mainwindow.h"
#include <treedelegate.h>
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
{
setWindowTitle("Hello Cube");
menuBar = new QMenuBar();
toolBar = new QToolBar("Shading",this);
statusBar = new QStatusBar(this);
//Views
scene = new Scene();
scene->setTesselation(1);
connect(scene,SIGNAL(activChanged()),this,SLOT(updateStatusBar()));
connect(scene,SIGNAL(activChanged()),this,SLOT(updateGL()));
controler = new Controler(this,scene);
Camera *perspectiveCam = new Camera(true);
perspectiveView = new GLView(scene,perspectiveCam,controler);
Camera *frontCam = new Camera(false);
frontCam->setHome(new QQuaternion(), new QVector3D(0.0,0.0,-4.0));
frontView = new GLView(scene,frontCam,controler);
Camera *leftCam = new Camera(false);
leftCam->setHome(new QQuaternion(QQuaternion::fromAxisAndAngle(0.0,1.0,0.0,90.0).toVector4D()),
new QVector3D(0.0,0.0,-4.0));
leftView = new GLView(scene,leftCam,controler);
Camera *topCam = new Camera(false);
topCam->setHome(new QQuaternion(QQuaternion::fromAxisAndAngle(1.0,0.0,0.0,90.0).toVector4D()),
new QVector3D(0.0,0.0,-4.0));
topView = new GLView(scene,topCam,controler);
topSplit = new QSplitter(Qt::Horizontal,this);
bottomSplit = new QSplitter(Qt::Horizontal,this);
verticalSplit = new QSplitter(Qt::Vertical,this);
camHome = new QAction(QIcon(":/img/cam_home.png"),"Cam Home", toolBar);
setActiveView(perspectiveView);
topSplit->addWidget(perspectiveView);
topSplit->addWidget(frontView);
bottomSplit->addWidget(leftView);
bottomSplit->addWidget(topView);
verticalSplit->addWidget(topSplit);
verticalSplit->addWidget(bottomSplit);
setCentralWidget(verticalSplit);
showQuad();
//showSingle();
//showDual();
//
//File Menu Actions
fileMenu = new QMenu("&File");
viewGoup = new QActionGroup(this);
viewMenu = new QMenu("View",this);
primitivesMenu = new QMenu("Primitives",this);
interactionGroup = new QActionGroup(this);
interactionMenu = new QMenu("Interaction",this);
exitAction = new QAction("E&xit",fileMenu);
exitAction->setShortcut(QKeySequence::Quit);
connect(exitAction, SIGNAL(triggered()), this, SLOT(close()));
//Interaction Actions
cameraMode = new QAction("Camera",this);
cameraMode->setCheckable(true);
cameraMode->setIcon(QIcon(":/img/camera.png"));
cameraMode->setChecked(true);
connect(cameraMode, SIGNAL(triggered()), controler, SLOT(setCamMode()));
interactionGroup->addAction(cameraMode);
editMode = new QAction("Edit",this);
editMode->setCheckable(true);
editMode->setIcon(QIcon(":/img/select.png"));
connect(editMode, SIGNAL(triggered()), controler, SLOT(setEditMode()));
interactionGroup->addAction(editMode);
//View Actions
singleView = new QAction("Single View",this);
singleView->setShortcut(QKeySequence("1"));
singleView->setCheckable(true);
singleView->setIcon(QIcon(":/img/view-single.png"));
connect(singleView, SIGNAL(triggered()), this, SLOT(showSingle()));
viewGoup->addAction(singleView);
dualView = new QAction("Dual View",this);
dualView->setShortcut(QKeySequence("2"));
dualView->setCheckable(true);
dualView->setIcon(QIcon(":/img/view-dual.png"));
connect(dualView, SIGNAL(triggered()), this, SLOT(showDual()));
viewGoup->addAction(dualView);
quadView = new QAction("Quad View",this);
quadView->setShortcut(QKeySequence("4"));
quadView->setCheckable(true);
quadView->setChecked(true);
quadView->setIcon(QIcon(":/img/viewports.png"));
connect(quadView, SIGNAL(triggered()), this, SLOT(showQuad()));
viewGoup->addAction(quadView);
viewMenu->addAction(singleView);
viewMenu->addAction(dualView);
viewMenu->addAction(quadView);
//Other Actions
aboutAction = new QAction("About",menuBar);
connect(aboutAction,SIGNAL(triggered()),this,SLOT(showAboutBox()));
slider = new QSlider(Qt::Horizontal,toolBar);
slider->setMinimum( 0 );
slider->setMaximum( 4 );
connect(slider,SIGNAL(valueChanged(int)),scene,SLOT(setTesselation(int)));
slider->setValue( 1 );
// Add Primitives
spheresAdd = new QAction("Sphere",this);
spheresAdd->setIcon(QIcon(":/img/sphere.png"));
connect(spheresAdd, SIGNAL(triggered()), scene, SLOT(addSphere()));
boxesAdd = new QAction("Box",this);
boxesAdd->setIcon(QIcon(":/img/box.png"));
connect(boxesAdd, SIGNAL(triggered()), scene, SLOT(addCube()));
cylindersAdd = new QAction("Cylinder",this);
cylindersAdd->setIcon(QIcon(":/img/cylinder.png"));
connect(cylindersAdd, SIGNAL(triggered()), scene, SLOT(addCylinder()));
coneAdd = new QAction("Cone",this);
coneAdd->setIcon(QIcon(":/img/cone.png"));
connect(coneAdd, SIGNAL(triggered()), scene, SLOT(addCone()));
torusAdd = new QAction("Torus",this);
torusAdd->setIcon(QIcon(":/img/torus.png"));
connect(torusAdd, SIGNAL(triggered()), scene, SLOT(addTorus()));
groupAdd = new QAction("Group",this);
groupAdd->setIcon(QIcon(":/img/wireframe.png"));
connect(groupAdd, SIGNAL(triggered()), scene, SLOT(addNode()));
activeDelete = new QAction("Delete",this);
activeDelete->setIcon(QIcon(":/img/delete.png"));
connect(activeDelete, SIGNAL(triggered()), scene, SLOT(deletActive()));
volumeAdd = new QAction("Volume",this);
//activeDelete->setIcon(QIcon(":/img/delete.png"));
connect(volumeAdd, SIGNAL(triggered()), scene, SLOT(addVolume()));
primitivesMenu->addAction(spheresAdd);
primitivesMenu->addAction(boxesAdd);
primitivesMenu->addAction(cylindersAdd);
primitivesMenu->addAction(coneAdd);
primitivesMenu->addAction(torusAdd);
primitivesMenu->addAction(groupAdd);
primitivesMenu->addAction(activeDelete);
primitivesMenu->addAction(volumeAdd);
showGridButton = new QToolButton(toolBar);
showGridButton->setCheckable(true);
gridSizeInput = new QSpinBox(toolBar);
gridSizeInput->setRange(0,100);
gridSizeInput->setValue(5);
gridSizeInput->setToolTip("Grid Size");
gridStepInput = new QSpinBox(toolBar);
gridStepInput->setRange(1,10);
gridStepInput->setToolTip("Grid Step Size");
connect(gridSizeInput,SIGNAL(valueChanged(int)),perspectiveView,SLOT(setGridSize(int)));
connect(gridStepInput,SIGNAL(valueChanged(int)),perspectiveView,SLOT(setGridStepSize(int)));
connect(showGridButton,SIGNAL(clicked(bool)),perspectiveView,SLOT(showGrid(bool)));
connect(gridSizeInput,SIGNAL(valueChanged(int)),topView,SLOT(setGridSize(int)));
connect(gridStepInput,SIGNAL(valueChanged(int)),topView,SLOT(setGridStepSize(int)));
connect(showGridButton,SIGNAL(clicked(bool)),topView,SLOT(showGrid(bool)));
connect(gridSizeInput,SIGNAL(valueChanged(int)),leftView,SLOT(setGridSize(int)));
connect(gridStepInput,SIGNAL(valueChanged(int)),leftView,SLOT(setGridStepSize(int)));
connect(showGridButton,SIGNAL(clicked(bool)),leftView,SLOT(showGrid(bool)));
connect(gridSizeInput,SIGNAL(valueChanged(int)),frontView,SLOT(setGridSize(int)));
connect(gridStepInput,SIGNAL(valueChanged(int)),frontView,SLOT(setGridStepSize(int)));
connect(showGridButton,SIGNAL(clicked(bool)),frontView,SLOT(showGrid(bool)));
connect(gridSizeInput,SIGNAL(valueChanged(int)),this,SLOT(updateGL()));
connect(gridStepInput,SIGNAL(valueChanged(int)),this,SLOT(updateGL()));
connect(showGridButton,SIGNAL(clicked(bool)),this,SLOT(updateGL()));
// Assemble Menus
fileMenu->addAction(exitAction);
menuBar->addMenu(fileMenu);
menuBar->addMenu(primitivesMenu);
menuBar->addAction(aboutAction);
setMenuBar(menuBar);
//Assemble Tool Bar
toolBar->addAction(cameraMode);
toolBar->addAction(editMode);
toolBar->addSeparator();
toolBar->addAction(camHome);
toolBar->addSeparator();
toolBar->addWidget(showGridButton);
toolBar->addWidget(gridSizeInput);
toolBar->addWidget(gridStepInput);
toolBar->addSeparator();
QToolButton* toolButton = new QToolButton();
toolButton->setIcon(QIcon(":/img/viewports.png"));
toolButton->setMenu(viewMenu);
toolButton->setPopupMode(QToolButton::InstantPopup);
QWidgetAction* toolButtonAction = new QWidgetAction(this);
toolButtonAction->setDefaultWidget(toolButton);
toolBar->addAction(toolButtonAction);
QToolButton* primitives = new QToolButton();
primitives->setIcon(QIcon(":/img/box.png"));
primitives->setMenu(primitivesMenu);
primitives->setPopupMode(QToolButton::InstantPopup);
QWidgetAction* primitiveActione = new QWidgetAction(this);
primitiveActione->setDefaultWidget(primitives);
toolBar->addAction(primitiveActione);
toolBar->addWidget(slider);
addToolBar( toolBar);
scene->simpleScene();
setStatusBar(statusBar);
initDoc();
}
void MainWindow::initDoc()
{
QDockWidget *dock = new QDockWidget("Scene", this);
dock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
sceneView = new QTreeView(this);
sceneView->setSelectionBehavior(QAbstractItemView::SelectRows);
sceneView->expandAll();
sceneView->setModel(scene);
TreeDelegate *delegate = new TreeDelegate();
sceneView->setItemDelegate(delegate);
connect(sceneView,SIGNAL(clicked(QModelIndex)),scene, SLOT(objectSelected(QModelIndex)));
connect(delegate,SIGNAL(nameChanged()),this, SLOT(updateStatusBar()));
dock->setWidget(sceneView);
addDockWidget(Qt::RightDockWidgetArea, dock);
}
void MainWindow::updateStatusBar()
{
QString text = scene->getActive()->getName();
statusBar->showMessage(text);
}
void MainWindow::showSingle(){
perspectiveView->show();
frontView->hide();
leftView->hide();
topView->hide();
}
void MainWindow::showDual(){
perspectiveView->show();
frontView->show();
leftView->hide();
topView->hide();
}
void MainWindow::showQuad(){
perspectiveView->show();
frontView->show();
leftView->show();
topView->show();
}
void MainWindow::updateGL()
{
perspectiveView->updateGL();
frontView->updateGL();
leftView->updateGL();
topView->updateGL();
}
void MainWindow::setActiveView(GLView * active)
{
perspectiveView->setAcive((perspectiveView == active));
frontView->setAcive((frontView == active));
leftView->setAcive((leftView == active));
topView->setAcive((topView == active));
disconnect(camHome, SIGNAL(triggered(bool)),perspectiveView,SLOT(home()));
disconnect(camHome, SIGNAL(triggered(bool)),frontView,SLOT(home()));
disconnect(camHome, SIGNAL(triggered(bool)),leftView,SLOT(home()));
disconnect(camHome, SIGNAL(triggered(bool)),topView,SLOT(home()));
connect(camHome, SIGNAL(triggered(bool)),active,SLOT(home()));
}
MainWindow::~MainWindow()
{
}
void MainWindow::showAboutBox()
{
QMessageBox msgBox;
msgBox.setWindowTitle("About Hello Cube!");
msgBox.setText("Written by Kai Westerkamp");
msgBox.exec();
}
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QMenu>
#include <QMenuBar>
#include <QAction>
#include <QActionGroup>
#include <QIcon>
#include <QMessageBox>
#include <QToolBar>
#include <QStatusBar>
#include <QSlider>
#include <QSplitter>
#include <glview.h>
#include <scene.h>
#include <camera.h>
#include <controler.h>
class MainWindow : public QMainWindow
{
Q_OBJECT
private:
QMenuBar *menuBar;
QMenu *fileMenu;
QAction *exitAction;
QMenu *interactionMenu;
QActionGroup *interactionGroup;
QAction *cameraMode;
QAction *editMode;
QMenu *viewMenu;
QActionGroup *viewGoup;
QAction *singleView;
QAction *dualView;
QAction *quadView;
QAction *aboutAction;
QAction *camHome;
QMenu *primitivesMenu;
QAction *spheresAdd;
QAction *boxesAdd;
QAction *cylindersAdd;
QAction *coneAdd;
QAction *torusAdd;
QAction *groupAdd;
QAction *activeDelete;
QAction *volumeAdd;
QToolBar *toolBar;
QStatusBar *statusBar;
QSlider *slider;
Scene* scene;
Controler *controler;
QSplitter *topSplit;
QSplitter *bottomSplit;
QSplitter *verticalSplit;
GLView *perspectiveView;
GLView *frontView;
GLView *leftView;
GLView *topView;
QTreeView *sceneView;
QSpinBox* gridSizeInput;
QSpinBox* gridStepInput;
QToolButton* showGridButton;
void initDoc();
public:
MainWindow(QWidget *parent = 0);
~MainWindow();
void setActiveView(GLView * active);
public slots:
void updateGL();
void updateStatusBar();
void showAboutBox();
void showSingle();
void showDual();
void showQuad();
};
#endif // MAINWINDOW_H
uniform bool shaded;
varying vec4 pick;
varying vec3 position;
varying vec3 normal;
void main(void)
{
vec3 N = normalize(normal);
vec3 L = normalize(gl_LightSource[0].position.xyz-position);
vec4 diffuse = vec4(max(dot(L,N),0.0));
vec4 Iamb = gl_FrontLightProduct[0].ambient;
vec4 Idiff = gl_FrontLightProduct[0].diffuse*diffuse;
Idiff = clamp(Idiff, 0.0, 1.0);
vec3 V = normalize(-position);
vec3 R = normalize(reflect(-L,N));
float specular = pow(max(dot(R,V),0.0),gl_FrontMaterial.shininess);//);
vec4 Ispec = gl_FrontLightProduct[0].specular * specular;
Ispec = clamp(Ispec, 0.0, 1.0);
vec4 color = (
Iamb
+ Idiff
+ Ispec
);
if(shaded)
gl_FragData[0] = color;
else
gl_FragData[0] = vec4(1,1,0,1);
gl_FragData[1] = pick;
gl_FragData[1] = vec4(abs(normal),1);
}
attribute vec4 gl_Vertex;
attribute vec3 gl_Normal;
attribute int pickID;
uniform mat4 gl_ModelViewProjectionMatrix;
uniform mat4 gl_ModelViewMatrix;
uniform mat3 gl_NormalMatrix;
varying vec3 position;
varying vec3 normal;
varying vec4 pick;
void main(void)
{
normal = normalize(gl_NormalMatrix * gl_Normal);
position = vec3(gl_ModelViewMatrix *gl_Vertex);
pick = vec4(pickID);
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
}
#include "scene.h"
#include <iostream>
Scene::Scene( )
{
root = new SceneNode();
root->setName("<NONE>");
active = root;
activeIndex = QModelIndex();
}
Scene::~Scene( )
{
delete root;
}
int Scene::simpleScene()
{
addCube();
moveActive(QVector3D(4,0,0));
addSphere();
moveActive(QVector3D(1.5,0,0));
addCylinder();
moveActive(QVector3D(0,1.5,-1.5));
// addNode();
addTorus();
moveActive(QVector3D(0,0,-3));
addCone();
moveActive(QVector3D(0,-1.5,-1.5));
//addVolume("D:/Projekte/GraPa/A3/MRI-head.raw");
return active->getID();
}
void Scene::addSceneObjectTaActive(SceneObject *obj){
SceneNode* parent;
QModelIndex parentIndex;
if(active->isNode()){
parent = static_cast<SceneNode*>(active);
parentIndex = activeIndex;
} else {
parent = static_cast<SceneNode*>(active->getParent());
parentIndex = activeIndex.parent();
}
beginInsertRows(parentIndex, parent->childCount(), parent->childCount());
parent->add(obj);
obj->setParent(parent);
endInsertRows();
activeIndex = index(parent->childCount()-1,0,parentIndex);
active = obj;
qDebug()<<"Adding"<<obj->getName()<<" to "<<getItem(parentIndex)->getName()<<" Active"<<getItem(activeIndex)->getName();
emit activChanged();
}
void Scene::addCube()
{
float color[] = {0.0,0.0,1.0};
ScenePrimitive *primitive = new ScenePrimitive(PrimitiveType::Quader,tesselation);
primitive->setMaterial(color);
addSceneObjectTaActive(primitive);
}
void Scene::addSphere()
{
float color[] = {0.0,1.0,0.0};
ScenePrimitive *primitive = new ScenePrimitive(PrimitiveType::Sphere,tesselation);
primitive->setMaterial(color);
addSceneObjectTaActive(primitive);
}
void Scene::addCylinder()
{
float color[] = {1.0,0.0,0.0};
ScenePrimitive *primitive = new ScenePrimitive(PrimitiveType::Cylinder,tesselation);
primitive->setMaterial(color);
addSceneObjectTaActive(primitive);
}
void Scene::addTorus()
{
float color[] = {1.0,0.0,1.0};
ScenePrimitive *primitive = new ScenePrimitive(PrimitiveType::Torus,tesselation);
primitive->setMaterial(color);
addSceneObjectTaActive(primitive);
}
void Scene::addCone()
{
float color[] = {0.0,1.0,1.0};
ScenePrimitive *primitive = new ScenePrimitive(PrimitiveType::Cone,tesselation);
primitive->setMaterial(color);
addSceneObjectTaActive(primitive);
}
void Scene::addNode()
{
SceneNode *node = new SceneNode();
node->setName("Graph Node");
addSceneObjectTaActive(node);
}
void Scene::deletActive()
{
QModelIndex parentIndex = activeIndex.parent();
SceneNode *parent = static_cast<SceneNode*>(active->getParent());
int pos = active->childNumber();
qDebug()<<"Delet Active in Scene"<<parentIndex<<parent->childCount()<<pos;
foreach (SceneObject * t, parent->getChildren()) {
qDebug()<<t->getName()<<t->childNumber();
}
beginRemoveRows(parentIndex, pos, pos);
parent->remove(pos);
endRemoveRows();
active = parent;
activeIndex = parentIndex;
qDebug()<<"Delet Active in Scene"<<active<<activeIndex<<active->getName();
emit activChanged();
}
void Scene::addVolume()
{
QString fn = QFileDialog::getOpenFileName(NULL, tr("Open Volume..."),
QString("D:\\Projekte\\GraPa\\A3"), tr("Volume Files (*.raw )"));
if(fn.isEmpty())
return;
qDebug()<<"Opening File:"<<fn;
addVolume(fn);
}
void Scene::addVolume(QString filePath){
QFile file(filePath);
if(!file.open(QIODevice::ReadOnly)) {
QMessageBox::information(0, "error", file.errorString());
}
QByteArray line1 = file.readLine();
QTextStream l1(line1);
QStringList line1Text = l1.readLine().split(" ");
int x = line1Text[0].toInt();
int y = line1Text[1].toInt();
int z = line1Text[2].toInt();
qDebug()<<line1Text<< x << y << z;
QByteArray line2 = file.readLine();
QTextStream l2(line2);
QStringList line1Text2 = l2.readLine().split(" ");
double dx = line1Text2[0].toDouble();
double dy = line1Text2[1].toDouble();
double dz = line1Text2[2].toDouble();
qDebug()<<line1Text2<< dx <<dy << dz;
QByteArray rawdata = file.readAll();
//qDebug()<<rawdata;
char ***data = new char**[z];
int count = 0;
// std::cout<<std::hex;
for(int k = 0; k < z; k++)
{
data[k] = new char*[y];
for(int j = 0; j < y; j++)
{
if(k == 150){
std::cout<<std::endl;
}
data[k][j] = new char[x];
for(int i = 0; i < x; i++)
{
data[k][j][i] = rawdata.at(count++);
if(k == 150 ){
int temp = ((uchar)data[k][j][i])*9/256;
std::cout<<temp;
// std::cout<<((uint)data[k][j][i]);
}
}
}
}
//qDebug()<<file.readData(data,file.size()-file.pos());
file.close();
qDebug()<<"File Read finish";
}
void Scene::setTesselation(int tesselation)
{
this->tesselation = tesselation;
}
SceneObject *Scene::setActive(int id){
active = root->find(id);
emit activChanged();
return active;
}
SceneObject *Scene::getActive(){
return active;
}
void Scene::draw(QGLShaderProgram *shader)
{
root->draw(shader);
}
SceneNode *Scene::getRoot()
{
return root;
}
void Scene::moveActive(QVector3D dir)
{
if(active != NULL)
active->move(dir);
}
void Scene::rotateActive(QQuaternion rot)
{
if(active != NULL)
active->rotate(rot);
}
//Model funktions
SceneObject *Scene::getItem(const QModelIndex &index) const
{
if (index.isValid()) {
SceneObject *item = static_cast<SceneObject*>(index.internalPointer());
if (item)
return item;
}
return root;
}
int Scene::rowCount(const QModelIndex &parent) const
{
SceneObject *parentItem = getItem(parent);
// qDebug()<<"ChildCount:"<<parentItem->childCount();
return parentItem->childCount();
}
int Scene::columnCount(const QModelIndex & parent ) const
{
SceneObject *item = getItem(parent);
// qDebug()<<"ColumnCount:"<<item->columnCount();
return item->columnCount();
}
Qt::ItemFlags Scene::flags(const QModelIndex &index) const
{
if (!index.isValid())
return 0;
return Qt::ItemIsEditable | QAbstractItemModel::flags(index);
}
QModelIndex Scene::index(int row, int column, const QModelIndex &parent) const
{
if (parent.isValid() && parent.column() != 0)
return QModelIndex();
SceneObject *parentItem = getItem(parent);
SceneObject *childItem = parentItem->children(row);
if (childItem)
return createIndex(row, column, childItem);
else
return QModelIndex();
}
QModelIndex Scene::parent(const QModelIndex &index) const
{
if (!index.isValid())
return QModelIndex();
SceneObject *childItem = getItem(index);
SceneObject *parentItem = childItem->getParent();
if (parentItem == root)
return QModelIndex();
return createIndex(parentItem->childNumber(), 0, parentItem);
}
QVariant Scene::data(const QModelIndex &index, int role) const
{
if (!index.isValid())
return QVariant();
if (role != Qt::DisplayRole && role != Qt::EditRole)
return QVariant();
SceneObject *item = getItem(index);
return item->data(index.column());
}
QVariant Scene::headerData(int section, Qt::Orientation orientation,
int role) const
{
if (orientation == Qt::Horizontal && role == Qt::DisplayRole)
return root->data(section);
return QVariant();
}
void Scene::objectSelected(QModelIndex index)
{
activeIndex = index;
active = getItem(index);
emit activChanged();
}
#ifndef SCENE_H
#define SCENE_H
#include <QObject>
#include <QtOpenGL>
#include <QGLFunctions>
#include <QOpenGLFunctions>
#include <QFile>
#include <scenenode.h>
#include <sceneobject.h>
#include <sceneprimitive.h>
class Scene: public QAbstractItemModel // QAbstractItemModel
{
Q_OBJECT
public:
Scene();
~Scene();
void draw(QGLShaderProgram *shader);
int simpleScene();
void moveActive(QVector3D dir);
void rotateActive(QQuaternion rot);
void addSceneObjectTaActive(SceneObject *obj);
SceneObject *getActive();
SceneObject *setActive(int id);
QVariant data(const QModelIndex &index, int role) const Q_DECL_OVERRIDE;
QVariant headerData(int section, Qt::Orientation orientation,
int role = Qt::DisplayRole) const Q_DECL_OVERRIDE;
QModelIndex index(int row, int column,
const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE;
QModelIndex parent(const QModelIndex &index) const Q_DECL_OVERRIDE;
int rowCount(const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE;
int columnCount(const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE;
Qt::ItemFlags flags(const QModelIndex &index) const Q_DECL_OVERRIDE;
int tesselation;
public slots:
void objectSelected(QModelIndex index);
void setTesselation(int tesselation);
void addCube();
void addSphere();
void addCylinder();
void addTorus();
void addCone();
void addNode();
void deletActive();
void addVolume();
void addVolume(QString filePath);
signals:
void activChanged();
private:
SceneNode *root;
SceneObject *active;
QModelIndex activeIndex;
SceneObject *getItem(const QModelIndex &index) const;
SceneNode *getRoot();
};
#endif // SCENE_H
#include "scenenode.h"
SceneNode::SceneNode()
:SceneObject()
{
childs = QList<SceneObject*>();
}
SceneNode::~SceneNode()
{
qDeleteAll(childs);
}
SceneObject *SceneNode::children(int number)
{
return childs.value(number);
}
int SceneNode::childCount() const
{
return childs.count();
}
void SceneNode::add(SceneObject *child)
{
childs.append(child);
}
void SceneNode::remove(int number)
{
delete childs.takeAt(number);
}
SceneObject *SceneNode::find(int id)
{
foreach (SceneObject *obj, childs) {
SceneObject *temp = obj->find(id);
if(temp != NULL)
return temp;
}
return NULL;
}
void SceneNode::draw(QGLShaderProgram *shader)
{
glPushMatrix();
applyTransformation();
foreach (SceneObject *obj, childs) {
obj->draw(shader);
}
glPopMatrix();
}
#ifndef SCENENODE_H
#define SCENENODE_H
#include <sceneobject.h>
#include <QList>
class SceneNode : public SceneObject
{
Q_OBJECT
private:
QList<SceneObject*> childs;
public:
SceneNode();
~SceneNode();
SceneObject *children(int number);
int childCount() const;
QList<SceneObject*> getChildren(){return childs;}
virtual bool isNode(){return true;qDebug()<<"isNode";}
SceneObject *find(int id);
void draw(QGLShaderProgram *shader);
void add(SceneObject *child);
void remove(int number);
};
#endif // SCENENODE_H
#include "sceneobject.h"
#include "scenenode.h"
int SceneNode::idCount = 1;
SceneObject::SceneObject()
{
id = idCount;
idCount++;
name = QString("Scene Object "+id);
rotation = QQuaternion();
translation = QVector3D();
parent = NULL;
}
SceneObject *SceneObject::getParent()
{
return parent;
}
SceneObject *SceneObject::children(int /* number*/)
{
return NULL;
}
int SceneObject::childCount() const
{
return 0;
}
int SceneObject::childNumber() const
{
if (parent){
SceneNode* node = static_cast<SceneNode*>(parent);
return node->getChildren().indexOf(const_cast<SceneObject*>(this));
}
return 0;
}
int SceneObject::columnCount() const
{
return 1+itemData.count();
}
QVariant SceneObject::data(int column) const
{
if(column == 0) return name;
return itemData.value(column);
}
bool SceneObject::setData(int column, const QVariant &value)
{
qDebug()<<"Set Data called";
if (column < 0 || column >= itemData.size())
return false;
if(column == 0) setName(value.toString());
else itemData[column] = value;
return true;
}
int SceneObject::getID(){return id;}
QString SceneObject::getName(){return name;}
QQuaternion SceneObject::getGlobalRotation(){
if(parent == NULL)
return QQuaternion();
else
return parent->getGlobalRotation() *rotation;
}
void SceneObject::move(QVector3D dir)
{
QQuaternion rot = parent->getGlobalRotation();
translation+=rot.conjugate().rotatedVector(dir);
}
void SceneObject::rotate(QQuaternion rot)
{
rotation = rot * rotation;
}
void SceneObject::draw(QGLShaderProgram *shader){qDebug()<<"Drawing abstract Scene Element";}
SceneObject *SceneObject::find(int id)
{
if(this->id == id){
return this;
} else{
return NULL;
}
}
void SceneObject::applyTransformation()
{
QMatrix4x4 mat = QMatrix4x4();
mat.translate(translation);
glMultMatrixf(mat.data());
mat = QMatrix4x4();
mat.rotate(rotation);
glMultMatrixf(mat.data());
}
#ifndef SCENEOBJECT_H
#define SCENEOBJECT_H
#include <QObject>
#include <QQuaternion>
#include <QVector3D>
#include <QVector>
#include <QtOpenGL>
#include <gl/GLU.h>
class SceneObject : public QObject
{
Q_OBJECT
static int idCount;
protected:
QQuaternion rotation;
QVector3D translation;
int id;
QString name;
void applyTransformation();
QVector<QVariant> itemData;
SceneObject *parent;
public:
SceneObject();
void setParent(SceneObject *parent){this->parent = parent;}
SceneObject *getParent();
virtual SceneObject *children(int number);
virtual bool isNode(){return false;}
int childNumber() const;
virtual int childCount() const;
int columnCount() const;
QVariant data(int column) const;
bool setData(int column, const QVariant &value);
virtual void draw(QGLShaderProgram *shader);
virtual SceneObject *find(int id);
int getID();
QString getName();
void setName(QString name){this->name = name;}
void move(QVector3D dir);
void rotate(QQuaternion rot);
QQuaternion getGlobalRotation();
};
#endif // SCENEOBJECT_H
#include "sceneprimitive.h"
#include "algorithm"
int ScenePrimitive::quaderCount = 1;
int ScenePrimitive::sphereCount = 1;
int ScenePrimitive::cylinderCount = 1;
int ScenePrimitive::torusCount = 1;
int ScenePrimitive::coneCount = 1;
ScenePrimitive::ScenePrimitive(PrimitiveType type, int tesselation)
:SceneObject()
{
this->type = type;
this->tesselation = tesselation;
qobj = gluNewQuadric();
gluQuadricNormals(qobj, GLU_SMOOTH);
this->color = new float[3];
this->color[0] = 0.0;
this->color[1] = 0.0;
this->color[2] = 0.0;
switch (this->type) {
case Quader:
name = QString("Quader %1").arg(ScenePrimitive::quaderCount);
ScenePrimitive::quaderCount++;
this->tesselation = pow(2,tesselation);
break;
case Sphere:
name = QString("Sphere %1").arg(ScenePrimitive::sphereCount);
ScenePrimitive::sphereCount++;
this->tesselation = 5*pow(2,tesselation);
break;
case Cylinder:
name = QString("Cylinder %1").arg(ScenePrimitive::cylinderCount);
ScenePrimitive::cylinderCount++;
this->tesselation = 5*pow(2,tesselation);
break;
case Torus:
name = QString("Torus %1").arg(ScenePrimitive::torusCount);
ScenePrimitive::torusCount++;
this->tesselation = 5*pow(2,tesselation);
break;
case Cone:
name = QString("Cone %1").arg(ScenePrimitive::coneCount);
ScenePrimitive::coneCount++;
this->tesselation = 5*pow(2,tesselation);
break;
default:
qDebug()<<"Enum Error";
break;
}
// qDebug()<<"Tesselation"<<this->tesselation<<getName();
}
void ScenePrimitive::draw(QGLShaderProgram *shader){
shader->setAttributeValue(4,getID());
glPushMatrix();
applyTransformation();
// qDebug()<<this->getName()<<"Matrial"<<*color<<"Trans"<<translation<<"Rot"<<rotation;
glMaterialfv(GL_FRONT,GL_AMBIENT,color);
GLfloat white[] = {1.0,1.0,1.0};
glMaterialfv(GL_FRONT,GL_DIFFUSE,color);
glMaterialfv(GL_FRONT,GL_SPECULAR,white);
GLfloat mShininess[] = {128};
glMaterialfv(GL_FRONT,GL_SHININESS,mShininess);
int radius = 1;
switch (this->type) {
case Quader:
drawCube(tesselation);
break;
case Sphere:
gluSphere(qobj,1,tesselation,tesselation);
break;
case Cylinder:
gluCylinder(qobj,radius,radius,3,tesselation,tesselation);
gluQuadricOrientation(qobj,GLU_INSIDE);
gluDisk( qobj, 0.0, radius, tesselation, 1);
glTranslatef(0,0,3);
gluQuadricOrientation(qobj,GLU_OUTSIDE);
gluDisk( qobj, 0.0 , radius, tesselation, 1);
break;
case Cone:
gluQuadricOrientation(qobj,GLU_OUTSIDE);
gluCylinder(qobj,radius,0,3,tesselation,tesselation);
gluQuadricOrientation(qobj,GLU_INSIDE);
gluDisk( qobj, 0.0, radius, tesselation, 1);
break;
case Torus:
glutSolidTorus(1, 2, tesselation, tesselation);
break;
default:
qDebug()<<"Enum Error";
break;
}
glPopMatrix();
}
void ScenePrimitive::setMaterial(float *color )
{
this->color = new float[3];
this->color[0] = color[0];
this->color[1] = color[1];
this->color[2] = color[2];
// qDebug()<< *this->color<<" "<<this->color[0]<<" "<<this->color[1]<<" "<<this->color[2];
}
void ScenePrimitive::drawCube(int tesselation)
{
float increment = 1.0/tesselation;
glBegin(GL_QUADS);
glNormal3f(0,1,0);
for (float x = -0.5; x < 0.5 ; x+= increment) {
for (float y = -0.5; y < 0.5 ; y+= increment ) {
glVertex3f( x+increment, 0.5f,y);
glVertex3f(x, 0.5f,y);
glVertex3f(x, 0.5f, y+increment);
glVertex3f( x+increment, 0.5f, y+increment);
}
}
glEnd();
glBegin(GL_QUADS);
glNormal3f(0,-1,0);
for (float x = -0.5; x < 0.5 ; x+= increment) {
for (float y = -0.5; y < 0.5 ; y+= increment ) {
glVertex3f( x+increment, -0.5f,y+increment);
glVertex3f(x, -0.5f,y+increment);
glVertex3f(x, -0.5f, y);
glVertex3f( x+increment, -0.5f, y);
}
}
glEnd();
glBegin(GL_QUADS);
glNormal3f(0,0,1);
for (float x = -0.5; x < 0.5 ; x+= increment) {
for (float y = -0.5; y < 0.5 ; y+= increment ) {
glVertex3f( x+increment,y+increment, 0.5f);
glVertex3f(x, y+increment, 0.5f);
glVertex3f(x, y, 0.5f);
glVertex3f( x+increment, y, 0.5f);
}
}
glEnd();
glBegin(GL_QUADS);
glNormal3f(0,0,-1);
for (float x = -0.5; x < 0.5 ; x+= increment) {
for (float y = -0.5; y < 0.5 ; y+= increment ) {
glVertex3f( x+increment,y, -0.5f);
glVertex3f(x, y,-0.5f);
glVertex3f(x, y+increment,-0.5f);
glVertex3f( x+increment,y+increment, -0.5f);
}
}
glEnd();
glBegin(GL_QUADS);
glNormal3f(-1,0,0);
for (float x = -0.5; x < 0.5 ; x+= increment) {
for (float y = -0.5; y < 0.5 ; y+= increment ) {
glVertex3f( -0.5f, x+increment,y+increment);
glVertex3f( -0.5f,x+increment,y);
glVertex3f( -0.5f,x, y);
glVertex3f( -0.5f,x, y+increment);
}
}
glEnd();
glBegin(GL_QUADS);
glNormal3f(1,0,0);
for (float x = -0.5; x < 0.5 ; x+= increment) {
for (float y = -0.5; y < 0.5 ; y+= increment ) {
glVertex3f( 0.5f, x+increment,y);
glVertex3f( 0.5f,x+increment,y+increment);
glVertex3f( 0.5f,x, y+increment);
glVertex3f( 0.5f,x, y);
}
}
glEnd();
}
#ifndef SCENEPRIMITIVE_H
#define SCENEPRIMITIVE_H
#include <sceneobject.h>
#include <glut.h>
enum PrimitiveType{Quader=0,Sphere,Cylinder,Torus,Cone};
class ScenePrimitive : public SceneObject
{
Q_OBJECT
private:
static int quaderCount;
static int sphereCount;
static int cylinderCount ;
static int torusCount;
static int coneCount;
PrimitiveType type;
int tesselation;
GLUquadric *qobj;
float *color;
void drawCube(int tesselation);
public:
void draw(QGLShaderProgram *shader);
void setMaterial(float *color);
ScenePrimitive(PrimitiveType type, int tesselation);
};
#endif // SCENEPRIMITIVE_H
#include "scenevolume.h"
SceneVolume::SceneVolume()
{
}
#ifndef SCENEVOLUME_H
#define SCENEVOLUME_H
#include <QObject>
#include <sceneobject.h>
class SceneVolume : public SceneObject
{
public:
SceneVolume();
};
#endif // SCENEVOLUME_H
#include "treedelegate.h"
#include <QDebug>
#include <QLineEdit>
#include <QString>
#include <scene.h>
TreeDelegate::TreeDelegate()
{
}
void TreeDelegate::setModelData(QWidget *editor, QAbstractItemModel *model,
const QModelIndex &index) const
{
qDebug()<<"out";
QLineEdit *lineEdit = qobject_cast<QLineEdit *>(editor);
if (!lineEdit->isModified()) {
return;
}
QString text = lineEdit->text();
text = text.trimmed();
if (text.isEmpty()) {
// If text is empty, do nothing - preserve the old value.
return;
} else {
if (index.isValid()) {
SceneObject *item = static_cast<SceneObject*>(index.internalPointer());
if (item)
item->setName(text);
}
emit nameChanged();
}
}
#ifndef TREEDELEGATE_H
#define TREEDELEGATE_H
#include <QItemDelegate>
class TreeDelegate : public QItemDelegate
{
Q_OBJECT;
public:
TreeDelegate();
void setModelData(QWidget *editor, QAbstractItemModel *model,
const QModelIndex &index) const;
signals:
void nameChanged() const;
};
#endif // TREEDELEGATE_H
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment