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

JavaScript Discussion :

Drag and drop et le Zoom qui ne marche avec OrbitControls


Sujet :

JavaScript

  1. #1
    Membre éclairé Avatar de labarre2002
    Homme Profil pro
    Inscrit en
    Avril 2008
    Messages
    250
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Autre

    Informations professionnelles :
    Secteur : High Tech - Matériel informatique

    Informations forums :
    Inscription : Avril 2008
    Messages : 250
    Par défaut Drag and drop et le Zoom qui ne marche avec OrbitControls
    Bonsoir

    Je viens d 'aborder la notion de OrbitControls sur ThreeJS

    mon code

    Code JS : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
     
    import * as THREE from "three"
    import { OrbitControls } from 'three/addons/controls/OrbitControls.js';
     
     
     
     const controls = new OrbitControls(camera, canvas);

    dans mon cours le drag and drop puis le zoom marchent

    mais dans mon cas rien ne se passe

    je poste l'intégralité de mon code ici

    Code JS : 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
     
     
    import * as THREE from "three"
    import { OrbitControls } from 'three/addons/controls/OrbitControls.js';
     
    console.log( OrbitControls)
     
     const canvas=document.querySelector('.webgl')
     
     const scene=new THREE.Scene()
     
     const geometry=new THREE.BoxGeometry(1,1,1)
     const material=new THREE.MeshBasicMaterial( {color:"blue",wireframe:true} )
     
     const mesh=new THREE.Mesh(geometry, material)
     scene.add(mesh)
     
     
     
     const sizes={
         width:800,
         height:600
     }
     
     //const aspectRatio=sizes.width/ sizes.height
    const camera=new THREE.PerspectiveCamera(75,sizes.width /sizes.height,0.1, 10000)
     
    //const camera=new THREE.OrthographicCamera(-1 * aspectRatio,1 * aspectRatio,1,-1 ,0.1,10000)
    scene.add(camera)
    camera.position.z=2
     
     
     
    //Heure
    const clock=new THREE.Clock()
     
     const renderer=new THREE.WebGLRenderer({
         canvas
     })
     
     const controls = new OrbitControls(camera, canvas);
     
     
     //cursor
     
     const cursor={
         x:0,
         y:0
     
     }
     
       window.addEventListener("mousemove" ,(event)=>{
           cursor.x=event.clientX / sizes.width - 0.5
           cursor.y= -(event.clientY / sizes.height - 0.5) 
     
       })
     
     console.log(cursor)
     
    const cx=()=>{
        const elapsedTime=clock.getElapsedTime()
        camera.position.x =Math.sin(cursor.x * Math.PI * 2) * 3
        camera.position.z=Math.cos(cursor.x * Math.PI * 2) * 3
        camera.position.y= cursor.y * 3
        camera.lookAt(new THREE.Vector3())
     
        renderer.render(scene, camera)
        window.requestAnimationFrame(cx)
    }
    cx()
     
     renderer.setSize(sizes.width, sizes.height)



    Puis je avoir des explications svp ?

  2. #2
    Membre éclairé Avatar de labarre2002
    Homme Profil pro
    Inscrit en
    Avril 2008
    Messages
    250
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Autre

    Informations professionnelles :
    Secteur : High Tech - Matériel informatique

    Informations forums :
    Inscription : Avril 2008
    Messages : 250
    Par défaut
    en commentant les lignes dans la fonction j'obtiens le résultat escompté

  3. #3
    Membre expérimenté
    Homme Profil pro
    OoW
    Inscrit en
    Juin 2019
    Messages
    146
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 55
    Localisation : Ukraine

    Informations professionnelles :
    Activité : OoW

    Informations forums :
    Inscription : Juin 2019
    Messages : 146
    Par défaut
    \ô/
    en commentant les lignes
    ... mais de quelles lignes parles-tu ??

  4. #4
    Membre éclairé Avatar de labarre2002
    Homme Profil pro
    Inscrit en
    Avril 2008
    Messages
    250
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Autre

    Informations professionnelles :
    Secteur : High Tech - Matériel informatique

    Informations forums :
    Inscription : Avril 2008
    Messages : 250
    Par défaut
    Code js : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
     
    const cx=()=>{
       // const elapsedTime=clock.getElapsedTime()
       // camera.position.x =Math.sin(cursor.x * Math.PI * 2) * 3
        //camera.position.z=Math.cos(cursor.x * Math.PI * 2) * 3
       // camera.position.y= cursor.y * 3
       // camera.lookAt(new THREE.Vector3())
     
        renderer.render(scene, camera)
        window.requestAnimationFrame(cx)
    }
    cx()

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

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