Unable to determine the resolutions for all parameters in PointerLockControls

I recently delved into learning three.js and have been looking to integrate it with Angular framework. Everything seems to be running smoothly so far, except for the issue I'm facing with the PointerLockControls service.

It appears that I might be overlooking something crucial, but I can't pinpoint exactly what it is.

I've gone ahead and installed three.js via NPM just to cover all bases.

Below is the snippet of code I am currently tinkering with.
The app component is where most of the specialized logic resides.

import {Component, Inject, OnInit} from '@angular/core';
import * as THREE from 'three';
import {BufferGeometry, Material, Object3D, PerspectiveCamera, Scene, WebGLRenderer} from 'three';
import {WINDOW} from '@typescript/window-injection.token';
import {DOCUMENT} from '@angular/common';
import {PointerLockControls} from 'three/examples/jsm/controls/PointerLockControls';

export const STYLESHEETS_SRC: string = '../stylesheets/css/';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: [STYLESHEETS_SRC + 'app.component.min.css'],
  providers: [Scene, PerspectiveCamera, WebGLRenderer, PointerLockControls]
})
export class AppComponent implements OnInit {
  private sensitivity: number = .02;

  constructor(
    @Inject(DOCUMENT) private document: Document,
    @Inject(WINDOW) private window: Window,
    private scene: Scene = new THREE.Scene(),
    private camera: PerspectiveCamera = new THREE.PerspectiveCamera(),
    private renderer: WebGLRenderer = new THREE.WebGLRenderer(),
    private pointerLock: PointerLockControls
  ) {
    camera.fov = 75;
    camera.aspect = window.innerWidth / window.innerHeight;
    camera.near = .1;
    camera.far = 1000;
    camera.position.z = 5;

    renderer.setSize(window.innerWidth, window.innerHeight);
    document.body.appendChild(renderer.domElement);

    renderer.domElement.addEventListener('mousemove', event => {
      if (event.button == 0) {
        camera.position.y -= event.movementY * this.sensitivity;
        camera.position.x += event.movementX * this.sensitivity;
      } else if (event.button == 2) {
        camera.quaternion.y -= event.movementX * this.sensitivity / 10;
        camera.quaternion.x += event.movementY * this.sensitivity / 10;
      }
    });

    this.pointerLock = new PointerLockControls(camera, renderer.domElement);
    pointerLock.lock();

    scene.add(new THREE.AxesHelper(5));
  }

  ngOnInit() {
    let geometry: BufferGeometry = new THREE.BoxGeometry(1, 1, 1);
    let material: Material = new THREE.MeshBasicMaterial({color: 0x00ff00});
    let cube: Object3D = new THREE.Mesh(geometry, material);
    this.scene.add(cube);

    let animate = () => {
      requestAnimationFrame(animate);

      cube.rotation.x += 0.01;
      cube.rotation.y += 0.01;

      this.renderer.render(this.scene, this.camera);
    };

    animate();
  }
}

If you have any insights or solutions, please share them!
If there are any details missing, feel free to point them out so I can update this post promptly.

Answer №1

Your component is generated using the concept of Dependency injection.

PointerLockControls cannot be included in the constructor. You will have to create an instance yourself.

An example would be:

const controls = new PointerLockControls( camera, document.body );

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

Creating a task list using arrays and functions

I am working on developing a to-do list using an array in JavaScript, where the functions are separated from the HTML code. I have managed to set up the HTML structure, but I am facing challenges in completing the necessary functions. Fortunately, the Even ...

Guide to retrieving data from a URL and storing it in a string variable with JavaScript

Attempting to retrieve the JSON data from a specific URL and store it in a variable. The code snippet below successfully loads the JSON into a div element: $("#siteloader").html('<object data="MYURL">'); However, the goal is to extract t ...

Is it possible for me to verify the login status of an Auth0 user within my custom NextJS _app.js file?

Currently working on a NextJS application with nextjs-auth0 for authentication, which is completely new to me. I followed the documentation's suggestion and wrapped my _app.js with UserProvider, also using getInitialProps to set a global online/offlin ...

