IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

OpenGL Discussion :

[VBO] positionner un VBO avec la souris


Sujet :

OpenGL

  1. #1
    Expert confirmé
    Avatar de GLDavid
    Homme Profil pro
    Service Delivery Manager
    Inscrit en
    Janvier 2003
    Messages
    2 852
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 47
    Localisation : France, Seine Saint Denis (Île de France)

    Informations professionnelles :
    Activité : Service Delivery Manager
    Secteur : Industrie Pharmaceutique

    Informations forums :
    Inscription : Janvier 2003
    Messages : 2 852
    Points : 4 759
    Points
    4 759
    Par défaut [VBO] positionner un VBO avec la souris
    Bonjour

    Je travaille sur un petit code demo où je cherche à afficher un carré en utilisant les VBO. Ensuite, je veux pouvoir "bouger" ce carré à l'aide de la souris. J'utilise Java6 et jogl 1.1.1. Voici mes codes. Le code MovingSquare.java contient la routine main et tout ce qu'il faut pour afficher et interagir avec la souris:
    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
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
     
    package demo;
     
     
    import com.sun.opengl.util.Animator;
    import com.sun.opengl.util.BufferUtil;
    import demo.geom.Square;
    import java.awt.BorderLayout;
    import java.awt.Point;
    import java.awt.event.MouseEvent;
    import java.awt.event.MouseListener;
    import java.awt.event.MouseMotionListener;
    import java.awt.event.MouseWheelEvent;
    import java.awt.event.MouseWheelListener;
    import java.nio.FloatBuffer;
    import java.nio.IntBuffer;
    import javax.media.opengl.GL;
    import javax.media.opengl.GLAutoDrawable;
    import javax.media.opengl.GLCanvas;
    import javax.media.opengl.GLCapabilities;
    import javax.media.opengl.GLEventListener;
    import javax.media.opengl.glu.GLU;
    import javax.swing.JFrame;
     
    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
    /**
     *
     * @author GLDavid
     */
    public class MovingSquare
            implements GLEventListener, MouseWheelListener, MouseMotionListener,
            MouseListener {
     
        private float zoom = -20;
        private Square square;
        private IntBuffer bufferName;
        private FloatBuffer positionData;
        private FloatBuffer colorData;
        private FloatBuffer falseColorData;
        private IntBuffer starts;
        private IntBuffer counts;
        private final int LIMIT = 3;
        private Point mousePosition;
        private boolean mustCheck;
        private static GLCanvas canvas;
     
        public MovingSquare() {
            this.square = new Square(0, 0, 0);
            this.bufferName = BufferUtil.newIntBuffer(LIMIT);
        }
     
        private void initDataBuffers(final GL gl){
            int i = 0;
            int j = 4;
            this.positionData.put(square.getBufferVertices());
            this.colorData.put(square.getBufferColor());
            this.falseColorData.position(square.sizeofBufferFalseColor());
            starts.put(i);
            counts.put(j);
            i = i + square.getBufferIndicesSize();
            j = square.getBufferIndicesSize();
            this.positionData.rewind();
            this.colorData.rewind();
            this.falseColorData.rewind();
        }
     
        private void pushNodesDataBuffers(final GL gl) {
            initDataBuffers(gl);
     
            gl.glBindBuffer(gl.GL_ARRAY_BUFFER, bufferName.get(0));
            gl.glBufferData(gl.GL_ARRAY_BUFFER,
                    this.square.sizeofBufferVertices() *
                    BufferUtil.SIZEOF_FLOAT,
                    positionData,
                    gl.GL_STREAM_DRAW);
            gl.glVertexPointer(3, gl.GL_FLOAT, 0, 0);
     
            gl.glBindBuffer(gl.GL_ARRAY_BUFFER, bufferName.get(1));
            gl.glBufferData(gl.GL_ARRAY_BUFFER,
                    this.square.sizeofBufferColor() *
                    BufferUtil.SIZEOF_FLOAT,
                    colorData,
                    gl.GL_STATIC_DRAW);
            gl.glColorPointer(4, gl.GL_FLOAT, 0, 0);
     
            gl.glBindBuffer(gl.GL_ARRAY_BUFFER, bufferName.get(2));
            gl.glBufferData(gl.GL_ARRAY_BUFFER,
                    this.square.sizeofBufferFalseColor() *
                    BufferUtil.SIZEOF_FLOAT,
                    falseColorData,
                    gl.GL_STATIC_DRAW);
            gl.glColorPointer(4, gl.GL_FLOAT, 0, 0);
     
            this.starts.rewind();
            this.counts.rewind();
        }
     
        public void init(GLAutoDrawable drawable) {
            final GL gl = drawable.getGL();
     
            drawable.addMouseWheelListener(this);
            drawable.addMouseMotionListener(this);
     
            gl.glShadeModel(gl.GL_SMOOTH);
            gl.glEnable(gl.GL_DEPTH_TEST);
     
            gl.glGenBuffers(LIMIT, bufferName);
     
            int constant = BufferUtil.SIZEOF_FLOAT;
            this.positionData = BufferUtil.newFloatBuffer(square.sizeofBufferVertices() * constant);
            this.colorData = BufferUtil.newFloatBuffer(square.sizeofBufferColor() * constant);
            this.falseColorData = BufferUtil.newFloatBuffer(square.sizeofBufferFalseColor() * constant);
            this.starts = BufferUtil.newIntBuffer(1);
            this.counts = BufferUtil.newIntBuffer(1);
     
            pushNodesDataBuffers(gl);
        }
     
        public void display(GLAutoDrawable drawable) {
            final GL gl = drawable.getGL();
            gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
            gl.glClearColor(1, 1, 1, 0);
     
            gl.glMatrixMode(gl.GL_MODELVIEW);
            gl.glLoadIdentity();
            gl.glTranslatef(0, 0, zoom);
     
            gl.glEnableClientState(GL.GL_VERTEX_ARRAY);
            gl.glEnableClientState(GL.GL_COLOR_ARRAY);
     
            gl.glBindBuffer(gl.GL_ARRAY_BUFFER, bufferName.get(0));
            gl.glVertexPointer(3, gl.GL_FLOAT, 0, 0);
            if(!mustCheck){
                gl.glBindBuffer(gl.GL_ARRAY_BUFFER, bufferName.get(1));
                gl.glColorPointer(4, gl.GL_FLOAT, 0, 0);
            }
            else{
                gl.glBindBuffer(gl.GL_ARRAY_BUFFER, bufferName.get(2));
                gl.glColorPointer(4, gl.GL_FLOAT, 0, 0);
            }
            gl.glMultiDrawArrays(gl.GL_QUADS, starts, counts, 1);
     
            if(mustCheck){
                checkFalseColor(gl);
            }
     
            gl.glFlush();
        }
     
        public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {
            final int maxZ = 1000;
            GL gl = drawable.getGL();
            gl.glViewport(0, 0, width, height);
            /*For the camera*/
            gl.glMatrixMode(gl.GL_PROJECTION);
            gl.glLoadIdentity();
            //Change this by glOrtho
            new GLU().gluPerspective(45., (float) width / height, 1., maxZ);
            /*Model & view*/
            gl.glMatrixMode(gl.GL_MODELVIEW);
            gl.glLoadIdentity();
        }
     
        public void displayChanged(GLAutoDrawable drawable, boolean modeChanged, boolean deviceChanged) {
        }
     
        public void mouseWheelMoved(MouseWheelEvent e) {
            if (e.getWheelRotation() > 0) {
                zoom += 0.5;
            } else {
                zoom -= 0.5;
            }
        }
     
        public void mouseDragged(MouseEvent e) {
            this.mousePosition = e.getPoint();
            mustCheck = true;
        }
     
        private boolean onNode(FloatBuffer fb){
            for(int i=0; i<3; i++){
                if(fb.get(i)!=0){
                    return false;
                }
            }
            return true;
        }
     
        private void moveNode(final GL gl) {
            final int constant = BufferUtil.SIZEOF_FLOAT;
            final int size = square.sizeofBufferVertices() * constant;
            this.square.changePosition(mousePosition.x, mousePosition.y, gl);
            gl.glBindBuffer(gl.GL_ARRAY_BUFFER, bufferName.get(0));
            gl.glBufferData(gl.GL_ARRAY_BUFFER,
                    size,
                    positionData,
                    gl.GL_STREAM_DRAW);
            FloatBuffer newPositions = square.getBufferVertices();
            gl.glBufferSubData(gl.GL_ARRAY_BUFFER, 0, size, newPositions);
        }
     
        private void checkFalseColor(final GL gl){
            int[]viewport = new int[4];
            gl.glGetIntegerv(GL.GL_VIEWPORT, viewport, 0);
            gl.glReadBuffer(GL.GL_BACK);
            FloatBuffer fb = BufferUtil.newFloatBuffer(3);
            gl.glPixelStorei (gl.GL_UNPACK_ALIGNMENT, 1);
            gl.glReadPixels(mousePosition.x, mousePosition.y, 1, 1, gl.GL_RGB,
                    gl.GL_FLOAT, fb);
            if(onNode(fb)){
                moveNode(gl);
            }
            mustCheck = false;
            canvas.display();
        }
     
        public static void main(String[] args) {
            GLCapabilities glc = new GLCapabilities();
            glc.setDoubleBuffered(true);
     
            canvas = new GLCanvas(glc);
            MovingSquare demo = new MovingSquare();
            canvas.addGLEventListener(demo);
            canvas.setAutoSwapBufferMode(true);
     
            final Animator animator = new Animator(canvas);
            animator.start();
     
            JFrame frame = new JFrame("Moving VBO square");
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.setLayout(new BorderLayout());
            canvas.setSize(400, 400);
            frame.add(canvas, BorderLayout.CENTER);
     
            frame.pack();
            frame.setVisible(true);
            canvas.requestFocus();
        }
     
        public void mouseMoved(MouseEvent arg0) {
        }
     
        public void mouseClicked(MouseEvent arg0) {
            throw new UnsupportedOperationException("Not supported yet.");
        }
     
        public void mousePressed(MouseEvent arg0) {
            throw new UnsupportedOperationException("Not supported yet.");
        }
     
        public void mouseReleased(MouseEvent arg0) {
            canvas.display();
        }
     
        public void mouseEntered(MouseEvent arg0) {
            throw new UnsupportedOperationException("Not supported yet.");
        }
     
        public void mouseExited(MouseEvent arg0) {
            throw new UnsupportedOperationException("Not supported yet.");
        }
    }
    Le code Square.java contient toutes les fonctions nécessaires pour dessiner un carré.
    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
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
     
    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
     
    package demo.geom;
     
    import com.sun.opengl.util.BufferUtil;
    import java.nio.ByteBuffer;
    import java.nio.FloatBuffer;
    import javax.media.opengl.GL;
    import javax.media.opengl.glu.GLU;
     
    /**
     *
     * @author GLDavid
     */
    public class Square {
     
        private final float side = 0.5f;
        private float x, y, z;
        final private byte[]indices = {0, 1, 2, 3};
        float[]coords;
        private int sizeOfBufferVertices;
        private FloatBuffer nodeVertices;
        private int sizeOfBufferColor;
        private FloatBuffer nodeColor;
        private ByteBuffer nodeIndices;
        private FloatBuffer nodeFalseColor;
        private int sizeOfBufferFalseColor;
     
        public Square(float x, float y, float z){
            setXY(x, y);
            this.z = z;
            setCoordinates();
            setupNodeVerticesBuffer();
            setupNodeColorBuffer();
            setupNodeFalseColorBuffer();
            setupNodeIndicesBuffer();
        }
     
        private void setXY(float x, float y){
            this.x = x;
            this.y = y;
        }
     
        private double[] convertIntoGL(final GL gl, double x, double y) {
            GLU glu = new GLU();
            int viewport[] = new int[4];
            double mvmatrix[] = new double[16];
            double projmatrix[] = new double[16];
            double wcoord[] = new double[4];// wx, wy, wz;// returned xyz coords
            gl.glGetIntegerv(GL.GL_VIEWPORT, viewport, 0);
            gl.glGetDoublev(GL.GL_MODELVIEW_MATRIX, mvmatrix, 0);
            gl.glGetDoublev(GL.GL_PROJECTION_MATRIX, projmatrix, 0);
            double realy = viewport[3] - (int) y - 1;
            glu.gluUnProject(x, realy, 0.0, mvmatrix, 0, projmatrix, 0, viewport, 0, wcoord, 0);
            return wcoord;
        }
     
        /**
         * Calculates the translation vector in 2D for two given points
         * @param xA X coordinate of the first point
         * @param yA Y coordinate of the first point
         * @param xB X coordinate of the second point
         * @param yB Y coordinate of the second point
         * @return an array of two float which is the translation vector
         */
        private float[] getTranslationVector(
                float xA,
                float yA,
                float xB,
                float yB) {
            float[] vector = new float[2];
            vector[0] = xB - xA;
            vector[1] = yB - yA;
            return vector;
        }
     
        public void changePosition(float x, float y, final GL gl){
            double[]coord = convertIntoGL(gl, x, y);
            float[]vector = getTranslationVector(this.x, this.y, (float)coord[0], (float)coord[1]);
            setXY(vector[0], vector[1]);
            setCoordinates();
            setupNodeVerticesBuffer();
        }
     
        public FloatBuffer getBufferVertices(){
            return this.nodeVertices;
        }
     
        public int sizeofBufferVertices(){
            return this.sizeOfBufferVertices;
        }
     
        public FloatBuffer getBufferColor(){
            return this.nodeColor;
        }
     
        public FloatBuffer getBufferFalseColor(){
            return this.nodeFalseColor;
        }
     
        public int sizeofBufferColor(){
            return this.sizeOfBufferColor;
        }
     
        public int sizeofBufferFalseColor(){
            return this.sizeOfBufferFalseColor;
        }
     
        public int getBufferIndicesSize(){
            return this.indices.length;
        }
     
        private void setCoordinates(){
            coords = new float[12];
            coords[0] = x-side;
            coords[1] = y+side;
            coords[2] = z;
            coords[3] = x+side;
            coords[4] = y+side;
            coords[5] = z;
            coords[6] = x+side;
            coords[7] = y-side;
            coords[8] = z;
            coords[9] = x-side;
            coords[10] = y-side;
            coords[11] = z;
        }
     
        private void setupNodeVerticesBuffer(){
            int bufferVerticesSize = coords.length;
            this.sizeOfBufferVertices = bufferVerticesSize * BufferUtil.SIZEOF_FLOAT;
            nodeVertices = BufferUtil.newFloatBuffer(bufferVerticesSize);
            nodeVertices.put(coords);
            nodeVertices.rewind();
        }
     
        private void setupNodeColorBuffer(){
            float[]colorComponds = {1, 0, 0, 0};
            int bufferColorSize = colorComponds.length * this.indices.length;
            this.sizeOfBufferColor = bufferColorSize * BufferUtil.SIZEOF_FLOAT;
            float[]allColorComponds = new float[bufferColorSize];
            int j=0;
            for(int i=0; i<allColorComponds.length; i++){
                allColorComponds[i] = colorComponds[j++];
                if(j==colorComponds.length){
                    j=0;
                }
            }
            nodeColor = BufferUtil.newFloatBuffer(allColorComponds.
                    length);
            nodeColor.put(allColorComponds);
            nodeColor.rewind();
        }
     
        private void setupNodeFalseColorBuffer(){
            float[]colorComponds = {0, 0, 0, 0};
            int bufferColorSize = colorComponds.length * this.indices.length;
            this.sizeOfBufferFalseColor = bufferColorSize * BufferUtil.SIZEOF_FLOAT;
            float[]allColorComponds = new float[bufferColorSize];
            int j=0;
            for(int i=0; i<allColorComponds.length; i++){
                allColorComponds[i] = colorComponds[j++];
                if(j==colorComponds.length){
                    j=0;
                }
            }
            nodeFalseColor = BufferUtil.newFloatBuffer(allColorComponds.
                    length);
            nodeFalseColor.put(allColorComponds);
            nodeFalseColor.rewind();
        }
     
        private void setupNodeIndicesBuffer(){
            nodeIndices = BufferUtil.newByteBuffer(this.indices.length);
            nodeIndices.put(this.indices);
            nodeIndices.rewind();
        }
     
    }
    Tout compile correctement et à l'exécution, tout s'affiche bien. Le problème est que lorsque je bouge mon carré avec la souris, celui-ci ne bouge qu'infiniment peu !
    Quelqu'un saurait-il me conseiller sur ce problème ?

    Merci d'avance.

    @++
    GLDavid
    Consultez la FAQ Perl ainsi que mes cours de Perl.
    N'oubliez pas les balises code ni le tag

    Je ne répond à aucune question technique par MP.

  2. #2
    Expert confirmé
    Avatar de GLDavid
    Homme Profil pro
    Service Delivery Manager
    Inscrit en
    Janvier 2003
    Messages
    2 852
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 47
    Localisation : France, Seine Saint Denis (Île de France)

    Informations professionnelles :
    Activité : Service Delivery Manager
    Secteur : Industrie Pharmaceutique

    Informations forums :
    Inscription : Janvier 2003
    Messages : 2 852
    Points : 4 759
    Points
    4 759
    Par défaut
    Un petit update. J'avais deux sources potentiels d'erreurs à vérifier:
    1) mauvaise gestion de la souris
    2) appel à glBufferSubData mal effectué.
    Pour vérifier le numéro 2, j'ai modifié mon code comme ce qui suit.
    Code MovingSquare.java:
    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
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
     
    package demo;
     
     
    import com.sun.opengl.util.Animator;
    import com.sun.opengl.util.BufferUtil;
    import demo.geom.Square;
    import java.awt.BorderLayout;
    import java.awt.Point;
    import java.awt.event.KeyEvent;
    import java.awt.event.KeyListener;
    import java.awt.event.MouseEvent;
    import java.awt.event.MouseListener;
    import java.awt.event.MouseMotionListener;
    import java.awt.event.MouseWheelEvent;
    import java.awt.event.MouseWheelListener;
    import java.nio.FloatBuffer;
    import java.nio.IntBuffer;
    import javax.media.opengl.GL;
    import javax.media.opengl.GLAutoDrawable;
    import javax.media.opengl.GLCanvas;
    import javax.media.opengl.GLCapabilities;
    import javax.media.opengl.GLEventListener;
    import javax.media.opengl.glu.GLU;
    import javax.swing.JFrame;
     
    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
    /**
     *
     * @author GLDavid
     */
    public class MovingSquare
            implements GLEventListener, MouseWheelListener, MouseMotionListener,
            MouseListener, KeyListener {
     
        private float zoom = -20;
        private Square square;
        private IntBuffer bufferName;
        private FloatBuffer positionData;
        private FloatBuffer colorData;
        private FloatBuffer falseColorData;
        private IntBuffer starts;
        private IntBuffer counts;
        private final int LIMIT = 3;
        private Point mousePosition;
        private boolean mustCheck;
        private static GLCanvas canvas;
        private float x, y, z;
        private boolean keyPressed;
     
        public MovingSquare() {
            this.square = new Square(x, y, z);
            this.bufferName = BufferUtil.newIntBuffer(LIMIT);
        }
     
        private void initDataBuffers(final GL gl){
            int i = 0;
            int j = 4;
            this.positionData.put(square.getBufferVertices());
            this.colorData.put(square.getBufferColor());
            this.falseColorData.position(square.sizeofBufferFalseColor());
            starts.put(i);
            counts.put(j);
            i = i + square.getBufferIndicesSize();
            j = square.getBufferIndicesSize();
            this.positionData.rewind();
            this.colorData.rewind();
            this.falseColorData.rewind();
        }
     
        private void pushNodesDataBuffers(final GL gl) {
            initDataBuffers(gl);
     
            gl.glBindBuffer(gl.GL_ARRAY_BUFFER, bufferName.get(0));
            gl.glBufferData(gl.GL_ARRAY_BUFFER,
                    this.square.sizeofBufferVertices() *
                    BufferUtil.SIZEOF_FLOAT,
                    positionData,
                    gl.GL_STREAM_DRAW);
            gl.glVertexPointer(3, gl.GL_FLOAT, 0, 0);
     
            gl.glBindBuffer(gl.GL_ARRAY_BUFFER, bufferName.get(1));
            gl.glBufferData(gl.GL_ARRAY_BUFFER,
                    this.square.sizeofBufferColor() *
                    BufferUtil.SIZEOF_FLOAT,
                    colorData,
                    gl.GL_STATIC_DRAW);
            gl.glColorPointer(4, gl.GL_FLOAT, 0, 0);
     
            gl.glBindBuffer(gl.GL_ARRAY_BUFFER, bufferName.get(2));
            gl.glBufferData(gl.GL_ARRAY_BUFFER,
                    this.square.sizeofBufferFalseColor() *
                    BufferUtil.SIZEOF_FLOAT,
                    falseColorData,
                    gl.GL_STATIC_DRAW);
            gl.glColorPointer(4, gl.GL_FLOAT, 0, 0);
     
            this.starts.rewind();
            this.counts.rewind();
        }
     
        public void init(GLAutoDrawable drawable) {
            final GL gl = drawable.getGL();
     
            drawable.addMouseWheelListener(this);
            drawable.addMouseMotionListener(this);
            drawable.addMouseListener(this);
            drawable.addKeyListener(this);
     
            gl.glShadeModel(gl.GL_SMOOTH);
            gl.glEnable(gl.GL_DEPTH_TEST);
     
            gl.glGenBuffers(LIMIT, bufferName);
     
            int constant = BufferUtil.SIZEOF_FLOAT;
            this.positionData = BufferUtil.newFloatBuffer(square.sizeofBufferVertices() * constant);
            this.colorData = BufferUtil.newFloatBuffer(square.sizeofBufferColor() * constant);
            this.falseColorData = BufferUtil.newFloatBuffer(square.sizeofBufferFalseColor() * constant);
            this.starts = BufferUtil.newIntBuffer(1);
            this.counts = BufferUtil.newIntBuffer(1);
     
            pushNodesDataBuffers(gl);
        }
     
        public void display(GLAutoDrawable drawable) {
            final GL gl = drawable.getGL();
            gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
            gl.glClearColor(1, 1, 1, 0);
     
            gl.glMatrixMode(gl.GL_MODELVIEW);
            gl.glLoadIdentity();
            gl.glTranslatef(0, 0, zoom);
     
            gl.glEnableClientState(GL.GL_VERTEX_ARRAY);
            gl.glEnableClientState(GL.GL_COLOR_ARRAY);
     
            if(keyPressed){
                moveNodeKeyboard(gl);
            }
     
            gl.glBindBuffer(gl.GL_ARRAY_BUFFER, bufferName.get(0));
            gl.glVertexPointer(3, gl.GL_FLOAT, 0, 0);
            if(!mustCheck){
                gl.glBindBuffer(gl.GL_ARRAY_BUFFER, bufferName.get(1));
                gl.glColorPointer(4, gl.GL_FLOAT, 0, 0);
            }
            else{
                gl.glBindBuffer(gl.GL_ARRAY_BUFFER, bufferName.get(2));
                gl.glColorPointer(4, gl.GL_FLOAT, 0, 0);
            }
            gl.glMultiDrawArrays(gl.GL_QUADS, starts, counts, 1);
     
            if(mustCheck){
                checkFalseColor(gl);
            }
     
            gl.glFlush();
        }
     
        public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {
            final int maxZ = 1000;
            GL gl = drawable.getGL();
            gl.glViewport(0, 0, width, height);
            /*For the camera*/
            gl.glMatrixMode(gl.GL_PROJECTION);
            gl.glLoadIdentity();
            //Change this by glOrtho
            new GLU().gluPerspective(45., (float) width / height, 1., maxZ);
            /*Model & view*/
            gl.glMatrixMode(gl.GL_MODELVIEW);
            gl.glLoadIdentity();
        }
     
        public void displayChanged(GLAutoDrawable drawable, boolean modeChanged, boolean deviceChanged) {
        }
     
        public void mouseWheelMoved(MouseWheelEvent e) {
            if (e.getWheelRotation() > 0) {
                zoom += 0.5;
            } else {
                zoom -= 0.5;
            }
        }
     
        public void mouseDragged(MouseEvent e) {
            this.mousePosition = e.getPoint();
            mustCheck = true;
        }
     
        private boolean onNode(FloatBuffer fb){
            for(int i=0; i<3; i++){
                if(fb.get(i)!=0){
                    return false;
                }
            }
            return true;
        }
     
        private void moveNode(final GL gl) {
            final int constant = BufferUtil.SIZEOF_FLOAT;
            final int size = square.sizeofBufferVertices() * constant;
            this.square.changePosition(mousePosition.x, mousePosition.y, true, gl);
            gl.glBindBuffer(gl.GL_ARRAY_BUFFER, bufferName.get(0));
            gl.glBufferData(gl.GL_ARRAY_BUFFER,
                    size,
                    positionData,
                    gl.GL_STREAM_DRAW);
            FloatBuffer newPositions = square.getBufferVertices();
            gl.glBufferSubData(gl.GL_ARRAY_BUFFER, 0, size, newPositions);
        }
     
        private void moveNodeKeyboard(final GL gl){
            final int constant = BufferUtil.SIZEOF_FLOAT;
            final int size = square.sizeofBufferVertices() * constant;
            this.square.changePosition(x, y, false, gl);
            gl.glBindBuffer(gl.GL_ARRAY_BUFFER, bufferName.get(0));
            gl.glBufferData(gl.GL_ARRAY_BUFFER,
                    size,
                    positionData,
                    gl.GL_STREAM_DRAW);
            FloatBuffer newPositions = square.getBufferVertices();
            gl.glBufferSubData(gl.GL_ARRAY_BUFFER, 0, size, newPositions);
        }
     
        private void checkFalseColor(final GL gl){
            int[]viewport = new int[4];
            gl.glGetIntegerv(GL.GL_VIEWPORT, viewport, 0);
            gl.glReadBuffer(GL.GL_BACK);
            FloatBuffer fb = BufferUtil.newFloatBuffer(3);
            gl.glPixelStorei (gl.GL_UNPACK_ALIGNMENT, 1);
            gl.glReadPixels(mousePosition.x, mousePosition.y, 1, 1, gl.GL_RGB,
                    gl.GL_FLOAT, fb);
            if(onNode(fb)){
                moveNode(gl);
            }
            mustCheck = false;
            canvas.display();
        }
     
        public static void main(String[] args) {
            GLCapabilities glc = new GLCapabilities();
            glc.setDoubleBuffered(true);
     
            canvas = new GLCanvas(glc);
            MovingSquare demo = new MovingSquare();
            canvas.addGLEventListener(demo);
            canvas.setAutoSwapBufferMode(true);
     
            final Animator animator = new Animator(canvas);
            animator.start();
     
            JFrame frame = new JFrame("Moving VBO square");
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.setLayout(new BorderLayout());
            canvas.setSize(400, 400);
            frame.add(canvas, BorderLayout.CENTER);
     
            frame.pack();
            frame.setVisible(true);
            canvas.requestFocus();
        }
     
        public void mouseMoved(MouseEvent arg0) {
        }
     
        public void mouseClicked(MouseEvent arg0) {
        }
     
        public void mousePressed(MouseEvent arg0) {
        }
     
        public void mouseReleased(MouseEvent arg0) {
            canvas.display();
        }
     
        public void mouseEntered(MouseEvent arg0) {
        }
     
        public void mouseExited(MouseEvent arg0) {
        }
     
        public void keyTyped(KeyEvent e) {
        }
     
        public void keyPressed(KeyEvent e) {
            final float length = 0.05f;
            switch(e.getKeyCode()){
                case KeyEvent.VK_DOWN:{
                    y-=length;
                }break;
                case KeyEvent.VK_UP:{
                    y+=length;
                }break;
                case KeyEvent.VK_LEFT:{
                    x-=length;
                }break;
                case KeyEvent.VK_RIGHT:{
                    x+=length;
                }break;
            }
            keyPressed = true;
            canvas.display();
        }
     
        public void keyReleased(KeyEvent e) {
            keyPressed = false;
        }
    }
    Code Square.java:
    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
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
     
    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
     
    package demo.geom;
     
    import com.sun.opengl.util.BufferUtil;
    import java.nio.ByteBuffer;
    import java.nio.FloatBuffer;
    import javax.media.opengl.GL;
    import javax.media.opengl.glu.GLU;
     
    /**
     *
     * @author GLDavid
     */
    public class Square {
     
        private final float side = 0.5f;
        private float x, y, z;
        final private byte[]indices = {0, 1, 2, 3};
        float[]coords;
        private int sizeOfBufferVertices;
        private FloatBuffer nodeVertices;
        private int sizeOfBufferColor;
        private FloatBuffer nodeColor;
        private ByteBuffer nodeIndices;
        private FloatBuffer nodeFalseColor;
        private int sizeOfBufferFalseColor;
     
        public Square(float x, float y, float z){
            setXY(x, y);
            this.z = z;
            setCoordinates();
            setupNodeVerticesBuffer();
            setupNodeColorBuffer();
            setupNodeFalseColorBuffer();
            setupNodeIndicesBuffer();
        }
     
        private void setXY(float x, float y){
            this.x = x;
            this.y = y;
        }
     
        private double[] convertIntoGL(final GL gl, double x, double y) {
            GLU glu = new GLU();
            int viewport[] = new int[4];
            double mvmatrix[] = new double[16];
            double projmatrix[] = new double[16];
            double wcoord[] = new double[4];// wx, wy, wz;// returned xyz coords
            gl.glGetIntegerv(GL.GL_VIEWPORT, viewport, 0);
            gl.glGetDoublev(GL.GL_MODELVIEW_MATRIX, mvmatrix, 0);
            gl.glGetDoublev(GL.GL_PROJECTION_MATRIX, projmatrix, 0);
            double realy = viewport[3] - (int) y - 1;
            glu.gluUnProject(x, realy, 0.0, mvmatrix, 0, projmatrix, 0, viewport, 0, wcoord, 0);
            return wcoord;
        }
     
        /**
         * Calculates the translation vector in 2D for two given points
         * @param xA X coordinate of the first point
         * @param yA Y coordinate of the first point
         * @param xB X coordinate of the second point
         * @param yB Y coordinate of the second point
         * @return an array of two float which is the translation vector
         */
        private float[] getTranslationVector(
                float xA,
                float yA,
                float xB,
                float yB) {
            float[] vector = new float[2];
            vector[0] = xB - xA;
            vector[1] = yB - yA;
            return vector;
        }
     
        public void changePosition(float x, float y, boolean convert, final GL gl){
            if(convert){
                double[]coord = convertIntoGL(gl, x, y);
                float[]vector = getTranslationVector(this.x, this.y, (float)coord[0], (float)coord[1]);
                setXY(vector[0], vector[1]);
            }
            else{
                setXY(x, y);
            }
            setCoordinates();
            setupNodeVerticesBuffer();
        }
     
        public FloatBuffer getBufferVertices(){
            return this.nodeVertices;
        }
     
        public int sizeofBufferVertices(){
            return this.sizeOfBufferVertices;
        }
     
        public FloatBuffer getBufferColor(){
            return this.nodeColor;
        }
     
        public FloatBuffer getBufferFalseColor(){
            return this.nodeFalseColor;
        }
     
        public int sizeofBufferColor(){
            return this.sizeOfBufferColor;
        }
     
        public int sizeofBufferFalseColor(){
            return this.sizeOfBufferFalseColor;
        }
     
        public int getBufferIndicesSize(){
            return this.indices.length;
        }
     
        private void setCoordinates(){
            coords = new float[12];
            coords[0] = x-side;
            coords[1] = y+side;
            coords[2] = z;
            coords[3] = x+side;
            coords[4] = y+side;
            coords[5] = z;
            coords[6] = x+side;
            coords[7] = y-side;
            coords[8] = z;
            coords[9] = x-side;
            coords[10] = y-side;
            coords[11] = z;
        }
     
        private void setupNodeVerticesBuffer(){
            int bufferVerticesSize = coords.length;
            this.sizeOfBufferVertices = bufferVerticesSize * BufferUtil.SIZEOF_FLOAT;
            nodeVertices = BufferUtil.newFloatBuffer(bufferVerticesSize);
            nodeVertices.put(coords);
            nodeVertices.rewind();
        }
     
        private void setupNodeColorBuffer(){
            float[]colorComponds = {1, 0, 0, 0};
            int bufferColorSize = colorComponds.length * this.indices.length;
            this.sizeOfBufferColor = bufferColorSize * BufferUtil.SIZEOF_FLOAT;
            float[]allColorComponds = new float[bufferColorSize];
            int j=0;
            for(int i=0; i<allColorComponds.length; i++){
                allColorComponds[i] = colorComponds[j++];
                if(j==colorComponds.length){
                    j=0;
                }
            }
            nodeColor = BufferUtil.newFloatBuffer(allColorComponds.
                    length);
            nodeColor.put(allColorComponds);
            nodeColor.rewind();
        }
     
        private void setupNodeFalseColorBuffer(){
            float[]colorComponds = {0, 0, 0, 0};
            int bufferColorSize = colorComponds.length * this.indices.length;
            this.sizeOfBufferFalseColor = bufferColorSize * BufferUtil.SIZEOF_FLOAT;
            float[]allColorComponds = new float[bufferColorSize];
            int j=0;
            for(int i=0; i<allColorComponds.length; i++){
                allColorComponds[i] = colorComponds[j++];
                if(j==colorComponds.length){
                    j=0;
                }
            }
            nodeFalseColor = BufferUtil.newFloatBuffer(allColorComponds.
                    length);
            nodeFalseColor.put(allColorComponds);
            nodeFalseColor.rewind();
        }
     
        private void setupNodeIndicesBuffer(){
            nodeIndices = BufferUtil.newByteBuffer(this.indices.length);
            nodeIndices.put(this.indices);
            nodeIndices.rewind();
        }
     
    }
    Evidemment, ça fonctionne au clavier. Moralité, j'ai mal fait ma gestion de souris. Je pense proposer un code sous peu fonctionnel aussi bien au clavier qu'à la souris.

    @++
    GLDavid
    Consultez la FAQ Perl ainsi que mes cours de Perl.
    N'oubliez pas les balises code ni le tag

    Je ne répond à aucune question technique par MP.

  3. #3
    Expert confirmé
    Avatar de GLDavid
    Homme Profil pro
    Service Delivery Manager
    Inscrit en
    Janvier 2003
    Messages
    2 852
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 47
    Localisation : France, Seine Saint Denis (Île de France)

    Informations professionnelles :
    Activité : Service Delivery Manager
    Secteur : Industrie Pharmaceutique

    Informations forums :
    Inscription : Janvier 2003
    Messages : 2 852
    Points : 4 759
    Points
    4 759
    Par défaut
    Apparemment, il y a une mauvaise gestion de la souris. J'ai toujours ce déplacement microscopique et qui ne dure pas.
    Si vous avez des idées, n'hésitez pas

    @++
    GLDavid
    Consultez la FAQ Perl ainsi que mes cours de Perl.
    N'oubliez pas les balises code ni le tag

    Je ne répond à aucune question technique par MP.

  4. #4
    Invité
    Invité(e)
    Par défaut
    Es-tu encore bloqué? Je vais jeter un coup d'oeil à ton code source tout de suite.

    Edit.: j'ai un doute sur ta méthode convertIntoGL.

  5. #5
    Expert confirmé
    Avatar de GLDavid
    Homme Profil pro
    Service Delivery Manager
    Inscrit en
    Janvier 2003
    Messages
    2 852
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 47
    Localisation : France, Seine Saint Denis (Île de France)

    Informations professionnelles :
    Activité : Service Delivery Manager
    Secteur : Industrie Pharmaceutique

    Informations forums :
    Inscription : Janvier 2003
    Messages : 2 852
    Points : 4 759
    Points
    4 759
    Par défaut
    Salut

    Hélas, je le suis toujours
    Mon code n'a que peu bougé donc, pas de souci pour que tu travailles dessus.
    En tout cas, merci de ton aide, j'apprécie beaucoup.
    Bon courage.

    @++
    GLDavid
    Consultez la FAQ Perl ainsi que mes cours de Perl.
    N'oubliez pas les balises code ni le tag

    Je ne répond à aucune question technique par MP.

  6. #6
    Invité
    Invité(e)
    Par défaut
    Les paramètres passés à gluUnproject semble corrects. Je continue de chercher. Sinon, tu peux essayer de voir comment c'est implémenté dans certains moteurs 3D écrits en Java (JMonkeyEngine 2.0, Ardor3D, Xith3D, 3dzzd, ...).

  7. #7
    Expert confirmé
    Avatar de GLDavid
    Homme Profil pro
    Service Delivery Manager
    Inscrit en
    Janvier 2003
    Messages
    2 852
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 47
    Localisation : France, Seine Saint Denis (Île de France)

    Informations professionnelles :
    Activité : Service Delivery Manager
    Secteur : Industrie Pharmaceutique

    Informations forums :
    Inscription : Janvier 2003
    Messages : 2 852
    Points : 4 759
    Points
    4 759
    Par défaut
    Hello

    Merci de ton aide. As-tu des valeurs à suggérer pour l'appel à gluUnproject ?
    Sinon, je vais tâcher de regarder dans les références que tu cites.
    Encore merci pour ton aide, on se tient au courant.

    @++
    GLDavid
    Consultez la FAQ Perl ainsi que mes cours de Perl.
    N'oubliez pas les balises code ni le tag

    Je ne répond à aucune question technique par MP.

  8. #8
    Expert confirmé
    Avatar de GLDavid
    Homme Profil pro
    Service Delivery Manager
    Inscrit en
    Janvier 2003
    Messages
    2 852
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 47
    Localisation : France, Seine Saint Denis (Île de France)

    Informations professionnelles :
    Activité : Service Delivery Manager
    Secteur : Industrie Pharmaceutique

    Informations forums :
    Inscription : Janvier 2003
    Messages : 2 852
    Points : 4 759
    Points
    4 759
    Par défaut
    Bonjour

    Un petit update de mon code. Donc, maintenant, je déplace à la souris (super !) mais le déplacement de mon carré est opposé à celu ide la souris
    Voici le code:
    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
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
    353
    354
    355
    356
    357
    358
    359
    360
    361
    362
    363
    364
    365
    366
    367
    368
    369
    370
    371
    372
    373
    374
    375
     
    package demo;
     
     
    import com.sun.opengl.util.Animator;
    import com.sun.opengl.util.BufferUtil;
    import com.bioxpr.demo.geom.Square;
    import java.awt.BorderLayout;
    import java.awt.Point;
    import java.awt.event.KeyEvent;
    import java.awt.event.KeyListener;
    import java.awt.event.MouseEvent;
    import java.awt.event.MouseListener;
    import java.awt.event.MouseMotionListener;
    import java.awt.event.MouseWheelEvent;
    import java.awt.event.MouseWheelListener;
    import java.nio.ByteBuffer;
    import java.nio.FloatBuffer;
    import java.nio.IntBuffer;
    import java.util.Arrays;
    import javax.media.opengl.GL;
    import javax.media.opengl.GLAutoDrawable;
    import javax.media.opengl.GLCanvas;
    import javax.media.opengl.GLCapabilities;
    import javax.media.opengl.GLEventListener;
    import javax.media.opengl.glu.GLU;
    import javax.swing.JFrame;
     
    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
    /**
     *
     * @author GLDavid
     */
    public class MovingSquare
            implements GLEventListener, MouseWheelListener, MouseMotionListener,
            MouseListener, KeyListener {
     
        private float zoom = -20;
        private Square square;
        private IntBuffer bufferName;
        private FloatBuffer positionData;
        private FloatBuffer colorData;
        private FloatBuffer falseColorData;
        private IntBuffer starts;
        private IntBuffer counts;
        private final int LIMIT = 3;
        private Point mousePosition;
        private static GLCanvas canvas;
        private float x, y, z;
        private boolean keyPressed;
        private boolean mouseOnNode;
        private int key;
     
        public MovingSquare() {
            this.square = new Square(x, y, z);
            this.bufferName = BufferUtil.newIntBuffer(LIMIT);
        }
     
        private void initDataBuffers(final GL gl){
            int i = 0;
            int j = 4;
            this.positionData.put(square.getBufferVertices());
            this.colorData.put(square.getBufferColor());
            this.falseColorData.position(square.sizeofBufferFalseColor());
            starts.put(i);
            counts.put(j);
            i = i + square.getBufferIndicesSize();
            j = square.getBufferIndicesSize();
            this.positionData.rewind();
            this.colorData.rewind();
            this.falseColorData.rewind();
        }
     
        private void pushNodesDataBuffers(final GL gl) {
            initDataBuffers(gl);
     
            gl.glBindBuffer(gl.GL_ARRAY_BUFFER, bufferName.get(0));
            gl.glBufferData(gl.GL_ARRAY_BUFFER,
                    this.square.sizeofBufferVertices() *
                    BufferUtil.SIZEOF_FLOAT,
                    positionData,
                    gl.GL_STREAM_DRAW);
            gl.glVertexPointer(3, gl.GL_FLOAT, 0, 0);
     
            gl.glBindBuffer(gl.GL_ARRAY_BUFFER, bufferName.get(1));
            gl.glBufferData(gl.GL_ARRAY_BUFFER,
                    this.square.sizeofBufferColor() *
                    BufferUtil.SIZEOF_FLOAT,
                    colorData,
                    gl.GL_STATIC_DRAW);
            gl.glColorPointer(4, gl.GL_FLOAT, 0, 0);
     
            gl.glBindBuffer(gl.GL_ARRAY_BUFFER, bufferName.get(2));
            gl.glBufferData(gl.GL_ARRAY_BUFFER,
                    this.square.sizeofBufferFalseColor() *
                    BufferUtil.SIZEOF_FLOAT,
                    falseColorData,
                    gl.GL_STATIC_DRAW);
            gl.glColorPointer(4, gl.GL_FLOAT, 0, 0);
     
            this.starts.rewind();
            this.counts.rewind();
        }
     
        public void init(GLAutoDrawable drawable) {
            final GL gl = drawable.getGL();
     
            drawable.addMouseWheelListener(this);
            drawable.addMouseMotionListener(this);
            drawable.addMouseListener(this);
            drawable.addKeyListener(this);
     
            gl.glShadeModel(gl.GL_SMOOTH);
            gl.glEnable(gl.GL_DEPTH_TEST);
     
            gl.glGenBuffers(LIMIT, bufferName);
     
            int constant = BufferUtil.SIZEOF_FLOAT;
            this.positionData = BufferUtil.newFloatBuffer(square.sizeofBufferVertices() * constant);
            this.colorData = BufferUtil.newFloatBuffer(square.sizeofBufferColor() * constant);
            this.falseColorData = BufferUtil.newFloatBuffer(square.sizeofBufferFalseColor() * constant);
            this.starts = BufferUtil.newIntBuffer(1);
            this.counts = BufferUtil.newIntBuffer(1);
     
            pushNodesDataBuffers(gl);
        }
     
        private void displayTrueColor(final GL gl){
            gl.glBindBuffer(gl.GL_ARRAY_BUFFER, bufferName.get(0));
            gl.glVertexPointer(3, gl.GL_FLOAT, 0, 0);
            gl.glBindBuffer(gl.GL_ARRAY_BUFFER, bufferName.get(1));
            gl.glColorPointer(4, gl.GL_FLOAT, 0, 0);
            gl.glMultiDrawArrays(gl.GL_QUADS, starts, counts, 1);
        }
     
        public void display(GLAutoDrawable drawable) {
            final GL gl = drawable.getGL();
            gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
            gl.glClearColor(1, 1, 1, 0);
     
            gl.glMatrixMode(gl.GL_MODELVIEW);
            gl.glLoadIdentity();
            gl.glTranslatef(0, 0, zoom);
     
            gl.glEnableClientState(GL.GL_VERTEX_ARRAY);
            gl.glEnableClientState(GL.GL_COLOR_ARRAY);
     
            System.out.println(mouseOnNode);
     
            if(keyPressed){
                moveNodeKeyboard(gl);
            }
            else {
                displayTrueColor(gl);
                if(mousePosition!=null){
                    if(!mouseOnNode){
                        mouseOnNode = checkTrueColor(gl);
                    }
                    else {
                        moveNodeMouse(gl);
                    }
                }
            }
     
            displayTrueColor(gl);
     
            gl.glDisableClientState(GL.GL_VERTEX_ARRAY);
            gl.glDisableClientState(GL.GL_COLOR_ARRAY);
     
            gl.glPointSize(2f);
            gl.glColor3f(0, 0, 0);
            gl.glBegin(gl.GL_POINT);
            gl.glVertex3f(0, 1, 0);
            gl.glEnd();
     
            gl.glFlush();
        }
     
        public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {
            final int maxZ = 1000;
            GL gl = drawable.getGL();
            gl.glViewport(0, 0, width, height);
            /*For the camera*/
            gl.glMatrixMode(gl.GL_PROJECTION);
            gl.glLoadIdentity();
            //Change this by glOrtho
            new GLU().gluPerspective(45., (float) width / height, 1., maxZ);
            /*Model & view*/
            gl.glMatrixMode(gl.GL_MODELVIEW);
            gl.glLoadIdentity();
        }
     
        public void displayChanged(GLAutoDrawable drawable, boolean modeChanged, boolean deviceChanged) {
        }
     
        public void mouseWheelMoved(MouseWheelEvent e) {
            if (e.getWheelRotation() > 0) {
                zoom += 0.5;
            } else {
                zoom -= 0.5;
            }
        }
     
        private float[]toArray(FloatBuffer fb){
            float[]array = new float[fb.limit()];
            for(int i=0; i<array.length; i++){
                array[i] = fb.get(i);
            }
            return array;
        }
     
        private boolean onNode(FloatBuffer fb){
            final float[]red = {1, 0, 0};
            return Arrays.equals(red, toArray(fb));
        }
     
        private double[] convertIntoGL(final GL gl, double x, double y) {
            GLU glu = new GLU();
            int viewport[] = new int[4];
            double mvmatrix[] = new double[16];
            double projmatrix[] = new double[16];
            double wcoord[] = new double[4];// wx, wy, wz;// returned xyz coords
            gl.glGetIntegerv(GL.GL_VIEWPORT, viewport, 0);
            gl.glGetDoublev(GL.GL_MODELVIEW_MATRIX, mvmatrix, 0);
            gl.glGetDoublev(GL.GL_PROJECTION_MATRIX, projmatrix, 0);
            double realy = viewport[3] - (int) y - 1;
            glu.gluUnProject(x, realy, 0, mvmatrix, 0, projmatrix, 0, viewport, 0, wcoord, 0);
            return wcoord;
        }
     
        /**
         * Calculates the translation vector in 2D for two given points
         * @param xA X coordinate of the first point
         * @param yA Y coordinate of the first point
         * @param xB X coordinate of the second point
         * @param yB Y coordinate of the second point
         * @return an array of two float which is the translation vector
         */
        private float[] getTranslationVector(float xA, float yA, float xB, float yB) {
            float[] vector = new float[2];
            vector[0] = xB - xA;
            vector[1] = yB - yA;
            return vector;
        }
     
        private void calculateNewCoordinates(final GL gl){
            double[]coord = convertIntoGL(gl, mousePosition.x, mousePosition.y);
            //float[]vector = getTranslationVector(x, y, (float) coord[0], (float) coord[1]);
            x = (float)coord[0];
            y = (float)coord[1];
        }
     
        private void moveNodeMouse(final GL gl) {
            x = this.square.getX();
            y = this.square.getY();
            calculateNewCoordinates(gl);
            this.square.changePosition(x, y, gl);
            gl.glBindBuffer(gl.GL_ARRAY_BUFFER, bufferName.get(0));
            FloatBuffer newPositions = square.getBufferVertices();
            ByteBuffer bb = gl.glMapBuffer(gl.GL_ARRAY_BUFFER, gl.GL_WRITE_ONLY);
            /*memcpy*/
            FloatBuffer fb = bb.asFloatBuffer();
            fb.rewind();
            fb.put(newPositions);
            /*End memcpy*/
            gl.glUnmapBuffer(gl.GL_ARRAY_BUFFER);
            mousePosition = null;
        }
     
        private void moveNodeKeyboard(final GL gl){
            final float length = 0.05f;
            x = this.square.getX();
            y = this.square.getY();
            switch(this.key){
                case KeyEvent.VK_DOWN:{
                    y-=length;
                }break;
                case KeyEvent.VK_UP:{
                    y+=length;
                }break;
                case KeyEvent.VK_LEFT:{
                    x-=length;
                }break;
                case KeyEvent.VK_RIGHT:{
                    x+=length;
                }break;
            }
            this.square.changePosition(x, y, gl);
            gl.glBindBuffer(gl.GL_ARRAY_BUFFER, bufferName.get(0));
            FloatBuffer newPositions = square.getBufferVertices();
            ByteBuffer bb = gl.glMapBuffer(gl.GL_ARRAY_BUFFER, gl.GL_WRITE_ONLY);
            /*memcpy*/
            FloatBuffer fb = bb.asFloatBuffer();
            fb.rewind();
            fb.put(newPositions);
            /*End memcpy*/
            gl.glUnmapBuffer(gl.GL_ARRAY_BUFFER);
            keyPressed = false;
        }
     
        private boolean checkTrueColor(final GL gl){
            int[]viewport = new int[4];
            gl.glGetIntegerv(GL.GL_VIEWPORT, viewport, 0);
            gl.glReadBuffer(GL.GL_FRONT);
            FloatBuffer fb = BufferUtil.newFloatBuffer(3);
            gl.glPixelStorei (gl.GL_UNPACK_ALIGNMENT, 1);
            gl.glReadPixels(mousePosition.x, mousePosition.y, 1, 1, gl.GL_RGB,
                    gl.GL_FLOAT, fb);
            return onNode(fb);
        }
     
        public static void main(String[] args) {
            GLCapabilities glc = new GLCapabilities();
            glc.setDoubleBuffered(true);
     
            canvas = new GLCanvas(glc);
            MovingSquare demo = new MovingSquare();
            canvas.addGLEventListener(demo);
            canvas.setAutoSwapBufferMode(true);
     
            final Animator animator = new Animator(canvas);
            animator.start();
     
            JFrame frame = new JFrame("Moving VBO square");
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.setLayout(new BorderLayout());
            canvas.setSize(400, 400);
            frame.add(canvas, BorderLayout.CENTER);
     
            frame.pack();
            frame.setVisible(true);
            canvas.requestFocus();
        }
     
        public void mouseDragged(MouseEvent e) {
            this.mousePosition = e.getPoint();
        }
     
        public void mouseMoved(MouseEvent arg0) {
        }
     
        public void mouseClicked(MouseEvent arg0) {
        }
     
        public void mousePressed(MouseEvent arg0) {
        }
     
        public void mouseReleased(MouseEvent arg0) {
            mousePosition = null;
            if(mouseOnNode){
                mouseOnNode = false;
            }
        }
     
        public void mouseEntered(MouseEvent arg0) {
        }
     
        public void mouseExited(MouseEvent arg0) {
        }
     
        public void keyTyped(KeyEvent e) {
        }
     
        public void keyPressed(KeyEvent e) {
            this.key = e.getKeyCode();
            keyPressed = true;
        }
     
        public void keyReleased(KeyEvent e) {
            keyPressed = false;
        }
    }
    Euh... où me suis-je planté ? Aurais-je oublié un ingrédient dans la marmite ?

    @++
    GLDavid
    Consultez la FAQ Perl ainsi que mes cours de Perl.
    N'oubliez pas les balises code ni le tag

    Je ne répond à aucune question technique par MP.

  9. #9
    Membre éclairé
    Avatar de Happy
    Homme Profil pro
    Développeur Web
    Inscrit en
    Juin 2005
    Messages
    665
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 34
    Localisation : Autre

    Informations professionnelles :
    Activité : Développeur Web

    Informations forums :
    Inscription : Juin 2005
    Messages : 665
    Points : 875
    Points
    875
    Par défaut
    J'ai pas su bien regarder le code, mais as-tu résolu en rendant négatives les valeurs de wcoord ?

  10. #10
    Expert confirmé
    Avatar de GLDavid
    Homme Profil pro
    Service Delivery Manager
    Inscrit en
    Janvier 2003
    Messages
    2 852
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 47
    Localisation : France, Seine Saint Denis (Île de France)

    Informations professionnelles :
    Activité : Service Delivery Manager
    Secteur : Industrie Pharmaceutique

    Informations forums :
    Inscription : Janvier 2003
    Messages : 2 852
    Points : 4 759
    Points
    4 759
    Par défaut
    Bonjour

    Voici une nouvelle tentative:
    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
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
    353
    354
    355
    356
    357
    358
    359
    360
    361
    362
    363
    364
    365
    366
    367
    368
    369
    370
    371
    372
    373
    374
    375
    376
    377
     
    package demo;
     
     
    import com.sun.opengl.util.Animator;
    import com.sun.opengl.util.BufferUtil;
    import com.bioxpr.demo.geom.Square;
    import java.awt.BorderLayout;
    import java.awt.Point;
    import java.awt.event.KeyEvent;
    import java.awt.event.KeyListener;
    import java.awt.event.MouseEvent;
    import java.awt.event.MouseListener;
    import java.awt.event.MouseMotionListener;
    import java.awt.event.MouseWheelEvent;
    import java.awt.event.MouseWheelListener;
    import java.nio.ByteBuffer;
    import java.nio.FloatBuffer;
    import java.nio.IntBuffer;
    import java.util.Arrays;
    import javax.media.opengl.GL;
    import javax.media.opengl.GLAutoDrawable;
    import javax.media.opengl.GLCanvas;
    import javax.media.opengl.GLCapabilities;
    import javax.media.opengl.GLEventListener;
    import javax.media.opengl.glu.GLU;
    import javax.swing.JFrame;
     
    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
    /**
     *
     * @author GLDavid
     */
    public class MovingSquare
            implements GLEventListener, MouseWheelListener, MouseMotionListener,
            MouseListener, KeyListener {
     
        private float zoom = -20;
        private Square square;
        private IntBuffer bufferName;
        private FloatBuffer positionData;
        private FloatBuffer colorData;
        private FloatBuffer falseColorData;
        private IntBuffer starts;
        private IntBuffer counts;
        private final int LIMIT = 3;
        private Point mousePosition;
        private static GLCanvas canvas;
        private boolean keyPressed;
        private boolean mouseOnNode;
        private int key;
     
        public MovingSquare() {
            this.square = new Square(0, 0, 0);
            this.bufferName = BufferUtil.newIntBuffer(LIMIT);
        }
     
        private void initDataBuffers(final GL gl){
            int i = 0;
            int j = 4;
            this.positionData.put(square.getBufferVertices());
            this.colorData.put(square.getBufferColor());
            this.falseColorData.position(square.sizeofBufferFalseColor());
            starts.put(i);
            counts.put(j);
            i = i + square.getBufferIndicesSize();
            j = square.getBufferIndicesSize();
            this.positionData.rewind();
            this.colorData.rewind();
            this.falseColorData.rewind();
        }
     
        private void pushNodesDataBuffers(final GL gl) {
            initDataBuffers(gl);
     
            gl.glBindBuffer(gl.GL_ARRAY_BUFFER, bufferName.get(0));
            gl.glBufferData(gl.GL_ARRAY_BUFFER,
                    this.square.sizeofBufferVertices() *
                    BufferUtil.SIZEOF_FLOAT,
                    positionData,
                    gl.GL_STREAM_DRAW);
            gl.glVertexPointer(3, gl.GL_FLOAT, 0, 0);
     
            gl.glBindBuffer(gl.GL_ARRAY_BUFFER, bufferName.get(1));
            gl.glBufferData(gl.GL_ARRAY_BUFFER,
                    this.square.sizeofBufferColor() *
                    BufferUtil.SIZEOF_FLOAT,
                    colorData,
                    gl.GL_STATIC_DRAW);
            gl.glColorPointer(4, gl.GL_FLOAT, 0, 0);
     
            gl.glBindBuffer(gl.GL_ARRAY_BUFFER, bufferName.get(2));
            gl.glBufferData(gl.GL_ARRAY_BUFFER,
                    this.square.sizeofBufferFalseColor() *
                    BufferUtil.SIZEOF_FLOAT,
                    falseColorData,
                    gl.GL_STATIC_DRAW);
            gl.glColorPointer(4, gl.GL_FLOAT, 0, 0);
     
            this.starts.rewind();
            this.counts.rewind();
        }
     
        public void init(GLAutoDrawable drawable) {
            final GL gl = drawable.getGL();
     
            drawable.addMouseWheelListener(this);
            drawable.addMouseMotionListener(this);
            drawable.addMouseListener(this);
            drawable.addKeyListener(this);
     
            gl.glShadeModel(gl.GL_SMOOTH);
            gl.glEnable(gl.GL_DEPTH_TEST);
     
            gl.glGenBuffers(LIMIT, bufferName);
     
            int constant = BufferUtil.SIZEOF_FLOAT;
            this.positionData = BufferUtil.newFloatBuffer(square.sizeofBufferVertices() * constant);
            this.colorData = BufferUtil.newFloatBuffer(square.sizeofBufferColor() * constant);
            this.falseColorData = BufferUtil.newFloatBuffer(square.sizeofBufferFalseColor() * constant);
            this.starts = BufferUtil.newIntBuffer(1);
            this.counts = BufferUtil.newIntBuffer(1);
     
            pushNodesDataBuffers(gl);
        }
     
        private void displayTrueColor(final GL gl){
            gl.glBindBuffer(gl.GL_ARRAY_BUFFER, bufferName.get(0));
            gl.glVertexPointer(3, gl.GL_FLOAT, 0, 0);
            gl.glBindBuffer(gl.GL_ARRAY_BUFFER, bufferName.get(1));
            gl.glColorPointer(4, gl.GL_FLOAT, 0, 0);
            gl.glMultiDrawArrays(gl.GL_QUADS, starts, counts, 1);
        }
     
        public void display(GLAutoDrawable drawable) {
            final GL gl = drawable.getGL();
            gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
            gl.glClearColor(1, 1, 1, 0);
     
            gl.glMatrixMode(gl.GL_MODELVIEW);
            gl.glLoadIdentity();
            gl.glTranslatef(0, 0, zoom);
     
            gl.glEnableClientState(GL.GL_VERTEX_ARRAY);
            gl.glEnableClientState(GL.GL_COLOR_ARRAY);
     
            //System.out.println(mouseOnNode);
     
            if(keyPressed){
                moveNodeKeyboard(gl);
            }
            else {
                displayTrueColor(gl);
                if(mousePosition!=null){
                    if(!mouseOnNode){
                        mouseOnNode = checkTrueColor(gl);
                    }
                    else {
                        moveNodeMouse(gl);
                    }
                }
            }
     
            displayTrueColor(gl);
     
            gl.glDisableClientState(GL.GL_VERTEX_ARRAY);
            gl.glDisableClientState(GL.GL_COLOR_ARRAY);
     
            gl.glPointSize(2f);
            gl.glColor3f(0, 0, 0);
            gl.glBegin(gl.GL_POINT);
            gl.glVertex3f(0, 1, 0);
            gl.glEnd();
     
            gl.glFlush();
        }
     
        public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {
            final int maxZ = 1000;
            GL gl = drawable.getGL();
            gl.glViewport(0, 0, width, height);
            /*For the camera*/
            gl.glMatrixMode(gl.GL_PROJECTION);
            gl.glLoadIdentity();
            //Change this by glOrtho
            new GLU().gluPerspective(45., (float) width / height, 1., maxZ);
            /*Model & view*/
            gl.glMatrixMode(gl.GL_MODELVIEW);
            gl.glLoadIdentity();
        }
     
        public void displayChanged(GLAutoDrawable drawable, boolean modeChanged, boolean deviceChanged) {
        }
     
        public void mouseWheelMoved(MouseWheelEvent e) {
            if (e.getWheelRotation() > 0) {
                zoom += 0.5;
            } else {
                zoom -= 0.5;
            }
        }
     
        private float[]toArray(FloatBuffer fb){
            float[]array = new float[fb.limit()];
            for(int i=0; i<array.length; i++){
                array[i] = fb.get(i);
            }
            return array;
        }
     
        private boolean onNode(FloatBuffer fb){
            final float[]red = {1, 0, 0};
            return Arrays.equals(red, toArray(fb));
        }
     
        private double[] convertIntoGL(final GL gl, double x, double y) {
            GLU glu = new GLU();
            int viewport[] = new int[4];
            double mvmatrix[] = new double[16];
            double projmatrix[] = new double[16];
            double wcoord[] = new double[4];// wx, wy, wz;// returned xyz coords
            gl.glGetIntegerv(GL.GL_VIEWPORT, viewport, 0);
            gl.glGetDoublev(GL.GL_MODELVIEW_MATRIX, mvmatrix, 0);
            gl.glGetDoublev(GL.GL_PROJECTION_MATRIX, projmatrix, 0);
            glu.gluUnProject(x, viewport[3]-y, 0, mvmatrix, 0, projmatrix, 0, viewport, 0, wcoord, 0);
            return wcoord;
        }
     
        /**
         * Calculates the translation vector in 2D for two given points
         * @param xA X coordinate of the first point
         * @param yA Y coordinate of the first point
         * @param xB X coordinate of the second point
         * @param yB Y coordinate of the second point
         * @return an array of two float which is the translation vector
         */
        private float[] getTranslationVector(float xA, float yA, float xB, float yB) {
            float[] vector = new float[2];
            vector[0] = xB - xA;
            vector[1] = yB - yA;
            return vector;
        }
     
        private void calculateNewCoordinates(final GL gl){
            double[]coord = convertIntoGL(gl, mousePosition.x, mousePosition.y);
            //float[]vector = getTranslationVector(this.square.getX(), this.square.getY(), (float) coord[0], (float) coord[1]);
            float factor = zoom;
            if(factor<0){
                factor = Math.abs(factor);
            }
            System.out.println("GL: "+coord[0]+"\t"+coord[1]);
            float x = factor*(float)coord[0];
            float y = factor*(float)coord[1];
            System.out.println("New position: "+x+"\t"+y);
            this.square.changePosition(x, y);
        }
     
        private void glMemcpy(final GL gl, int buffer){
            gl.glBindBuffer(gl.GL_ARRAY_BUFFER, bufferName.get(buffer));
            FloatBuffer newPositions = square.getBufferVertices();
            ByteBuffer bb = gl.glMapBuffer(gl.GL_ARRAY_BUFFER, gl.GL_WRITE_ONLY);
            /*memcpy*/
            FloatBuffer fb = bb.asFloatBuffer();
            //fb.rewind();
            fb.put(newPositions);
            /*End memcpy*/
            newPositions.clear(); newPositions = null;
            gl.glUnmapBuffer(gl.GL_ARRAY_BUFFER);
        }
     
        private void moveNodeMouse(final GL gl) {
            /*x = this.square.getX();
            y = this.square.getY();*/
            calculateNewCoordinates(gl);
            //this.square.changePosition(x, y, gl);
            glMemcpy(gl, 0);
            mousePosition = null;
        }
     
        private void moveNodeKeyboard(final GL gl){
            final float length = 0.05f;
            float x = this.square.getX();
            float y = this.square.getY();
            switch(this.key){
                case KeyEvent.VK_DOWN:{
                    y=y-length;
                }break;
                case KeyEvent.VK_UP:{
                    y=y+length;
                }break;
                case KeyEvent.VK_LEFT:{
                    x=x-length;
                }break;
                case KeyEvent.VK_RIGHT:{
                    x=x+length;
                }break;
            }
            this.square.changePosition(x, y);
            glMemcpy(gl, 0);
            keyPressed = false;
        }
     
        private boolean checkTrueColor(final GL gl){
            int[]viewport = new int[4];
            gl.glGetIntegerv(GL.GL_VIEWPORT, viewport, 0);
            gl.glReadBuffer(GL.GL_FRONT);
            FloatBuffer fb = BufferUtil.newFloatBuffer(3);
            gl.glPixelStorei (gl.GL_UNPACK_ALIGNMENT, 1);
            gl.glReadPixels(mousePosition.x, mousePosition.y, 1, 1, gl.GL_RGB,
                    gl.GL_FLOAT, fb);
            return onNode(fb);
        }
     
        public static void main(String[] args) {
            GLCapabilities glc = new GLCapabilities();
            glc.setDoubleBuffered(true);
     
            canvas = new GLCanvas(glc);
            MovingSquare demo = new MovingSquare();
            canvas.addGLEventListener(demo);
            canvas.setAutoSwapBufferMode(true);
     
            final Animator animator = new Animator(canvas);
            animator.start();
     
            JFrame frame = new JFrame("Moving VBO square");
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.setLayout(new BorderLayout());
            canvas.setSize(400, 400);
            frame.add(canvas, BorderLayout.CENTER);
     
            frame.pack();
            frame.setVisible(true);
            canvas.requestFocus();
        }
     
        public void mouseDragged(MouseEvent e) {
            this.mousePosition = e.getPoint();
        }
     
        public void mouseMoved(MouseEvent arg0) {
        }
     
        public void mouseClicked(MouseEvent arg0) {
        }
     
        public void mousePressed(MouseEvent arg0) {
        }
     
        public void mouseReleased(MouseEvent arg0) {
            mousePosition = null;
            if(mouseOnNode){
                mouseOnNode = false;
            }
        }
     
        public void mouseEntered(MouseEvent arg0) {
        }
     
        public void mouseExited(MouseEvent arg0) {
        }
     
        public void keyTyped(KeyEvent e) {
        }
     
        public void keyPressed(KeyEvent e) {
            this.key = e.getKeyCode();
            keyPressed = true;
        }
     
        public void keyReleased(KeyEvent e) {
            keyPressed = false;
        }
    }
    Apparemment, mon carré se déplace correctement avec la souris. Youpi ? Et bien non !
    Car si je reclique sur le carré, rien ne se passe. Il faut que je reclique en Y opposé pour déplacer mon carré ! Notez qu'en plus, mon carré se déplace instantanément en Y opposé.
    Mis à part le fait que je fais de la magie, quelqu'un pourrait-il m'expliquer d'où vient cette étrangeté ?

    Merci d'avance.

    @++
    GLDavid
    Consultez la FAQ Perl ainsi que mes cours de Perl.
    N'oubliez pas les balises code ni le tag

    Je ne répond à aucune question technique par MP.

  11. #11
    Expert confirmé
    Avatar de GLDavid
    Homme Profil pro
    Service Delivery Manager
    Inscrit en
    Janvier 2003
    Messages
    2 852
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 47
    Localisation : France, Seine Saint Denis (Île de France)

    Informations professionnelles :
    Activité : Service Delivery Manager
    Secteur : Industrie Pharmaceutique

    Informations forums :
    Inscription : Janvier 2003
    Messages : 2 852
    Points : 4 759
    Points
    4 759
    Par défaut
    Youhou !

    J'ai trouvé, le problème était dans la lecture de la couleur pour savoir si on était sur le carré ou non, depuis ça fonctionne !
    Ô joie.
    Voici le code:
    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
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
    353
    354
    355
    356
    357
    358
    359
    360
    361
    362
    363
    364
    365
    366
    367
    368
    369
    370
    371
    372
    373
    374
    375
    376
    377
     
    package demo;
     
     
    import com.sun.opengl.util.Animator;
    import com.sun.opengl.util.BufferUtil;
    import com.bioxpr.demo.geom.Square;
    import java.awt.BorderLayout;
    import java.awt.Point;
    import java.awt.event.KeyEvent;
    import java.awt.event.KeyListener;
    import java.awt.event.MouseEvent;
    import java.awt.event.MouseListener;
    import java.awt.event.MouseMotionListener;
    import java.awt.event.MouseWheelEvent;
    import java.awt.event.MouseWheelListener;
    import java.nio.ByteBuffer;
    import java.nio.FloatBuffer;
    import java.nio.IntBuffer;
    import java.util.Arrays;
    import javax.media.opengl.GL;
    import javax.media.opengl.GLAutoDrawable;
    import javax.media.opengl.GLCanvas;
    import javax.media.opengl.GLCapabilities;
    import javax.media.opengl.GLEventListener;
    import javax.media.opengl.glu.GLU;
    import javax.swing.JFrame;
     
    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
    /**
     *
     * @author GLDavid
     */
    public class MovingSquare
            implements GLEventListener, MouseWheelListener, MouseMotionListener,
            MouseListener, KeyListener {
     
        private float zoom = -20;
        private Square square;
        private IntBuffer bufferName;
        private FloatBuffer positionData;
        private FloatBuffer colorData;
        private FloatBuffer falseColorData;
        private IntBuffer starts;
        private IntBuffer counts;
        private final int LIMIT = 3;
        private Point mousePosition;
        private static GLCanvas canvas;
        private boolean keyPressed;
        private boolean mouseOnNode;
        private int key;
     
        public MovingSquare() {
            this.square = new Square(0, 0, 0);
            this.bufferName = BufferUtil.newIntBuffer(LIMIT);
        }
     
        private void initDataBuffers(final GL gl){
            int i = 0;
            int j = 4;
            this.positionData.put(square.getBufferVertices());
            this.colorData.put(square.getBufferColor());
            this.falseColorData.position(square.sizeofBufferFalseColor());
            starts.put(i);
            counts.put(j);
            i = i + square.getBufferIndicesSize();
            j = square.getBufferIndicesSize();
            this.positionData.rewind();
            this.colorData.rewind();
            this.falseColorData.rewind();
        }
     
        private void pushNodesDataBuffers(final GL gl) {
            initDataBuffers(gl);
     
            gl.glBindBuffer(gl.GL_ARRAY_BUFFER, bufferName.get(0));
            gl.glBufferData(gl.GL_ARRAY_BUFFER,
                    this.square.sizeofBufferVertices() *
                    BufferUtil.SIZEOF_FLOAT,
                    positionData,
                    gl.GL_STREAM_DRAW);
            gl.glVertexPointer(3, gl.GL_FLOAT, 0, 0);
     
            gl.glBindBuffer(gl.GL_ARRAY_BUFFER, bufferName.get(1));
            gl.glBufferData(gl.GL_ARRAY_BUFFER,
                    this.square.sizeofBufferColor() *
                    BufferUtil.SIZEOF_FLOAT,
                    colorData,
                    gl.GL_STATIC_DRAW);
            gl.glColorPointer(4, gl.GL_FLOAT, 0, 0);
     
            gl.glBindBuffer(gl.GL_ARRAY_BUFFER, bufferName.get(2));
            gl.glBufferData(gl.GL_ARRAY_BUFFER,
                    this.square.sizeofBufferFalseColor() *
                    BufferUtil.SIZEOF_FLOAT,
                    falseColorData,
                    gl.GL_STATIC_DRAW);
            gl.glColorPointer(4, gl.GL_FLOAT, 0, 0);
     
            this.starts.rewind();
            this.counts.rewind();
        }
     
        public void init(GLAutoDrawable drawable) {
            final GL gl = drawable.getGL();
     
            drawable.addMouseWheelListener(this);
            drawable.addMouseMotionListener(this);
            drawable.addMouseListener(this);
            drawable.addKeyListener(this);
     
            gl.glShadeModel(gl.GL_SMOOTH);
            gl.glEnable(gl.GL_DEPTH_TEST);
     
            gl.glGenBuffers(LIMIT, bufferName);
     
            int constant = BufferUtil.SIZEOF_FLOAT;
            this.positionData = BufferUtil.newFloatBuffer(square.sizeofBufferVertices() * constant);
            this.colorData = BufferUtil.newFloatBuffer(square.sizeofBufferColor() * constant);
            this.falseColorData = BufferUtil.newFloatBuffer(square.sizeofBufferFalseColor() * constant);
            this.starts = BufferUtil.newIntBuffer(1);
            this.counts = BufferUtil.newIntBuffer(1);
     
            pushNodesDataBuffers(gl);
        }
     
        private void displayTrueColor(final GL gl){
            gl.glBindBuffer(gl.GL_ARRAY_BUFFER, bufferName.get(0));
            gl.glVertexPointer(3, gl.GL_FLOAT, 0, 0);
            gl.glBindBuffer(gl.GL_ARRAY_BUFFER, bufferName.get(1));
            gl.glColorPointer(4, gl.GL_FLOAT, 0, 0);
            gl.glMultiDrawArrays(gl.GL_QUADS, starts, counts, 1);
        }
     
        public void display(GLAutoDrawable drawable) {
            final GL gl = drawable.getGL();
            gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
            gl.glClearColor(1, 1, 1, 0);
     
            gl.glMatrixMode(gl.GL_MODELVIEW);
            gl.glLoadIdentity();
            gl.glTranslatef(0, 0, zoom);
     
            gl.glEnableClientState(GL.GL_VERTEX_ARRAY);
            gl.glEnableClientState(GL.GL_COLOR_ARRAY);
     
            //System.out.println(mouseOnNode);
     
            if(keyPressed){
                moveNodeKeyboard(gl);
            }
            else {
                displayTrueColor(gl);
                if(mousePosition!=null){
                    if(!mouseOnNode){
                        mouseOnNode = checkTrueColor(gl);
                    }
                    else {
                        moveNodeMouse(gl);
                    }
                }
            }
     
            displayTrueColor(gl);
     
            gl.glDisableClientState(GL.GL_VERTEX_ARRAY);
            gl.glDisableClientState(GL.GL_COLOR_ARRAY);
     
            gl.glPointSize(2f);
            gl.glColor3f(0, 0, 0);
            gl.glBegin(gl.GL_POINT);
            gl.glVertex3f(0, 1, 0);
            gl.glEnd();
     
            gl.glFlush();
        }
     
        public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {
            final int maxZ = 1000;
            GL gl = drawable.getGL();
            gl.glViewport(0, 0, width, height);
            /*For the camera*/
            gl.glMatrixMode(gl.GL_PROJECTION);
            gl.glLoadIdentity();
            //Change this by glOrtho
            new GLU().gluPerspective(45., (float) width / height, 1., maxZ);
            /*Model & view*/
            gl.glMatrixMode(gl.GL_MODELVIEW);
            gl.glLoadIdentity();
        }
     
        public void displayChanged(GLAutoDrawable drawable, boolean modeChanged, boolean deviceChanged) {
        }
     
        public void mouseWheelMoved(MouseWheelEvent e) {
            if (e.getWheelRotation() > 0) {
                zoom += 0.5;
            } else {
                zoom -= 0.5;
            }
        }
     
        private float[]toArray(FloatBuffer fb){
            float[]array = new float[fb.limit()];
            for(int i=0; i<array.length; i++){
                array[i] = fb.get(i);
            }
            return array;
        }
     
        private boolean onNode(FloatBuffer fb){
            final float[]red = {1, 0, 0};
            return Arrays.equals(red, toArray(fb));
        }
     
        private double[] convertIntoGL(final GL gl, double x, double y) {
            GLU glu = new GLU();
            int viewport[] = new int[4];
            double mvmatrix[] = new double[16];
            double projmatrix[] = new double[16];
            double wcoord[] = new double[4];// wx, wy, wz;// returned xyz coords
            gl.glGetIntegerv(GL.GL_VIEWPORT, viewport, 0);
            gl.glGetDoublev(GL.GL_MODELVIEW_MATRIX, mvmatrix, 0);
            gl.glGetDoublev(GL.GL_PROJECTION_MATRIX, projmatrix, 0);
            glu.gluUnProject(x, viewport[3]-y, 0, mvmatrix, 0, projmatrix, 0, viewport, 0, wcoord, 0);
            return wcoord;
        }
     
        /**
         * Calculates the translation vector in 2D for two given points
         * @param xA X coordinate of the first point
         * @param yA Y coordinate of the first point
         * @param xB X coordinate of the second point
         * @param yB Y coordinate of the second point
         * @return an array of two float which is the translation vector
         */
        private float[] getTranslationVector(float xA, float yA, float xB, float yB) {
            float[] vector = new float[2];
            vector[0] = xB - xA;
            vector[1] = yB - yA;
            return vector;
        }
     
        private void calculateNewCoordinates(final GL gl){
            double[]coord = convertIntoGL(gl, mousePosition.x, mousePosition.y);
            //float[]vector = getTranslationVector(this.square.getX(), this.square.getY(), (float) coord[0], (float) coord[1]);
            float factor = zoom;
            if(factor<0){
                factor = Math.abs(factor);
            }
            System.out.println("GL: "+coord[0]+"\t"+coord[1]);
            float x = factor*(float)coord[0];
            float y = factor*(float)coord[1];
            System.out.println("New position: "+x+"\t"+y);
            this.square.changePosition(x, y);
        }
     
        private void glMemcpy(final GL gl, int buffer){
            gl.glBindBuffer(gl.GL_ARRAY_BUFFER, bufferName.get(buffer));
            FloatBuffer newPositions = square.getBufferVertices();
            ByteBuffer bb = gl.glMapBuffer(gl.GL_ARRAY_BUFFER, gl.GL_WRITE_ONLY);
            /*memcpy*/
            FloatBuffer fb = bb.asFloatBuffer();
            //fb.rewind();
            fb.put(newPositions);
            /*End memcpy*/
            newPositions.clear(); newPositions = null;
            gl.glUnmapBuffer(gl.GL_ARRAY_BUFFER);
        }
     
        private void moveNodeMouse(final GL gl) {
            /*x = this.square.getX();
            y = this.square.getY();*/
            calculateNewCoordinates(gl);
            //this.square.changePosition(x, y, gl);
            glMemcpy(gl, 0);
            mousePosition = null;
        }
     
        private void moveNodeKeyboard(final GL gl){
            final float length = 0.05f;
            float x = this.square.getX();
            float y = this.square.getY();
            switch(this.key){
                case KeyEvent.VK_DOWN:{
                    y=y-length;
                }break;
                case KeyEvent.VK_UP:{
                    y=y+length;
                }break;
                case KeyEvent.VK_LEFT:{
                    x=x-length;
                }break;
                case KeyEvent.VK_RIGHT:{
                    x=x+length;
                }break;
            }
            this.square.changePosition(x, y);
            glMemcpy(gl, 0);
            keyPressed = false;
        }
     
        private boolean checkTrueColor(final GL gl){
            int[]viewport = new int[4];
            gl.glGetIntegerv(GL.GL_VIEWPORT, viewport, 0);
            gl.glReadBuffer(GL.GL_FRONT);
            FloatBuffer fb = BufferUtil.newFloatBuffer(3);
            gl.glPixelStorei (gl.GL_UNPACK_ALIGNMENT, 1);
            gl.glReadPixels(mousePosition.x, viewport[3]-mousePosition.y, 1, 1, gl.GL_RGB,
                    gl.GL_FLOAT, fb);
            return onNode(fb);
        }
     
        public static void main(String[] args) {
            GLCapabilities glc = new GLCapabilities();
            glc.setDoubleBuffered(true);
     
            canvas = new GLCanvas(glc);
            MovingSquare demo = new MovingSquare();
            canvas.addGLEventListener(demo);
            canvas.setAutoSwapBufferMode(true);
     
            final Animator animator = new Animator(canvas);
            animator.start();
     
            JFrame frame = new JFrame("Moving VBO square");
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.setLayout(new BorderLayout());
            canvas.setSize(400, 400);
            frame.add(canvas, BorderLayout.CENTER);
     
            frame.pack();
            frame.setVisible(true);
            canvas.requestFocus();
        }
     
        public void mouseDragged(MouseEvent e) {
            this.mousePosition = e.getPoint();
        }
     
        public void mouseMoved(MouseEvent arg0) {
        }
     
        public void mouseClicked(MouseEvent arg0) {
        }
     
        public void mousePressed(MouseEvent arg0) {
        }
     
        public void mouseReleased(MouseEvent arg0) {
            mousePosition = null;
            if(mouseOnNode){
                mouseOnNode = false;
            }
        }
     
        public void mouseEntered(MouseEvent arg0) {
        }
     
        public void mouseExited(MouseEvent arg0) {
        }
     
        public void keyTyped(KeyEvent e) {
        }
     
        public void keyPressed(KeyEvent e) {
            this.key = e.getKeyCode();
            keyPressed = true;
        }
     
        public void keyReleased(KeyEvent e) {
            keyPressed = false;
        }
    }
    Voilà, on peut désormais bouger un carré (.i.e un VBO) à la souris et au clavier

    @++
    GLDavid
    Consultez la FAQ Perl ainsi que mes cours de Perl.
    N'oubliez pas les balises code ni le tag

    Je ne répond à aucune question technique par MP.

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Positionner n objet en java avec la souris
    Par sousou89 dans le forum Interfaces Graphiques en Java
    Réponses: 1
    Dernier message: 22/05/2014, 14h16
  2. [C#] Déplacer un composant avec la souris
    Par GéniuS77 dans le forum Windows Forms
    Réponses: 8
    Dernier message: 07/04/2011, 23h12
  3. Déplacer un panel avec la souris
    Par Harry dans le forum Delphi
    Réponses: 14
    Dernier message: 05/06/2006, 19h18
  4. Curses - Toujours avec la souris
    Par Caine dans le forum Linux
    Réponses: 7
    Dernier message: 05/01/2005, 16h49
  5. comment tourner la vue avec la souris
    Par delfare dans le forum OpenGL
    Réponses: 13
    Dernier message: 12/09/2004, 17h44

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo