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

AWT/Swing Java Discussion :

Drag and drop dans une JPanel


Sujet :

AWT/Swing Java

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre très actif

    Homme Profil pro
    Hobbyiste
    Inscrit en
    Juillet 2018
    Messages
    128
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Belgique

    Informations professionnelles :
    Activité : Hobbyiste

    Informations forums :
    Inscription : Juillet 2018
    Messages : 128
    Billets dans le blog
    1
    Par défaut Drag and drop dans une JPanel
    Bonjour,

    Mon souci (j'ai cherché des sources sur le net sans succès) est de déplacer un Poin3D dans une visualisation 2D par Drag and Drop.
    Un ZBuffer dessine les objets. Les points de contrôles sont affichés en surimpression.
    Deux fonctionalités que je cherche à implémenter:

    1) Drag and drop de points. Comment sélectionner le point et faire la transition. Au moment du drop comment mettre les coordonnées du point dans le plan de la caméra (de 2D à 3D)
    2) Sélectionner un point sur un objet (courbe, surface) et faire tourner l'objet autour du point.

    https://github.com/manuelddahmen/e3gui

    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
     
            addMouseMotionListener(new MouseMotionListener() {
                public Point3D mousePoint3D;
                Point mousePoint = null;
     
                @Override
                public void mouseDragged(MouseEvent e) {
                    if (main.getUpdateView().getzRunner().isGraphicalEditing()) {
     
                        if (cellList != null)
                            cellList.forEach(cell -> {
                                Point point = getzRunner().getzBuffer().coordonneesPoint2D((Point3D) cell.o);
                                if (e.getX() - 1 > point.getX() && e.getX()+1 < point.getX() 
                                        && e.getY() - 1 > point.getY() && e.getY()+1 < point.getY()) {
                                    mousePoint = point;
                                    mousePoint3D = (Point3D) cell.o;
                                }
                            });
     
                    }
                }
     
                @Override
                public void mouseMoved(MouseEvent e) {
                    if (mousePoint3D != null) {
                        mousePoint3D.changeTo(getzRunner().getzBuffer().invert((int) e.getPoint().getX(), (int) e.getPoint().getY(), mousePoint3D.getZ()));
                    }
     
     
                }
            });
    Nom : wop-deplacer-les-points.png
