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

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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T16:05:47+00:00 2026-05-25T16:05:47+00:00

I’m working on a JavaScript/Canvas 3D FPS-like engine and desperately need a normal vector

  • 0

I’m working on a JavaScript/Canvas 3D FPS-like engine and desperately need a normal vector (or look-at vector if you will) for near and far plane clipping. I have the x and y axis rotation angles and am able to do it easily with only one of them at the time, but I just can’t figure out how to get both of them…

The idea is to use this vector it to calculate a point in front of the camera, the near and far clipping planes must also be definable by constants so the vector has to be normalized, I hoped that with only the angles it would be possible to get this vector length to 1 without normalizing, but that’s not the problem.

I don’t have any roll (rotation around z axis) so it’s that much easier.

My math looks like this:

zNear = 200; // near plane at an arbitrary 200 "points" away from camera position

// normal calculated with only y rotation angle (vertical axis)
normal = {
    x: Math.sin(rotation.y),
    y: 0,
    z: Math.cos(rotation.y)};

Then clip a point in 3D space by testing the vector from the plane to it by means of a dot product.

nearPlane = {
    x: position.x+normal.x*zNear,
    y: position.y+normal.y*zNear,
    z: position.z+normal.z*zNear};

// test a point at x, y, z against the near clipping plane
if(
    (nearPlane.x-x)*normal.x+
    (nearPlane.y-y)*normal.y+
    (nearPlane.z-z)*normal.z < 0
)
{
    return;
}

// then project the 3D point to screen

When a point is behind the player its projection coordinates are reversed (x=-x, y=-y) so nothing makes sense any more, that’s why I’m trying to remove them.

enter image description here

I want that green arrow there, but in 3D.

  • 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-05-25T16:05:47+00:00Added an answer on May 25, 2026 at 4:05 pm

    After some intensive brain processing I figured out that

    1. My original look-at vector was (0, 0, 1)
    2. The z-rotation angle (roll) was always 0
    3. There was no reason for the rotation matrix found on Wikipedia not to work

    By applying the full rotation matrix on the (0, 0, 1) vector and taking in account that rz = 0 the solution I got was:

    normal = {
        x: Math.cos(camera.rotation.x)*Math.sin(camera.rotation.y),
        y: -Math.sin(camera.rotation.x),
        z: Math.cos(camera.rotation.y)*Math.cos(camera.rotation.x)};
    

    And now everything works perfectly. The error was using only the x and y rotation matrices without taking in account rz = 0 for all angles which changed the matrix a little.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I used javascript for loading a picture on my website depending on which small
I've got a string that has curly quotes in it. I'd like to replace
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have some data like this: 1 2 3 4 5 9 2 6
I need to clean up various Word 'smart' characters in user input, including but
Is it possible to replace javascript w/ HTML if JavaScript is not enabled on
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and

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.