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

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

The Archive Base Latest Questions

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

I’m writing a simple JavaScript 3D engine from scratch using Canvas and box like

  • 0

I’m writing a simple JavaScript 3D engine from scratch using Canvas and box like primitives (à la Minecraft) for the hell of it. I’m implementing as much optimizations as I can and so far I have back face culling and hidden face occlusion, but I can’t figure out how to do frustum culling the optimal way.

I’ve tried 2D culling, but that has one specific problem I can’t solve: if a single vertex of a 4 point plane goes is behind the camera it is still drawn but completely distorted (x and y coordinates are reversed I think) – see image.

I’m beginning to think this hasn’t got a real solution without using much more complicated math and rendering sequences.

At first everything's ok

enter image description here

I’ve tried to limit the vertices x and y coordinates inside the 2D screen as long as at least one of the 4 vertices is still inside the screen (see below), but that completely distorts the square face (although I guess I can go with more fancy math and additional triangles).

enter image description here

I have some experience in OpenGL and it renders stuff completely differently so this isn’t even a problem there.

Do I have any chance of fixing it without pulling my hair?


Solution

The final solution was to test each of the 8 vertices against the near clipping plane in 3D before doing 2D projection and then screen clipping.

This is the second clipping step, the first one is to test if the box is completely behind the clipping plane using bounding sphere of radius sqrt(3/2)*boxSideLength.

Additional triangles (actually points in this case) was way too complicated and math intensive, this solution isn’t perfect but quite pretty.

  • 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-25T20:47:35+00:00Added an answer on May 25, 2026 at 8:47 pm

    You can’t project a 3d point that is behind your camera into 2d screen space and have it make any sense. so you’ll need to define atleast a near plane to clip to. After you transform the points from world space into camera space, but before you project to screen space, you’ll need up do some clipping. You’ll want to define a near plane, something like z = 1 or something close to but in front of the camera and will define a space where points are capable of being projected into screen space.

    You have three options, the first is if any point in the polygon falls behind the near plane, then don’t draw the entire polygon. This is simple but usually unacceptable. Compare each point against the near plane (if polygon.points[i].z < near.z). But this will make polygons disappear and reappear seemingly randomly at the edges of the screen.

    Your second option is to clip your polygon to the near plane. For triangles if all three points are behind the near plane then don’t draw. If two points are behind then clip the two line segments to the near plane and draw the triangle. If one point is behind the near plane, then clip and make two new triangles and draw. If none are behind the near plane then just draw. If I wasn’t posting this from my phone I would go into more detail, but hopefully that makes sense.

    Lastly you can do full fustrum clipping and instead of just clipping to your near plane, clip for all 6 sides of your visible frustum.

    There are optimization algorithms for each of these approaches but I would start with the basics and work forward. Each step is basically an extension of the last so I would start by going with the first and then getting more complicated, until you get the visual and performance levels you are looking for.

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

Sidebar

Related Questions

For some reason, after submitting a string like this Jack’s Spindle from a text
I'm making a simple page using Google Maps API 3. My first. One marker
link Im having trouble converting the html entites into html characters, (&# 8217;) i
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
I used javascript for loading a picture on my website depending on which small
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I've got a string that has curly quotes in it. I'd like to replace
Seemingly simple, but I cannot find anything relevant on the web. What is the
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... 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.