Bonjour,

J'ai un problème avec le picking, ca marche seulement si l'objet reste à sa position initiale mais j'aimerais le déplacer vers une autre position. Lorsque je le déplace avec le glisser - déplacer et que je le dépose à un autre endroit, je ne peut plus le sélectionner par la suite, ca me donne aucun hit. J'ai beau faire de la boucanne avec le bouton de la souris, ca veut rien savoir.

Mais si je le sélectionne, je le déplace n'importe ou sans lâcher le bouton et que je le dépose à sa position initiale, je peut le sélectionner par la suite. C'est pas trop commode et pourtant le picking semble correct. Il y a surement de quoi que je fait que je ne voit pas.

Pouvez vous m'éclairer là dessus?

Voici le code en cause ( C# ) < Méthode pour la sélection >
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
private void Selection(double mouseX, double mouseY)
{
     uint[] buffer = new uint[512];
     int[] viewport = new int[4];
 
     GL.glGetIntegerv(GL.GL_VIEWPORT, viewport);  // Get viewport information
 
     GL.glSelectBuffer(512, buffer); // Indicate the buffer selection to use
     GL.glRenderMode(GL.GL_SELECT);  // Selection mode
 
     GL.glInitNames();
     GL.glPushName(0);
 
     GL.glMatrixMode(GL.GL_PROJECTION);
     GL.glPushMatrix();
     GL.glLoadIdentity();
 
     GLU.gluPickMatrix(mouseX, viewport[3] - mouseY , 1.0f, 1.0f, viewport);
     GLU.gluPerspective(45.0f, (viewport[2]-viewport[0])/viewport[3]-viewport[1], 0.1f, 4000.0f);
 
 
     GL.glMatrixMode(GL.GL_MODELVIEW);
     GL.glLoadIdentity();
 
     scene.DrawingSelectedObject();
 
     GL.glMatrixMode(GL.GL_PROJECTION);
     GL.glPopMatrix();
 
     GL.glMatrixMode(GL.GL_MODELVIEW);
 
     int nbHits = (int)GL.glRenderMode(GL.GL_RENDER);
 
     playerSelected = buffer[3];
 
 
}
<Méthode ou la sélection est appelé ( un click gauche ) >
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
private void MainWindow_MouseDown(object sender, MouseEventArgs e)
{
     if (e.Button == MouseButtons.Left)
     {
         /* Take only y value for horizontaly move*/
         lastMousePos[0] = (float)e.X;
         lastMousePos[1] = (float)e.Y;
 
         Selection(e.X, e.Y);
 
         if (playerSelected == 0)
             isRotationInY = true;
         else if(playerSelected > 0 )
                 move = true;
     }
}
< Classe scene ( gestion de mes objets ) >
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
class Scene
    {
        /* Member variable */
        private Plateau plateau;            // Game table
        private Hashtable pichenotteList;   // Contain all pichenotte
        private Pichenotte[] dogList;       // Contain all dog 
 
        /**********************************************************************
         * Constructor
         **/
        public Scene()
        {
            pichenotteList = new Hashtable();
            dogList = new Pichenotte[4];
        }
 
        /**********************************************************************
         * Load entire object of the scene
         **/
        public bool LoadScene()
        {
            /* Local variable */
            float[] position;
            double[] scale;
 
            /* Load the pichenotte table */
            position = new float[] {0.0f,0.0f,0.0f};
            scale = new double[] { 2.0, 2.0, 2.0 };
            plateau = new Plateau("TableJeu.ase", position, scale);
 
            /* Load the dog pichenottes */
            position = new float[] { 0.0f, 2.32f, 0.0f };
            scale = new double[] { 2.0, 2.0, 2.0 };
            Pichenotte dog = new Pichenotte("Pichenotte.ase", position, scale);
            dogList[0] = dog;    // Player 1
 
 
            return true;   // Success
        }
 
        /**********************************************************************
         * Get the object position
         **/
        public float[] GetPlayerPos(uint idPlayer)
        {
            Pichenotte dog = dogList[idPlayer - 1];
            return dog.VPos;
        }
 
        /**********************************************************************
         * Move the dog of the player x at new position
         **/
        public void MovePlayer(uint idPlayer, float x, float z)
        {
            Pichenotte dog = dogList[idPlayer - 1];
            dog.MoveTo( dog.PosX + x, dog.PosY, dog.PosZ + z);
        }
 
         /**********************************************************************
         * Draw entire object
         **/
        public void DrawScene()
        {
            /* Draw game table */
            plateau.Draw();
 
            /* Draw dog */
            //foreach (Pichenotte obj in dogList)
             //   obj.Draw();
            dogList[0].Draw();
 
            /* Draw pichenotte */
            foreach (Pichenotte obj in pichenotteList.Values)
                obj.Draw();
        }
 
        /**********************************************************************
         * Test
         **/
        public void DrawingSelectedObject()
        {
            /* Dog for the player 1 */
            GL.glLoadName(1);
            dogList[0].Draw();
 
            /* Dog for the player 2 */
 
            // if ( nbPlayer > 2 )
            /* Dog for the player 3 */
 
            /* Dog for the player 4 */
        }
 
        /**********************************************************************
        * Rotate a object
        **/
       /* public void YRotate(uint id, float angle)
        {
            BasicObject obj = (BasicObject)objectList[id];
            obj.YRotate(angle);
        }*/
    }
< Class Pichenotte ( l'objet en question ) >
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
class Pichenotte : BasicObject
    {
        /**********************************************************************
         * First constructor ( Load object with scaling information )
         **/
        public Pichenotte(String fileName, float[] position, double[] scale)
            : base(fileName, position, scale)
        {}
 
        /**********************************************************************
         * Second constructor ( Load object without scaling information )
         **/
        public Pichenotte(String fileName, float[] position)
            : base(fileName, position)
        {}
 
        /**********************************************************************
         * Draw the object
         **/
        public override void Draw()
        {
            GL.glPushMatrix();
            GL.glTranslatef(posX, posY, posZ);
            GL.glRotatef(xRot, 1.0f, 0.0f, 0.0f);
            GL.glRotatef(yRot, 0.0f, 1.0f, 0.0f);
            GL.glRotatef(zRot, 0.0f, 0.0f, 1.0f);
            if (isScaling)
                GL.glScaled(sX, sY, sZ);
 
            GL.glColor3f(0.9f, 0.7f, 0.0f);         // A ajuster la couleur
            obj.Draw();
 
            GL.glPopMatrix();
        }
    }
<Class BasicObjet >
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
abstract class BasicObject
    {
        /* Members variables */
        protected float posX, posY, posZ;   // Position
        protected float[] pos = new float[3];
        protected float xRot, yRot, zRot;   // Rotation
        protected double sX, sY, sZ;        // Scale     
        protected Object3D obj;             
 
        protected bool isScaling;           // He must modifying scale?
 
        /**********************************************************************
         * First constructor
         **/
        public BasicObject(String fileName, float[] position, double[] scale)
        {
            this.obj = Object3DLoader.Load(fileName);
 
            posX = position[0];
            posY = position[1];
            posZ = position[2];
 
            // test
            pos[0] = position[0];
            pos[1] = position[1];
            pos[2] = position[2];
 
            xRot = 0.0f;
            yRot = 0.0f;
            zRot = 0.0f;
 
            sX = scale[0];
            sY = scale[1];
            sZ = scale[2];
 
            isScaling = true;
        }
 
        /**********************************************************************
         * Second constructor
         **/
        public BasicObject(String fileName, float[] position)
        {
            this.obj = Object3DLoader.Load(fileName);
 
            posX = position[0];
            posY = position[1];
            posZ = position[2];
 
            // test
            pos[0] = position[0];
            pos[1] = position[1];
            pos[2] = position[2];
 
 
            xRot = 0.0f;
            yRot = 0.0f;
            zRot = 0.0f;
 
            sX = 1.0;
            sY = 1.0;
            sZ = 1.0;
 
            isScaling = false;
        }
 
        /**********************************************************************
         * Assessor
         **/
        public float PosX { get { return posX; } }
        public float PosY { get { return posY; } }
        public float PosZ { get { return posZ; } }
        public float RotX { get { return xRot; } }
        public float RotY { get { return yRot; } }
        public float RotZ { get { return zRot; } }
 
        // test
        public float[] VPos { get { return pos; } }
 
        /**********************************************************************
         * Draw the object ( Must be override )
         **/
        public abstract void Draw();
 
        /**********************************************************************
         * Move at position
         **/
        public void MoveTo(float x, float y, float z)
        {
            posX = x;
            posY = y;
            posZ = z;
 
            // test
            pos[0] = x;
            pos[1] = y;
            pos[2] = z;
        }
 
        /**********************************************************************
         * Rotate
         **/
        public void Rotate(float angleX, float angleY, float angleZ)
        {
            xRot = angleX;
            yRot = angleY;
            zRot = angleZ;
        }
 
        /**********************************************************************
         * Rotate around X
         **/
        public void XRotate(float angleX)
        {
            xRot = angleX;
        }
 
        /**********************************************************************
         * Rotate around Y
         **/
        public void YRotate(float angleY)
        {
            yRot = angleY;
        }
 
        /**********************************************************************
         * Rotate around Z
         **/
        public void ZRotate(float angleZ)
        {
            zRot = angleZ;
        }
 
        /**********************************************************************
         * Scaling
         **/
        public void Scale(double scaleX, double scaleY, double scaleZ)
        {
            sX = scaleX;
            sY = scaleY;
            sZ = scaleZ;
        }
    }
<class Object3D qui a été charger à partir d'un loader que je me suis fait >
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
40
41
42
43
44
45
46
47
48
49
class Object3D
    {
        /* Member variable */
        private ArrayList meshList;
 
        /**********************************************************************
         * Constructor
         **/
        public Object3D()
        {
            meshList = new ArrayList();
        }
 
        /**********************************************************************
         * Add a new mesh to object
         **/
        public void AddMesh(float[] vertices, float[] normales, uint[] inds)
        {
            meshList.Add(new Mesh(vertices,normales,inds));
        }
 
        //public Get
 
        /**********************************************************************
         * Draw the object
         **/
        public void Draw()
        {
            //GL.glEnable(GL.GL_NORMALIZE);
 
            foreach (Mesh mesh in meshList)
            {
                GL.glEnableClientState(GL.GL_VERTEX_ARRAY);
                GL.glEnableClientState(GL.GL_NORMAL_ARRAY);
 
                GL.glVertexPointer(3, GL.GL_FLOAT, 0, mesh.vertices);
                GL.glNormalPointer(GL.GL_FLOAT, 0, mesh.normales);
 
                GL.glDrawElements(GL.GL_TRIANGLES, mesh.vertexIndices.Length,
                                  GL.GL_UNSIGNED_int, mesh.vertexIndices);
 
                GL.glDisableClientState(GL.GL_VERTEX_ARRAY);
                GL.glDisableClientState(GL.GL_NORMAL_ARRAY);
            }
 
           // GL.glDisable(GL.GL_NORMALIZE);
 
        }
    }
Si vous désirez le code faite le moi savoir, je pourrais vous l'envoyer par courriel. C'est en C#

Merci