Adjust the camera position in React-VR while swapping out the PanoPopMatrix

I'm new to react-vr and I am working on developing a tour app. My issue is that when I update the Pano pictures, the camera/scene remains in the same position as before loading the new picture.

Below is a snippet of the code:

 render() {
if (!this.state.data) {
  return null;
}

const locationId = this.state.locationId;
const isLoading = this.state.nextLocationId !== this.state.locationId;

return (

    <View>
      <Pano
        style={{
          position: 'absolute'
           }}
        onLoad={() => {
          this.setState({
          locationId: this.state.nextLocationId
          });
        }}
        source={asset(this.state.data.photos360[this.state.nextLocationId].uri)}
      />

      {tooltips && tooltips.map((tooltip, index) => {
        return(
          <NavButton
            key={index}
            isLoading={isLoading}
            onInput={() => {
                    this.setState({
                        nextLocationId: tooltip.linkedPhoto360Id});
            }}
            source={asset(this.state.data.nav_icon)}
            textLabel={tooltip.text}
            rotateY={(tooltip.rotationY && tooltip.rotationY) || 0}
            rotateX={(tooltip.rotationX && tooltip.rotationX) || 0}
            translateZ={(tooltip.translateZ && tooltip.translateZ) || this.translateZ}
          />
        );
      })}
    </View>

);}

My challenge now is how to set the camera position or transform the picture so that it starts at a specific point on the image.

I have not been able to find a way to retrieve the current camera position or set the camera position in react-vr.

Any suggestions on the best approach to tackle this?
Thank you for your assistance

Answer №1

After coming up with a solution, I decided to share it here in case others encounter a similar issue.

render() {
// When the pano source changes, this function will render
// It calculates the position in degrees along the x and y axis using VrHeadModel
const rotationY = VrHeadModel.yawPitchRoll()[1] + offestY;
const rotationX = VrHeadModel.yawPitchRoll()[0] + offsetX;

return (
  <Pano
        style={{
          position: 'absolute',
            transform:[
             {rotateY: rotationY},
             {rotateX: rotationX},
             ]
        }}
        source={asset("photo.png")}
   />
 );
}

To implement this functionality, make sure to import VrHeadModel from react-vr.
This code ensures that when the pano changes, the new picture will rotate to align with the camera's current position. This maintains consistency when loading new images on the pano surface.

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

Error: The function sessions.map cannot be performed

Recently started my journey with Nodejs and I'm following a course on pluralsight to learn more. I encountered an issue while working on the code provided in the course, and now I'm stuck at this point. Error : > TypeError: C:\Users&bsol ...

Filtering tables in Angular 6 using checkbox options

I have a functional code snippet that filters a table using checkboxes. However, I am facing an issue when unchecking a checkbox. It does not return the original array as expected. .html <ng-container *ngFor="let group of groups"> <label cla ...

The operand n used in this context is not valid

I tried implementing the example from the Backbone manual, but it doesn't seem to be working as expected. var View = Backbone.View.extend({ tagName: 'li' }); var ex_view = new View(); console.log(ex_view.el); This code snippet throws ...

Personalized HTML ProgressBar featuring indicators

As I explore options for creating a progress bar/timeline with the ability to add markings (white lines shown in the image below) upon clicking a button, I've looked into HTML5 canvas and custom jQuery solutions. I'm curious if anyone has any spe ...

Tips for automatically checking a form's accuracy before moving to the next stage in a multi-step form with zod and react-hook-form

In my application, there is a multi-step form. Currently, if a user skips some steps and tries to submit the form, it won't go through because they missed non-optional fields. The error messages appear at the previous steps, leaving the user unaware t ...

Is it possible to load modal content using ajax bootstrap pagination without having to refresh the main page?

Whenever I utilize the bootstrap modal and pagination for modal content, clicking the next/prev button causes the entire page, including the main window, to reload. Here are the scripting lines: $("#ajax_process_page").html("<%= escape_javascript(rend ...

Creating Awesome Icons in Kendo Grid with Code In this tutorial, we will learn how to programm

Looking to have a Kendo grid display a green fas-fa-clock icon if isActive is true, and a grey far-fa-clock icon if false. Clicking on the icon should toggle between true and false. Currently, the grid just shows the word true or false in the column. Cod ...

Close dynamic overlay modal when client-side validation fails during submission

When a user clicks on the "Apply" button after opening a "confirm" modal, client-side validation checks all fields. However, in case of failure, the modal does not close and I am struggling to find a solution. I attempted to use an event handler on the su ...

Utilizing numerous X-axis data points in highcharts

I'm working with a line graph that dips straight down, like starting at (1, 100) and dropping to (1,0). The issue I'm facing is that Highcharts (https://www.highcharts.com/) only displays information for one of the points. Is there a way to make ...

Is it possible to make the info box centered and adjust everything to seamlessly fit on all screen sizes?

Is there a way to create a centered info box that stretches to fit any screen size? ...

Generating landscapes through block-based procedural methods

I'm currently utilizing three.js to generate terrain procedurally using Perlin Noise. My terrain is composed of blocks, but the heights along their borders do not match up, as evidenced below. What is the best approach for aligning height maps acros ...

Does utilizing this.someFunction.bind(this) serve a purpose or is it duplicative

As I analyze someone's code, I stumbled upon the following snippet: this.device_name.changes().onValue(this.changeName.bind(this)) My interpretation so far is that onValue requires a callback function, which in this case is this.changeName.bind(this ...

Simply interested in extracting the JSON Class specifically, not all of the data

Looking for a way to extract only text from a specific class using $.getJSON and YQL. Currently, it retrieves all data and removes tags. Is there a method to achieve this? function filterData(data){ // remove unwanted elements // no body tags ...

The value of the view variable in AngularJS remains stagnant and does not update

Hello there, I am just starting to explore Angularjs. Here is the code snippet that I have been working on : .html file : <!DOCTYPE html> <html ng-app="showcase.angularWay.dataChange"> <head> <script src='js/jquery-1 ...

What is the best way to showcase just 5 photos while also incorporating a "load more" function with

Is there a way to display only 5 images from a list on the first load, and then show all images when the user clicks on "load more"? Here is the code I have: $('.photos-list').hide(); $('.photos-list').slice(1, 5).show(); $ ...

Sequencing asynchronous operations with node.js using sails.js

When setting up my Sails.js app, I have a series of tasks that need to be executed in order, with each task depending on the successful completion of the previous one. If any task encounters an error, the entire process should stop and prevent the app from ...

How can I display milliseconds from a date in Angular2+?

I recently encountered an issue while working with a custom pipe that was used to display time. I attempted to modify it so that it could also show milliseconds: {{log.LogDate|jsonDate|date:'dd.MM.yyyy &nbsp; HH:mm:ss.sss'}} Here is the cod ...

Can Cesium "separate" intersecting polylines?

Currently, I am utilizing Cesium and aiming to visually display multiple polylines between two entities. Specifically, I want a green polyline from entity A to entity B, as well as a blue polyline from entity A to entity B. My intention is for these lines ...

Creating dynamic visual representations of algorithms using JavaScript

I am currently exploring how to create animations for algorithms using JavaScript. I'm curious about the process of creating algorithm animations in other languages, such as Java. Is the animation aspect typically separate from the algorithm logic? Fo ...

Is the Angularjs Date formatting consistent across different browsers?

Below is the code I am working with: app.filter('myDateFormat',function myDateFormat($filter){ return function(text){ var tempdate= new Date(text.replace(/-/g,"/")); return $filter('date')(tempdate, "dd-MM-yyyy HH:m ...