Affichages : 136
Taille : 35,6 Ko

  2. #2
    Membre très actif

    Homme Profil pro
    Hobbyiste
    Inscrit en
    Juillet 2018
    Messages
    128
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Belgique

    Informations professionnelles :
    Activité : Hobbyiste

    Informations forums :
    Inscription : Juillet 2018
    Messages : 128
    Billets dans le blog
    1
    Par défaut
    Donc je simplifie ma question qui se résout à un problème de math.

    Camera.calculerPoint2D(Point3D p) : p2 # donne les coordonnées du point à l'écran grâce à la matrice m (P2 = m*p)
    ZBuffer.invert(int x, int y, Point3D p0, Camera c) : p3 coordonnées du point Point3D déplacé à l'aide de la souris dans le plan de p0 perpendiculairement au plan de la caméra.


    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
     
     
        public Point3D invert(int x, int y, Point3D orig, Camera camera)
        {
            x = (x-largeur()/2);
            y = (y-hauteur()/2);
            double dist = orig.moins(camera.getEye()).norme();
     
            double pX = Math.cos(camera.getAngleX())*dist;
            double pY = Math.cos(camera.getAngleY())*dist;
     
            return camera.getMatrice().tild().mult(new Point3D(
                    pX*2.0*x/largeur(),
                    -pY*2.0*y/hauteur(), orig.getZ()
                    ));
        }

  3. #3
    Membre très actif

    Homme Profil pro
    Hobbyiste
    Inscrit en
    Juillet 2018
    Messages
    128
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Belgique

    Informations professionnelles :
    Activité : Hobbyiste

    Informations forums :
    Inscription : Juillet 2018
    Messages : 128
    Billets dans le blog
    1
    Par défaut Solution
    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
           addMouseListener(new MouseAdapter() {
                public Representable representable;
                public ThreadDrawing threadDrawing;
                Point3D mousePoint3D;
                Point mousePoint = null;
                ArcBall arcBall;
     
                class ThreadDrawing extends Thread {
                    boolean running;
                    private boolean pause = false;
     
                    public void run() {
                        running = true;
                             while (!isRunning()) {
                                 while (isPause()) {
                                     try {
                                         Thread.sleep(100);
                                     } catch (InterruptedException e) {
                                         e.printStackTrace();
                                     }
                                 }
                                Point location = MouseInfo.getPointerInfo().getLocation();
                                SwingUtilities.convertPointFromScreen(location, main.getUpdateView());
                                mousePoint = location;
                                try {
                                    if (main.isSelectAndRotate()) {
                                        arcBall.arcball_move((int) mousePoint.getX(), (int) mousePoint.getY());
                                        //System.out.println(arcBall.ab_curr);
                                    } else
                                        drawPoint(mousePoint);
                                } catch (ArrayIndexOutOfBoundsException ex) {
                                }
                            }
     
                    }
     
                    private boolean isRunning() {
                        return running;
                    }
     
                    public void setRunning(boolean running) {
                        this.running = running;
                    }
     
                    public boolean isPause() {
                        return pause;
                    }
                }
     
     
                @Override
                public void mousePressed(MouseEvent e) {
                    System.out.println("Mouse Pressed");
                    if (main.isSelectAndRotate()) {
                        System.out.println("Mouse starts dragging rotating");
                        arcBall = new ArcBall();
                        representable = zRunner.getzBuffer().representableAt(e.getX(), e.getY());
                        arcBall.arcball_init(representable);
                        //System.out.println("Representable: " + representable);
                        arcBall.arcball_setzoom(10.0, main.getUpdateView().getzRunner().getzBuffer().camera().eye(),
                                main.getUpdateView().getzRunner().getzBuffer().camera().getVerticale().getElem());
                        arcBall.arcball_start(e.getX(), e.getY());
                        if (threadDrawing == null) {
                            threadDrawing = new ThreadDrawing();
                            threadDrawing.start();
                        }
                    } else if (main.getUpdateView().getzRunner().isGraphicalEditing()) {
                        List<ModelBrowser.Cell> cellList;
                        cellList = new ModelBrowser(main.getDataModel().getScene(), Point3D.class).getObjects();
                        if (cellList != null)
                            cellList.forEach(cell -> {
                                Point point = getzRunner().getzBuffer().camera().coordonneesPoint2D((Point3D) cell.o
                                ,
                                        getzRunner().getzBuffer());
                                if (e != null && point != null &&
                                        e.getX() - 2 < point.getX() && e.getX() + 2 > point.getX()
                                        && e.getY() - 2 < point.getY() && e.getY() + 2 > point.getY()) {
                                    mousePoint = point;
                                    mousePoint3D = (Point3D) cell.o;
                                    if (threadDrawing == null) {
                                        threadDrawing = new ThreadDrawing();
                                        threadDrawing.start();
                                    }
                                }
                            });
     
                    }
                }
     
     
                @Override
                public void mouseReleased(MouseEvent e) {
                    System.out.println("Mouse Released");
                    if (main.getUpdateView().getzRunner().isGraphicalEditing()) {
                        if (mousePoint3D != null) {
                            mousePoint3D.changeTo(getzRunner().getzBuffer().invert((int) e.getPoint().getX(), (int) e.getPoint().getY(), mousePoint3D, getzRunner().getzBuffer().camera()));
                        }
                        System.out.println(mousePoint3D);
                    }
                    if (threadDrawing != null) {
                        threadDrawing.setRunning(false);
                        threadDrawing = null;
                    }
                    mousePoint3D = null;
                    mousePoint = null;
                }
            });

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

Discussions similaires

  1. Drag And Drop dans une Grid
    Par amandinerenard dans le forum Windows Presentation Foundation
    Réponses: 4
    Dernier message: 13/05/2013, 17h41
  2. Drag and drop dans une seul listview
    Par jacko842 dans le forum VB.NET
    Réponses: 0
    Dernier message: 21/04/2010, 13h42
  3. [script.aculo.us] Drag and drop dans une div avec un scroll horizontal
    Par ridan dans le forum Bibliothèques & Frameworks
    Réponses: 7
    Dernier message: 21/07/2009, 19h14
  4. [VB.net] Drag and drop dans une Treeview
    Par gégécap dans le forum Windows Forms
    Réponses: 2
    Dernier message: 19/10/2006, 10h05
  5. [VB.NET]Drag and Drop dans une Listview
    Par gégécap dans le forum Windows Forms
    Réponses: 5
    Dernier message: 23/08/2006, 18h41

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