What is the axis typically designated for the near and far planes in perspective camera settings?

I recently completed a project and went through an informative tutorial on three.js. However, I found the explanation lacking when it came to creating the perspective camera.

In my project, I placed an object at the default location of (0,0,0) in the scene, and then moved the camera back by 10 units to ensure visibility. I specified a near plane of 0.1 and a far plane of 1000. Despite this setup, I am unsure about which axis these planes are oriented on. None of the default object's axes are greater than or equal to 0.1, as required by the near and far planes for visibility.

Can someone clarify why the object is still visible in the scene, shed light on the orientation of the near and far planes, or provide a comprehensive resource that explains this concept effectively?

For those interested, here's the code snippet:

import * as THREE from 'three';
import 'bootstrap';
import css from '../css/custom_css.css';

let scene = new THREE.Scene();

/* Constants */
let WIDTH = window.innerWidth;
let HEIGHT = window.innerHeight;

/* Camera */
let field_of_view = 75;
let aspect_ratio = WIDTH / HEIGHT;
let near_plane = 0.1;
let far_plane = 1000;
let camera = new THREE.PerspectiveCamera(field_of_view, aspect_ratio, near_plane, far_plane);
// Setting initial object position at ( 0, 0, 0 ) and moving camera back slightly
camera.position.set( 0, 0, 10 );

/* Renderer */
let renderer = new THREE.WebGLRenderer({ antialias: true, canvas: my_canvas });
renderer.setSize(WIDTH, HEIGHT);
renderer.setClearColor(0xE8E2DD, 1);

// Create the shape
let geometry = new THREE.BoxGeometry(1, 1, 1);
// Defining material with color and wireframe properties
let material = new THREE.MeshBasicMaterial({
    color: 0xFF0000,
    wireframe: true
});

// Cube creation
let cube = new THREE.Mesh(geometry, material);
scene.add(cube);

// Game Logic - rotating the cube
let update = function(){
    cube.rotation.x += 0.01;
    cube.rotation.y += 0.005;
};

// Render Scene
let render = function(){
  renderer.render(scene, camera);
};

// Running the game loop for updating and rendering continuously
let gameLoop = function(){
    requestAnimationFrame(gameLoop);

    update();
    render();
};

gameLoop();

Answer №1

When working with a perspective camera, it's important to remember that the near and far planes are not aligned with the global scene axes; rather, they are relative to the camera itself.

In your specific scenario, the near plane is positioned 0.1 units from the camera along its central axis or "look" vector, while the far plane sits 1000 units away. Anything that you want rendered must fall within this range, creating what is known as the camera's "view frustum."

For instance, if your camera is focused on an object located 10 units away, it falls within the view frustum and will be visible in the render. To get a better visual understanding of this concept, check out this youtube video: https://www.youtube.com/watch?v=KyTaxN2XUyQ

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

What could be the reason for PassportJS in Node failing to clear the session upon logout?

I am encountering an issue with my system not successfully logging out using PassportJS. The logout route appears to be triggered, but the session is not being removed as intended. I would like it to return a 401 error if the user is not logged in on a spe ...

Creating an Object with Quoted Key in JavaScript/Typescript for MongoDB's '$push' Feature

