Is there a way to determine my position in the cycle of WebGL/THREE radians that range from 0 to 1.57, then back to 0, and down to -1.57?

Hey, I've noticed that the radians seem to fluctuate when looking at a camera and trying to animate a flyover. I'm getting repetitive numbers when the camera rotates more than 90 degrees on either side. What could I be overlooking?

function calculateCameraDirection(camera){
  radian = camera.rotation.y;
  console.log(camera.rotation);
  console.log(radian);
  var xCoord = Math.sin(radian);
  var zCoord = Math.cos(radian);
  return new THREE.Vector3(xCoord, 0, zCoord); 
}

var camMovingDirection = calculateCameraDirection(ctx.camera);        
ctx.camera.position.z += 10 * camMovingDirection.z;
ctx.camera.position.x += 10 * camMovingDirection.x;

Answer №1

To determine the camera's viewpoint, use the following method:

var viewDirection = new THREE.Vector3(); // initialize once

...

camera.getWorldDirection( viewDirection );

If you simply need to move the camera forward, you can achieve this as follows:

camera.translateZ( -10 ); // moving forward means along the negative-z axis in camera space

Using three.js version r.71

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Top method for independently scrolling overlapping elements in both the x and y directions

Sorry if this is repeating information. I have a structure of nested divs like this: -container -row In order to enable scrolling without the default scrollbar appearing, each container and row has an additional container. My goal is to be able to scrol ...

"Adding properties to objects in a map: a step-by-step guide

During my attempt to add a property within a map loop, I noticed that the update appeared to occur on a duplicate rather than the original object. MY_ARRAY.map(function(d){ d.size = DO_SOMETHING }); ...

Guide on dynamically setting values for two indexes in ng-options using Angular.js

Can someone help me with this issue? I am trying to use two indexes ($index, $parent.$index) in the ng-options object with Angular.js. Below is my code explanation. <tr ng-repeat="d in days"> <td>{{d.day_name}}</td> <t ...

Tips on saving wavefront .obj models in mongodb

I need to save 3D models in .obj format into a MongoDB database. Would it be better to convert them to binary before storing? Any advice on how to tackle this situation would be highly valued. Thank you! ...

Is there a way to use JavaScript to modify the position of a div element

Can we adjust the div position using CSS (absolute or relative) with JavaScript? Here's an example code snippet: <div id="podpis" style="margin-top: 2rem;"> <div class="invoice-signature"> <span><?=$xml->sanitiz ...

Tips for managing asynchronous code that invokes other asynchronous code in AngularJs

My factory utilizes indexedDB and a method called getRecipe that relies on this indexed db to fetch data. The issue arises because indexedDB returns its instance in an asynchronous call, and getRecipe is another method that also returns its value asynchro ...

Unable to successfully cancel requestAnimationRequest in a React component when using hooks

I'm currently working on a progress bar project where I aim to halt the animation (using cancelAnimationRequest) once it reaches a specific value (10, 100, ... N) and reset it back to 0. Unfortunately, in my existing code, although it resets to 0, th ...

Utilizing JavaScript to verify the presence of a div element within dynamically injected HTML code

While working on a website, I have implemented an embed function which involves calling a javascript from my server to inject HTML on another remote server. To ensure that these embeds also benefit from Google ranking, I have included a piece of HTML in t ...

Efficiently Managing and Recording Complex JavaScript Projects Across Multiple Files

Embarking on a sizable JavaScript project, I've decided to organize everything within one or more namespaces to limit the use of global scope. Currently, only one element exists in the global scope. To maintain organization, I prefer keeping each cla ...

Is there a way to access and troubleshoot the complete source code within .vue files?

I've been struggling for hours trying to understand why I'm unable to view the full source of my .vue files in the Chrome debugger. When I click on webpack://, I can see the files listed there like they are in my project tree, but when I try to o ...

Adjust the transparency and add animation effects using React JS

When working on a React project, I encountered an issue where a square would appear under a paragraph when hovered over and disappear when no longer hovered. However, the transition was too abrupt for my liking, so I decided to implement a smoother change ...

Keep a close eye on your Vue app to make sure it's

<template> <v-form :model='agency'> <v-layout row wrap> <v-flex xs12 sm12 lg12 > <v-layout row wrap> <v-flex xs12 md12 class="add-col-padding-right"> <v-radio-group v-mod ...

Tips for successfully passing an object as a prop in nextjs

Struggling to understand how to pass an object as a prop using useState in Next JS. My javascript functions include a lorem ipsum generator, housed in a component called Paragraphs. This component requires two properties: Number of paragraphs Sentence le ...

The webpage becomes unresponsive due to an Ajax request

Creating a generic way to call ajax requests on my webpage has been challenging. I've developed an extension method for calling post requests asynchronously. $.tiqPost = function(action,data,callback) { alert('Posting...'); $.fancyb ...

What is the best way to modify the text color within a Navbar, especially when the Navbar is displayed within a separate component?

First question on StackOverflow. I have a Next App and the Navbar is being imported in the _app.js file. import Navbar from "../Components/Navbar"; function MyApp({ Component, pageProps }) { return ( <> <Navbar /> ...

Why is my console showing a SyntaxError with JSON.parse and an unexpected character?

I am facing an issue. When I attempt to call a PHP page for some data with specific requested parameters using AJAX asynchronous call, I encounter the following error: SyntaxError: JSON.parse: unexpected character var jsonData = $.ajax({ u ...

Is it possible to upload files without using AJAX and instead through synchronous drag-and-drop functionality in the foreground?

Currently, my website has a standard <input type="file"> file upload feature that sends data to the backend upon form submission. I am looking to enhance the functionality of the form by allowing users to drag and drop files from anywhere within the ...

Changing the time zone of a browser using JavaScript or jQuery

After researching numerous discussions on the topic, it appears that changing the browser's timezone programmatically is not possible. Although the moment-timezone.js library allows us to set timezone for its objects, it does not affect the browser&ap ...

Checkbox input with alphabetical ordering

I am currently facing an issue with a form that has checkboxes, but the text is not in alphabetical order. While there are plenty of examples for lists, finding examples for checkboxes has been challenging. http://jsfiddle.net/fG9qm/ <form> < ...

What is the best way to utilize the .done() callback in order to execute a function when new data is loaded upon request?

I have a web page that pulls data from a JSON feed, and there's also a button to load more content from the feed when clicked. I want to add additional elements inside the page for each item in the feed. I've managed to create a function that doe ...