Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9190033
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T20:22:10+00:00 2026-06-17T20:22:10+00:00

I have a problem . I want move the earth in 360° with the

  • 0

I have a problem .

I want move the earth in 360° with the mouse but nothing happens .

However , I would like the world is fixed and does not move when I use the mouse to rotate 360 .

Waiting for a response .

<!DOCTYPE html>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
    <style>
        body {
            color: #808080;
            font-family:Monospace;
            font-size:13px;
            text-align:center;

            background-color: #000000;
            margin: 0px;
            overflow: hidden;
        }

        #info {
            position: absolute;
            top: 0px; width: 100%;
            padding: 5px;
        }

        a {

            color: #0080ff;
        }

    </style>
</head>
<body>

    <div id="container"></div>
    <div id="info"><a href="http://threejs.org" target="_blank">three.js</a> - earth demo</div>

    <script src="../build/three.min.js"></script>
    <script src="js/libs/stats.min.js"></script>

    <script>

        var container, stats;
        var camera, scene, renderer;
        var group;
        var mouseX = 0, mouseY = 0;


        init();
        animate();

        function init() {

            container = document.getElementById( 'container' );

            camera = new THREE.PerspectiveCamera( 45, window.innerWidth / window.innerHeight, 1, 10000 );
            camera.position.z = 900;

            scene = new THREE.Scene();

            group = new THREE.Object3D();
            scene.add( group );

            // earth

            var earthTexture = new THREE.Texture();
            var loader = new THREE.ImageLoader();

            loader.addEventListener( 'load', function ( event ) {

                earthTexture.image = event.content;
                earthTexture.needsUpdate = true;

            } );

            loader.load( 'textures/1.jpg');

            var geometry = new THREE.SphereGeometry( 250, 55, 55 );
            var material = new THREE.MeshBasicMaterial( { map: earthTexture, overdraw: true } );

            var mesh = new THREE.Mesh( geometry, material );
            group.add( mesh );

            // shadow

            var canvas = document.createElement( 'canvas' );
            canvas.width = 128;
            canvas.height = 128;

            var context = canvas.getContext( '2d' );
            var gradient = context.createRadialGradient( canvas.width / 2, canvas.height / 2, 0, canvas.width / 2, canvas.height / 2, canvas.width / 2 );
            gradient.addColorStop( 0.1, 'rgba(210,210,210,1)' );
            gradient.addColorStop( 1, 'rgba(255,255,255,1)' );

            context.fillStyle = gradient;
            context.fillRect( 0, 0, canvas.width, canvas.height );

            var texture = new THREE.Texture( canvas );
            texture.needsUpdate = true;

            var geometry = new THREE.PlaneGeometry( 300, 300, 3, 3 );
            var material = new THREE.MeshBasicMaterial( { map: texture, overdraw: true } );



            renderer = new THREE.CanvasRenderer();
            renderer.setSize( window.innerWidth, window.innerHeight );

            container.appendChild( renderer.domElement );

            stats = new Stats();
            stats.domElement.style.position = 'absolute';
            stats.domElement.style.top = '0px';
            container.appendChild( stats.domElement );

            document.addEventListener( 'mousemove', onDocumentMouseMove, false );

            //

            window.addEventListener( 'resize', onWindowResize, false );

        }

        function onWindowResize() {

            windowHalfX = window.innerWidth / 2;
            windowHalfY = window.innerHeight / 2;

            camera.aspect = window.innerWidth / window.innerHeight;
            camera.updateProjectionMatrix();

            renderer.setSize( window.innerWidth, window.innerHeight );

        }

        function onDocumentMouseMove( event ) {

            mouseX = ( event.clientX - windowHalfX );
            mouseY = ( event.clientY - windowHalfY );



        }

        //

        function animate() {

            requestAnimationFrame( animate );

            render();
            stats.update();

        }

        function render() {

            camera.position.x += ( mouseX - camera.position.x ) * 0.50;
            camera.position.y += ( - mouseY - camera.position.y ) * 0.50;
            camera.lookAt( scene.position );

            group.rotation.y -= 0.01;

            renderer.render( scene, camera );



        }
    // add subtle ambient lighting
    var ambientLight = new THREE.AmbientLight(0x555555);
    scene.add(ambientLight);


    </script>

</body>

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T20:22:12+00:00Added an answer on June 17, 2026 at 8:22 pm

    the problem that you are having is that you are only moving the camera in the X and Y direction, when the camera is a 3D entity.

    In order to do the rotation, you need to move convert the mouse coordinate from 3D spherical coordinates (like latitude, longitude, altitude, assuming a constant altitude, you can assign X to longitude and Y to latitude).

    Then assign the 3D cartesian coordinates to your camera:

    The formula is (replacing what you have in your render function):

    (assume altitude is 960, which works with your model)

    camera.position.x = 960 * Math.sin(mouseX) * Math.cos(mouseY);
    camera.position.y = 960 * Math.sin(mouseX) * Math.sin(mouseY);
    camera.position.z = 960 * Math.cos(mouseX);
    

    The next caveat is that sin and cos take radians (range from -pi to pi (-3.14159 to 3.14159)…so you will need to adjust your onDocumentMouseMove event to something like

    mouseX = -Math.PI + (event.clientX)/(windowHalfX*2)*Math.PI*2;
    mouseY = -Math.PI + (event.clientY)/(windowHalfY*2)*Math.PI*2;
    

    This will cause the mouse to act in lat/long coordinate (which can still be a little strange if you are looking at the top of the world. You could restrict mouseY=0, then the X rotation would always be on the equator.

    The math is a little more complicated if you want moving the mouse to be on a moving frame vs. the earth centric frame I’ve shown. But this should at least be a start.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to place UItextField in UITableViewCell but I have problem. Text field don't
I want to move a file I have in PROJECT/PROJECT.xcodeproj to PROJECT/Classes. The problem
I have a problem where I want to fade out an image, then move
I have a problem with jquery and position() . I want to move a
My problem is that I have an object I want to move forward in
I have an application that I want to move the window the problem is
I have a CCSprite that I want to move around using gestures. Problem is
i have a problem with my script that use canvas. I want to move
I have a problem with my winforms C# project. I want to move a
I have this problem: I want to generate a new source code file from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.