C++ QT4 OpenGL
-
Hallo,
ich bin neu in dem Forum und muss gleich mal um Hilfe rufen!
Hab seit längerem nicht mehr programmiert und wollte mir jetzt mal OpenGL ansehen...
Dummerweise funktioniert das momentan nicht ganz so wie ich will.
Hab den Code von nem tut etwas abgeändert und ich weiß nicht wieso dieser Fehler auftritt!!!Compiler:
tetrahedron.cpp: In function "void berechne_eckpunkte(float, float, float)": tetrahedron.cpp:39: error: "hinten" was not declared in this scope tetrahedron.cpp:43: error: "vorne_links" was not declared in this scope tetrahedron.cpp:47: error: "vorne_rechts" was not declared in this scope tetrahedron.cpp:51: error: "oben" was not declared in this scopeAber in der Headerdatei steht es doch unter public Zeile 11!!!!!!!
Also was zum Teufel geht hier ab?!Tetrahedron.h:
#ifndef TETRAHEDRON_H #define TETRAHEDRON_H #include <QGLWidget> class Tetrahedron : public QGLWidget { Q_OBJECT public: Tetrahedron(QWidget *parent = 0); float hinten[3], vorne_links[3], vorne_rechts[3], oben[3]; void berechne_eckpunkte(float ursprungX, float ursprungY, float ursprungZ); protected: void initializeGL(); void resizeGL(int width, int height); void paintGL(); void mousePressEvent(QMouseEvent *event); void mouseMoveEvent(QMouseEvent *event); void mouseDoubleClickEvent(QMouseEvent *event); private: void draw(); int faceAtPosition(const QPoint &pos); GLfloat rotationX; GLfloat rotationY; GLfloat rotationZ; QColor faceColors[4]; QPoint lastPos; }; #endifTetrahedron.cpp:
#include <QtGui> #include <QtOpenGL> #include <cmath> #include "tetrahedron.h" Tetrahedron::Tetrahedron(QWidget *parent) : QGLWidget(parent) { setFormat(QGLFormat(QGL::DoubleBuffer | QGL::DepthBuffer)); } void Tetrahedron::initializeGL() { qglClearColor(Qt::black); glShadeModel(GL_FLAT); glEnable(GL_DEPTH_TEST); glEnable(GL_CULL_FACE); } void Tetrahedron::resizeGL(int width, int height) { glViewport(0, 0, width, height); glMatrixMode(GL_PROJECTION); glLoadIdentity(); GLfloat x = GLfloat(width) / height; glFrustum(-x, x, -1.0, 1.0, 4.0, 15.0); glMatrixMode(GL_MODELVIEW); } void Tetrahedron::paintGL() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); draw(); } void berechne_eckpunkte(float ursprungX, float ursprungY, float ursprungZ) { hinten[0] = ursprungX; hinten[1] = ursprungY; hinten[2] = ursprungZ; vorne_links[0] = ursprungX - 0.5; vorne_links[1] = ursprungY; vorne_links[2] = ursprungZ + (sqrt(3.0)/2.0); vorne_rechts[0] = ursprungX + 0.5; vorne_rechts[1] = ursprungY; vorne_rechts[2] = ursprungZ + (sqrt(3.0)/2.0); oben[0] = ursprungX; oben[1] = ursprungY + (sqrt(6.0)/3.0); oben[2] = ursprungZ + (sqrt(3.0)/3.0); } void Tetrahedron::draw() { glMatrixMode(GL_MODELVIEW); glLoadIdentity(); berechne_eckpunkte(0.0, 0.0, 0.0); glBegin(GL_POLYGON); glVertex3f(hinten[0],hinten[1],hinten[2]); glVertex3f(vorne_links[0],vorne_links[1],vorne_links[2]); glVertex3f(oben[0],oben[1],oben[2]); glVertex3f(vorne_links[0],vorne_links[1],vorne_links[2]); glVertex3f(vorne_rechts[0],vorne_rechts[1],vorne_rechts[2]); glVertex3f(oben[0],oben[1],oben[2]); glVertex3f(vorne_rechts[0],vorne_rechts[1],vorne_rechts[2]); glVertex3f(hinten[0],hinten[1],hinten[2]); glVertex3f(oben[0],oben[1],oben[2]); glVertex3f(hinten[0],hinten[1],hinten[2]); glVertex3f(vorne_links[0],vorne_links[1],vorne_links[2]); glVertex3f(vorne_rechts[0],vorne_rechts[1],vorne_rechts[2]); glEnd(); } void Tetrahedron::mousePressEvent(QMouseEvent *event) { lastPos = event->pos(); } void Tetrahedron::mouseMoveEvent(QMouseEvent *event) { GLfloat dx = GLfloat(event->x() - lastPos.x()) / width(); GLfloat dy = GLfloat(event->y() - lastPos.y()) / height(); if (event->buttons() & Qt::LeftButton) { rotationX += 180*dy; rotationY += 180*dx; updateGL(); } else { if (event->buttons() & Qt::RightButton) { rotationX += 180*dy; rotationZ += 180*dx; updateGL(); } } lastPos = event->pos(); } void Tetrahedron::mouseDoubleClickEvent(QMouseEvent *event) { int face = faceAtPosition(event->pos()); if (face != -1) { QColor color = QColorDialog::getColor(faceColors[face], this); if (color.isValid()) { faceColors[face] = color; updateGL(); } } } int Tetrahedron::faceAtPosition(const QPoint &pos) { const int MaxSize = 512; GLuint buffer[MaxSize]; GLint viewport[4]; makeCurrent(); glGetIntegerv(GL_VIEWPORT, viewport); glSelectBuffer(MaxSize, buffer); glRenderMode(GL_SELECT); glInitNames(); glPushName(0); glMatrixMode(GL_PROJECTION); glPushMatrix(); glLoadIdentity(); gluPickMatrix(GLdouble(pos.x()), GLdouble(viewport[3] - pos.y()), 5.0, 5.0, viewport); GLfloat x = GLfloat(width()) / height(); glFrustum(-x, x, -1.0, 1.0, 4.0, 15.0); draw(); glMatrixMode(GL_PROJECTION); glPopMatrix(); if (!glRenderMode(GL_RENDER)) { return -1; } return buffer[3]; }Main.cpp:
#include <QApplication> #include <iostream> #include "tetrahedron.h" int main(int argc, char *argv[]) { QApplication app(argc, argv); if (!QGLFormat::hasOpenGL()) { std::cerr << "Geht nicht" << std::endl; return 1; } Tetrahedron tetrahedron; tetrahedron.setWindowTitle("Tetrahedron"); tetrahedron.resize(300, 300); tetrahedron.show(); return app.exec(); }Danke an alle, die versuchen mir zu helfen und sorry für so viel Code!
-
void berechne_eckpunkte(float ursprungX, float ursprungY, float ursprungZ)=>
void Tetrahedron::berechne_eckpunkte(float ursprungX, float ursprungY, float ursprungZ)
-
ohhhhhh!!!!!
*eigenen schädel einkloppen*DANKE!
-
mhh, weiß jemand, wie ich die pyramide bei linksklick drehen kann?
btw: wie kann ich die "kamera" bewegen?