Struggling to format the data in order to add an element into a nested array within MongoDB. Currently attempting this in TypeScript: var data = {$push:{"foo.12.bar":{ prop1: prop1, prop2: prop2, // referenced values above this code snippet ...

Utilizing consistent form elements throughout various tabs

I'm working on an HTML project where I need to replicate form elements across different tabs with each tab having unique values. To achieve this, I found a helpful resource at . Here is what I've attempted: <html> <link rel="stylesheet" ...

The jQuery .load() method fails to retrieve a valid value from @Url.Action

Being new to MVC, I need a simple and specific explanation. I am trying to open a modal dialog using jQuery but @Url.Action is returning a null value. If I hardcode the path instead, it works fine. Here's the code snippet below. Script: <script t ...

There are no HTTP methods being exported in this specific file. Remember to export a named export for each individual HTTP method

Currently, I am working on a React.js/Next.js project that incorporates Google reCAPTCHA. The frontend appears to be functioning properly as I have implemented print statements throughout the code. However, I am encountering an error in the backend display ...

Trouble with Bootstrap scrollspy upon resizing the browser dimensions

Welcome to all you talented Stackoverflow bootstrappers! I have a burning question that I believe has not yet been asked, and I am eager to discover the solution. Let me walk you through how to replicate this bug: First, navigate to the following page: ...

Looking for a solution to fix the VueJS calculator that only works once?

My calculator project using VueJS, HTML and CSS is almost complete. However, I'm facing an issue where it only works once. For example, if I input 6x3, it correctly gives me 18. But if I then clear the result and try to input a new calculation like 3 ...

What is the best way to reset an HTML file input using JavaScript?

Looking for a way to reset the file input in my form. I've tried setting the sources to the same method, but it doesn't delete the selected file path. Important: Trying to find a solution without having to reload the page, reset the form, or us ...

Learn the technique of storing a sequence of functions within a variable using jQuery

For instance, I am looking to assign a sequential process to multiple variables and utilize them in various scenarios. var disable_btn = true; var button_me = $('#contents.getsamplekit .sample-form .form #submit-btn-freeSample-me'); var button_d ...

The event handler is not defined and is failing to recognize in the React context

Currently, as I delve into the realm of learning React, I find myself facing a perplexing issue regarding the mysterious undefined state of this event handler. Why is it behaving in such an enigmatic manner? const Login = () => { handleSubmit = (e) ...

What is the best way to transfer attribute values from multiple elements and paste them each into a separate element?

I have multiple elements with the tag <a class="banner2">. Each of these elements has a different URL for the background image and href value. <a href="#" target="_blank" class="banner2" style="background-image:url('<?php echo get_templat ...

When organizing data, the key value pair automatically sorts information according to the specified key

I have created a key value pair in Angular. The key represents the questionId and the value is the baseQuestion. The baseQuestion value may be null. One issue I am facing is that after insertion, the key value pairs are automatically sorted in ascending ...

issue related to prototypejs event handlers and event triggering

Currently, I am in the process of learning both the prototype framework and javascript as a whole. My current task involves refactoring some existing code to generate HTML from data within a class by utilizing an event listener. Despite my efforts, I am en ...

JavaScript decimal validation not functioning as intended

Hey everyone! I've created a script that restricts textboxes to allow only decimal numbers. Take a look at the code snippet below: function onlyDecimal(evt) { if (!(evt.keyCode == 46 || (evt.keyCode >= 48 && evt.keyCode <= 57))) ...

The spacebar is not functioning properly within a `button` element while using HTML5 `contenteditable`. What steps can I take to fix this issue and get it working correctly?

When using the HTML5 contenteditable attribute, I've noticed that the spacebar does not work in the button element, but it works perfectly fine in the div element. Does anyone have a solution to get it working properly? You can see the issue here: ht ...

Navigating Through Secondary Navigation with Ease

In my React project, I am developing a mega-menu styled dropdown navigation. As a functional component, I am utilizing the useState hook to manage the state and control the display of sub-navigation items. The functionality of the dropdown is operational, ...

jQuery has already been submitted compared to currently being submitted

I am currently developing a jQuery function that sends form data to a page without interrupting the usual submission process. I have been successful in accomplishing this by capturing the submit action with .submit(), but now I need to find a way for jQuer ...

I'm encountering some issues trying to install next-auth in my project built with Next.js and React

I recently set up my Next.js project with React using yarn create next-app. However, I am facing an issue as the next-auth package is not installed in my project. Currently, my node version is LTS 16.15.1, yarn version is 1.22.18, and npm version is 8.9. ...

How can a CSS class be used to toggle the visibility of a DIV element with JavaScript?

I've been researching and came across several scripts that allow for toggling the contents of a DIV by clicking on a button, however, they all use IDs. What I am looking to achieve is similar but using classes instead of IDs. This way, if I want to h ...

The appearance of the image is distorted once it is inserted into the carousel

I am currently working on a carousel that contains 5 images with varying heights and widths. However, I am experiencing some issues with the way the images are displayed - some are stretched while others are centered within the carousel. My goal is to ens ...