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 8168379
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T20:30:13+00:00 2026-06-06T20:30:13+00:00

I am developing a javascript application in which it is possible to design your

  • 0

I am developing a javascript application in which it is possible to design your own closet. I want it to be possible to rotate the closet smoothly (without changing the distance from the camera to the closet). Normally it would be easiest to rotate the object itself, but that’s not an option considering the different meshes have different origins (their relative (0,0) points are different from the global (0,0)). Instead, I figured I have to rotate the camera around the closet as if on a sphere. So what I want to do is calculate the exact position the camera needs to have based on any longitude and latitude (user input). As a result, the rotation is really odd. The application in its current state is here (important: doesn’t work with IE, there will be a plugin in the future though). The relevant code is below. Note: I found these formulas online. I did the math myself several times and was able to confirm the formula’s every time. The only thing I am pretty sure of is that the distance (radius) to the offset point (xOffset, yOffset, zOffset) is constant but the whole thing just rotates very oddly. I found another question like this here. I tried replacing my formula’s with theirs (even though they don’t make sense, although they seem to work for them) but that didn’t help at all (rotations were still odd and the radius didn’t even seem constant anymore).

Pseudo:

x = xOffset + radius * cos(longitude) * cos(latitude)
y = yOffset + radius * cos(longitude) * sin(latitude)
z = zOffset + radius * sin(longitude)
camera.lookAt(xOffset, yOffset, zOffset)

Relevant code (note: degrees are converted to radians):

var lon = 30;
var lat = -90;
var cameraRadius = 400;

function cameraReposition() {   
var lon = dimensions.lon;
var lat = dimensions.lat;
camera.position.x = cameraX + cameraRadius * Math.cos(Math.PI * lon / 180) * Math.cos(Math.PI * lat / 180);
camera.position.y = cameraY + cameraRadius * Math.cos(Math.PI * lon / 180) * Math.sin(Math.PI * lat / 180);
camera.position.z = cameraZ + cameraRadius * Math.sin(Math.PI * lon / 180); 
camera.lookAt(new THREE.Vector3(cameraX, cameraY, cameraZ));
}


$('#visiblecanvas').mousemove(function(e){
    if(mousedown || rightMousedown) {
        var clickX = e.pageX - this.offsetLeft;    
        var clickY = e.pageY - this.offsetLeft;
        lon += (clickY - lastY) / 10;
        lat -= (clickX - lastX) / 10;
        lastY = clickY;
        lastX = clickX;
        if (lon > 360)
            lon -= 360;
        if (lon < -360)
            lon += 360;
        if (lat > 360)
            lat -= 180;
        if (lat < -360)
            lat += 360;
    }
});

Another note: the way lon and lat are changed when they go past 360 is not very relevant right now as both lon and lat are controlled through the gui for now (for debugging purposes).

EDIT: Wrong link to the application! fixed.

  • 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-06T20:30:15+00:00Added an answer on June 6, 2026 at 8:30 pm

    The camera positioning looks OK to me, at least it follows the proper trajectories when either latitude or longitude is varied, while the other one is kept constant. What does look odd is the orientation of the camera — lookAt doesn’t specify where “up” is, so it can choose any orientation, e.g. you might end up looking at the right point, but upside down.

    I haven’t tried Three.js myself, but in the documentation I do not see the way to give that additional info to the camera. You might have to set the projectionMatrix and its inverse manually.

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

Sidebar

Related Questions

I am developing a DHTML/Javascript application which relies on some advanced features (DOM manipulation,
I was developing an application which uses the places API through the Javascript Library
I am developing a javascript application which - among a lot of other controls
I have been developing a new JavaScript application which is rapidly growing in size.
The application I am developing needs to work in a browser without javascript. At
I am developing an application which uses .js files stored in the Resources/javascript folder
I'm developing an ASP.NET MVC application in which I want to encrypt a short
I'm developing a Flash application which is communicating with Javascript to allow more features
I'm developing a JavaScript application using Google Visualization API. I wrote a event listener
I am developing a RIA application with JavaScript in Eclipse. How can I enable

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.