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

  • Home
  • SEARCH
  • 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 8004039
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T16:48:48+00:00 2026-06-04T16:48:48+00:00

I have a simple Three.js scene around which I want to move the camera.

  • 0

I have a simple Three.js scene around which I want to move the camera. The camera needs to be able not only just to move, but to change the angle around a certain focus point. The focus point is actually the camera position, and at the time of rendering, I actually just translate the camera by cameraBuff and it places it on a sphere, and then I tell it to look at the focus point.

Until the camera is moved, everything works OK, I can rotate the camera and all that. But, once I start moving, something just seems to break! At normal angles (vertical, 0 < x < 180) it just freezes and cannot rotate around the focus point at all. Once I move it down a little bit, everything starts working again. Just to elaborate, the problems are happening once the cameraBuff point become perpendicular to the surface.

This is the code I use to rotate the cameraBuff vector/point around the focus:

//mouse.onDown* things are recorded once the mouse is initially pressed
theta = -((event.clientX - mouse.onDownPosition.x) * 0.5) + mouse.onDownTheta;
phi = ((event.clientY - mouse.onDownPosition.y) * 0.5) + mouse.onDownPhi;

phi = Math.min(180, Math.max(0, phi));

cameraBuff.x = radius * Math.sin(theta * Math.PI / 360 ) * Math.cos( phi * Math.PI / 360 );
cameraBuff.y = radius * Math.sin(phi * Math.PI / 360 );
cameraBuff.z = radius * Math.cos(theta * Math.PI / 360 ) * Math.cos( phi * Math.PI / 360 );

Once I change phi = Math.min(180, Math.max(0, phi));to phi = Math.min(160, Math.max(20, phi));, for example, things work, but I am not able to even get the camera to be perpendicular to the surface, or even lower it.

This is what happens when, for example, w is pressed:

if (input.w)
{
    var speed = [game.direction.x*60, game.direction.z*60];

    game.camera.position.x -= speed[0]; //camera.position and focus are basically the same point all the time.
    game.focus.x -= speed[0];

    game.camera.position.z -= speed[1];
    game.focus.z -= speed[1];
}

And the direction is calculated like this:

var c = Math.sqrt(cameraBuff.x*cameraBuff.x + cameraBuff.z*cameraBuff.z);
var rat = 1/c;

game.direction.x = cameraBuff.x*rat;
game.direction.z = cameraBuff.z*rat;

Can someone explain what is wrong with my code?

  • 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-04T16:48:49+00:00Added an answer on June 4, 2026 at 4:48 pm

    A 3D camera needs a vector so it knows how to tilt the camera. This is normally the up direction, and is a positive Y vector. If the camera is parallel to the up direction, it has no idea what is up, so it guesses, and you can’t tilt the camera. To let the camera tilt, you need to modify the up direction.

    I haven’t used Three.js, but I think you can use the camera.up vector.

    You may also get it to work by limiting angles to 0.1 < x < 179.9

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

Sidebar

Related Questions

suppose I have a simple container which have three element: <div> <span>hello world</span> <input
I have a simple solid modeling application in which I want to implement several
I have an OpenGL scene in which the user can rotate the camera. I
I have a simple three table reference. It looks plain enough. The associations there
I have a simple JavaScript file that has three jQuery $document.ready functions. All three
I have a simple object that allows you to assign three properties (x,y,z) (lets
I have a very simple Setup project that copies three dlls into the GAC.
I have a simple tree which takes the shape below ROOT /\ A B
I just want to do a simple animation (for example in C++ using OpenGL)
I'm pretty new to J2ME development scene. And for that matter, have just recently

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.