vendredi 29 mai 2015

OpenGL error "function call missing arguments list"

Have anyone any idea how I can solve this problem from my code?

'Sphere::handleKeypress': function call missing argument list; use '&Sphere::handleKeypress' to create a pointer to member

here is my code

Sphere class:

#include "glos.h"
#include <glut.h>
#include <math.h>  
class Sphere{

private:
    float x2, y2, z2, r2;
public:
    float x, y, z, r,speed = 0.10;
    Sphere(float x, float y, float z, float r){
        this->x = x;
        this->y = y;
        this->z = z;
        this->r = r;
    }
    bool colision(Sphere sfera){
        x2 = sfera.x;
        y2 = sfera.y;
        z2 = sfera.z;
        r2 = sfera.r;
        float d = sqrt(pow(x - x2, 2) + pow(y - y2, 2) + pow(z - z2, 2));
        if (d <= r + r2){
            return true;
        }
        else{
            return false;
        }
    }
    void draw(){
        glPushMatrix();
        glTranslatef(x, y, z);
        glutSolidSphere(r, 100, 100);
        glPopMatrix();
    }
    void handleKeypress(unsigned char key, int x, int y){
        Sphere sfera(x2, y2, z2, r2);
        if (key == 'a'){
            if (!colision(sfera)){
                x -= speed;
            }
            else{
                if (x  <  x2){
                    x -= speed;
                }
            }
        }
        if (key == 'd'){
            if (!colision(sfera)){
                x += speed;
            }
            else{
                if (x  >  x2){
                    x += speed;
                }
            }
        }
        if (key == 's'){
            if (!colision(sfera)){
                y -= speed;
            }
            else{
                if (y  <  y2){
                    y -= speed;
                }
            }
        }
        if (key == 'w'){
            if (!colision(sfera)){
                y += speed;
            }
            else{
                if (y  >  y2){
                    y += speed;
                }
            }
        }
        if (key == 'e'){
            if (!colision(sfera)){
                z += speed;
            }
            else{
                if (z  >  z2){
                    y += speed;
                }
            }
        }
        if (key == 'q'){
            if (!colision(sfera)){
                z -= speed;
            }
            else{
                if (z  <  z2){
                    z -= speed;
                }
            }
        }
        glutPostRedisplay();
    }
};

Main class:

#include "glos.h"
#include <gl.h>
#include <glu.h>
#include <glut.h>
#include <glaux.h>
#include <math.h>  
#include "Sphere.cpp"
using namespace std;

Sphere sfera1(0, 0, 0, 1);
Sphere sfera2(5, 0, 0, 1);

void myinit(void);

void myinit(void)
{
    glEnable(GL_LIGHTING); // activare iluminare
    glEnable(GL_LIGHT0);    // activare sursa 0

    glDepthFunc(GL_LESS);
    glEnable(GL_DEPTH_TEST);
}

void  display(void)
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    sfera1.draw();
    sfera2.draw();
    glFlush();
}

void  myReshape(GLsizei w, GLsizei h)
{
    if (!h) return;
    glViewport(0, 0, w, h);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluPerspective(65.0, (GLfloat)w / (GLfloat)h, 1.0, 20.0);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    glRotated(25, 0.0, 1.0, 1.0);
    glTranslatef(0.0, -1.0, -6.0);
}

int main(int argc, char** argv)
{
    glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH);
    glutInitWindowSize(640, 640);
    glutInitWindowPosition(10, 10);
    glutCreateWindow("Programming Techniques - 3D Spheres");
    myinit();
    glutReshapeFunc(myReshape);
    glutDisplayFunc(display);
    while (!sfera1.colision(sfera2)){
        glutKeyboardFunc(sfera1.handleKeypress);
    }
    glutMainLoop();
    return(0);

}

Thx for help

Aucun commentaire:

Enregistrer un commentaire