Dialogue box closes automatically within a dropdown menu

I am using shadcn in my next.js 13 project and I want to implement a dropdown feature that allows users to edit or delete an entry. However, when the user clicks on "delete", the dialog pops up for only about 0.5 seconds before closing along with the dropd ...

Transferring data from controller to repository in Laravel: a step-by-step guide

Looking for some assistance here! I need to pass an ID to my repository but keep getting the error message illegal offstring id. Any help is appreciated! Here's my controller: public function delete() { $response = ['status' => false ...

Generating varying commitments from one function

I have encountered an issue where I am returning a promise from a function that is part of a $q.all array. Initially, this setup works perfectly on page load. However, the challenge arises when I need to call this function multiple times afterward to updat ...

Preventing the dispatch function from being overwritten by an empty state

Scenario: I am currently exploring the concept of React/Redux and aiming to understand the data flow. The process involves axios dispatching actions -> reducers setting state to props -> Component rendering. As a newcomer to the Frontend world, ...

Using nightwatch.js to verify elements across different parts of a webpage

Currently engaged in working with nightwatch.js and encountering an issue with a particular page file structure: sections: { table: { selector: '.sr-filterable-data-layout--collection', elements: { header: { ...

Using Javascript to automate the organization of links based on predefined criteria is an

Picture This: A digital library full of categorized links, totaling 1000 in number. Diverse themes are covered by these links, making it a treasure trove of information. Displayed prominently at the top are buttons labeled ALL, MOBILE, CARS, BOOKS, and TE ...

Determining the position and offset of an element

Currently, I am facing a dilemma with my table of images. I want to add an icon to the corner of each image so that they align perfectly. I attempted to achieve this using relative CSS positioning, but it resulted in the icons extending beyond the cells an ...

Unable to retrieve data in Node Express after querying completion

I created a basic custom module that is intended to return database records from its methods. After executing a query, I can retrieve all the records but when attempting to assign them to a variable, it shows as null. I'm unsure of what's causin ...

Identifying the completion of scrolling within a container

I'm facing a challenge with my dynamic website that has numerous blog posts. My goal is to initially load only four posts and then add another four as the user scrolls to the end of the page. While I have figured out how to handle this on the backend, ...

What steps should I take to enable TypeScript IntelliSense to recommend correct suggestions within discriminated unions?

I am working on creating a checkbox UI component based on a design in Figma. The outline variant is specified to only be compatible with the large size, while the solid variant can be used with all sizes. As a result, I am trying to build an interface whe ...

Delivering emails with attachments using Angular 8

I've been attempting to send an email with an attachment using Angular 8. Here's the code I've tried: <a href="mailto:<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="51283e2423343c30383d11343c30383d7f323e3c"&g ...

What is the best way to manage the "checked" state of an input checkbox using React?

I'm currently developing an application that features a form with radio buttons. One of the radio button options can be toggled on/off using a checkbox, but I want to ensure that the checkbox is disabled if the corresponding radio button is not selec ...

Trouble With OnClick and On/Off Class Script Functionality in Chrome and Internet Explorer

I am working on a page with two iframes and a basic navigation bar. The navigation bar links are set up to target one of the iframes and replace its content when clicked. However, I am having trouble highlighting the currently selected link in the iframe - ...

Tips for showcasing images and videos in a full-screen mode resembling the TIKTOK APP through the use of Angular, Ionic 4, and Capacitor

Currently, I am diving into the world of Angular Ionic 4 with Capacitor. My goal is to create a feature that allows images and videos to be displayed in full screen, similar to how it works in the TikTok app. If anyone has experience with this functional ...

Displaying data using JSON on a fabric.js canvas

I've been encountering some issues while attempting to store data in JSON and then reload it onto the canvas using fabric.js. My code is quite simple: canvas.add(new fabric.Rect({ width: 50, height: 50, fill: 'red', top: 100, left: 100 })); ...

Adjust the button's hue upon clicking it

The current function is operational. Upon pressing the button, it toggles between displaying "click me" and "click me again". However, I desire the button to appear blue when showing "click me" and red when displaying "click me again". <!DOCTYPE html ...