Salut !

Je viens de bricoler une petite classe destinée à gérer une caméra avec OpenGL, mais j'ai une erreur que je ne comprends pas... Dans le fichier "camera.cpp", les références aux membres Camera::position ou Camera::orientation sont systèmatiquement indéfinies. Je vous présente mon code :

1 fichier entete.h qui déclare ma classe Camera et la petite hiérarchie de données Point :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
struct Point
{
    virtual Point& setX(float i) = 0;
    virtual Point& setY(float i) = 0;
};
 
struct Point2d: public Point
{
    float x;
    float y;
 
    Point& setX(float i);
    Point& setY(float i);
};
 
struct Point3d: public Point
{
    float x;
    float y;
    float z;
 
    Point& setX(float i);
    Point& setY(float i);
    Point& setZ(float i);
};
 
class Camera
{
    public:
        Camera(float x, float y, float z);
        ~Camera();
 
        static void setPosition(float x, float y, float z);
        static void setOrientation(float x, float y, float z);
        Camera& show();
    private:
        static Point3d position;
        static Point3d orientation;
};
Le fichier points.cpp, qui définit les structures de données Point2d et Point3d :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
/* structure Point2d */
 
Point& Point2d::setX(float i)
{
    this->x = i;
    return *this;
}
Point& Point2d::setY(float i)
{
    this->y = i;
    return *this;
}
 
/* structure Point3d */
 
Point& Point3d::setX(float i)
{
    this->x = i;
    return *this;
}
Point& Point3d::setY(float i)
{
    this->y = i;
    return *this;
}
Point& Point3d::setZ(float i)
{
    this->z = i;
    return *this;
}
Et le fichier problèmatique camera.cpp :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
Camera::Camera(float x, float y, float z)
{
    setPosition(x, y, z);
    setOrientation(0.0, 0.0, -100.0);
}
 
Camera::~Camera()
{ /* rien à détruire */
}
 
void Camera::setPosition(float x, float y, float z)
{
    Camera::position.x = x; /* références indéfinies */
    Camera::position.y = y;
    Camera::position.z = z;
}
 
void Camera::setOrientation(float x, float y, float z)
{
    Camera::orientation.x = x; /* références indéfinies */
    Camera::orientation.x = y;
    Camera::orientation.z = z;
}
 
Camera& Camera::show()
{
    gluLookAt(position.x, position.y, position.z, orientation.x, orientation.y, orientation.z, 0.0, 1.0, 0.0);
 
    return *this;
}
L'erreur exacte renvoyée est :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
--------------------------------------------------------------------------------
Switching to target: default
Compiling: main.cpp
Compiling: points.cpp
Compiling: camera.cpp
Linking executable: Test2D.exe
.objs\camera.o:camera.cpp:(.text+0x93): undefined reference to `Camera::position'
.objs\camera.o:camera.cpp:(.text+0x9b): undefined reference to `Camera::position'
.objs\camera.o:camera.cpp:(.text+0xa3): undefined reference to `Camera::position'
.objs\camera.o:camera.cpp:(.text+0xb1): undefined reference to `Camera::orientation'
.objs\camera.o:camera.cpp:(.text+0xb9): undefined reference to `Camera::orientation'
.objs\camera.o:camera.cpp:(.text+0xc1): undefined reference to `Camera::orientation'
.objs\camera.o:camera.cpp:(.text+0xe2): undefined reference to `Camera::orientation'
.objs\camera.o:camera.cpp:(.text+0xec): undefined reference to `Camera::orientation'
.objs\camera.o:camera.cpp:(.text+0xf6): more undefined references to `Camera::orientation' follow
.objs\camera.o:camera.cpp:(.text+0x100): undefined reference to `Camera::position'
.objs\camera.o:camera.cpp:(.text+0x10a): undefined reference to `Camera::position'
.objs\camera.o:camera.cpp:(.text+0x114): undefined reference to `Camera::position'
collect2: ld returned 1 exit status
Process terminated with status 1 (0 minutes, 6 seconds)
Et sinon, dois-je mettre dans le constructeur de la classe Camera :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
position = Point3d();
orientation = Point3d();
ou est-ce facultatif ?

Merci d'avance